Skip to content

Commit

Permalink
MAP-480: Fix error in move for_supplier method that was causing 500 e…
Browse files Browse the repository at this point in the history
…rrors
  • Loading branch information
jimbali committed Nov 24, 2023
1 parent 815909c commit 23dd834
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions app/models/move.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ def self.for_supplier(supplier)
where(supplier:)
.or(Move.where(from_location: supplier.locations))
.or(Move.where(to_location: supplier.locations))
.includes(:lodgings)
.or(Lodging.where('lodgings.location' => supplier.locations))
.or(Move.where(id: Move.joins(:lodgings).where('lodgings.location' => supplier.locations)))
end

def approve(date:)
Expand Down
5 changes: 5 additions & 0 deletions spec/models/move_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,21 @@

let(:supplier) { create(:supplier) }
let(:location) { create(:location, suppliers: [supplier]) }
let(:location2) { create(:location, suppliers: [supplier]) }

let(:move1) { create(:move, supplier:) }
let(:move2) { create(:move, to_location: location) }
let(:move3) { create(:move, from_location: location) }
let(:move4) { create(:move) }
let(:move5) { create(:move) }

before { create(:lodging, location: location2, move: move5) }

it { is_expected.to include(move1) }
it { is_expected.to include(move2) }
it { is_expected.to include(move3) }
it { is_expected.not_to include(move4) }
it { is_expected.to include(move5) }
end

describe '#reference' do
Expand Down

0 comments on commit 23dd834

Please sign in to comment.