diff --git a/spec/controllers/action_page_controller_spec.rb b/spec/controllers/action_page_controller_spec.rb index 5b9b0b72..80b35edd 100644 --- a/spec/controllers/action_page_controller_spec.rb +++ b/spec/controllers/action_page_controller_spec.rb @@ -1,11 +1,7 @@ require "rails_helper" RSpec.describe ActionPageController, type: :controller do - include Devise::Test::ControllerHelpers - let(:action_page) { FactoryBot.create :action_page } - let(:admin) { login_as_admin } - let(:collaborator) { login_as_collaborator } describe "GET #index" do render_views @@ -78,13 +74,13 @@ end it "notifies admin users that a page is unpublished" do - admin + sign_in FactoryBot.create(:admin_user) get :show, params: { id: unpublished_action_page } expect(flash[:notice]).to include("not published") end it "notifies collaborator users that a page is unpublished" do - collaborator + sign_in FactoryBot.create(:collaborator_user) get :show, params: { id: unpublished_action_page } expect(flash[:notice]).to include("not published") end diff --git a/spec/controllers/admin/institutions_controller_spec.rb b/spec/controllers/admin/institutions_controller_spec.rb index 678b056f..d892fea7 100644 --- a/spec/controllers/admin/institutions_controller_spec.rb +++ b/spec/controllers/admin/institutions_controller_spec.rb @@ -1,8 +1,6 @@ require "rails_helper" RSpec.describe Admin::InstitutionsController, type: :controller do - include Devise::Test::ControllerHelpers - # This should return the minimal set of attributes required to create a valid # Admin::Institution. As you add validations to Admin::InstitutionSet, be sure to # adjust the attributes here as well. @@ -11,8 +9,6 @@ end before(:each) do - # Admin login - @request.env["devise.mapping"] = Devise.mappings[:admin] sign_in FactoryBot.create(:admin_user) # Set parent action diff --git a/spec/controllers/admin/petitions_controller_spec.rb b/spec/controllers/admin/petitions_controller_spec.rb index 89592e07..5e7c8092 100644 --- a/spec/controllers/admin/petitions_controller_spec.rb +++ b/spec/controllers/admin/petitions_controller_spec.rb @@ -1,10 +1,7 @@ require "rails_helper" RSpec.describe Admin::PetitionsController, type: :controller do - include Devise::Test::ControllerHelpers - before(:each) do - @request.env["devise.mapping"] = Devise.mappings[:admin] sign_in FactoryBot.create(:admin_user) end diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index 14655f69..bc664026 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -1,9 +1,7 @@ require "rails_helper" RSpec.describe Admin::UsersController, type: :controller do - include Devise::Test::ControllerHelpers - - before { login_as_admin } + before { sign_in FactoryBot.create(:admin_user) } describe "GET #index" do it "returns http success" do diff --git a/spec/features/action_pages/call_action_spec.rb b/spec/features/action_pages/call_action_spec.rb index d37fed01..4959eefe 100644 --- a/spec/features/action_pages/call_action_spec.rb +++ b/spec/features/action_pages/call_action_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.feature "Call actions", type: :feature, js: true do +RSpec.describe "Call actions", type: :system, js: true do let!(:action) do FactoryBot.create(:call_campaign).action_page end diff --git a/spec/features/action_pages/congress_action_spec.rb b/spec/features/action_pages/congress_action_spec.rb index 8f6fb197..0d668008 100644 --- a/spec/features/action_pages/congress_action_spec.rb +++ b/spec/features/action_pages/congress_action_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.feature "Congress actions", type: :feature, js: true do +RSpec.describe "Congress actions", type: :system, js: true do let!(:action) do FactoryBot.create(:action_page_with_congress_message) end diff --git a/spec/features/action_pages/custom_email_action_spec.rb b/spec/features/action_pages/custom_email_action_spec.rb index 847b5840..dba865dd 100644 --- a/spec/features/action_pages/custom_email_action_spec.rb +++ b/spec/features/action_pages/custom_email_action_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.feature "Custom email actions", type: :feature, js: true do +RSpec.describe "Custom email actions", type: :system, js: true do let!(:custom_action) do FactoryBot.create(:email_campaign, :custom_email).action_page end diff --git a/spec/features/action_pages/petition_action_spec.rb b/spec/features/action_pages/petition_action_spec.rb index 50d7638f..dee8383f 100644 --- a/spec/features/action_pages/petition_action_spec.rb +++ b/spec/features/action_pages/petition_action_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.feature "Petition actions", type: :feature, js: true do +RSpec.describe "Petition actions", type: :system, js: true do let!(:action) do FactoryBot.create(:petition).action_page end diff --git a/spec/features/action_pages/state_leg_email_action_spec.rb b/spec/features/action_pages/state_leg_email_action_spec.rb index 346622b3..d7a56cf9 100644 --- a/spec/features/action_pages/state_leg_email_action_spec.rb +++ b/spec/features/action_pages/state_leg_email_action_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.feature "State legislator email actions", type: :feature, js: true do +RSpec.describe "State legislator email actions", type: :system, js: true do let!(:state_action) do FactoryBot.create(:email_campaign, :state_leg).action_page end diff --git a/spec/features/action_pages/tweet_action_spec.rb b/spec/features/action_pages/tweet_action_spec.rb index 4f177ab8..ebf067ca 100644 --- a/spec/features/action_pages/tweet_action_spec.rb +++ b/spec/features/action_pages/tweet_action_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.feature "Tweet actions", type: :feature, js: true do +RSpec.describe "Tweet actions", type: :system, js: true do let!(:tweet_action) do FactoryBot.create(:tweet, message: "Default message").action_page end diff --git a/spec/features/congress_message.rb b/spec/features/congress_message.rb index e227c72e..3eb2be12 100644 --- a/spec/features/congress_message.rb +++ b/spec/features/congress_message.rb @@ -1,6 +1,6 @@ require "rails_helper" -RSpec.feature "Submit congress message", type: :feature do +RSpec.describe "Submit congress message", type: :system do let(:action_page) { FactoryBot.create(:action_page_with_congress_message, :with_partner) } let(:partner) { action_page.partners.first } diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index bb33dd5f..eb3a932f 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -35,8 +35,10 @@ RSpec.configure do |config| config.include Devise::Test::ControllerHelpers, type: :controller + config.include Devise::Test::IntegrationHelpers, type: :system + config.include Devise::Test::IntegrationHelpers, type: :request config.include Warden::Test::Helpers, type: :request - config.include Warden::Test::Helpers, type: :feature + config.include Warden::Test::Helpers, type: :system # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = Rails.root.join("spec/fixtures") @@ -64,9 +66,17 @@ # https://relishapp.com/rspec/rspec-rails/docs config.infer_spec_type_from_file_location! - config.before(:each, type: :feature) do + config.before(:each) do # disable call tool by default; it will be stubbed for tests that need it - disable_call_tool + allow(CallTool).to receive(:enabled?).and_return(false) + end + + config.before(:each, type: :system) do + driven_by :rack_test + end + + config.before(:each, type: :system, js: true) do + driven_by :selenium_chrome_headless end FileUtils.mkdir_p(Rails.root.join("tmp/cache")) @@ -74,14 +84,3 @@ Rails.cache.clear end end - -# for request tests -def login(user) - login_path = "/login" - post login_path, params: { - user: { - email: user.email, - password: "strong passwords defeat lobsters covering wealth" - } - } -end diff --git a/spec/requests/admin/action_pages_spec.rb b/spec/requests/admin/action_pages_spec.rb index 66a4dab1..daec0326 100644 --- a/spec/requests/admin/action_pages_spec.rb +++ b/spec/requests/admin/action_pages_spec.rb @@ -25,7 +25,7 @@ describe "Admins" do before(:each) do @admin = FactoryBot.create(:admin_user) - login @admin + sign_in @admin end it "should allow them creating action pages with valid attributes" do diff --git a/spec/requests/admin/events_spec.rb b/spec/requests/admin/events_spec.rb index 5a3a352d..712ded15 100644 --- a/spec/requests/admin/events_spec.rb +++ b/spec/requests/admin/events_spec.rb @@ -2,7 +2,7 @@ RSpec.describe "Admin Action Page Analytics", type: :request do let(:action_page) { FactoryBot.create(:action_page_with_views) } - before { login FactoryBot.create(:admin_user) } + before { sign_in FactoryBot.create(:admin_user) } describe "#index" do context "with type param" do diff --git a/spec/requests/admin/petition_spec.rb b/spec/requests/admin/petition_spec.rb index 1532858d..f2938505 100644 --- a/spec/requests/admin/petition_spec.rb +++ b/spec/requests/admin/petition_spec.rb @@ -4,7 +4,7 @@ describe "admins" do before(:each) do @admin = FactoryBot.create(:admin_user) - login @admin + sign_in @admin end it "should let admins download the CSV" do diff --git a/spec/requests/admin/s3_uploads_spec.rb b/spec/requests/admin/s3_uploads_spec.rb index 85b103de..bee08847 100644 --- a/spec/requests/admin/s3_uploads_spec.rb +++ b/spec/requests/admin/s3_uploads_spec.rb @@ -28,8 +28,7 @@ end it "should allow admins" do - @admin = FactoryBot.create(:admin_user) - login @admin + sign_in FactoryBot.create(:admin_user) expect do post "/admin/source_files", params: valid_attributes @@ -37,14 +36,12 @@ end it "should have valid response" do - @admin = FactoryBot.create(:admin_user) - login @admin + sign_in FactoryBot.create(:admin_user) post "/admin/source_files", params: valid_attributes expect(response.parsed_body).to include( - "id" => 1, - "delete_url" => "/admin/source_files/1.json", + "delete_url" => a_string_matching(%r{/admin/source_files/[0-9]+.json}), "full_url" => a_string_matching(%r{/uploads/3be325f2b4e64d9d92a89405577280a4/img.png}), "image" => true, "name" => "img.png", diff --git a/spec/requests/admin/users_spec.rb b/spec/requests/admin/users_spec.rb index efc63257..0017abd3 100644 --- a/spec/requests/admin/users_spec.rb +++ b/spec/requests/admin/users_spec.rb @@ -3,7 +3,7 @@ RSpec.describe "Admin Users", type: :request do before(:each) do admin = FactoryBot.create(:admin_user) - login admin + sign_in admin end describe "#index" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a4273d25..75aad578 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -43,17 +43,6 @@ config.timestamp_enabled = false end -# for controller tests -def login_as_admin - @request.env["devise.mapping"] = Devise.mappings[:admin] - sign_in FactoryBot.create(:admin_user) -end - -def login_as_collaborator - @request.env["devise.mapping"] = Devise.mappings[:admin] - sign_in FactoryBot.create(:collaborator_user) -end - def set_weak_password(user) weak_password = "12345678" user.password = weak_password diff --git a/spec/support/feature_helpers.rb b/spec/support/feature_helpers.rb index 9b791f99..13e063c8 100644 --- a/spec/support/feature_helpers.rb +++ b/spec/support/feature_helpers.rb @@ -12,10 +12,6 @@ def sign_out_user(_user) find("input[value='Logout']", visible: :all, match: :first).click end - def disable_call_tool - allow(CallTool).to receive(:enabled?).and_return(false) - end - def fill_in_editor(locator, with:) within_frame find(locator, visible: :all).sibling("div").find("iframe") do within_frame find("#epiceditor-editor-frame") do