Skip to content

Commit

Permalink
feat(tube-resource): adds racked_tube relationship to v2 tube api
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTopping committed Feb 12, 2025
1 parent 067132c commit cd6db6e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/resources/api/v2/tube_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def sibling_tubes
# @!attribute [r] transfer_requests_as_target
# @return [Array<Api::V2::TransferRequestResource>] An array of transfer requests into this tube.
has_many :transfer_requests_as_target, readonly: true

# @!attribute [r] racked_tube
# @return [Api::V2::RackedTubeResource] The racked tube association.
has_one :racked_tube, readonly: true, foreign_key_on: :related
end
end
end
4 changes: 4 additions & 0 deletions spec/requests/api/v2/tubes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
expect(json.dig('data', 'relationships', 'transfer_requests_as_target')).to be_present
end

it 'returns a reference to the racked_tube relationship' do
expect(json.dig('data', 'relationships', 'racked_tube')).to be_present
end

it 'does not include attributes for related resources' do
expect(json['included']).not_to be_present
end
Expand Down
1 change: 1 addition & 0 deletions spec/resources/api/v2/tube_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
it { is_expected.to have_a_readonly_has_many(:aliquots).with_class_name('Aliquot') }
it { is_expected.to have_a_readonly_has_one(:receptacle).with_class_name('Receptacle') }
it { is_expected.to have_a_readonly_has_many(:transfer_requests_as_target).with_class_name('TransferRequest') }
it { is_expected.to have_a_readonly_has_many(:racked_tube).with_class_name('RackedTube') }

# Behaviours
it_behaves_like 'a labware resource'
Expand Down

0 comments on commit cd6db6e

Please sign in to comment.