Browse Source

User case log helper methods

pull/114/head
baarkerlounger 4 years ago
parent
commit
4a3107b5e8
  1. 12
      app/models/user.rb
  2. 10
      spec/models/user_spec.rb

12
app/models/user.rb

@ -6,4 +6,16 @@ class User < ApplicationRecord
belongs_to :organisation
has_many :owned_case_logs, through: :organisation
has_many :managed_case_logs, through: :organisation
def case_logs
CaseLog.for_organisation(organisation)
end
def completed_case_logs
case_logs.completed
end
def not_completed_case_logs
case_logs.not_completed
end
end

10
spec/models/user_spec.rb

@ -7,6 +7,7 @@ RSpec.describe User, type: :model do
let!(:owned_case_log) do
FactoryBot.create(
:case_log,
:completed,
owning_organisation: user.organisation,
managing_organisation: other_organisation
)
@ -30,5 +31,14 @@ RSpec.describe User, type: :model do
it "has managed case logs through their organisation" do
expect(user.managed_case_logs.first).to eq(managed_case_log)
end
it "has case logs through their organisation" do
expect(user.case_logs.to_a).to eq([owned_case_log, managed_case_log])
end
it "has case log status helper methods" do
expect(user.completed_case_logs.to_a).to eq([owned_case_log])
expect(user.not_completed_case_logs.to_a).to eq([managed_case_log])
end
end
end

Loading…
Cancel
Save