From ce7d144170a994cef9cfd981877ed43e9031ed4b Mon Sep 17 00:00:00 2001 From: elasticspoon Date: Sun, 12 May 2024 10:20:36 -0400 Subject: [PATCH] refactor(tests): remove reliance on seeded db (system 3) (#4349) * refactor(tests): remove reliance on seeded db (system 1) * refactor: remove extra partner being generate * fix: incorrect count --- spec/system/account_request_system_spec.rb | 7 +- .../admin/account_requests_system_spec.rb | 6 +- .../system/admin/barcode_items_system_spec.rb | 24 +++--- spec/system/admin/base_items_system_spec.rb | 28 +++---- .../system/admin/organizations_system_spec.rb | 16 ++-- spec/system/admin/users_system_spec.rb | 37 +++++++--- spec/system/annual_reports_system_spec.rb | 11 ++- spec/system/audit_system_spec.rb | 33 +++++---- spec/system/barcode_item_system_spec.rb | 34 +++++---- spec/system/dashboard_system_spec.rb | 51 +++++++------ spec/system/donation_site_system_spec.rb | 9 ++- spec/system/item_system_spec.rb | 38 ++++++---- spec/system/manage_system_spec.rb | 22 +++--- spec/system/partner_system_spec.rb | 73 ++++++++++--------- 14 files changed, 226 insertions(+), 163 deletions(-) diff --git a/spec/system/account_request_system_spec.rb b/spec/system/account_request_system_spec.rb index fa8f3fd0e2..a3a8c9545c 100644 --- a/spec/system/account_request_system_spec.rb +++ b/spec/system/account_request_system_spec.rb @@ -1,4 +1,7 @@ -RSpec.describe 'Account request flow', type: :system, js: true do +RSpec.describe 'Account request flow', type: :system, js: true, skip_seed: true do + let(:organization) { create(:organization, skip_items: true) } + let(:super_admin) { create(:super_admin, organization: organization) } + context 'when in staging' do before do allow(Rails.env).to receive(:staging?).and_return(true) @@ -53,7 +56,7 @@ expect(page).to have_content('We will be processing your request now.') # Access link within email sent to admin user to process the request. - sign_in(@super_admin) + sign_in(super_admin) visit new_admin_organization_path(token: created_account_request.identity_token) fill_in 'Short name', with: 'fakeshortname' diff --git a/spec/system/admin/account_requests_system_spec.rb b/spec/system/admin/account_requests_system_spec.rb index aae172487d..b77c93dc67 100644 --- a/spec/system/admin/account_requests_system_spec.rb +++ b/spec/system/admin/account_requests_system_spec.rb @@ -1,4 +1,6 @@ -RSpec.describe "Account Requests Admin", type: :system do +RSpec.describe "Account Requests Admin", type: :system, skip_seed: true do + let(:super_admin) { create(:super_admin) } + context "while signed in as a super admin" do let!(:request1) { create(:account_request, confirmed_at: Time.zone.today, status: 'admin_approved') } let!(:request2) { @@ -11,7 +13,7 @@ let!(:request6) { create(:account_request, created_at: Time.zone.today - 2.days, status: 'started') } before do - sign_in(@super_admin) + sign_in(super_admin) end around do |ex| diff --git a/spec/system/admin/barcode_items_system_spec.rb b/spec/system/admin/barcode_items_system_spec.rb index 4b96872460..5a74d792d6 100644 --- a/spec/system/admin/barcode_items_system_spec.rb +++ b/spec/system/admin/barcode_items_system_spec.rb @@ -1,14 +1,17 @@ -RSpec.describe "Barcode Items Admin", type: :system do +RSpec.describe "Barcode Items Admin", type: :system, skip_seed: true do + let(:organization) { create(:organization, skip_items: true) } + let(:super_admin) { create(:super_admin, organization: organization) } + + let!(:base_item) { create(:base_item) } + let!(:item) { create(:item, base_item: base_item) } + let!(:barcode_item) { create(:global_barcode_item, base_item: base_item) } + context "while signed in as a super admin" do before do - sign_in(@super_admin) + sign_in(super_admin) end context "user visits the index page" do - let!(:item) { create(:item) } - let!(:base_item) { create(:base_item) } - let!(:barcode_item) { create(:global_barcode_item) } - before do visit admin_barcode_items_path end @@ -38,9 +41,6 @@ end context "user visits the new page" do - let!(:item) { create(:item) } - let!(:base_item) { create(:base_item) } - before do visit new_admin_barcode_item_path end @@ -58,10 +58,6 @@ end context "user visits the edit page" do - let!(:item) { create(:item) } - let!(:base_item) { create(:base_item) } - let!(:barcode_item) { create(:global_barcode_item) } - before do visit edit_admin_barcode_item_path(barcode_item) end @@ -79,8 +75,6 @@ end context "user visits the show page" do - let!(:barcode_item) { create(:global_barcode_item) } - before do visit admin_barcode_item_path(barcode_item) end diff --git a/spec/system/admin/base_items_system_spec.rb b/spec/system/admin/base_items_system_spec.rb index a31188a21a..de83e5ba9b 100644 --- a/spec/system/admin/base_items_system_spec.rb +++ b/spec/system/admin/base_items_system_spec.rb @@ -1,7 +1,13 @@ -RSpec.describe "Base Item Admin", type: :system, js: true do +RSpec.describe "Base Item Admin", type: :system, js: true, skip_seed: true do + let(:organization) { create(:organization, skip_items: true) } + let(:user) { create(:user, organization: organization) } + let(:super_admin) { create(:super_admin, organization: organization) } + let(:super_admin_no_org) { create(:super_admin, organization: nil) } + let(:base_item) { create(:base_item) } + context "While signed in as an Administrative User (super admin)" do before do - sign_in(@super_admin) + sign_in(super_admin) end let!(:url_prefix) {} @@ -30,7 +36,6 @@ before do visit edit_admin_base_item_path(base_item) end - let(:base_item) { BaseItem.first } it "should succeed when changing the name" do fill_in "Name", with: base_item.name + " new" @@ -46,8 +51,7 @@ end it "can view a listing of all Base Items that shows a summary of its sub-items" do - base_item = BaseItem.first - create_list(:item, 2, base_item: base_item) + create_list(:item, 2, base_item: base_item, organization: organization) count = base_item.item_count visit admin_base_items_path expect(page).to have_content(base_item.name) @@ -57,7 +61,6 @@ end it "can view a single Base Item" do - base_item = BaseItem.first visit admin_base_item_path(base_item) expect(page).to have_content(base_item.name) end @@ -65,7 +68,7 @@ context "While signed in as an Administrative User with no organization (super admin no org)" do before do - sign_in(@super_admin_no_org) + sign_in(super_admin_no_org) end let!(:url_prefix) {} @@ -94,7 +97,6 @@ before do visit edit_admin_base_item_path(base_item) end - let(:base_item) { BaseItem.first } it "should succeed when changing the name" do fill_in "Name", with: base_item.name + " new" @@ -110,8 +112,7 @@ end it "can view a listing of all Base Items that shows a summary of its sub-items" do - base_item = BaseItem.first - create_list(:item, 2, base_item: base_item) + create_list(:item, 2, base_item: base_item, organization: organization) count = base_item.item_count visit admin_base_items_path expect(page).to have_content(base_item.name) @@ -121,7 +122,6 @@ end it "can view a single Base Item" do - base_item = BaseItem.first visit admin_base_item_path(base_item) expect(page).to have_content(base_item.name) end @@ -129,16 +129,18 @@ context "While signed in as a normal user" do before do - sign_in(@user) + sign_in(user) end it "should have a normal user not see anything" do visit new_admin_base_item_path expect(page).to have_content("Access Denied") + visit admin_base_items_path expect(page).to have_content("Access Denied") - base_item = create(:base_item) + visit admin_base_item_path(base_item) expect(page).to have_content("Access Denied") + visit edit_admin_base_item_path(base_item) expect(page).to have_content("Access Denied") end diff --git a/spec/system/admin/organizations_system_spec.rb b/spec/system/admin/organizations_system_spec.rb index c9af3db56b..9783f3450c 100644 --- a/spec/system/admin/organizations_system_spec.rb +++ b/spec/system/admin/organizations_system_spec.rb @@ -1,11 +1,15 @@ -RSpec.describe "Admin Organization Management", type: :system, js: true do - let!(:foo_org) { create(:organization, name: 'foo') } - let!(:bar_org) { create(:organization, name: 'bar') } - let!(:baz_org) { create(:organization, name: 'baz') } +RSpec.describe "Admin Organization Management", type: :system, js: true, skip_seed: true do + let(:organization) { create(:organization, skip_items: true) } + let(:super_admin) { create(:super_admin, organization: organization) } + let(:super_admin_no_org) { create(:super_admin, organization: nil) } + + let!(:foo_org) { create(:organization, name: 'foo', skip_items: true) } + let!(:bar_org) { create(:organization, name: 'bar', skip_items: true) } + let!(:baz_org) { create(:organization, name: 'baz', skip_items: true) } context "While signed in as an Administrative User (super admin)" do before :each do - sign_in(@super_admin) + sign_in(super_admin) end it "filters by organizations by name in organizations index page" do @@ -91,7 +95,7 @@ end context "While signed in as an Administrative User with no organization (super admin no org)" do before :each do - sign_in(@super_admin_no_org) + sign_in(super_admin_no_org) end it "creates a new organization" do diff --git a/spec/system/admin/users_system_spec.rb b/spec/system/admin/users_system_spec.rb index a546d648fd..27d4a660b0 100644 --- a/spec/system/admin/users_system_spec.rb +++ b/spec/system/admin/users_system_spec.rb @@ -1,7 +1,12 @@ -RSpec.describe "Admin Users Management", type: :system, js: true do +RSpec.describe "Admin Users Management", type: :system, js: true, skip_seed: true do + let(:organization) { create(:organization, skip_items: true) } + let(:user) { create(:user, organization: organization) } + let(:organization_admin) { create(:organization_admin, organization: organization) } + let(:super_admin) { create(:super_admin, organization: organization) } + context "While signed in as an Administrative User (super admin)" do before do - sign_in(@super_admin) + sign_in(super_admin) end it "creates an user" do @@ -16,11 +21,14 @@ end it "edits an existing user" do + create(:user, organization: organization, name: "AAlphabetically First User") + visit admin_users_path click_link "Edit", match: :first - expect(page).to have_content("Update #{@organization_admin.name}") + expect(page).to have_content("Update AAlphabetically First User") + fill_in "user_name", with: "TestUser" - select(@organization.name, from: 'user_organization_id') + select(organization.name, from: 'user_organization_id') click_on "Save" expect(page.find(".alert")).to have_content "TestUser updated" @@ -28,12 +36,13 @@ # Check if the organization role has been updated tbody = find('#filterrific_results table tbody') first_row = tbody.find('tr', text: 'TestUser') - expect(first_row).to have_text(@organization.name) + expect(first_row).to have_text(organization.name) end it 'adds a role' do - user = FactoryBot.create(:user, name: 'User 123') - FactoryBot.create(:partner, name: 'Partner ABC') + user = create(:user, name: 'User 123', organization: organization) + create(:partner, name: 'Partner ABC', organization: organization) + visit edit_admin_user_path(user) expect(page).to have_content('User 123') select "Partner", from: "resource_type" @@ -48,7 +57,10 @@ end it "deletes an existing user" do + create(:user, organization: organization, name: "AAlphabetically First User") + visit admin_users_path + page.accept_confirm do click_link "Delete", match: :first end @@ -57,22 +69,29 @@ end it "filters users by name" do - user_names = User.all.pluck(:name) + create(:user, name: "UserA", organization: organization) + create(:user, name: "UserB", organization: organization) + create(:user, name: "UserC", organization: organization) + + user_names = ["UserA", "UserB", "UserC"] visit admin_users_path + user_names.each do |name| expect(page.find("table")).to have_content(name) end fill_in "filterrific_search_name", with: user_names.first + user_names[1..].each do |name| expect(page.find("table")).not_to have_content(name) end + expect(page.find("table")).to have_content(user_names.first) end it "filters users by email" do - user_email = @organization_admin.email + user_email = organization_admin.email visit admin_users_path fill_in "filterrific_search_email", with: user_email diff --git a/spec/system/annual_reports_system_spec.rb b/spec/system/annual_reports_system_spec.rb index d093f0657a..6c89805ad8 100644 --- a/spec/system/annual_reports_system_spec.rb +++ b/spec/system/annual_reports_system_spec.rb @@ -1,12 +1,15 @@ -RSpec.describe "Annual Reports", type: :system, js: true do - let(:url_prefix) { "/#{@organization.short_name}" } +RSpec.describe "Annual Reports", type: :system, js: true, skip_seed: true do + let(:organization) { create(:organization, skip_items: true) } + let(:organization_admin) { create(:organization_admin, organization: organization) } + + let(:url_prefix) { "/#{organization.short_name}" } context "while signed in as an organization admin" do subject { url_prefix + "/reports/annual_reports" } - let!(:purchase) { create(:purchase, :with_items, item_quantity: 10, issued_at: 1.year.ago) } + let!(:purchase) { create(:purchase, :with_items, item_quantity: 10, issued_at: 1.year.ago, organization: organization) } before do - sign_in @organization_admin + sign_in organization_admin visit subject.to_s end diff --git a/spec/system/audit_system_spec.rb b/spec/system/audit_system_spec.rb index b0fa40a0fd..57b78f8457 100644 --- a/spec/system/audit_system_spec.rb +++ b/spec/system/audit_system_spec.rb @@ -1,12 +1,16 @@ -RSpec.describe "Audit management", type: :system, js: true do - let!(:url_prefix) { "/#{@organization.to_param}" } +RSpec.describe "Audit management", type: :system, js: true, skip_seed: true do + let(:organization) { create(:organization, skip_items: true) } + let(:user) { create(:user, organization: organization) } + let(:organization_admin) { create(:organization_admin, organization: organization) } + + let!(:url_prefix) { "/#{organization.to_param}" } let(:quantity) { 7 } let(:item) { create(:item) } - let!(:storage_location) { create(:storage_location, :with_items, item: item, item_quantity: 10, organization: @organization) } + let!(:storage_location) { create(:storage_location, :with_items, item: item, item_quantity: 10, organization: organization) } context "while signed in as a normal user" do before do - sign_in(@user) + sign_in(user) end it "should not be able to visit the audits #index page" do @@ -32,12 +36,11 @@ context "while signed in as an organization admin" do before do - sign_in(@organization_admin) + sign_in(organization_admin) end context "when starting a new audit" do subject { url_prefix + "/audits/new" } - let(:item) { Item.alphabetized.first } it "does not display quantities in line-item drop down selector" do create(:storage_location, :with_items, item: item, item_quantity: 10) @@ -52,9 +55,9 @@ subject { url_prefix + "/audits" } it "should be able to filter the #index by storage location" do - storage_location2 = create(:storage_location, name: "there", organization: @organization) - create(:audit, organization: @organization, storage_location: storage_location) - create(:audit, organization: @organization, storage_location: storage_location2) + storage_location2 = create(:storage_location, name: "there", organization: organization) + create(:audit, organization: organization, storage_location: storage_location) + create(:audit, organization: organization, storage_location: storage_location2) visit subject select storage_location.name, from: "filters[at_location]" @@ -66,8 +69,12 @@ it "should be able to save progress of an audit" do visit subject click_link "New Audit" - select storage_location.name, from: "Storage location" - select Item.last.name, from: "audit_line_items_attributes_0_item_id" + + await_select2("#audit_line_items_attributes_0_item_id") do + select storage_location.name, from: "Storage location" + end + + select item.name, from: "audit_line_items_attributes_0_item_id" fill_in "audit_line_items_attributes_0_quantity", with: quantity.to_s expect do @@ -213,8 +220,8 @@ expect(page).not_to have_content("Delete Audit") expect(page).not_to have_content("Finalize Audit") visit url_prefix + "/audits/" + audit.to_param + "/edit" - expect(page).not_to have_current_path(edit_audit_path(@organization.to_param, audit.to_param)) - expect(page).to have_current_path(audits_path(@organization.to_param)) + expect(page).not_to have_current_path(edit_audit_path(organization.to_param, audit.to_param)) + expect(page).to have_current_path(audits_path(organization.to_param)) end it "should not be able to delete the audit that is finalized" do diff --git a/spec/system/barcode_item_system_spec.rb b/spec/system/barcode_item_system_spec.rb index ecfb51a473..87b73db02a 100644 --- a/spec/system/barcode_item_system_spec.rb +++ b/spec/system/barcode_item_system_spec.rb @@ -1,8 +1,13 @@ -RSpec.describe "Barcode management", type: :system, js: true do +RSpec.describe "Barcode management", type: :system, js: true, skip_seed: true do + let(:organization) { create(:organization, skip_items: true) } + let(:user) { create(:user, organization: organization) } + let(:organization_admin) { create(:organization_admin, organization: organization) } + let(:base_item) { create(:base_item) } + before do - sign_in(@user) + sign_in(user) end - let(:url_prefix) { "/#{@organization.to_param}" } + let(:url_prefix) { "/#{organization.to_param}" } context "While viewing the barcode items index page" do subject { url_prefix + "/barcode_items" } @@ -12,15 +17,15 @@ end it "should only show the barcodes created within the organization" do - create(:barcode_item, organization_id: @organization.id) + create(:barcode_item, organization_id: organization.id) create(:global_barcode_item) visit subject expect(page).to have_css("table tbody tr", count: 1) end it "can have a user filter the #index by barcode value" do - b = create(:barcode_item, organization: @organization) - create(:barcode_item, organization: @organization) + b = create(:barcode_item, organization: organization) + create(:barcode_item, organization: organization) visit subject fill_in "filters[by_value]", with: b.value click_button "Filter" @@ -44,8 +49,8 @@ end it "can have a user filter the #index by item type" do - b = create(:barcode_item, organization: @organization) - create(:barcode_item, organization: @organization) + b = create(:barcode_item, organization: organization) + create(:barcode_item, organization: organization) visit subject select b.item.name, from: "filters[barcodeable_id]" click_button "Filter" @@ -54,10 +59,11 @@ end it "can have a user filter the #index by base item type" do - item = create(:item, name: "Red 1T Diapers", base_item: BaseItem.first) - item2 = create(:item, name: "Blue 1T Diapers", base_item: BaseItem.first) - create(:barcode_item, organization: @organization, barcodeable: item) - create(:barcode_item, organization: @organization, barcodeable: item2) + item = create(:item, name: "Red 1T Diapers", base_item: base_item) + item2 = create(:item, name: "Blue 1T Diapers", base_item: base_item) + create(:barcode_item, organization: organization, barcodeable: item) + create(:barcode_item, organization: organization, barcodeable: item2) + visit subject select BaseItem.first.name, from: "filters[by_item_partner_key]" click_button "Filter" @@ -67,7 +73,7 @@ end context "With organization-specific barcodes" do - let(:barcode_traits) { attributes_for(:barcode_item, organization_id: @organization.id) } + let(:barcode_traits) { attributes_for(:barcode_item, organization_id: organization.id) } it "can have a user add a new barcode" do Item.delete_all @@ -89,7 +95,7 @@ context "when editing an existing barcode" do subject { url_prefix + "/barcode_items/#{barcode.id}/edit" } - let!(:barcode) { create(:barcode_item, organization_id: @organization.id) } + let!(:barcode) { create(:barcode_item, organization_id: organization.id) } it "saves the changes if they are valid" do create(:item) diff --git a/spec/system/dashboard_system_spec.rb b/spec/system/dashboard_system_spec.rb index 6429d41d82..052d5348d8 100644 --- a/spec/system/dashboard_system_spec.rb +++ b/spec/system/dashboard_system_spec.rb @@ -1,20 +1,19 @@ require 'ostruct' -RSpec.describe "Dashboard", type: :system, js: true do +RSpec.describe "Dashboard", type: :system, js: true, skip_seed: true do + let(:organization) { create(:organization, skip_items: true) } + let(:user) { create(:user, organization: organization) } + let(:organization_admin) { create(:organization_admin, organization: organization) } + context "With a new essentials bank" do - before :each do - @new_organization = create(:organization) - @user = create(:user, organization: @new_organization) - @org_short_name = new_organization.short_name - end - attr_reader :new_organization, :org_short_name, :user + let!(:org_short_name) { organization.short_name } before do sign_in(user) end it "displays the getting started guide until the steps are completed" do - org_dashboard_page = OrganizationDashboardPage.new org_short_name: org_short_name + org_dashboard_page = OrganizationDashboardPage.new(org_short_name: org_short_name) org_dashboard_page.visit # rubocop:disable Layout/ExtraSpacing @@ -27,7 +26,7 @@ expect(org_dashboard_page).not_to have_add_inventory_call_to_action # After we create a partner, ensure that we are on step 2 (Storage Locations) - @partner = create(:partner, organization: new_organization) + create(:partner, organization: organization) org_dashboard_page.visit expect(org_dashboard_page).to have_getting_started_guide @@ -37,7 +36,7 @@ expect(org_dashboard_page).not_to have_add_inventory_call_to_action # After we create a storage location, ensure that we are on step 3 (Donation Site) - create(:storage_location, organization: new_organization) + create(:storage_location, organization: organization) org_dashboard_page.visit expect(org_dashboard_page).to have_getting_started_guide @@ -47,7 +46,7 @@ expect(org_dashboard_page).not_to have_add_inventory_call_to_action # After we create a donation site, ensure that we are on step 4 (Inventory) - create(:donation_site, organization: new_organization) + create(:donation_site, organization: organization) org_dashboard_page.visit expect(org_dashboard_page).to have_getting_started_guide @@ -59,7 +58,7 @@ # rubocop:enable Layout/ExtraSpacing # After we add inventory to a storage location, ensure that the getting starting guide is gone - create(:storage_location, :with_items, item_quantity: 125, organization: new_organization) + create(:storage_location, :with_items, item_quantity: 125, organization: organization) org_dashboard_page.visit expect(org_dashboard_page).not_to have_getting_started_guide @@ -68,11 +67,11 @@ context "With an existing essentials bank" do before do - sign_in(@user) + sign_in(user) end - let!(:storage_location) { create(:storage_location, :with_items, item_quantity: 1, organization: @organization) } - let(:org_short_name) { @organization.short_name } + let!(:storage_location) { create(:storage_location, :with_items, item_quantity: 1, organization: organization) } + let(:org_short_name) { organization.short_name } let(:org_dashboard_page) { OrganizationDashboardPage.new org_short_name: org_short_name } describe "Signage" do @@ -96,7 +95,7 @@ describe "Inventory Totals" do describe "Summary" do before do - create_list(:storage_location, 3, :with_items, item_quantity: 111, organization: @organization) + create_list(:storage_location, 3, :with_items, item_quantity: 111, organization: organization) org_dashboard_page.visit end @@ -194,7 +193,7 @@ def create_next_donation(donation_date:) quantity_in_donation = @item_quantity.next - create :donation, :with_items, issued_at: donation_date, item_quantity: quantity_in_donation, storage_location: storage_location, organization: @organization + create :donation, :with_items, issued_at: donation_date, item_quantity: quantity_in_donation, storage_location: storage_location, organization: organization quantity_in_donation end @@ -313,7 +312,7 @@ def create_next_donation(donation_date:) def create_next_purchase(purchase_date:) quantity_in_purchase = @item_quantity.next - create :purchase, :with_items, issued_at: purchase_date, item_quantity: quantity_in_purchase, storage_location: storage_location, organization: @organization + create :purchase, :with_items, issued_at: purchase_date, item_quantity: quantity_in_purchase, storage_location: storage_location, organization: organization quantity_in_purchase end @@ -382,7 +381,7 @@ def create_next_product_drive_donation(donation_date:) quantity_in_donation = @item_quantity.next drive = @product_drives.sample - create :product_drive_donation, :with_items, product_drive: drive.drive, product_drive_participant: @product_drive_participant, issued_at: donation_date, item_quantity: quantity_in_donation, storage_location: storage_location, organization: @organization, + create :product_drive_donation, :with_items, product_drive: drive.drive, product_drive_participant: @product_drive_participant, issued_at: donation_date, item_quantity: quantity_in_donation, storage_location: storage_location, organization: organization, money_raised: @money_raised_on_each_product_drive OpenStruct.new drive_name: drive.name, quantity: quantity_in_donation, money_raised: @money_raised_on_each_product_drive @@ -507,8 +506,8 @@ def create_next_product_drive_donation(donation_date:) # create a different donation -- which shouldn't get included in to our totals or shown under product drive quantity_in_donation = @item_quantity.next - manufacturer = create :manufacturer, name: "Manufacturer for product drive test", organization: @organization - create :manufacturer_donation, :with_items, manufacturer: manufacturer, issued_at: test_time, item_quantity: quantity_in_donation, storage_location: storage_location, organization: @organization, money_raised: @money_raised_on_each_manufacturer_donation + manufacturer = create :manufacturer, name: "Manufacturer for product drive test", organization: organization + create :manufacturer_donation, :with_items, manufacturer: manufacturer, issued_at: test_time, item_quantity: quantity_in_donation, storage_location: storage_location, organization: organization, money_raised: @money_raised_on_each_manufacturer_donation org_dashboard_page.visit end @@ -602,7 +601,7 @@ def create_next_product_drive_donation(donation_date:) def create_next_manufacturer_donation(manufacturer:, donation_date:) quantity_in_donation = @item_quantity.next - create :manufacturer_donation, :with_items, manufacturer: manufacturer, issued_at: donation_date, item_quantity: quantity_in_donation, storage_location: storage_location, organization: @organization + create :manufacturer_donation, :with_items, manufacturer: manufacturer, issued_at: donation_date, item_quantity: quantity_in_donation, storage_location: storage_location, organization: organization quantity_in_donation end @@ -612,7 +611,7 @@ def create_next_manufacturer_donation(manufacturer:, donation_date:) @item_quantity.rewind manufacturer_name = "In-date-range Manufacturer #{index}" - manufacturer = create :manufacturer, name: manufacturer_name, organization: @organization + manufacturer = create :manufacturer, name: manufacturer_name, organization: organization # Ensure at least 1 donation in the filtered period donation_quantities = Array.new(rand(1..3)) do @@ -634,7 +633,7 @@ def create_next_manufacturer_donation(manufacturer:, donation_date:) prefix, date = _1 manufacturer_name = "#{prefix}-date-range Manufacturer" - manufacturer = create :manufacturer, name: manufacturer_name, organization: @organization + manufacturer = create :manufacturer, name: manufacturer_name, organization: organization quantity_donated = create_next_manufacturer_donation manufacturer: manufacturer, donation_date: date OpenStruct.new manufacturer_name: manufacturer_name, total_quantity_donated: quantity_donated @@ -755,14 +754,14 @@ def create_next_manufacturer_donation(manufacturer:, donation_date:) # without relying on fetching info from production code @partners = (1..rand(2..5)).map do name = "Partner #{_1}" - OpenStruct.new name: name, partner: create(:partner, name: name, organization: @organization) + OpenStruct.new name: name, partner: create(:partner, name: name, organization: organization) end def create_next_product_drive_distribution(date_picker:) quantity_in_distribution = @item_quantity.next partner = @partners.sample - create :distribution, :with_items, partner: partner.partner, issued_at: date_picker, item_quantity: quantity_in_distribution, storage_location: storage_location, organization: @organization + create :distribution, :with_items, partner: partner.partner, issued_at: date_picker, item_quantity: quantity_in_distribution, storage_location: storage_location, organization: organization OpenStruct.new partner_name: partner.name, quantity: quantity_in_distribution end diff --git a/spec/system/donation_site_system_spec.rb b/spec/system/donation_site_system_spec.rb index 449c3bcfbf..d7e75f7f82 100644 --- a/spec/system/donation_site_system_spec.rb +++ b/spec/system/donation_site_system_spec.rb @@ -1,9 +1,12 @@ -RSpec.describe "Donation Site", type: :system, js: true do +RSpec.describe "Donation Site", type: :system, js: true, skip_seed: true do + let(:organization) { create(:organization, skip_items: true) } + let(:user) { create(:user, organization: organization) } + before do - sign_in(@user) + sign_in(user) end - let(:url_prefix) { "/#{@organization.to_param}" } + let(:url_prefix) { "/#{organization.to_param}" } let(:donation_site) { create(:donation_site) } context "When a user views the index page" do diff --git a/spec/system/item_system_spec.rb b/spec/system/item_system_spec.rb index 6946fbec1e..f9967ba0d3 100644 --- a/spec/system/item_system_spec.rb +++ b/spec/system/item_system_spec.rb @@ -1,14 +1,19 @@ -RSpec.describe "Item management", type: :system do +RSpec.describe "Item management", type: :system, skip_seed: true do + let(:organization) { create(:organization, skip_items: true) } + let(:user) { create(:user, organization: organization) } + before do - sign_in(@user) + sign_in(user) end - let!(:url_prefix) { "/#{@organization.to_param}" } + let!(:url_prefix) { "/#{organization.to_param}" } it "can create a new item as a user" do - visit url_prefix + "/items/new" + create(:base_item, name: "BaseItem") item_traits = attributes_for(:item) + + visit url_prefix + "/items/new" fill_in "Name", with: item_traits[:name] - select BaseItem.last.name, from: "Base Item" + select "BaseItem", from: "Base Item" click_button "Save" expect(page.find(".alert")).to have_content "added" @@ -22,11 +27,14 @@ end it "can create a new item with dollars decimal amount for value field" do - visit url_prefix + "/items/new" + create(:base_item, name: "BaseItem") item_traits = attributes_for(:item) + + visit url_prefix + "/items/new" + fill_in "Name", with: item_traits[:name] fill_in "item_value_in_dollars", with: '1,234.56' - select BaseItem.last.name, from: "Base Item" + select "BaseItem", from: "Base Item" click_button "Save" expect(page.find(".alert")).to have_content "added" @@ -67,10 +75,13 @@ it "can filter the #index by base item as a user" do Item.delete_all - create(:item, base_item: BaseItem.first) - create(:item, base_item: BaseItem.last) + base_item1 = create(:base_item, name: "First Base Item") + base_item2 = create(:base_item) + create(:item, base_item: base_item1) + create(:item, base_item: base_item2) + visit url_prefix + "/items" - select BaseItem.first.name, from: "filters[by_base_item]" + select "First Base Item", from: "filters[by_base_item]" click_button "Filter" within "#items-table" do expect(page).to have_css("tbody tr", count: 1) @@ -160,6 +171,9 @@ end describe 'Item Category Management' do + let!(:base_item) { create(:base_item, name: "BaseItem") } + let!(:item) { create(:item, name: "SomeRandomItem", organization: organization) } + before do visit url_prefix + "/items" end @@ -177,8 +191,6 @@ end context 'and associating to a existing item' do - let(:item) { Item.first } - before do find("tr[data-item-id=\"#{item.id}\"]").find('a', text: 'Edit').click select new_item_category, from: 'Category' @@ -196,7 +208,7 @@ before do click_on 'New Item' - select BaseItem.first.name, from: 'Base Item' + select "BaseItem", from: 'Base Item' fill_in 'Name *', with: new_item_name select new_item_category, from: 'Category' diff --git a/spec/system/manage_system_spec.rb b/spec/system/manage_system_spec.rb index db46ac07ff..b81083bd54 100644 --- a/spec/system/manage_system_spec.rb +++ b/spec/system/manage_system_spec.rb @@ -1,9 +1,13 @@ -RSpec.describe "Organization Administration", type: :system, js: true do - subject { "/#{@organization.to_param}/organization" } +RSpec.describe "Organization Administration", type: :system, js: true, skip_seed: true do + let(:organization) { create(:organization, skip_items: true) } + let(:user) { create(:user, organization: organization) } + let(:organization_admin) { create(:organization_admin, organization: organization) } + + subject { "/#{organization.to_param}/organization" } context "while signed in as a normal user" do before do - sign_in(@user) + sign_in(user) visit subject end @@ -14,12 +18,12 @@ context "while signed in as an organization admin" do before do - sign_in(@organization_admin) + sign_in(organization_admin) visit subject end it "can bail back to their own site as a user" do - expect(page).to have_xpath("//a[@href='#{dashboard_path(organization_name: @organization.to_param)}']") + expect(page).to have_xpath("//a[@href='#{dashboard_path(organization_name: organization.to_param)}']") end it "can edit the properties for an organization as an admin" do @@ -33,14 +37,14 @@ context "When looking at a single organization" do before do user = create(:user, email: "yet_another_user@website.com") - user.add_role(Role::ORG_USER, @organization) + user.add_role(Role::ORG_USER, organization) visit subject end it "can view details about an organization, including the users as an admin" do - expect(page).to have_content(@organization.email) - expect(page).to have_content(@organization.address) - @organization.users.each do |u| + expect(page).to have_content(organization.email) + expect(page).to have_content(organization.address) + organization.users.each do |u| expect(page).to have_content(u.email) end end diff --git a/spec/system/partner_system_spec.rb b/spec/system/partner_system_spec.rb index 7436a65eab..b03b0e6d19 100644 --- a/spec/system/partner_system_spec.rb +++ b/spec/system/partner_system_spec.rb @@ -1,9 +1,14 @@ Capybara.using_wait_time 10 do # allow up to 10 seconds for content to load in the test - RSpec.describe "Partner management", type: :system, js: true do + RSpec.describe "Partner management", type: :system, js: true, skip_seed: true do + let(:organization) { create(:organization, skip_items: true) } + let(:user) { create(:user, organization: organization) } + let(:organization_admin) { create(:organization_admin, organization: organization) } + let(:partner) { create(:partner, organization: organization) } + before do - sign_in(@user) + sign_in(user) end - let!(:url_prefix) { "/#{@organization.to_param}" } + let!(:url_prefix) { "/#{organization.to_param}" } let!(:page_content_wait) { 10 } # allow up to 10 seconds for content to load in the test describe 'approving a partner that is awaiting approval' do @@ -62,7 +67,7 @@ end before do visit url_prefix + "/partners" - assert page.has_content? "Partner Agencies for #{@organization.name}" + assert page.has_content? "Partner Agencies for #{organization.name}" click_on 'New Partner Agency' @@ -94,7 +99,7 @@ end before do visit url_prefix + "/partners" - assert page.has_content? "Partner Agencies for #{@organization.name}" + assert page.has_content? "Partner Agencies for #{organization.name}" click_on 'New Partner Agency' fill_in 'Name *', with: partner_attributes[:name] @@ -104,7 +109,7 @@ it 'should have not added a new partner and indicate the failure' do assert page.has_content? "Failed to add partner due to: " - assert page.has_content? "New Partner for #{@organization.name}" + assert page.has_content? "New Partner for #{organization.name}" partner = Partner.find_by(name: partner_attributes[:name]) expect(partner).to eq(nil) @@ -121,7 +126,7 @@ context "when partner is uninvited and one step partner invite setting is on" do it "shows Invite and Approve button and approves the partner when clicked" do - @organization.update!(one_step_partner_invite: true) + organization.update!(one_step_partner_invite: true) visit url_prefix + "/partners" assert page.has_content? "Invite and Approve" @@ -133,11 +138,11 @@ context "when one step partner invite setting is off" do it "does not show invite and approve button" do - @organization.update!(one_step_partner_invite: false) + organization.update!(one_step_partner_invite: false) visit url_prefix + "/partners" - assert page.should have_no_content "Invite and Approve" + expect(page).to_not have_content "Invite and Approve" end end end @@ -147,8 +152,8 @@ let!(:partner_to_request_recertification) { create(:partner, status: 'approved') } before do - sign_in(@user) - visit partners_path(@organization) + sign_in(user) + visit partners_path(organization) end it 'should notify the user that its been successful and change the partner status' do @@ -156,7 +161,7 @@ find_button('Request Recertification').click end - assert page.has_content? "#{partner_to_request_recertification.name} recertification successfully requested!" + expect(page).to have_content "#{partner_to_request_recertification.name} recertification successfully requested!" expect(partner_to_request_recertification.reload.recertification_required?).to eq(true) end end @@ -164,23 +169,23 @@ describe "#index" do before(:each) do - @uninvited = create(:partner, name: "Bcd", status: :uninvited) - @invited = create(:partner, name: "Abc", status: :invited) - @approved = create(:partner, :approved, name: "Cde", status: :approved) - @deactivated = create(:partner, name: "Def", status: :deactivated) + @uninvited = create(:partner, name: "Bcd", status: :uninvited, organization: organization) + @invited = create(:partner, name: "Abc", status: :invited, organization: organization) + @approved = create(:partner, :approved, name: "Cde", status: :approved, organization: organization) + @deactivated = create(:partner, name: "Def", status: :deactivated, organization: organization) visit url_prefix + "/partners" end it "displays the partner agency names in alphabetical order" do - expect(page).to have_css("table tr", count: 5, wait: page_content_wait) + expect(page).to have_css("table tr", count: 4, wait: page_content_wait) expect(page.find(:xpath, "//table/tbody/tr[1]/td[1]")).to have_content(@invited.name) expect(page.find(:xpath, "//table/tbody/tr[3]/td[1]")).to have_content(@approved.name) - expect(page.find(:xpath, %(//*[@id="partner-status"]))).to have_content("4 Active") + expect(page.find(:xpath, %(//*[@id="partner-status"]))).to have_content("3 Active") expect(page.find(:xpath, %(//*[@id="partner-status"]))).to have_content("1 Deactivated") end it "allows a user to invite a partner", js: true do - partner = create(:partner, name: 'Charities') + partner = create(:partner, name: 'Charities', organization: organization) partner.primary_user.delete visit url_prefix + "/partners" @@ -190,8 +195,8 @@ within(ele) { click_on "Invite" } end - # assert page.has_content? "Partner #{partner.name} invited!", wait: page_content_wait - # expect(page.find(".alert")).to have_content "invited!", wait: page_content_wait + expect(page).to have_content "Partner #{partner.name} invited!", wait: page_content_wait + expect(page.find(".alert")).to have_content "invited!", wait: page_content_wait end it "shows invite button only for unapproved partners" do @@ -256,7 +261,7 @@ context "when viewing an invited partner as a partner" do let(:partner) { create(:partner, name: "Invited Partner", status: :invited) } before do - sign_out(@user) + sign_out(user) sign_in(partner.users.first) end it "redirects user to partners page root page (dashboard) with error message" do @@ -418,14 +423,14 @@ describe 'changing partner group association' do before do - sign_in(@user) - visit url_prefix + "/partners/#{@partner.id}" + sign_in(user) + visit url_prefix + "/partners/#{partner.id}" end let!(:existing_partner_group) { create(:partner_group) } context 'when the partner has no partner group' do before do - expect(@partner.partner_group).to be_nil + expect(partner.partner_group).to be_nil end it 'it should say they can request every item' do @@ -437,12 +442,12 @@ context 'when a partner is assigned to partner group' do before do assert page.has_content? 'All Items Requestable' - @partner.update!(partner_group: nil) + partner.update!(partner_group: nil) end context 'that has requestable item categories' do let!(:item_category) do - ic = create(:item_category, organization: @organization) + ic = create(:item_category, organization: organization) existing_partner_group.item_categories << ic ic end @@ -456,7 +461,7 @@ it 'should properly indicate the requestable items and adjust the partners requestable items' do assert page.has_content? item_category.name - expect { @partner.reload }.to change(@partner, :requestable_items).from([]).to(match_array(items_in_category)) + expect { partner.reload }.to change(partner, :requestable_items).from([]).to(match_array(items_in_category)) end end @@ -470,7 +475,7 @@ it 'should properly indicate the requestable items and adjust the partners requestable items' do assert page.has_content? 'No Items Requestable' - expect { @partner.reload }.to change(@partner, :requestable_items).from([]).to([]) + expect { partner.reload }.to change(partner, :requestable_items).from([]).to([]) end end end @@ -478,12 +483,12 @@ describe "partner group management", type: :system, js: true do before do - sign_in(@user) + sign_in(user) end - let!(:url_prefix) { "/#{@organization.to_param}" } - let!(:item_category_1) { create(:item_category, organization: @organization) } - let!(:item_category_2) { create(:item_category, organization: @organization) } + let!(:url_prefix) { "/#{organization.to_param}" } + let!(:item_category_1) { create(:item_category, organization: organization) } + let!(:item_category_2) { create(:item_category, organization: organization) } let!(:items_in_category_1) { create_list(:item, 3, item_category_id: item_category_1.id) } let!(:items_in_category_2) { create_list(:item, 3, item_category_id: item_category_2.id) } @@ -507,7 +512,7 @@ end describe 'editing a existing partner group' do - let!(:existing_partner_group) { create(:partner_group, organization: @organization) } + let!(:existing_partner_group) { create(:partner_group, organization: organization) } before do existing_partner_group.item_categories << item_category_1 end