Skip to content

Commit ce7d144

Browse files
authored
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
1 parent d103c7e commit ce7d144

14 files changed

Lines changed: 226 additions & 163 deletions

spec/system/account_request_system_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
RSpec.describe 'Account request flow', type: :system, js: true do
1+
RSpec.describe 'Account request flow', type: :system, js: true, skip_seed: true do
2+
let(:organization) { create(:organization, skip_items: true) }
3+
let(:super_admin) { create(:super_admin, organization: organization) }
4+
25
context 'when in staging' do
36
before do
47
allow(Rails.env).to receive(:staging?).and_return(true)
@@ -53,7 +56,7 @@
5356
expect(page).to have_content('We will be processing your request now.')
5457

5558
# Access link within email sent to admin user to process the request.
56-
sign_in(@super_admin)
59+
sign_in(super_admin)
5760
visit new_admin_organization_path(token: created_account_request.identity_token)
5861

5962
fill_in 'Short name', with: 'fakeshortname'

spec/system/admin/account_requests_system_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
RSpec.describe "Account Requests Admin", type: :system do
1+
RSpec.describe "Account Requests Admin", type: :system, skip_seed: true do
2+
let(:super_admin) { create(:super_admin) }
3+
24
context "while signed in as a super admin" do
35
let!(:request1) { create(:account_request, confirmed_at: Time.zone.today, status: 'admin_approved') }
46
let!(:request2) {
@@ -11,7 +13,7 @@
1113
let!(:request6) { create(:account_request, created_at: Time.zone.today - 2.days, status: 'started') }
1214

1315
before do
14-
sign_in(@super_admin)
16+
sign_in(super_admin)
1517
end
1618

1719
around do |ex|

spec/system/admin/barcode_items_system_spec.rb

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
RSpec.describe "Barcode Items Admin", type: :system do
1+
RSpec.describe "Barcode Items Admin", type: :system, skip_seed: true do
2+
let(:organization) { create(:organization, skip_items: true) }
3+
let(:super_admin) { create(:super_admin, organization: organization) }
4+
5+
let!(:base_item) { create(:base_item) }
6+
let!(:item) { create(:item, base_item: base_item) }
7+
let!(:barcode_item) { create(:global_barcode_item, base_item: base_item) }
8+
29
context "while signed in as a super admin" do
310
before do
4-
sign_in(@super_admin)
11+
sign_in(super_admin)
512
end
613

714
context "user visits the index page" do
8-
let!(:item) { create(:item) }
9-
let!(:base_item) { create(:base_item) }
10-
let!(:barcode_item) { create(:global_barcode_item) }
11-
1215
before do
1316
visit admin_barcode_items_path
1417
end
@@ -38,9 +41,6 @@
3841
end
3942

4043
context "user visits the new page" do
41-
let!(:item) { create(:item) }
42-
let!(:base_item) { create(:base_item) }
43-
4444
before do
4545
visit new_admin_barcode_item_path
4646
end
@@ -58,10 +58,6 @@
5858
end
5959

6060
context "user visits the edit page" do
61-
let!(:item) { create(:item) }
62-
let!(:base_item) { create(:base_item) }
63-
let!(:barcode_item) { create(:global_barcode_item) }
64-
6561
before do
6662
visit edit_admin_barcode_item_path(barcode_item)
6763
end
@@ -79,8 +75,6 @@
7975
end
8076

8177
context "user visits the show page" do
82-
let!(:barcode_item) { create(:global_barcode_item) }
83-
8478
before do
8579
visit admin_barcode_item_path(barcode_item)
8680
end

spec/system/admin/base_items_system_spec.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
RSpec.describe "Base Item Admin", type: :system, js: true do
1+
RSpec.describe "Base Item Admin", type: :system, js: true, skip_seed: true do
2+
let(:organization) { create(:organization, skip_items: true) }
3+
let(:user) { create(:user, organization: organization) }
4+
let(:super_admin) { create(:super_admin, organization: organization) }
5+
let(:super_admin_no_org) { create(:super_admin, organization: nil) }
6+
let(:base_item) { create(:base_item) }
7+
28
context "While signed in as an Administrative User (super admin)" do
39
before do
4-
sign_in(@super_admin)
10+
sign_in(super_admin)
511
end
612

713
let!(:url_prefix) {}
@@ -30,7 +36,6 @@
3036
before do
3137
visit edit_admin_base_item_path(base_item)
3238
end
33-
let(:base_item) { BaseItem.first }
3439

3540
it "should succeed when changing the name" do
3641
fill_in "Name", with: base_item.name + " new"
@@ -46,8 +51,7 @@
4651
end
4752

4853
it "can view a listing of all Base Items that shows a summary of its sub-items" do
49-
base_item = BaseItem.first
50-
create_list(:item, 2, base_item: base_item)
54+
create_list(:item, 2, base_item: base_item, organization: organization)
5155
count = base_item.item_count
5256
visit admin_base_items_path
5357
expect(page).to have_content(base_item.name)
@@ -57,15 +61,14 @@
5761
end
5862

5963
it "can view a single Base Item" do
60-
base_item = BaseItem.first
6164
visit admin_base_item_path(base_item)
6265
expect(page).to have_content(base_item.name)
6366
end
6467
end
6568

6669
context "While signed in as an Administrative User with no organization (super admin no org)" do
6770
before do
68-
sign_in(@super_admin_no_org)
71+
sign_in(super_admin_no_org)
6972
end
7073

7174
let!(:url_prefix) {}
@@ -94,7 +97,6 @@
9497
before do
9598
visit edit_admin_base_item_path(base_item)
9699
end
97-
let(:base_item) { BaseItem.first }
98100

99101
it "should succeed when changing the name" do
100102
fill_in "Name", with: base_item.name + " new"
@@ -110,8 +112,7 @@
110112
end
111113

112114
it "can view a listing of all Base Items that shows a summary of its sub-items" do
113-
base_item = BaseItem.first
114-
create_list(:item, 2, base_item: base_item)
115+
create_list(:item, 2, base_item: base_item, organization: organization)
115116
count = base_item.item_count
116117
visit admin_base_items_path
117118
expect(page).to have_content(base_item.name)
@@ -121,24 +122,25 @@
121122
end
122123

123124
it "can view a single Base Item" do
124-
base_item = BaseItem.first
125125
visit admin_base_item_path(base_item)
126126
expect(page).to have_content(base_item.name)
127127
end
128128
end
129129

130130
context "While signed in as a normal user" do
131131
before do
132-
sign_in(@user)
132+
sign_in(user)
133133
end
134134
it "should have a normal user not see anything" do
135135
visit new_admin_base_item_path
136136
expect(page).to have_content("Access Denied")
137+
137138
visit admin_base_items_path
138139
expect(page).to have_content("Access Denied")
139-
base_item = create(:base_item)
140+
140141
visit admin_base_item_path(base_item)
141142
expect(page).to have_content("Access Denied")
143+
142144
visit edit_admin_base_item_path(base_item)
143145
expect(page).to have_content("Access Denied")
144146
end

spec/system/admin/organizations_system_spec.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
RSpec.describe "Admin Organization Management", type: :system, js: true do
2-
let!(:foo_org) { create(:organization, name: 'foo') }
3-
let!(:bar_org) { create(:organization, name: 'bar') }
4-
let!(:baz_org) { create(:organization, name: 'baz') }
1+
RSpec.describe "Admin Organization Management", type: :system, js: true, skip_seed: true do
2+
let(:organization) { create(:organization, skip_items: true) }
3+
let(:super_admin) { create(:super_admin, organization: organization) }
4+
let(:super_admin_no_org) { create(:super_admin, organization: nil) }
5+
6+
let!(:foo_org) { create(:organization, name: 'foo', skip_items: true) }
7+
let!(:bar_org) { create(:organization, name: 'bar', skip_items: true) }
8+
let!(:baz_org) { create(:organization, name: 'baz', skip_items: true) }
59

610
context "While signed in as an Administrative User (super admin)" do
711
before :each do
8-
sign_in(@super_admin)
12+
sign_in(super_admin)
913
end
1014

1115
it "filters by organizations by name in organizations index page" do
@@ -91,7 +95,7 @@
9195
end
9296
context "While signed in as an Administrative User with no organization (super admin no org)" do
9397
before :each do
94-
sign_in(@super_admin_no_org)
98+
sign_in(super_admin_no_org)
9599
end
96100

97101
it "creates a new organization" do

spec/system/admin/users_system_spec.rb

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
RSpec.describe "Admin Users Management", type: :system, js: true do
1+
RSpec.describe "Admin Users Management", type: :system, js: true, skip_seed: true do
2+
let(:organization) { create(:organization, skip_items: true) }
3+
let(:user) { create(:user, organization: organization) }
4+
let(:organization_admin) { create(:organization_admin, organization: organization) }
5+
let(:super_admin) { create(:super_admin, organization: organization) }
6+
27
context "While signed in as an Administrative User (super admin)" do
38
before do
4-
sign_in(@super_admin)
9+
sign_in(super_admin)
510
end
611

712
it "creates an user" do
@@ -16,24 +21,28 @@
1621
end
1722

1823
it "edits an existing user" do
24+
create(:user, organization: organization, name: "AAlphabetically First User")
25+
1926
visit admin_users_path
2027
click_link "Edit", match: :first
21-
expect(page).to have_content("Update #{@organization_admin.name}")
28+
expect(page).to have_content("Update AAlphabetically First User")
29+
2230
fill_in "user_name", with: "TestUser"
23-
select(@organization.name, from: 'user_organization_id')
31+
select(organization.name, from: 'user_organization_id')
2432
click_on "Save"
2533

2634
expect(page.find(".alert")).to have_content "TestUser updated"
2735

2836
# Check if the organization role has been updated
2937
tbody = find('#filterrific_results table tbody')
3038
first_row = tbody.find('tr', text: 'TestUser')
31-
expect(first_row).to have_text(@organization.name)
39+
expect(first_row).to have_text(organization.name)
3240
end
3341

3442
it 'adds a role' do
35-
user = FactoryBot.create(:user, name: 'User 123')
36-
FactoryBot.create(:partner, name: 'Partner ABC')
43+
user = create(:user, name: 'User 123', organization: organization)
44+
create(:partner, name: 'Partner ABC', organization: organization)
45+
3746
visit edit_admin_user_path(user)
3847
expect(page).to have_content('User 123')
3948
select "Partner", from: "resource_type"
@@ -48,7 +57,10 @@
4857
end
4958

5059
it "deletes an existing user" do
60+
create(:user, organization: organization, name: "AAlphabetically First User")
61+
5162
visit admin_users_path
63+
5264
page.accept_confirm do
5365
click_link "Delete", match: :first
5466
end
@@ -57,22 +69,29 @@
5769
end
5870

5971
it "filters users by name" do
60-
user_names = User.all.pluck(:name)
72+
create(:user, name: "UserA", organization: organization)
73+
create(:user, name: "UserB", organization: organization)
74+
create(:user, name: "UserC", organization: organization)
75+
76+
user_names = ["UserA", "UserB", "UserC"]
6177

6278
visit admin_users_path
79+
6380
user_names.each do |name|
6481
expect(page.find("table")).to have_content(name)
6582
end
6683

6784
fill_in "filterrific_search_name", with: user_names.first
85+
6886
user_names[1..].each do |name|
6987
expect(page.find("table")).not_to have_content(name)
7088
end
89+
7190
expect(page.find("table")).to have_content(user_names.first)
7291
end
7392

7493
it "filters users by email" do
75-
user_email = @organization_admin.email
94+
user_email = organization_admin.email
7695

7796
visit admin_users_path
7897
fill_in "filterrific_search_email", with: user_email

spec/system/annual_reports_system_spec.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
RSpec.describe "Annual Reports", type: :system, js: true do
2-
let(:url_prefix) { "/#{@organization.short_name}" }
1+
RSpec.describe "Annual Reports", type: :system, js: true, skip_seed: true do
2+
let(:organization) { create(:organization, skip_items: true) }
3+
let(:organization_admin) { create(:organization_admin, organization: organization) }
4+
5+
let(:url_prefix) { "/#{organization.short_name}" }
36

47
context "while signed in as an organization admin" do
58
subject { url_prefix + "/reports/annual_reports" }
6-
let!(:purchase) { create(:purchase, :with_items, item_quantity: 10, issued_at: 1.year.ago) }
9+
let!(:purchase) { create(:purchase, :with_items, item_quantity: 10, issued_at: 1.year.ago, organization: organization) }
710

811
before do
9-
sign_in @organization_admin
12+
sign_in organization_admin
1013
visit subject.to_s
1114
end
1215

0 commit comments

Comments
 (0)