Skip to content

Commit

Permalink
Replace CalendarsController spec with Cucumber. [#54]
Browse files Browse the repository at this point in the history
  • Loading branch information
marnen committed Sep 23, 2011
1 parent 571e61c commit 659ea2f
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 131 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -73,7 +73,7 @@ def require_user
unless current_user
store_location
flash[:notice] = _("Please log in to view this page.")
redirect_to new_user_session_url
redirect_to login_url
return false
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/calendars/edit.html.haml
@@ -1,6 +1,6 @@
= form_for @current_object do |f|
%table.edit
%tr
%th&= _('Name')
%th= f.label :name, _('Name')
%td= f.text_field :name
= submit_tag(h(_('Save')))
19 changes: 16 additions & 3 deletions features/calendars/administer_calendars.feature
Expand Up @@ -8,7 +8,18 @@ Feature: Administer calendars
And I am subscribed to "Calendar 1"
And I am on the homepage
Then I should not see "Admin tools"


Scenario Outline: Non-admin users should not be able to get to calendar admin pages
Given I am logged in
And I am subscribed to "<calendar>"
When I go to the <page> for "<calendar>"
Then I should not be on the <page> for "<calendar>"

Examples:
| calendar | page |
| Calendar 1 | user list |
| Calendar 2 | calendar edit page |

Scenario: Admin users should see "Admin tools" link
Given I am logged in
And I am an admin of "Calendar 1"
Expand All @@ -30,7 +41,7 @@ Feature: Administer calendars
And I am an admin of "My calendar"
And I am on the admin page
When I follow "properties"
And I fill in "calendar[name]" with "New name"
And I fill in "Name" with "New name"
And I press "Save"
Then I should be on the admin page
And I should not see /My calendar\s*\(properties \| users\)/
Expand All @@ -39,6 +50,8 @@ Feature: Administer calendars
Scenario: Admin users should be able to see user lists for calendars they control
Given I am logged in
And I am an admin of "My calendar"
And "John Smith" is subscribed to "My calendar"
And I am on the admin page
When I follow "users"
Then I should be on the user list for "My calendar"
Then I should be on the user list for "My calendar"
And I should see "Smith, John"
7 changes: 6 additions & 1 deletion features/calendars/create_calendars.feature
Expand Up @@ -3,7 +3,7 @@ Feature: Create calendars
any registered user should be able to
create new calendars at any time.

Scenario: Non-admin users can create new calendars and will have admin rights to them.
Scenario: Non-admin users can create new calendars and will have admin rights to them
Given I am logged in
And I am subscribed to "Old calendar"
And I am on the homepage
Expand All @@ -12,3 +12,8 @@ Feature: Create calendars
And I press "Save"
Then I should have a calendar called "New calendar"
And I should be an admin of "New calendar"

Scenario:
Given I am not logged in
When I go to the new calendar page
Then I should be on the login page
12 changes: 9 additions & 3 deletions features/step_definitions/calendar_steps.rb
@@ -1,9 +1,15 @@
# coding: UTF-8

Given /^I am subscribed to "([^\"]*)"$/ do |calendar|
Given /^(I|"[^\"]*") (?:am|is) subscribed to "([^\"]*)"$/ do |user, calendar|
if user == 'I'
user = User.current_user
else
names = user.gsub(/^"|"$/, '').split(' ', 2)
user = Factory :user, :firstname => names.first, :lastname => names.last
end
cal = Calendar.find_by_name(calendar) || FactoryGirl.create(:calendar, :name => calendar)
Permission.destroy(cal.permissions.find_all_by_user_id(User.current_user.id).collect(&:id)) # make sure we don't have any superfluous admin permissions hanging around
FactoryGirl.create :permission, :user => User.current_user, :calendar => cal
Permission.destroy(cal.permissions.find_all_by_user_id(user.id).collect(&:id)) # make sure we don't have any superfluous admin permissions hanging around
FactoryGirl.create :permission, :user => user, :calendar => cal
end

Given /^I am an admin(?:istrator)? of "([^\"]*)"$/ do |calendar|
Expand Down
5 changes: 5 additions & 0 deletions features/step_definitions/extra_web_steps.rb
Expand Up @@ -15,3 +15,8 @@
Then /^I should not see an element matching "([^\"]*)"$/ do |selector|
page.should_not have_selector(selector) and response.should_not have_xpath(selector)
end

Then /^(?:|I )should not be on (.+)$/ do |page_name|
current_path = URI.parse(current_url).path
current_path.should_not == path_to(page_name)
end
2 changes: 2 additions & 0 deletions features/support/paths.rb
Expand Up @@ -29,6 +29,8 @@ def path_to(page_name)
login_path
when /the user list for "([^"]*)"$/
url_for :controller => 'calendars', :id => Calendar.find_by_name($1).id, :action => 'users', :only_path => true
when /the calendar edit page for "([^"]*)"$/
url_for :controller => 'calendars', :id => Calendar.find_by_name($1).id, :action => 'edit', :only_path => true

else
begin
Expand Down
122 changes: 0 additions & 122 deletions spec/controllers/calendars_controller_spec.rb

This file was deleted.

0 comments on commit 659ea2f

Please sign in to comment.