Skip to content

Commit

Permalink
Merge branch '54-remove-controller-and-view-specs'
Browse files Browse the repository at this point in the history
  • Loading branch information
marnen committed Sep 23, 2011
2 parents 5ca38af + 99fc892 commit 43a883e
Show file tree
Hide file tree
Showing 21 changed files with 205 additions and 430 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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')))
36 changes: 18 additions & 18 deletions app/views/users/new.html.haml
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
- if !current_user
%h1&= _("Register")
%h1= _("Register")
= error_messages_for :user
= form_for :user, :url => current_user ? edit_user_path(current_user) : users_path do |f|
%h2&= _("Who are you?")
%h2= _("Who are you?")
%table.edit
%tr
%th
&= _("E-mail address")
= f.label :email, _("E-mail address")
%br
%span.hint&= _("(this will be your user name)")
%td= f.text_field :email
%span.hint= _("(this will be your user name)")
%td= f.email_field :email
%tr
%th&= _("First name")
%th= f.label :firstname, _("First name")
%td= f.text_field :firstname
%tr
%th&= _("Last name")
%th= f.label :lastname, _("Last name")
%td= f.text_field :lastname
%tr
%th&= _("Password")
%th= f.label :password, _("Password")
%td= f.password_field :password
%tr
%th
&= _("Password again")
= f.label :password_confirmation, _("Password again")
%br
%span.hint&= _("(for confirmation)")
%span.hint= _("(for confirmation)")
%td= f.password_field :password_confirmation

%h2&= _("Where do you live?")
%p&= _("This information is optional, but if you provide it, we can tell you the distance from your house to events. And of course we'll never share it with anyone else without your permission (except anonymously for geocoding).")
%h2= _("Where do you live?")
%p= _("This information is optional, but if you provide it, we can tell you the distance from your house to events. And of course we'll never share it with anyone else without your permission (except anonymously for geocoding).")
%table.edit
%tr
%th&= _("Street address")
%th= f.label :street, _("Street address")
%td= f.text_field :street
%tr
%th&= _("Address line 2")
%th= f.label :street2, _("Address line 2")
%td= f.text_field :street2
%tr
%th&= _("City")
%th= f.label :city, _("City")
%td= f.text_field :city
%tr
%th&= _("State")
%th= f.label :state_id, _("State")
%td= f.collection_select(:state_id, Acts::Addressed::State.find(:all, :order => :name), :id, :name, :include_blank => true)
%tr
%th&= _("ZIP code")
%th= f.label :zip, _("ZIP code")
%td= f.text_field :zip
%p
%label
= f.check_box :show_contact
&= _('Make my address visible in the contact list (available to administrators only)')
= _('Make my address visible in the contact list (available to administrators only)')

= submit_tag(current_user ? _('Save') : _('Sign up'))
22 changes: 18 additions & 4 deletions features/calendars/administer_calendars.feature
Original file line number Diff line number Diff line change
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 @@ -21,15 +32,16 @@ Feature: Administer calendars
And I am subscribed to "Someone else's calendar"
And I am on the homepage
When I follow "Admin tools"
Then I should see "My calendar"
Then I should be on the admin page
And I should see "My calendar"
And I should not see "Someone else's calendar"

Scenario: Admin users should be able to change the name of calendars they control
Given I am logged in
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 @@ -38,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
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion features/events/delete_events.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Feature: Edit events
Feature: Delete events
In order to remove unneeded content
any administrator should be able to
delete events already created.
Expand Down
File renamed without changes.
38 changes: 38 additions & 0 deletions features/events/list_events.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Feature: List events
As a registered user
I can see events on calendars I subscribe to
So I can keep track of what's going on

Scenario: Unregistered users can't get to event list
Given I am not logged in
When I go to the events page
Then I should be on the login page

Scenario Outline: It should sort events by date
Given I am logged in
And I am subscribed to "<calendar>"
And the following events exist:
| calendar | name | date |
| the calendar | November | 2100-11-01 |
| the calendar | October | 2100-10-01 |
| the calendar | December | 2100-12-01 |
When I go to the events page
Then I should see the following in order:
| October |
| November |
| December |

Examples:
| calendar |
| My Amazing Calendar |

Scenario Outline: It should not show deleted events
Given I am logged in
And I am subscribed to "<calendar>"
And a deleted event exists with name: "<deleted>", calendar: the calendar
When I go to the events page
Then I should not see "<deleted>"

Examples:
| calendar | deleted |
| Deletion test | I'm invisible! |
2 changes: 1 addition & 1 deletion features/events/search_events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Feature: Search events

Scenario: Search form is displayed
Given I am logged in
When I am on the event list
And I am on the event list
Then I should see an element matching "input[@type=submit][@value=Search]"

52 changes: 44 additions & 8 deletions features/manage_subscriptions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,38 @@ Feature: Manage subscriptions
any registered user should be able to
subscribe to and unsubscribe from any calendar of which ey is not an admin.

Scenario: Anyone can subscribe to a calendar
Scenario Outline: Anyone can subscribe to a calendar
Given I am logged in
And someone else has a calendar called "Someone else's calendar"
And someone else has a calendar called "<calendar>"
And I am on the homepage
When I follow "Subscriptions"
Then I should see the word "subscribe"
Then I should see "<calendar>"
And I should see the word "subscribe"
When I follow "subscribe"
Then I should be subscribed to "<calendar>"

Scenario: Non-admin users can unsubscribe from their calendars
Examples:
| calendar |
| Someone else's calendar |

Scenario: Don't show the list of unsubscribed calendars if it's empty
Given I am logged in
And I am subscribed to "My calendar"
And I am on the subscriptions page
Then I should not see "subscribe to these calendars"

Scenario Outline: Non-admin users can unsubscribe from their calendars
Given I am logged in
And I am subscribed to "<calendar>"
And I am on the homepage
When I follow "Subscriptions"
Then I should see the word "unsubscribe"
Then I should see "<calendar>"
And I should see the word "unsubscribe"
When I follow "unsubscribe"
Then I should not be subscribed to "<calendar>"

Examples:
| calendar |
| My calendar |

Scenario: Admin users cannot unsubscribe from calendars they control
Given I am logged in
Expand All @@ -30,5 +49,22 @@ Feature: Manage subscriptions
And I am subscribed to "Someone else's calendar"
And I am on the homepage
When I follow "Subscriptions"
Then I should see /\bunsubscribe\W+Someone else's calendar/

Then I should see the following in order:
| unsubscribe |
| Someone else's calendar |

Scenario Outline: I should see the role for each subscribed calendar
Given I am logged in
And I am an admin of "<mine>"
And I am subscribed to "<other>"
And I am on the subscriptions page
Then I should see the following in order:
| <mine> |
| admin |
And I should see the following in order:
| <other> |
| user |

Examples:
| mine | other |
| My calendar | Someone Else's Calendar |
36 changes: 30 additions & 6 deletions features/register_as_new_user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,37 @@ Feature: Register as new user
anyone should be able to
create an account if not already logged in.

Scenario: Create an account when not logged in
Scenario Outline: Create an account when not logged in
Given I am not logged in
And there is no user account for "quentin@example.com"
And there is no user account for "<email>"
And I am on the login page
When I follow "register"
And I fill in "user[email]" with "quentin@example.com"
And I fill in "user[password]" with "passw0rd"
And I fill in "user[password_confirmation]" with "passw0rd"
And I fill in the following:
| E-mail address | <email> |
| Password | <password> |
| Password again | <password> |
And I press "Sign up"
Then I should have a user account for "quentin@example.com"
Then I should have a user account for "<email>"

Examples:
| email | password |
| quentin@example.com | passw0rd |

Scenario Outline: Do not create account if e-mail or password is missing, or if password confirmation is incorrect
Given I am not logged in
And there is no user account for "<email>"
And I am on the register page
When I fill in the following:
| E-mail address | <email> |
| Password | <password> |
| Password again | <password2> |
And I press "Sign up"
Then I should not have a user account for "<email>"

Examples:
| email | password | password2 |
| | passw0rd | passw0rd |
| quentin@example.com | | |
| quentin@example.com | | passw0rd |
| quentin@example.com | passw0rd | |
| quentin@example.com | passw0rd | dr0wssap |
25 changes: 21 additions & 4 deletions features/step_definitions/calendar_steps.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# coding: UTF-8

Given /^I am subscribed to "([^\"]*)"$/ do |calendar|
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
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 = create_model(:calendar, :name => calendar)
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 All @@ -25,4 +31,15 @@
admin = Role.find_or_create_by_name('admin')
cal = Calendar.find_by_name(calendar)
User.current_user.permissions.find_by_calendar_id_and_role_id(cal.id, admin.id).should_not be_nil
end

Then /^I should (not )?be subscribed to "([^"]*)"$/ do |negation, calendar|
calendar = Calendar.find_by_name(calendar)
user = User.current_user
permission = user.permissions.find_by_calendar_id(calendar)
if negation
permission.should be_nil
else
permission.should_not be_nil
end
end
12 changes: 12 additions & 0 deletions features/step_definitions/extra_web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@
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 see the following in order:$/ do |table|
# table is a Cucumber::Ast::Table
regexp = %r{#{table.raw.flatten.collect {|x| Regexp.escape x }.join '.*'}}m

page.should have_xpath('//*', :text => regexp)
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
9 changes: 7 additions & 2 deletions features/step_definitions/user_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
end
end

Then /^I should have a user account for "([^\"]*)"$/ do |email|
User.find_by_email(email).should_not be_nil
Then /^I should (not )?have a user account for "([^\"]*)"$/ do |negation, email|
user = User.find_by_email(email)
if negation
user.should be_nil
else
user.should_not be_nil
end
end

0 comments on commit 43a883e

Please sign in to comment.