Skip to content

Commit

Permalink
Merge partner user factories into one
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyli97 committed Jul 16, 2024
1 parent 592cf81 commit f431a68
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 42 deletions.
16 changes: 0 additions & 16 deletions spec/factories/partner_user.rb

This file was deleted.

16 changes: 0 additions & 16 deletions spec/factories/partners/user.rb

This file was deleted.

16 changes: 16 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@
end
end

factory :partners_user do
name { "Partner User" }
sequence(:email) { |n| "partner_user_#{n}@example.com" }
password { "password!" }
password_confirmation { "password!" }
invitation_sent_at { Time.current - 1.day }
last_sign_in_at { Time.current }
organization { nil }
transient do
partner { Partner.first || create(:partner) }
end
after(:create) do |instance, evaluator|
instance.add_role(Role::PARTNER, evaluator.partner)
end
end

factory :organization_admin do
name { "Very Organized Admin" }
after(:create) do |user, evaluator|
Expand Down
6 changes: 3 additions & 3 deletions spec/mailers/custom_devise_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RSpec.describe CustomDeviseMailer, type: :mailer do
describe "#invitation_instructions" do
let(:user) { create(:partner_user) }
let(:user) { create(:partners_user) }
let(:mail) { described_class.invitation_instructions(user, SecureRandom.uuid) }

context "when partner is invited" do
Expand All @@ -12,7 +12,7 @@
end

let(:user) do
create(:partner_user, partner: partner)
create(:partners_user, partner: partner)
end

it "invites to primary user" do
Expand All @@ -23,7 +23,7 @@

context "when other partner users invited" do
let(:partner) { create(:partner) }
let(:user) { create(:partner_user, partner: partner) }
let(:user) { create(:partners_user, partner: partner) }

it "invites to partner user" do
expect(mail.subject).to eq("You've been invited to #{user.partner.name}'s Human Essentials account")
Expand Down
2 changes: 1 addition & 1 deletion spec/models/distribution_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
item2 = create(:item, name: "Item2", organization: organization)
request = create(:request,
organization: organization,
partner_user: create(:partner_user),
partner_user: create(:partners_user),
request_items: [
{ item_id: item1.id, quantity: 15 },
{ item_id: item2.id, quantity: 18 }
Expand Down
8 changes: 4 additions & 4 deletions spec/models/users_role_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@

context "for partner user" do
it "should return partner user" do
user = create(:partner_user)
user = create(:partners_user)
expect(UsersRole.current_role_for(user).name).to eq("partner")
end
end
end
context "when last_role is not nil" do
it "should return last role" do
user = create(:partner_user)
user = create(:partners_user)

UsersRole.set_last_role_for(user, user.roles.last)

Expand All @@ -52,7 +52,7 @@
describe "#set_last_role_for" do
context "when user has the role" do
it "should set last role" do
user = create(:partner_user)
user = create(:partners_user)
role = user.roles.first

UsersRole.set_last_role_for(user, role)
Expand All @@ -63,7 +63,7 @@

context "when user does not have the role" do
it "should not set last role" do
user = create(:partner_user)
user = create(:partners_user)
role = Role.find_by(name: "org_user")

UsersRole.set_last_role_for(user, role)
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/sessions_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
end

describe "POST #create" do
let(:partner_user) { create(:partner_user) }
let(:partner_user) { create(:partners_user) }
let(:partner_role) { partner_user.roles.first }
let(:organization) { create(:organization) }

Expand Down
2 changes: 1 addition & 1 deletion spec/requests/users_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

describe "POST #send_partner_user_reset_password" do
let(:partner) { create(:partner, organization: organization) }
let!(:user) { create(:partner_user, partner: partner, email: "me@partner.com") }
let!(:user) { create(:partners_user, partner: partner, email: "me@partner.com") }
let(:params) { { organization_name: organization.short_name, partner_id: partner.id, email: "me@partner.com" } }

it "should send a password" do
Expand Down

0 comments on commit f431a68

Please sign in to comment.