Browse Source

Add user case log association

pull/114/head
baarkerlounger 4 years ago
parent
commit
165a605af3
  1. 3
      app/models/user.rb
  2. 23
      spec/models/user_spec.rb

3
app/models/user.rb

@ -4,5 +4,6 @@ class User < ApplicationRecord
devise :database_authenticatable, :recoverable, :rememberable, :validatable
belongs_to :organisation
has_many :case_logs, through: :organisation
has_many :owned_case_logs, through: :organisation
has_many :managed_case_logs, through: :organisation
end

23
spec/models/user_spec.rb

@ -3,9 +3,32 @@ require "rails_helper"
RSpec.describe User, type: :model do
describe "#new" do
let(:user) { FactoryBot.create(:user) }
let(:other_organisation) { FactoryBot.create(:organisation) }
let!(:owned_case_log) do
FactoryBot.create(
:case_log,
owning_organisation: user.organisation,
managing_organisation: other_organisation
)
end
let!(:managed_case_log) do
FactoryBot.create(
:case_log,
owning_organisation: other_organisation,
managing_organisation: user.organisation
)
end
it "belongs to an organisation" do
expect(user.organisation).to be_a(Organisation)
end
it "has owned case logs through their organisation" do
expect(user.owned_case_logs.first).to eq(owned_case_log)
end
it "has managed case logs through their organisation" do
expect(user.managed_case_logs.first).to eq(managed_case_log)
end
end
end

Loading…
Cancel
Save