Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/sequencescape-api/associations/belongs_to.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ def object
def uuid_only?
@object.__send__(:uuid_only?)
end

delegate :hash, to: :uuid

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to top


def eql?(other)
uuid == other.uuid
end
end

def belongs_to(association, options = {}, &block)
Expand Down
6 changes: 5 additions & 1 deletion lib/sequencescape-api/resource/attribute_groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ module Json
def as_json_for_update(options)
super.tap do |json|
begin
json.fetch(json_root).merge!(attribute_group_json(options))
if options[:root]
json.fetch(json_root).merge!(attribute_group_json(options))
else
json.merge!(attribute_group_json(options))
end
rescue KeyError => e
# If we get a key error, append the json to out exception to assist diagnosing issues
e.message << " in #{json.to_json}"
Expand Down
2 changes: 1 addition & 1 deletion lib/sequencescape-api/resource/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def associations_for_json(options)
]
end
private :associations_for_json

def must_output_full_json?(options, target = self)
options[:force] or (options[:action] == :create) or target.changed?
end
Expand Down
3 changes: 3 additions & 0 deletions lib/sequencescape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ module Sequencescape
require 'sequencescape/work_completion'
require 'sequencescape/custom_metadatum_collection'

require 'sequencescape/transfer_request_collection'
require 'sequencescape/transfer_request'

# Pulldown API support
require 'sequencescape/plate_creation'
require 'sequencescape/pooled_plate_creation'
Expand Down
1 change: 1 addition & 0 deletions lib/sequencescape/plate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Sequencescape::Plate < ::Sequencescape::Asset

has_many :wells
has_many :submission_pools
has_many :transfer_request_collections

belongs_to :plate_purpose
belongs_to :custom_metadatum_collection
Expand Down
10 changes: 10 additions & 0 deletions lib/sequencescape/transfer_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'sequencescape-api/resource'

class Sequencescape::TransferRequest < ::Sequencescape::Api::Resource

belongs_to :source_asset, :class_name => 'Asset'
belongs_to :target_asset, :class_name => 'Asset'

attribute_accessor :type, :state

end
7 changes: 7 additions & 0 deletions lib/sequencescape/transfer_request_collection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'sequencescape-api/resource'

class Sequencescape::TransferRequestCollection < ::Sequencescape::Api::Resource
belongs_to :user
has_many :transfer_requests, disposition: :inline
has_many :target_tubes, disposition: :inline, class_name: 'Tube'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
POST /model_c/create HTTP/1.1
Accept: application/json
Content-Type: application/json
Cookie: WTSISignOn=single-sign-on-cookie

{
"model_c": {
"model_bs": [{"test_attribute":"test_value"}]
}
}
10 changes: 10 additions & 0 deletions spec/sequencescape-api/modifications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@
it 'raises if not given an enumerable'
end

context 'has_many disposition: :inline nested' do
stub_request_from('create-model-c-has-many-inline-nested') { response('model-c-instance-created') }

it 'takes an array of objects and converts them to UUID'
it 'assumes an array of strings are UUIDs' do
target.create!(:model_bs => [{ "test_attribute" => "test_value" }])
end
it 'raises if not given an enumerable'
end

context 'has_many' do
stub_request_from('create-model-c-has-many') { response('model-c-instance-created') }

Expand Down
1 change: 1 addition & 0 deletions spec/support/namespaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ModelB < Sequencescape::Api::Resource
belongs_to :model_by_simple_name, :class_name => 'ModelA'
belongs_to :model_by_full_name, :class_name => 'Nested::Model'
belongs_to :model_with_early_data, :class_name => 'ModelA'
attribute_accessor :test_attribute
end

class ModelC < Sequencescape::Api::Resource
Expand Down