From fc94af96f186879a2214b7819b8bd01adeaae7d1 Mon Sep 17 00:00:00 2001 From: Georgiy Date: Fri, 26 Oct 2018 10:41:22 +0500 Subject: [PATCH] move all login method to macros --- spec/controllers/events_controller_spec.rb | 6 ------ spec/features/email_spec.rb | 7 ------- spec/features/event_draft_spec.rb | 6 ------ spec/features/events_spec.rb | 6 ------ spec/features/participants_spec.rb | 12 ------------ spec/features/user_spec.rb | 6 ------ spec/rails_helper.rb | 1 + spec/spec_helper.rb | 4 ++-- spec/support/login_macros.rb | 7 +++++++ 9 files changed, 10 insertions(+), 45 deletions(-) create mode 100644 spec/support/login_macros.rb diff --git a/spec/controllers/events_controller_spec.rb b/spec/controllers/events_controller_spec.rb index ecfba88f..5ecb9750 100644 --- a/spec/controllers/events_controller_spec.rb +++ b/spec/controllers/events_controller_spec.rb @@ -586,10 +586,4 @@ expect(page_analysis.pages.size).to be >= 3 end end - - def login(role) - @profile = FactoryGirl.create(:profile) - @profile.user.role = role - login_as(@profile.user, :scope => :user) - end end diff --git a/spec/features/email_spec.rb b/spec/features/email_spec.rb index 1936548c..aa572d3c 100644 --- a/spec/features/email_spec.rb +++ b/spec/features/email_spec.rb @@ -97,11 +97,4 @@ expect(page.find('#email_subject').value).to eq(@template.subject) expect(page.find('#email_content').value).to eq(@template.content) end - - - def login(role) - @profile = FactoryGirl.create(:profile) - @profile.user.role = role - login_as(@profile.user, :scope => :user) - end end diff --git a/spec/features/event_draft_spec.rb b/spec/features/event_draft_spec.rb index 4824f02b..f89ba349 100644 --- a/spec/features/event_draft_spec.rb +++ b/spec/features/event_draft_spec.rb @@ -65,10 +65,4 @@ visit events_path expect(page).to_not have_text(@event.name) end - - def login(role) - @profile = FactoryGirl.create(:profile) - @profile.user.role = role - login_as(@profile.user, :scope => :user) - end end diff --git a/spec/features/events_spec.rb b/spec/features/events_spec.rb index c1f2be01..5d0d29cf 100644 --- a/spec/features/events_spec.rb +++ b/spec/features/events_spec.rb @@ -440,10 +440,4 @@ expect(page).to have_every_text(not_accepted_names) expect(page).to have_no_text(accepted_names) end - - def login(role) - @profile = FactoryGirl.create(:profile) - @profile.user.role = role - login_as(@profile.user, :scope => :user) - end end diff --git a/spec/features/participants_spec.rb b/spec/features/participants_spec.rb index 88571e72..44a7c232 100644 --- a/spec/features/participants_spec.rb +++ b/spec/features/participants_spec.rb @@ -77,12 +77,6 @@ expect(page.body).to contain_ordered(expected_order.reverse) end - - def login(role) - @profile = FactoryGirl.create(:profile) - @profile.user.role = role - login_as(@profile.user, :scope => :user) - end end RSpec.feature "Event participants overview", :type => :feature do @@ -123,10 +117,4 @@ def login(role) expect{click_button I18n.t('emails.email_form.send')}.to change{ActionMailer::Base.deliveries.count}.by(0) expect(page).to have_text(I18n.t('emails.submit.sending_failed')) end - - def login(role) - @profile = FactoryGirl.create(:profile) - @profile.user.role = role - login_as(@profile.user, :scope => :user) - end end diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index 0cc7697b..f63a2211 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -213,10 +213,4 @@ expect(page).to have_text(max2.profile.last_name) expect(page).to_not have_text(user3.profile.last_name) end - - def login(role) - @profile = FactoryGirl.create(:profile) - @profile.user.role = role - login_as(@profile.user, :scope => :user) - end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 3b466d21..670b6f97 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -51,6 +51,7 @@ config.include Warden::Test::Helpers config.include Devise::Test::ControllerHelpers, :type => :controller config.include Devise::Test::ControllerHelpers, :type => :view + config.include LoginMacros, type: :feature # Reset warden after each test config.after :each do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f1fd93dd..88ada4fc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -29,8 +29,8 @@ # Skip PhantomJS tests if PhantomJS is not installed. config.filter_run_excluding :js => (not Cliver::detect('phantomjs')) - # load custom matchers - Dir[File.dirname(__FILE__) + "/support/matchers/*.rb"].each {|f| require f} + # load custom matchers and helpers + Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } # Use color not only in STDOUT but also in pagers and files # config.tty = true diff --git a/spec/support/login_macros.rb b/spec/support/login_macros.rb new file mode 100644 index 00000000..f5b4bc13 --- /dev/null +++ b/spec/support/login_macros.rb @@ -0,0 +1,7 @@ +module LoginMacros + def login(role) + @profile = FactoryGirl.create(:profile) + @profile.user.role = role + login_as(@profile.user, :scope => :user) + end +end \ No newline at end of file