Skip to content

Commit c659af3

Browse files
committed
Starting out writing features for rboard. Fixed endless subscriptions index page redirection
1 parent 475be9c commit c659af3

37 files changed

+1356
-14
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "vendor/plugins/cucumber"]
2+
path = vendor/plugins/cucumber
3+
url = git://github.com/aslakhellesoy/cucumber.git

app/controllers/subscriptions_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
class SubscriptionsController < ApplicationController
22
before_filter :find_topic, :only => [:create]
33
before_filter :login_required
4-
before_filter :store_location, :only => [:index]
54
before_filter :can_not_subscribe?
5+
before_filter :store_location, :only => [:index]
66

77
def index
88
@subscriptions = current_user.subscriptions.all(:joins => :topic, :order => "updated_at DESC")

app/models/post.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Post < ActiveRecord::Base
1515
validates_length_of :text, :minimum => 4
1616
validates_presence_of :text
1717

18-
unless THINKING_SPHINX
18+
unless SEARCHING
1919
define_index do
2020
indexes text
2121
set_property :delta => true

app/models/topic.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Topic < ActiveRecord::Base
3333
after_create :increment_counters
3434
before_destroy :decrement_counters
3535

36-
unless THINKING_SPHINX
36+
unless SEARCHING
3737
define_index do
3838
indexes subject
3939
end

app/views/layouts/application.html.erb

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
<%= link_to t(:Edit_Profile), [:edit, current_user] %> |
3131
<%= link_to t(:Member_List), users_path %> |
3232
<%= link_to t(:x_new_messages, :count => @current_user.unread_messages.size), messages_path %> |
33-
<%= link_to t(:Subscriptions), subscriptions_path %> |
33+
<% if current_user.can?(:subscribe) %>
34+
<%= link_to t(:Subscriptions), subscriptions_path %> |
35+
<% end %>
3436
<%= link_to t(:Logout), logout_path %>
3537
<% end %>
3638
</div>

app/views/topics/_form.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<% fields_for @post do |post| %>
88
<tr>
9-
<td valign='top'><%= f.label 'text', t(:Text) %></td>
9+
<td valign='top'><%= post.label 'text', t(:Text) %></td>
1010
<td><%= post.text_area "text", :cols => "80" %></td>
1111
</tr>
1212
<% end %>

config/environment.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
if File.readlines(database).empty?
1414
raise "Your database.yml file is empty. Please add your database information."
1515
end
16-
Rails::Initializer.run do |config|
16+
CONFIG = Rails::Initializer.run do |config|
1717

1818
config.gem 'chronic'
1919
config.gem 'RedCloth'
@@ -49,7 +49,7 @@
4949
STANDALONE = true
5050

5151
## Set this to false if you don't want to use thinking sphinx.
52-
THINKING_SPHINX = true
52+
SEARCHING = true
5353

5454
# Change this if your locale is not english
5555
# I18n.default_locale = "en"

config/environments/cucumber.rb

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
config.cache_classes = true # This must be true for Cucumber to operate correctly!
2+
3+
# Log error messages when you accidentally call methods on nil.
4+
config.whiny_nils = true
5+
6+
# Show full error reports and disable caching
7+
config.action_controller.consider_all_requests_local = true
8+
config.action_controller.perform_caching = false
9+
10+
# Disable request forgery protection in test environment
11+
config.action_controller.allow_forgery_protection = false
12+
13+
# Tell Action Mailer not to deliver emails to the real world.
14+
# The :test delivery method accumulates sent emails in the
15+
# ActionMailer::Base.deliveries array.
16+
config.action_mailer.delivery_method = :test

features/forums.feature

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Feature: Manage forums
2+
In order to restrict people to the right forums
3+
Administrators
4+
want to ensure people are shown only the right forums
5+
6+
Scenario: Viewing forums index
7+
Given I am on the forums page
8+
Then I should see "Public Forum"
9+
10+
Scenario: Viewing the public forum
11+
Given I am on the forums page
12+
When I follow "Public Forum"
13+
Then I should see "Viewing forum: Public Forum"
14+
15+
Scenario: Registered users should be able to post new topics
16+
Given I am logged in as "registered_user"
17+
And I am on the forums page
18+
When I follow "Public Forum"
19+
When I follow "New Topic"
20+
When I fill in "subject" with "Tribute"
21+
When I fill in "Text" with "This is just a tribute"
22+
When I press "Create"
23+
Then I should see "rBoard -> Public Forum -> Tribute"
24+
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Given /^I am logged in as "([^\"]*)"$/ do |user|
2+
Given "I am on the login page"
3+
When "I fill in \"login\" with \"#{user}\""
4+
When "I fill in \"password\" with \"password\""
5+
When "I press \"Login\""
6+
Then "I should see \"Logged in successfully.\""
7+
end

features/step_definitions/forums_steps.rb

Whitespace-only changes.
+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
2+
3+
# Commonly used webrat steps
4+
# http://github.com/brynary/webrat
5+
6+
Given /^I am on (.+)$/ do |page_name|
7+
visit path_to(page_name)
8+
end
9+
10+
When /^I go to (.+)$/ do |page_name|
11+
visit path_to(page_name)
12+
end
13+
14+
When /^I press "([^\"]*)"$/ do |button|
15+
click_button(button)
16+
end
17+
18+
When /^I follow "([^\"]*)"$/ do |link|
19+
click_link(link)
20+
end
21+
22+
When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
23+
fill_in(field, :with => value)
24+
end
25+
26+
When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
27+
select(value, :from => field)
28+
end
29+
30+
# Use this step in conjunction with Rail's datetime_select helper. For example:
31+
# When I select "December 25, 2008 10:00" as the date and time
32+
When /^I select "([^\"]*)" as the date and time$/ do |time|
33+
select_datetime(time)
34+
end
35+
36+
# Use this step when using multiple datetime_select helpers on a page or
37+
# you want to specify which datetime to select. Given the following view:
38+
# <%= f.label :preferred %><br />
39+
# <%= f.datetime_select :preferred %>
40+
# <%= f.label :alternative %><br />
41+
# <%= f.datetime_select :alternative %>
42+
# The following steps would fill out the form:
43+
# When I select "November 23, 2004 11:20" as the "Preferred" date and time
44+
# And I select "November 25, 2004 10:30" as the "Alternative" date and time
45+
When /^I select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
46+
select_datetime(datetime, :from => datetime_label)
47+
end
48+
49+
# Use this step in conjunction with Rail's time_select helper. For example:
50+
# When I select "2:20PM" as the time
51+
# Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
52+
# will convert the 2:20PM to 14:20 and then select it.
53+
When /^I select "([^\"]*)" as the time$/ do |time|
54+
select_time(time)
55+
end
56+
57+
# Use this step when using multiple time_select helpers on a page or you want to
58+
# specify the name of the time on the form. For example:
59+
# When I select "7:30AM" as the "Gym" time
60+
When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
61+
select_time(time, :from => time_label)
62+
end
63+
64+
# Use this step in conjunction with Rail's date_select helper. For example:
65+
# When I select "February 20, 1981" as the date
66+
When /^I select "([^\"]*)" as the date$/ do |date|
67+
select_date(date)
68+
end
69+
70+
# Use this step when using multiple date_select helpers on one page or
71+
# you want to specify the name of the date on the form. For example:
72+
# When I select "April 26, 1982" as the "Date of Birth" date
73+
When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
74+
select_date(date, :from => date_label)
75+
end
76+
77+
When /^I check "([^\"]*)"$/ do |field|
78+
check(field)
79+
end
80+
81+
When /^I uncheck "([^\"]*)"$/ do |field|
82+
uncheck(field)
83+
end
84+
85+
When /^I choose "([^\"]*)"$/ do |field|
86+
choose(field)
87+
end
88+
89+
When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
90+
attach_file(field, path)
91+
end
92+
93+
Then /^I should see "([^\"]*)"$/ do |text|
94+
response.should contain(text)
95+
end
96+
97+
Then /^I should not see "([^\"]*)"$/ do |text|
98+
response.should_not contain(text)
99+
end
100+
101+
Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
102+
field_labeled(field).value.should =~ /#{value}/
103+
end
104+
105+
Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
106+
field_labeled(field).value.should_not =~ /#{value}/
107+
end
108+
109+
Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
110+
field_labeled(label).should be_checked
111+
end
112+
113+
Then /^I should be on (.+)$/ do |page_name|
114+
URI.parse(current_url).path.should == path_to(page_name)
115+
end

features/subscriptions.feature

Whitespace-only changes.

features/support/blueprints.rb

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# I tried using Machinist.
2+
# It didn't work out so well.
3+
# It claimed named blueprints didn't exist... when they did!
4+
5+
class User < ActiveRecord::Base
6+
def self.make(name)
7+
opts = case name.to_s
8+
when 'anonymous'
9+
group = Group.find_by_name("anonymous") || Group.make(:anonymous)
10+
{ :login => "anonymous",
11+
:password => "password",
12+
:password_confirmation => "password",
13+
:email => "[email protected]",
14+
:groups => [group] }
15+
when 'administrator'
16+
{ :login => "administrator",
17+
:password => "password",
18+
:password_confirmation => "password",
19+
:email => "[email protected]"
20+
}
21+
when 'registered_user'
22+
group = Group.find_by_name("Registered Users") || Group.make(:registered_users)
23+
{ :login => "registered_user",
24+
:password => "password",
25+
:password_confirmation => "password",
26+
:email => "[email protected]",
27+
:groups => [group]
28+
}
29+
end
30+
puts "creating user with #{opts.inspect}"
31+
User.create!(opts)
32+
end
33+
end
34+
35+
class Group < ActiveRecord::Base
36+
def self.make(name)
37+
opts = case name.to_s
38+
when 'administrators'
39+
{ :name => "Administrators" }
40+
when 'anonymous'
41+
{ :name => "Anonymous",
42+
:owner => User.find_by_login("Administrator") || User.make(:administrator) }
43+
when 'registered_users'
44+
{ :name => "Registered Users",
45+
:owner => User.find_by_login("Administrator") || User.make(:administrator) }
46+
end
47+
Group.create!(opts)
48+
end
49+
end
50+
51+
class Permission < ActiveRecord::Base
52+
def self.make(name)
53+
opts = case name.to_s
54+
when 'anonymous'
55+
{ :can_see_forum => true,
56+
:group => Group.find_by_name("Anonymous") || Group.make(:anonymous)
57+
}
58+
when 'registered_users'
59+
{ :can_see_forum => true,
60+
:can_reply_to_topics => true,
61+
:can_start_new_topics => true,
62+
:group => Group.find_by_name("Registered Users") || Group.make(:registered_users)
63+
}
64+
end
65+
Permission.create!(opts)
66+
end
67+
end
68+
69+
class Forum < ActiveRecord::Base
70+
def self.make(name)
71+
opts = case name.to_s
72+
when 'public_forum'
73+
{ :title => "Public Forum",
74+
:description => "For all to see" }
75+
end
76+
Forum.create!(opts)
77+
end
78+
end
79+
80+
81+
82+
83+
84+
85+

features/support/env.rb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Sets up the Rails environment for Cucumber
2+
ENV["RAILS_ENV"] ||= "cucumber"
3+
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
4+
require 'cucumber/rails/world'
5+
require 'cucumber/formatter/unicode' # Comment out this line if you don't want Cucumber Unicode support
6+
Cucumber::Rails.use_transactional_fixtures
7+
Cucumber::Rails.bypass_rescue # Comment out this line if you want Rails own error handling
8+
# (e.g. rescue_action_in_public / rescue_responses / rescue_from)
9+
10+
require 'webrat'
11+
require 'features/support/setup'
12+
13+
Webrat.configure do |config|
14+
config.mode = :rails
15+
end
16+
17+
require 'cucumber/rails/rspec'
18+
require 'webrat/core/matchers'

features/support/paths.rb

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module NavigationHelpers
2+
# Maps a name to a path. Used by the
3+
#
4+
# When /^I go to (.+)$/ do |page_name|
5+
#
6+
# step definition in webrat_steps.rb
7+
#
8+
def path_to(page_name)
9+
case page_name
10+
11+
when /the homepage/
12+
'/'
13+
when /the forums page/
14+
forums_path
15+
when /login page/
16+
login_path
17+
18+
# Add more mappings here.
19+
# Here is a more fancy example:
20+
#
21+
# when /^(.*)'s profile page$/i
22+
# user_profile_path(User.find_by_login($1))
23+
24+
else
25+
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
26+
"Now, go and add a mapping in #{__FILE__}"
27+
end
28+
end
29+
end
30+
31+
World(NavigationHelpers)

features/support/setup.rb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require 'features/support/blueprints'
2+
Forum.delete_all
3+
Group.delete_all
4+
Permission.delete_all
5+
User.delete_all
6+
7+
# The anonymous user
8+
User.make(:anonymous)
9+
10+
# Set up the permissions
11+
# Also sets up admin user
12+
Permission.make(:registered_users)
13+
Permission.make(:anonymous)
14+
15+
# Create the user
16+
User.make(:registered_user)
17+
18+
Forum.make(:public_forum)

0 commit comments

Comments
 (0)