-
-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent global state modification by tests
- Loading branch information
1 parent
e877802
commit 08a811d
Showing
12 changed files
with
193 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "Users", type: :request, clean_and_seed_db: true do | ||
RSpec.describe "Users", type: :request, seed_db: 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) } | ||
let(:default_params) do | ||
{ organization_name: @organization.to_param } | ||
{ organization_name: organization.to_param } | ||
end | ||
|
||
before do | ||
sign_in(@user) | ||
sign_in(user) | ||
end | ||
|
||
describe "GET #index" do | ||
|
@@ -25,13 +29,13 @@ | |
end | ||
|
||
describe "POST #send_partner_user_reset_password" do | ||
let(:partner) { create(:partner) } | ||
let(:partner) { create(:partner, organization: organization) } | ||
let!(:user) { create(:partner_user, partner: partner, email: "[email protected]") } | ||
let(:params) { default_params.merge(partner_id: partner.id, email: "[email protected]") } | ||
|
||
it "should send a password" do | ||
post partner_user_reset_password_users_path(params) | ||
expect(response).to redirect_to(root_path(organization_name: @organization.to_param)) | ||
expect(response).to redirect_to(root_path(organization_name: organization.to_param)) | ||
expect(ActionMailer::Base.deliveries.size).to eq(1) | ||
end | ||
|
||
|
@@ -62,21 +66,21 @@ | |
end | ||
context "with a partner role" do | ||
it "should redirect to the partner path" do | ||
@user.add_role(Role::PARTNER, partner) | ||
get switch_to_role_users_path(@organization, | ||
role_id: @user.roles.find { |r| r.name == Role::PARTNER.to_s }) | ||
user.add_role(Role::PARTNER, partner) | ||
get switch_to_role_users_path(organization, | ||
role_id: user.roles.find { |r| r.name == Role::PARTNER.to_s }) | ||
# all bank controllers add organization_id to all routes - there's no way to | ||
# avoid it | ||
expect(response).to redirect_to(partners_dashboard_path(organization_name: @organization.to_param)) | ||
expect(response).to redirect_to(partners_dashboard_path(organization_name: organization.to_param)) | ||
end | ||
end | ||
|
||
context "without a partner role" do | ||
it "should redirect to the root path with an error" do | ||
get switch_to_role_users_path(@organization, role_id: admin_user.roles.first.id) | ||
get switch_to_role_users_path(organization, role_id: admin_user.roles.first.id) | ||
message = "Attempted to switch to a role that doesn't belong to you!" | ||
expect(flash[:alert]).to eq(message) | ||
expect(response).to redirect_to(root_path(@organization)) | ||
expect(response).to redirect_to(root_path(organization)) | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.