Skip to content

Commit 6603dd5

Browse files
elasticspoondorner
authored andcommitted
refactor: removed db seeding dependency
find and replace in requests
1 parent e68403a commit 6603dd5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+297
-220
lines changed

spec/requests/account_requests_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'rails_helper'
22

3-
RSpec.describe "/account_requests", type: :request do
3+
RSpec.describe "/account_requests", type: :request, skip_seed: true do
44
describe "GET #new" do
55
it "renders a successful response" do
66
get new_account_request_url
@@ -37,7 +37,7 @@
3737
context 'when given a token that has already been confirmed' do
3838
let!(:account_request) { FactoryBot.create(:account_request) }
3939
before do
40-
FactoryBot.create(:organization, account_request_id: account_request.id)
40+
create(:organization, account_request_id: account_request.id)
4141
end
4242

4343
it 'should render a error that says that is code provided is invalid' do

spec/requests/adjustments_requests_spec.rb

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
require "rails_helper"
22

3-
RSpec.describe "Adjustments", type: :request do
3+
RSpec.describe "Adjustments", type: :request, skip_seed: true do
4+
let(:organization) { create(:organization, skip_items: true) }
5+
let(:user) { create(:user, organization: organization) }
6+
47
let(:default_params) do
5-
{ organization_name: @organization.to_param }
8+
{ organization_name: organization.to_param }
69
end
710

811
# This should return the minimal set of attributes required to create a valid
912
# Adjustment. As you add validations to Adjustment, be sure to
1013
# adjust the attributes here as well.
1114
let(:valid_attributes) do
1215
{
13-
organization_id: @organization.id,
14-
storage_location_id: create(:storage_location, organization: @organization).id
16+
organization_id: organization.id,
17+
storage_location_id: create(:storage_location, organization: organization).id
1518
}
1619
end
1720

@@ -24,11 +27,11 @@
2427
# AdjustmentsController. Be sure to keep this updated too.
2528
let(:valid_session) { {} }
2629

27-
let(:adjustment) { Adjustment.create! valid_attributes.merge(user_id: @user.id) }
30+
let(:adjustment) { Adjustment.create! valid_attributes.merge(user_id: user.id) }
2831

2932
describe "while signed in" do
3033
before do
31-
sign_in(@user)
34+
sign_in(user)
3235
end
3336

3437
describe "GET #index" do
@@ -113,7 +116,7 @@
113116

114117
it "assigns a user id from the current user" do
115118
post adjustments_path(default_params.merge(adjustment: valid_attributes))
116-
expect(assigns(:adjustment).user_id).to eq(@user.id)
119+
expect(assigns(:adjustment).user_id).to eq(user.id)
117120
end
118121

119122
it "redirects to the #show after created adjustment" do

spec/requests/admin/account_requests_requests_spec.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
require 'rails_helper'
22

3-
RSpec.describe 'Admin::AccountRequestsController', type: :request do
3+
RSpec.describe 'Admin::AccountRequestsController', type: :request, skip_seed: true do
4+
let(:organization) { create(:organization, skip_items: true) }
5+
46
context 'while signed in as a super admin' do
57
before do
6-
sign_in(@super_admin)
8+
sign_in(create(:super_admin, organization: organization))
79
end
810

911
describe 'GET #index' do
@@ -14,7 +16,7 @@
1416
end
1517

1618
describe 'GET #for_rejection' do
17-
let(:account_request) { FactoryBot.create(:account_request, organization_name: 'Test Org 1') }
19+
let(:account_request) { create(:account_request, organization_name: 'Test Org 1') }
1820

1921
context 'with an invalid token' do
2022
it 'should show a not found message' do
@@ -26,7 +28,7 @@
2628

2729
context 'with a valid token' do
2830
it 'should show the request' do
29-
FactoryBot.create(:account_request, organization_name: 'Test Org 2')
31+
create(:account_request, organization_name: 'Test Org 2')
3032
allow(AccountRequest).to receive(:get_by_identity_token).and_return(account_request)
3133
get for_rejection_admin_account_requests_path(token: 'my token')
3234
expect(response.body).to match(/Test Org 1/)

spec/requests/admin/barcode_items_requests_spec.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
require 'rails_helper'
22

3-
RSpec.describe 'Admin::BarcodeItemsController', type: :request do
3+
RSpec.describe 'Admin::BarcodeItemsController', type: :request, skip_seed: true do
4+
let(:organization) { create(:organization, skip_items: true) }
5+
46
context 'while signed in as a super admin' do
57
before do
6-
sign_in(@super_admin)
8+
sign_in(create(:super_admin, organization: organization))
79
end
810

911
describe 'GET #index' do

spec/requests/admin/base_items_requests_spec.rb

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
require 'rails_helper'
22

3-
RSpec.describe "Admin::BaseItems", type: :request do
3+
RSpec.describe "Admin::BaseItems", type: :request, skip_seed: true do
4+
let(:organization) { create(:organization, skip_items: true) }
5+
let(:user) { create(:user, organization: organization) }
6+
let(:organization_admin) { create(:organization_admin, organization: organization) }
7+
8+
# TODO: should this be testing something?
49
context "while signed in as a super admin" do
510
before do
611
sign_in(@super_admin)
@@ -9,7 +14,7 @@
914

1015
context "When logged in as an organization admin" do
1116
before do
12-
sign_in(@organization_admin)
17+
sign_in(organization_admin)
1318
end
1419

1520
describe "GET #new" do
@@ -35,28 +40,28 @@
3540

3641
describe "GET #show" do
3742
it "returns http success" do
38-
get admin_base_item_path(id: @organization.id)
43+
get admin_base_item_path(id: organization.id)
3944
expect(response).to have_http_status(:found)
4045
end
4146
end
4247

4348
describe "GET #edit" do
4449
it "returns http success" do
45-
get edit_admin_base_item_path(id: @organization.id)
50+
get edit_admin_base_item_path(id: organization.id)
4651
expect(response).to have_http_status(:found)
4752
end
4853
end
4954

5055
describe "PUT #update" do
5156
it "redirect" do
52-
put admin_base_item_path(id: @organization.id, organization: { name: "Foo" })
57+
put admin_base_item_path(id: organization.id, organization: { name: "Foo" })
5358
expect(response).to be_redirect
5459
end
5560
end
5661

5762
describe "DELETE #destroy" do
5863
it "redirects" do
59-
delete admin_base_item_path(id: @organization.id)
64+
delete admin_base_item_path(id: organization.id)
6065
expect(response).to be_redirect
6166
end
6267
end

spec/requests/admin/broadcast_announcements_spec.rb

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
require "rails_helper"
22

3-
RSpec.describe "BroadcastAnnouncements", type: :request do
3+
RSpec.describe "BroadcastAnnouncements", type: :request, skip_seed: true do
4+
let(:organization) { create(:organization, skip_items: true) }
5+
let(:user) { create(:super_admin, organization: organization) }
6+
let(:super_admin) { create(:super_admin, organization: organization) }
7+
let(:organization_admin) { create(:organization_admin, organization: organization) }
8+
49
before do
5-
sign_in(@super_admin)
10+
sign_in(super_admin)
611
end
12+
713
let(:valid_attributes) {
814
{
915
expiry: Time.zone.today,
1016
link: "http://google.com",
1117
message: "test",
12-
user_id: @user.id,
18+
user_id: user.id,
1319
organization_id: nil
1420
}
1521
}
@@ -74,8 +80,8 @@
7480
expiry: Time.zone.yesterday,
7581
link: "http://google.com",
7682
message: "new_test",
77-
user_id: @user.id,
78-
organization_id: @organization.id
83+
user_id: user.id,
84+
organization_id: organization.id
7985
}
8086
}
8187

@@ -109,20 +115,20 @@
109115

110116
context "When logged in as an organization_admin" do
111117
before do
112-
sign_in @organization_admin
118+
sign_in organization_admin
113119
end
114120

115121
describe "GET /new" do
116122
it "redirects" do
117123
get new_admin_broadcast_announcement_url
118-
expect(response).to redirect_to(dashboard_path(organization_name: @organization_admin.organization))
124+
expect(response).to redirect_to(dashboard_path(organization_name: organization_admin.organization))
119125
end
120126
end
121127

122128
describe "POST /create" do
123129
it "redirects" do
124-
post admin_broadcast_announcements_url, params: {user: @user.id, message: "test"}
125-
expect(response).to redirect_to(dashboard_path(organization_name: @organization_admin.organization))
130+
post admin_broadcast_announcements_url, params: {user: user.id, message: "test"}
131+
expect(response).to redirect_to(dashboard_path(organization_name: organization_admin.organization))
126132
end
127133
end
128134
end

spec/requests/admin/ndbn_members_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "rails_helper"
22

3-
RSpec.describe "NDBNMembers", type: :request do
3+
RSpec.describe "NDBNMembers", type: :request, skip_seed: true do
44
let(:user) { create(:super_admin) }
55

66
before do

spec/requests/admin/organizations_requests_spec.rb

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
RSpec.describe "Admin::Organizations", type: :request do
1+
RSpec.describe "Admin::Organizations", type: :request, skip_seed: true do
2+
let(:organization) { create(:organization, skip_items: true) }
23
let(:default_params) do
3-
{ organization_name: @organization.id }
4+
{ organization_name: organization.id }
45
end
56

67
context "When logged in as a super admin" do
78
before do
8-
sign_in(@super_admin)
9+
sign_in(create(:super_admin, organization: organization))
910
end
1011

1112
describe "GET #new" do
@@ -15,10 +16,10 @@
1516
end
1617

1718
context 'when given a valid account request token in the query parameters' do
18-
let!(:account_request) { FactoryBot.create(:account_request) }
19+
let!(:account_request) { create(:account_request) }
1920

2021
it 'should render new with pre populate input fields from the account_request' do
21-
ndbn_member = FactoryBot.create(:ndbn_member)
22+
ndbn_member = create(:ndbn_member)
2223
account_request.ndbn_member = ndbn_member
2324
account_request.save
2425

@@ -160,22 +161,22 @@
160161

161162
describe "PUT #update" do
162163
it "redirect" do
163-
put admin_organization_path({ id: @organization.id, organization: { name: "Foo" } })
164+
put admin_organization_path({ id: organization.id, organization: { name: "Foo" } })
164165
expect(response).to be_redirect
165166
end
166167
end
167168

168169
describe "DELETE #destroy" do
169170
it "redirects" do
170-
delete admin_organization_path({ id: @organization.id })
171+
delete admin_organization_path({ id: organization.id })
171172
expect(response).to redirect_to(admin_organizations_path)
172173
end
173174
end
174175
end
175176

176177
context "When logged in as a non-admin user" do
177178
before do
178-
sign_in(@user)
179+
sign_in(create(:user, organization: organization))
179180
end
180181

181182
describe "GET #new" do
@@ -201,14 +202,14 @@
201202

202203
describe "GET #edit" do
203204
it "redirects" do
204-
get edit_admin_organization_path({ id: @organization.id })
205+
get edit_admin_organization_path({ id: organization.id })
205206
expect(response).to be_redirect
206207
end
207208
end
208209

209210
describe "PUT #update" do
210211
it "redirects" do
211-
put admin_organization_path({ id: @organization.id, organization: { name: "Foo" } })
212+
put admin_organization_path({ id: organization.id, organization: { name: "Foo" } })
212213
expect(response).to be_redirect
213214
end
214215
end

spec/requests/admin/partners_requests_spec.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
require 'rails_helper'
22

3-
RSpec.describe "Admin::Partners", type: :request do
3+
RSpec.describe "Admin::Partners", type: :request, skip_seed: true do
4+
let(:organization) { create(:organization, skip_items: true) }
5+
let(:user) { create(:user, organization: organization) }
6+
let(:organization_admin) { create(:organization_admin, organization: organization) }
7+
48
context "When logged in as a super admin" do
59
before do
6-
sign_in(@super_admin)
10+
sign_in(create(:super_admin, organization: nil))
711
end
812

913
let(:partner) { create(:partner) }

spec/requests/admin/questions_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
require "rails_helper"
22

3-
RSpec.describe "Admin::Questions", type: :request do
3+
RSpec.describe "Admin::Questions", type: :request, skip_seed: true do
44
context "while signed in as a super admin" do
55
before do
6-
sign_in(@super_admin_no_org)
6+
sign_in(create(:super_admin, organization: nil))
77
end
88

99
describe "GET #index" do

spec/requests/admin_requests_spec.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
RSpec.describe "Admin", type: :request do
1+
RSpec.describe "Admin", type: :request, 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+
26
context "while signed in as a super admin" do
37
before do
4-
sign_in(@super_admin_no_org)
8+
sign_in(create(:super_admin, organization: nil))
59
end
610

711
it "allows a user to load the dashboard" do
@@ -52,7 +56,7 @@
5256

5357
context "while signed in as a non-super-admin" do
5458
it "disallows dashboard access, redirecting to the normal dashboard" do
55-
[@organization_admin, @user].each do |u|
59+
[organization_admin, user].each do |u|
5660
sign_in(u)
5761
get admin_dashboard_path
5862
expect(response).to redirect_to(dashboard_path(organization_name: u.organization))

spec/requests/attachments_requests_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
RSpec.describe "Attachments", type: :request do
1+
RSpec.describe "Attachments", type: :request, skip_seed: true do
22
before do
3-
sign_in(@user)
3+
sign_in(create(:user))
44
end
55

66
describe "DELETE #destroy" do

0 commit comments

Comments
 (0)