From 5e8aebbfa52591a478541c06332ccbc5e09ce8e7 Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Sat, 3 Mar 2012 23:18:08 +0800 Subject: [PATCH] Failing cucumber scenario for issue #305. --- features/admin/login.feature | 56 +++++++++++++----------- features/step_definitions/admin_steps.rb | 22 ++++++++++ 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/features/admin/login.feature b/features/admin/login.feature index 09ef66ab..a8fea2df 100644 --- a/features/admin/login.feature +++ b/features/admin/login.feature @@ -3,31 +3,37 @@ Feature: Login As an administrator I want to log in -Background: - Given I have the site: "test site" set up + Background: + Given I have the site: "test site" set up -Scenario: Successfully logging in - When I go to login - And I fill in "Email" with "admin@locomotiveapp.org" - And I fill in "Password" with "easyone" - And I press "Log in" - Then I should see "Listing pages" + Scenario: Successfully logging in + When I go to login + And I fill in "Email" with "admin@locomotiveapp.org" + And I fill in "Password" with "easyone" + And I press "Log in" + Then I should see "Listing pages" -Scenario: Attempting to login with an invalid emai or password - When I go to login - And I fill in "Email" with "admin@locomotiveapp.org" - And I fill in "Password" with "" - And I press "Log in" - Then I should not see "Listing pages" - And I should see "Invalid email or password" + Scenario: Attempting to login with an invalid emai or password + When I go to login + And I fill in "Email" with "admin@locomotiveapp.org" + And I fill in "Password" with "" + And I press "Log in" + Then I should not see "Listing pages" + And I should see "Invalid email or password" -Scenario: Attempting to login with an account without a membership - Given the following accounts exist: - | email | password | password_confirmation | - | john@locomotiveapp.org | bluecheese | bluecheese | - When I go to login - And I fill in "Email" with "john@locomotiveapp.org" - And I fill in "Password" with "bluecheese" - And I press "Log in" - Then I should not see "Listing pages" - And I should see "not a member of this site" + Scenario: Attempting to login with an account without a membership + Given the following accounts exist: + | email | password | password_confirmation | + | john@locomotiveapp.org | bluecheese | bluecheese | + When I go to login + And I fill in "Email" with "john@locomotiveapp.org" + And I fill in "Password" with "bluecheese" + And I press "Log in" + Then I should not see "Listing pages" + And I should see "not a member of this site" + + Scenario: Being redirected to the previous admin page after login + Given I have an admin account + And I attempt to access an admin page when not logged in + When I login with my admin account + Then I should be redirected the the admin page I was attempting to access diff --git a/features/step_definitions/admin_steps.rb b/features/step_definitions/admin_steps.rb index 2a85d18b..6c75c004 100644 --- a/features/step_definitions/admin_steps.rb +++ b/features/step_definitions/admin_steps.rb @@ -28,6 +28,28 @@ Then /^I am redirected to "([^\"]*)"$/ do |url| visit location end +Given /^I have an admin account$/ do + @member = Site.first.memberships.where(:role => 'admin').first || FactoryGirl.create(:admin, :site => Site.first, :password => 'easyone') + @email = @member.account.email + @password = 'easyone' +end + +Given /^I attempt to access an admin page when not logged in$/ do + @admin_path = edit_admin_current_site_path + visit @admin_path +end + +When /^I login with my admin account$/ do + fill_in 'Email', :with => @email + fill_in 'Password', :with => @password + click_button 'Log in' +end + +Then /^I should be redirected the the admin page I was attempting to access$/ do + save_and_open_page + current_path.should == edit_admin_current_site_path +end + ### Cross-domain authentication When /^I forget to press the button on the cross-domain notice page$/ do