From 241c3cfdc089ed2d214af8acfe4ddbcca7b8c63d Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 3 Jan 2017 22:02:21 +1300 Subject: [PATCH 1/2] Moves model name into spec description so we can tell which failed. --- spec/features/signin_spec.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/spec/features/signin_spec.rb b/spec/features/signin_spec.rb index 41aa1ecd1..4b9e5be60 100644 --- a/spec/features/signin_spec.rb +++ b/spec/features/signin_spec.rb @@ -29,16 +29,22 @@ feature "signin", js: true do expect(current_path).to eq new_member_session_path end - scenario "after signin, redirect to what you were trying to do" do - models = %w[plantings harvests posts photos gardens seeds] - models.each do |model| - visit "/#{model}/new" + shared_examples "redirects to what you were trying to do" do + scenario do + visit "/#{model_name}/new" expect(current_path).to eq new_member_session_path fill_in 'Login', with: member.login_name fill_in 'Password', with: member.password click_button 'Sign in' - expect(current_path).to eq "/#{model}/new" - click_link 'Sign out' + expect(current_path).to eq "/#{model_name}/new" + end + end + + describe "redirects to what you were trying to do" do + %w[plantings harvests posts photos gardens seeds].each do |m| + it_behaves_like "redirects to what you were trying to do" do + let(:model_name) { m } + end end end From b38728c5dffd92e0f07e59254844afc582bf05e0 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 3 Jan 2017 22:12:55 +1300 Subject: [PATCH 2/2] Add login() to signin spec to reduce code duplication --- spec/features/signin_spec.rb | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/spec/features/signin_spec.rb b/spec/features/signin_spec.rb index 4b9e5be60..963345874 100644 --- a/spec/features/signin_spec.rb +++ b/spec/features/signin_spec.rb @@ -6,21 +6,23 @@ feature "signin", js: true do let(:wrangler) { create :crop_wrangling_member } let(:notification) { create :notification } - scenario "redirect to previous page after signin" do - visit crops_path # some random page - click_link 'Sign in' + def login fill_in 'Login', with: member.login_name fill_in 'Password', with: member.password click_button 'Sign in' + end + + scenario "redirect to previous page after signin" do + visit crops_path # some random page + click_link 'Sign in' + login expect(current_path).to eq crops_path end scenario "don't redirect to devise pages after signin" do visit new_member_registration_path # devise signup page click_link 'Sign in' - fill_in 'Login', with: member.login_name - fill_in 'Password', with: member.password - click_button 'Sign in' + login expect(current_path).to eq root_path end @@ -33,9 +35,7 @@ feature "signin", js: true do scenario do visit "/#{model_name}/new" expect(current_path).to eq new_member_session_path - fill_in 'Login', with: member.login_name - fill_in 'Password', with: member.password - click_button 'Sign in' + login expect(current_path).to eq "/#{model_name}/new" end end @@ -51,9 +51,7 @@ feature "signin", js: true do scenario "after signin, redirect to new notifications page" do visit new_notification_path(recipient: recipient) expect(current_path).to eq new_member_session_path - fill_in 'Login', with: member.login_name - fill_in 'Password', with: member.password - click_button 'Sign in' + login expect(current_path).to eq new_notification_path end