From c7068c9bb4ab75aa17af2c2f92509c3a7eb24328 Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Thu, 19 Sep 2024 12:00:35 +0100 Subject: [PATCH 01/10] Create an API v2 endpoint for PooledPlateCreations --- .../v2/pooled_plate_creations_controller.rb | 12 +++ .../api/v2/pooled_plate_creation_resource.rb | 93 +++++++++++++++++++ config/routes.rb | 1 + 3 files changed, 106 insertions(+) create mode 100644 app/controllers/api/v2/pooled_plate_creations_controller.rb create mode 100644 app/resources/api/v2/pooled_plate_creation_resource.rb diff --git a/app/controllers/api/v2/pooled_plate_creations_controller.rb b/app/controllers/api/v2/pooled_plate_creations_controller.rb new file mode 100644 index 0000000000..07a8524041 --- /dev/null +++ b/app/controllers/api/v2/pooled_plate_creations_controller.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module Api + module V2 + # Provides a JSON API controller for Pooled Plate Creations + # See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation + class PooledPlateCreationsController < JSONAPI::ResourceController + # By default JSONAPI::ResourceController provides most the standard + # behaviour, and in many cases this file may be left empty. + end + end +end diff --git a/app/resources/api/v2/pooled_plate_creation_resource.rb b/app/resources/api/v2/pooled_plate_creation_resource.rb new file mode 100644 index 0000000000..958d9449c8 --- /dev/null +++ b/app/resources/api/v2/pooled_plate_creation_resource.rb @@ -0,0 +1,93 @@ +# frozen_string_literal: true + +module Api + module V2 + # @todo This documentation does not yet include a detailed description of what this resource represents. + # @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters. + # @todo This documentation does not yet include any example usage of the API via cURL or similar. + # + # @note This resource cannot be modified after creation: its endpoint will not accept `PATCH` requests. + # @note Access this resource via the `/api/v2/pooled_plate_creation/` endpoint. + # + # Provides a JSON:API representation of {PooledPlateCreation}. + # + # For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/) + # or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation + # of the JSON:API standard. + class PooledPlateCreationResource < BaseResource + ### + # Attributes + ### + + # @!attribute [w] child_purpose_uuid + # @param value [String] The UUID of a child purpose to use in the creation of the child plate. + # @return [Void] + attribute :child_purpose_uuid + + def child_purpose_uuid=(value) + @model.child_purpose = Purpose.with_uuid(value).first + end + + # @!attribute [w] parent_uuids + # This is declared for convenience where parents are not available to set as a relationship. + # Setting this attribute alongside the `parents` relationship will prefer the relationship value. + # @deprecated Use the `parents` relationship instead. + # @param value [Array] The UUIDs of labware that will be the parents for the created plate. + # @return [Void] + # @see #parents + attribute :parent_uuids + + def parent_uuids=(value) + @model.parents = value.map { |uuid| Labware.with_uuid(uuid).first } + end + + # @!attribute [w] user_uuid + # This is declared for convenience where the user is not available to set as a relationship. + # Setting this attribute alongside the `user` relationship will prefer the relationship value. + # @deprecated Use the `user` relationship instead. + # @param value [String] The UUID of the user who initiated the creation of this pooled plate. + # @return [Void] + # @see #user + attribute :user_uuid + + def user_uuid=(value) + @model.user = User.with_uuid(value).first + end + + # @!attribute [r] uuid + # @return [String] The UUID of the state change. + attribute :uuid, readonly: true + + ### + # Relationships + ### + + # @!attribute [r] child + # @return [PlateResource] The child plate which was created. + has_many :child, class_name: 'Plate' + + # @!attribute [rw] parents + # Setting this relationship alongside the `parent_uuids` attribute will override the attribute value. + # @return [Array] An array of the parents of the plate being created. + # @note This relationship is required. + has_many :parents, class_name: 'Labware' + + # @!attribute [rw] user + # Setting this relationship alongside the `user_uuid` attribute will override the attribute value. + # @return [UserResource] The user who initiated the creation of the pooled plate. + # @note This relationship is required. + has_one :user + + def self.creatable_fields(context) + # UUID is set by the system. + super - %i[uuid] + end + + def fetchable_fields + # The tube_attributes attribute is only available during resource creation. + # UUIDs for relationships are not fetchable. They should be accessed via the relationship itself. + super - %i[child_purpose_uuid parent_uuids user_uuid] + end + end + end +end diff --git a/config/routes.rb b/config/routes.rb index 575a660901..4367197daf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,6 +39,7 @@ jsonapi_resources :plate_templates jsonapi_resources :plates jsonapi_resources :poly_metadata + jsonapi_resources :pooled_plate_creations, except: %i[update] jsonapi_resources :pre_capture_pools jsonapi_resources :primer_panels jsonapi_resources :projects From 2ef64d8a2c7f7b1abfe2daf12b670ffa8a0c3b88 Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Thu, 19 Sep 2024 14:52:23 +0100 Subject: [PATCH 02/10] Use correct plurality for child relationship --- app/resources/api/v2/pooled_plate_creation_resource.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/resources/api/v2/pooled_plate_creation_resource.rb b/app/resources/api/v2/pooled_plate_creation_resource.rb index 958d9449c8..3db50371c7 100644 --- a/app/resources/api/v2/pooled_plate_creation_resource.rb +++ b/app/resources/api/v2/pooled_plate_creation_resource.rb @@ -64,7 +64,7 @@ def user_uuid=(value) # @!attribute [r] child # @return [PlateResource] The child plate which was created. - has_many :child, class_name: 'Plate' + has_one :child, class_name: 'Plate' # @!attribute [rw] parents # Setting this relationship alongside the `parent_uuids` attribute will override the attribute value. From 366b02362b3cf118b6aa7eade8a1973f032756ad Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Thu, 19 Sep 2024 15:08:02 +0100 Subject: [PATCH 03/10] Create attribute/relationship tests for PooledPlateCreationResource --- spec/factories/pooled_plate_creation.rb | 12 ++++++++++ .../v2/pooled_plate_creation_resource_spec.rb | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 spec/factories/pooled_plate_creation.rb create mode 100644 spec/resources/api/v2/pooled_plate_creation_resource_spec.rb diff --git a/spec/factories/pooled_plate_creation.rb b/spec/factories/pooled_plate_creation.rb new file mode 100644 index 0000000000..785555881b --- /dev/null +++ b/spec/factories/pooled_plate_creation.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory(:pooled_plate_creation) do + child_purpose { |target| target.association(:plate_purpose) } + user { |target| target.association(:user) } + + # When giving a tube as a parent, we change the prefix away from NT to avoid clashes with tubes created as children + # by other instances of this model. + parents { |target| [target.association(:plate), target.association(:tube, prefix: 'PT')] } + end +end diff --git a/spec/resources/api/v2/pooled_plate_creation_resource_spec.rb b/spec/resources/api/v2/pooled_plate_creation_resource_spec.rb new file mode 100644 index 0000000000..0f076f663f --- /dev/null +++ b/spec/resources/api/v2/pooled_plate_creation_resource_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'rails_helper' +require './app/resources/api/v2/pooled_plate_creation_resource' + +RSpec.describe Api::V2::PooledPlateCreationResource, type: :resource do + subject(:resource) { described_class.new(resource_model, {}) } + + let(:resource_model) { build_stubbed :pooled_plate_creation } + + # Attributes + it { is_expected.to have_readonly_attribute :uuid } + + it { is_expected.to have_writeonly_attribute :child_purpose_uuid } + it { is_expected.to have_writeonly_attribute :parent_uuids } + it { is_expected.to have_writeonly_attribute :user_uuid } + + # Relationships + it { is_expected.to have_one(:child).with_class_name('Plate') } + it { is_expected.to have_many(:parents).with_class_name('Labware') } + it { is_expected.to have_one(:user).with_class_name('User') } +end From 9fc4fd313cff37d00f966943a8c90a54f90506ac Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Thu, 19 Sep 2024 16:43:06 +0100 Subject: [PATCH 04/10] Add request tests for PooledPlateCreations --- .../api/v2/pooled_plate_creations_spec.rb | 286 ++++++++++++++++++ 1 file changed, 286 insertions(+) create mode 100644 spec/requests/api/v2/pooled_plate_creations_spec.rb diff --git a/spec/requests/api/v2/pooled_plate_creations_spec.rb b/spec/requests/api/v2/pooled_plate_creations_spec.rb new file mode 100644 index 0000000000..f61fde5046 --- /dev/null +++ b/spec/requests/api/v2/pooled_plate_creations_spec.rb @@ -0,0 +1,286 @@ +# frozen_string_literal: true + +require 'rails_helper' +require './spec/requests/api/v2/shared_examples/api_key_authenticatable' +require './spec/requests/api/v2/shared_examples/post_requests' + +describe 'Pooled Plate Creations API', with: :api_v2 do + let(:model_class) { PooledPlateCreation } + let(:base_endpoint) { "/api/v2/#{resource_type}" } + let(:resource_type) { model_class.name.demodulize.pluralize.underscore } + + it_behaves_like 'ApiKeyAuthenticatable' + + include BarcodeHelper + before { mock_plate_barcode_service } + + context 'with a list of resources' do + let(:resource_count) { 5 } + + before do + create_list(:pooled_plate_creation, resource_count) + end + + describe '#GET all resources' do + before { api_get base_endpoint } + + it 'responds with a success http code' do + expect(response).to have_http_status(:success) + end + + it 'returns all the resources' do + expect(json['data'].length).to eq(resource_count) + end + end + end + + context 'with a single resource' do + describe '#GET resource by ID' do + let(:resource) { create :pooled_plate_creation } + + context 'without included relationships' do + before { api_get "#{base_endpoint}/#{resource.id}" } + + it 'responds with a success http code' do + expect(response).to have_http_status(:success) + end + + it 'returns the correct resource' do + expect(json.dig('data', 'id')).to eq(resource.id.to_s) + expect(json.dig('data', 'type')).to eq(resource_type) + end + + it 'returns the correct attributes' do + expect(json.dig('data', 'attributes', 'uuid')).to eq(resource.uuid) + end + + it 'excludes unfetchable attributes' do + expect(json.dig('data', 'attributes', 'child_purpose_uuid')).not_to be_present + expect(json.dig('data', 'attributes', 'parent_uuids')).not_to be_present + expect(json.dig('data', 'attributes', 'tube_attributes')).not_to be_present + end + + it 'returns references to related resources' do + expect(json.dig('data', 'relationships', 'child')).to be_present + expect(json.dig('data', 'relationships', 'parents')).to be_present + expect(json.dig('data', 'relationships', 'user')).to be_present + end + + it 'does not include attributes for related resources' do + expect(json['included']).not_to be_present + end + end + + context 'with included relationships' do + context 'with child' do + let(:related_name) { 'child' } + + it_behaves_like 'a POST request including a has_one relationship' + end + + context 'with parents' do + let(:related_name) { 'parents' } + + it_behaves_like 'a POST request including a has_many relationship' + end + + context 'with user' do + let(:related_name) { 'user' } + + it_behaves_like 'a POST request including a has_one relationship' + end + end + end + end + + describe '#PATCH a resource' do + let(:resource_model) { create :pooled_plate_creation } + let(:purpose) { create :plate_purpose } + let(:payload) do + { data: { id: resource_model.id, type: resource_type, attributes: { child_purpose_uuid: [purpose.uuid] } } } + end + + it 'finds no route for the method' do + expect { api_patch "#{base_endpoint}/#{resource_model.id}", payload }.to raise_error( + ActionController::RoutingError + ) + end + end + + describe '#POST a create request' do + let(:purpose) { create :plate_purpose } + let(:parents) { [create(:plate), create(:tube, prefix: 'PT')] } + let(:user) { create(:user) } + + let(:base_attributes) do + { child_purpose_uuid: purpose.uuid } + end + + let(:parents_relationship) { { data: parents.map { |p| { id: p.id, type: 'labware' } } } } + let(:user_relationship) { { data: { id: user.id, type: 'users' } } } + + context 'with a valid payload' do + shared_examples 'a valid request' do + before { api_post base_endpoint, payload } + + it 'creates a new resource' do + expect { api_post base_endpoint, payload }.to change(model_class, :count).by(1) + end + + it 'responds with success' do + expect(response).to have_http_status(:success) + end + + it 'responds with the correct attributes' do + new_record = model_class.last + + expect(json.dig('data', 'type')).to eq(resource_type) + expect(json.dig('data', 'attributes', 'uuid')).to eq(new_record.uuid) + end + + it 'excludes unfetchable attributes' do + expect(json.dig('data', 'attributes', 'child_purpose_uuid')).not_to be_present + expect(json.dig('data', 'attributes', 'parent_uuids')).not_to be_present + expect(json.dig('data', 'attributes', 'tube_attributes')).not_to be_present + end + + it 'returns references to related resources' do + expect(json.dig('data', 'relationships', 'child')).to be_present + expect(json.dig('data', 'relationships', 'parents')).to be_present + expect(json.dig('data', 'relationships', 'user')).to be_present + end + + it 'applies the relationships to the new record' do + new_record = model_class.last + + expect(new_record.child_purpose).to eq(purpose) + expect(new_record.parents).to eq(parents) + expect(new_record.user).to eq(user) + end + + it 'generated a child with valid attributes' do + new_record = model_class.last + + expect(new_record.child.purpose).to eq(purpose) + end + end + + context 'with complete attributes' do + let(:payload) do + { + data: { + type: resource_type, + attributes: + base_attributes.merge( + { + parent_uuids: parents.map(&:uuid), + user_uuid: user.uuid + } + ) + } + } + end + + it_behaves_like 'a valid request' + end + + context 'with relationships' do + let(:payload) do + { + data: { + type: resource_type, + attributes: base_attributes, + relationships: { + parents: parents_relationship, + user: user_relationship + } + } + } + end + + it_behaves_like 'a valid request' + end + + context 'with conflicting relationships' do + let(:other_parents) { create_list :plate, 2 } + let(:other_user) { create :user } + let(:payload) do + { + data: { + type: resource_type, + attributes: + base_attributes.merge({ parent_uuids: other_parents.map(&:uuid), user_uuid: other_user.uuid }), + relationships: { + parents: parents_relationship, + user: user_relationship + } + } + } + end + + # This test should pass because the relationships are preferred over the attributes. + it_behaves_like 'a valid request' + end + end + + context 'with a read-only attribute in the payload' do + context 'with uuid' do + let(:disallowed_attribute) { 'uuid' } + let(:payload) do + { + data: { + type: resource_type, + attributes: base_attributes.merge({ uuid: '111111-2222-3333-4444-555555666666' }) + } + } + end + + it_behaves_like 'a POST request with a disallowed attribute' + end + end + + context 'without a required relationship' do + context 'without parent_uuids' do + let(:error_detail_message) { "parent - can't be blank" } + let(:payload) { { data: { type: resource_type, attributes: base_attributes.merge({ user_uuid: user.uuid }) } } } + + it_behaves_like 'an unprocessable POST request with a specific error' + end + + context 'without user_uuid' do + let(:error_detail_message) { "user - can't be blank" } + let(:payload) do + { data: { type: resource_type, attributes: base_attributes.merge({ parent_uuids: parents.map(&:uuid) }) } } + end + + it_behaves_like 'an unprocessable POST request with a specific error' + end + + context 'without parents' do + let(:error_detail_message) { "parent - can't be blank" } + let(:payload) do + { data: { type: resource_type, attributes: base_attributes, relationships: { user: user_relationship } } } + end + + it_behaves_like 'an unprocessable POST request with a specific error' + end + + context 'without user' do + let(:error_detail_message) { "user - can't be blank" } + let(:payload) do + { + data: { + type: resource_type, + attributes: base_attributes, + relationships: { + parents: parents_relationship + } + } + } + end + + it_behaves_like 'an unprocessable POST request with a specific error' + end + end + end +end From 0a8ac9d021256c1c23056b0b145127fb5259aa9a Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Thu, 19 Sep 2024 17:02:33 +0100 Subject: [PATCH 05/10] Rubocop and prettier --- .../api/v2/pooled_plate_creations_spec.rb | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/spec/requests/api/v2/pooled_plate_creations_spec.rb b/spec/requests/api/v2/pooled_plate_creations_spec.rb index f61fde5046..b8798b7f7e 100644 --- a/spec/requests/api/v2/pooled_plate_creations_spec.rb +++ b/spec/requests/api/v2/pooled_plate_creations_spec.rb @@ -9,17 +9,15 @@ let(:base_endpoint) { "/api/v2/#{resource_type}" } let(:resource_type) { model_class.name.demodulize.pluralize.underscore } - it_behaves_like 'ApiKeyAuthenticatable' - include BarcodeHelper before { mock_plate_barcode_service } + it_behaves_like 'ApiKeyAuthenticatable' + context 'with a list of resources' do let(:resource_count) { 5 } - before do - create_list(:pooled_plate_creation, resource_count) - end + before { create_list(:pooled_plate_creation, resource_count) } describe '#GET all resources' do before { api_get base_endpoint } @@ -112,9 +110,7 @@ let(:parents) { [create(:plate), create(:tube, prefix: 'PT')] } let(:user) { create(:user) } - let(:base_attributes) do - { child_purpose_uuid: purpose.uuid } - end + let(:base_attributes) { { child_purpose_uuid: purpose.uuid } } let(:parents_relationship) { { data: parents.map { |p| { id: p.id, type: 'labware' } } } } let(:user_relationship) { { data: { id: user.id, type: 'users' } } } @@ -170,13 +166,7 @@ { data: { type: resource_type, - attributes: - base_attributes.merge( - { - parent_uuids: parents.map(&:uuid), - user_uuid: user.uuid - } - ) + attributes: base_attributes.merge({ parent_uuids: parents.map(&:uuid), user_uuid: user.uuid }) } } end From 219a09ee219648319cbfd97d9d5c0dc15ff7a28f Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Thu, 19 Sep 2024 17:05:26 +0100 Subject: [PATCH 06/10] Remove unnecessary override of Tube prefixes in factory --- spec/factories/pooled_plate_creation.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/spec/factories/pooled_plate_creation.rb b/spec/factories/pooled_plate_creation.rb index 785555881b..dc28ba39ba 100644 --- a/spec/factories/pooled_plate_creation.rb +++ b/spec/factories/pooled_plate_creation.rb @@ -3,10 +3,7 @@ FactoryBot.define do factory(:pooled_plate_creation) do child_purpose { |target| target.association(:plate_purpose) } + parents { |target| [target.association(:plate), target.association(:tube)] } user { |target| target.association(:user) } - - # When giving a tube as a parent, we change the prefix away from NT to avoid clashes with tubes created as children - # by other instances of this model. - parents { |target| [target.association(:plate), target.association(:tube, prefix: 'PT')] } end end From 4605a7482c6a4cab9215f9930545f0b3c18fb1b1 Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Thu, 19 Sep 2024 17:46:31 +0100 Subject: [PATCH 07/10] Jump through hoops to avoid calling Baracoda during tests --- app/models/plate_creation.rb | 2 +- spec/factories/pooled_plate_creation.rb | 3 ++- spec/requests/api/v2/pooled_plate_creations_spec.rb | 8 +++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/models/plate_creation.rb b/app/models/plate_creation.rb index 84cd06da7e..411ff9a4cf 100644 --- a/app/models/plate_creation.rb +++ b/app/models/plate_creation.rb @@ -34,7 +34,7 @@ def children private :children def create_children! - self.child = child_purpose.create!(barcode: barcode) + self.child = child_purpose.create!(sanger_barcode: barcode) end private :create_children! end diff --git a/spec/factories/pooled_plate_creation.rb b/spec/factories/pooled_plate_creation.rb index dc28ba39ba..756ab779ec 100644 --- a/spec/factories/pooled_plate_creation.rb +++ b/spec/factories/pooled_plate_creation.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true FactoryBot.define do - factory(:pooled_plate_creation) do + factory :pooled_plate_creation do + barcode { create(:plate_barcode) } child_purpose { |target| target.association(:plate_purpose) } parents { |target| [target.association(:plate), target.association(:tube)] } user { |target| target.association(:user) } diff --git a/spec/requests/api/v2/pooled_plate_creations_spec.rb b/spec/requests/api/v2/pooled_plate_creations_spec.rb index b8798b7f7e..e029379ed4 100644 --- a/spec/requests/api/v2/pooled_plate_creations_spec.rb +++ b/spec/requests/api/v2/pooled_plate_creations_spec.rb @@ -9,9 +9,6 @@ let(:base_endpoint) { "/api/v2/#{resource_type}" } let(:resource_type) { model_class.name.demodulize.pluralize.underscore } - include BarcodeHelper - before { mock_plate_barcode_service } - it_behaves_like 'ApiKeyAuthenticatable' context 'with a list of resources' do @@ -115,6 +112,11 @@ let(:parents_relationship) { { data: parents.map { |p| { id: p.id, type: 'labware' } } } } let(:user_relationship) { { data: { id: user.id, type: 'users' } } } + # Mock the plate barcode service because it is not available in the test environment. + # This wasn't needed above because the only records being created were via the factory which supplies a barcode. + include BarcodeHelper + before { mock_plate_barcode_service } + context 'with a valid payload' do shared_examples 'a valid request' do before { api_post base_endpoint, payload } From fee438c5a91cdf166385e7d76dd973fce9716a29 Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Thu, 19 Sep 2024 18:21:54 +0100 Subject: [PATCH 08/10] Continue to fight with tests trying to go to Baracoda --- app/models/plate_creation.rb | 3 ++- app/models/pooled_plate_creation.rb | 2 +- features/api/plate_creations.feature | 2 +- spec/factories/pooled_plate_creation.rb | 4 +++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/models/plate_creation.rb b/app/models/plate_creation.rb index 411ff9a4cf..04cc1537c7 100644 --- a/app/models/plate_creation.rb +++ b/app/models/plate_creation.rb @@ -7,6 +7,7 @@ class PlateCreation < AssetCreation # This is the child that is created from the parent. It cannot be assigned before validation. belongs_to :parent, class_name: 'Plate' attr_accessor :barcode + attr_accessor :sanger_barcode def record_creation_of_children parent.events.create_plate!(child_purpose, child, user) @@ -34,7 +35,7 @@ def children private :children def create_children! - self.child = child_purpose.create!(sanger_barcode: barcode) + self.child = child_purpose.create!(sanger_barcode: sanger_barcode) end private :create_children! end diff --git a/app/models/pooled_plate_creation.rb b/app/models/pooled_plate_creation.rb index dc6f4e4001..9ddb938606 100644 --- a/app/models/pooled_plate_creation.rb +++ b/app/models/pooled_plate_creation.rb @@ -2,7 +2,7 @@ # Creating an instance of this class causes a child plate, with the specified plate type, to be created from # the parent. class PooledPlateCreation < AssetCreation - attr_accessor :barcode + attr_accessor :sanger_barcode has_many :parent_associations, foreign_key: 'asset_creation_id', class_name: 'AssetCreation::ParentAssociation' diff --git a/features/api/plate_creations.feature b/features/api/plate_creations.feature index b4ad4bd126..6d74b77e6f 100644 --- a/features/api/plate_creations.feature +++ b/features/api/plate_creations.feature @@ -12,7 +12,7 @@ Feature: Access plate creations through the API And the WTSI single sign-on service recognises "I-am-authenticated" as "John Smith" Given I am using the latest version of the API -And I have a "full" authorised user with the key "cucumber" + And I have a "full" authorised user with the key "cucumber" Given a user with UUID "99999999-8888-7777-6666-555555555555" exists diff --git a/spec/factories/pooled_plate_creation.rb b/spec/factories/pooled_plate_creation.rb index 756ab779ec..b60b41a6d8 100644 --- a/spec/factories/pooled_plate_creation.rb +++ b/spec/factories/pooled_plate_creation.rb @@ -2,7 +2,9 @@ FactoryBot.define do factory :pooled_plate_creation do - barcode { create(:plate_barcode) } + # Without this, create_children! tries to go to Baracoda for a barcode. + sanger_barcode { create(:plate_barcode) } + child_purpose { |target| target.association(:plate_purpose) } parents { |target| [target.association(:plate), target.association(:tube)] } user { |target| target.association(:user) } From 663cafba2266353d9f74eb7855e731f1f4494674 Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Mon, 23 Sep 2024 11:53:38 +0100 Subject: [PATCH 09/10] Remove barcode attribute from PlateCreation --- app/models/plate_creation.rb | 1 - spec/factories/pulldown_factories.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/plate_creation.rb b/app/models/plate_creation.rb index 04cc1537c7..3066eec729 100644 --- a/app/models/plate_creation.rb +++ b/app/models/plate_creation.rb @@ -6,7 +6,6 @@ class PlateCreation < AssetCreation # This is the child that is created from the parent. It cannot be assigned before validation. belongs_to :parent, class_name: 'Plate' - attr_accessor :barcode attr_accessor :sanger_barcode def record_creation_of_children diff --git a/spec/factories/pulldown_factories.rb b/spec/factories/pulldown_factories.rb index 9bd4bf6a39..7af01ec0f5 100644 --- a/spec/factories/pulldown_factories.rb +++ b/spec/factories/pulldown_factories.rb @@ -61,7 +61,7 @@ factory(:plate_creation) do user - barcode { create(:sequencescape22).barcode } + sanger_barcode { create(:sequencescape22).barcode } parent factory: %i[full_plate], well_count: 2 child_purpose factory: %i[plate_purpose] From c376ee8cb552a153a0eb88db6321b7baa38588bf Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Mon, 23 Sep 2024 15:11:00 +0100 Subject: [PATCH 10/10] Stop pulling the string from the barcode object during testing --- spec/factories/pulldown_factories.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories/pulldown_factories.rb b/spec/factories/pulldown_factories.rb index 7af01ec0f5..c9786a425c 100644 --- a/spec/factories/pulldown_factories.rb +++ b/spec/factories/pulldown_factories.rb @@ -61,7 +61,7 @@ factory(:plate_creation) do user - sanger_barcode { create(:sequencescape22).barcode } + sanger_barcode { create(:sequencescape22) } parent factory: %i[full_plate], well_count: 2 child_purpose factory: %i[plate_purpose]