diff --git a/Gemfile b/Gemfile
index 77a1058..c40a5c7 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,6 +1,5 @@
source 'https://rubygems.org'
-
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.3'
# Use sqlite3 as the database for Active Record
@@ -41,7 +40,7 @@ gem 'kaminari'
gem 'backbone-on-rails'
-gem 'rest-client'
+gem 'pmb-client', '0.1.0', :github => 'sanger/pmb-client'
gem 'exception_notification'
diff --git a/Gemfile.lock b/Gemfile.lock
index 58e2777..2279489 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,3 +1,10 @@
+GIT
+ remote: git://github.com/sanger/pmb-client.git
+ revision: 016f151a3bde84448ed64e528259c3511282dcdb
+ specs:
+ pmb-client (0.1.0)
+ json_api_client (~> 1.1)
+
GEM
remote: https://rubygems.org/
specs:
@@ -78,8 +85,6 @@ GEM
database_cleaner (1.4.1)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
- domain_name (0.5.25)
- unf (>= 0.0.5, < 1.0.0)
eco (1.0.0)
coffee-script
eco-source
@@ -96,13 +101,15 @@ GEM
factory_girl_rails (4.5.0)
factory_girl (~> 4.5.0)
railties (>= 3.0.0)
+ faraday (0.9.2)
+ multipart-post (>= 1.2, < 3)
+ faraday_middleware (0.10.0)
+ faraday (>= 0.7.4, < 0.10)
ffi (1.9.8)
font-awesome-rails (4.5.0.0)
railties (>= 3.2, < 5.0)
globalid (0.3.6)
activesupport (>= 4.1.0)
- http-cookie (1.0.2)
- domain_name (~> 0.5)
i18n (0.7.0)
jbuilder (2.3.1)
activesupport (>= 3.0.0, < 5)
@@ -119,6 +126,12 @@ GEM
json (1.8.3)
json-schema (2.6.0)
addressable (~> 2.3.8)
+ json_api_client (1.1.1)
+ activemodel (>= 3.2.0)
+ activesupport (>= 3.2.0)
+ addressable (~> 2.2)
+ faraday (~> 0.9)
+ faraday_middleware (~> 0.9)
kaminari (0.16.3)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
@@ -132,9 +145,9 @@ GEM
mini_portile (0.6.2)
minitest (5.8.3)
multi_json (1.11.2)
+ multipart-post (2.0.0)
mysql2 (0.3.20)
net-ldap (0.12.0)
- netrc (0.11.0)
nokogiri (1.6.6.3)
mini_portile (~> 0.6.0)
phantomjs (1.9.8.0)
@@ -183,10 +196,6 @@ GEM
uri_template (~> 0.7)
rdoc (4.2.0)
ref (2.0.0)
- rest-client (1.8.0)
- http-cookie (>= 1.0.2, < 2.0)
- mime-types (>= 1.16, < 3.0)
- netrc (~> 0.7)
rouge (1.10.1)
rspec-core (3.2.3)
rspec-support (~> 3.2.0)
@@ -250,9 +259,6 @@ GEM
uglifier (2.7.1)
execjs (>= 0.3.0)
json (>= 1.8.0)
- unf (0.1.4)
- unf_ext
- unf_ext (0.0.7.1)
uri_template (0.7.0)
web-console (2.2.1)
activemodel (>= 4.0)
@@ -290,12 +296,12 @@ DEPENDENCIES
mysql2 (= 0.3.20)
net-ldap
phantomjs
+ pmb-client (= 0.1.0)!
poltergeist
puma
rails (= 4.2.3)
rake
raml_ruby (~> 0.1.1)
- rest-client
rspec-rails (~> 3.1)
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
@@ -310,4 +316,4 @@ DEPENDENCIES
with_model
BUNDLED WITH
- 1.11.2
+ 1.12.1
diff --git a/app/assets/javascripts/batches.coffee b/app/assets/javascripts/batches.coffee
index 70119c7..bed57d3 100644
--- a/app/assets/javascripts/batches.coffee
+++ b/app/assets/javascripts/batches.coffee
@@ -5,7 +5,7 @@ $ ->
userFavouritesCollection = new Mixtio.Collections.UserFavourites(Mixtio.Bootstrap.UserFavourites)
consumableTypesCollection = new Mixtio.Collections.ConsumableTypes(Mixtio.Bootstrap.ConsumableTypes)
kitchensCollection = new Mixtio.Collections.Kitchens(Mixtio.Bootstrap.Kitchens)
- ingredientsCollection = new Mixtio.Collections.Ingredients()
+ ingredientsCollection = new Mixtio.Collections.Ingredients(Mixtio.Bootstrap.Ingredients)
# Create the Views
consumableTypeView = new Mixtio.Views.ConsumableTypes(
@@ -48,7 +48,7 @@ $ ->
favouritesStarView.update(model, options)
expiryDateView.update(model)
consumablesView.update(model)
-
+
ingredients = model?.get('latest_batch')?.ingredients?.map (ingredient) ->
type = Mixtio.Bootstrap.ConsumableTypes.filter((type) -> type.id == ingredient.consumable_type_id)[0]
{
@@ -66,5 +66,7 @@ $ ->
# And finally render
consumableTypeView.render()
+ consumableTypeView.setSelected(Mixtio.Bootstrap.SelectedConsumableType)
+ ingredientsView.render()
$('[data-toggle="tooltip"]').tooltip()
\ No newline at end of file
diff --git a/app/assets/javascripts/views/consumable_types.coffee b/app/assets/javascripts/views/consumable_types.coffee
index 1cb5876..e7a065d 100644
--- a/app/assets/javascripts/views/consumable_types.coffee
+++ b/app/assets/javascripts/views/consumable_types.coffee
@@ -1,7 +1,7 @@
class Mixtio.Views.ConsumableTypes extends Backbone.View
events:
- change: 'setSelected'
+ change: 'onChange'
initialize: (options) ->
@favourites_collection = options.favourites
@@ -30,7 +30,10 @@ class Mixtio.Views.ConsumableTypes extends Backbone.View
@$el.append(view)
)
- setSelected: () ->
+ setSelected: (val) ->
+ @$el.val(val)
+
+ onChange: () ->
id = @$el.val()
if id is ""
diff --git a/app/assets/javascripts/views/expiry_date.coffee b/app/assets/javascripts/views/expiry_date.coffee
index 1651767..7761f7b 100644
--- a/app/assets/javascripts/views/expiry_date.coffee
+++ b/app/assets/javascripts/views/expiry_date.coffee
@@ -5,5 +5,5 @@ class Mixtio.Views.ExpiryDate extends Backbone.View
@render()
render: () ->
- @$el.datepicker('setDate', @model?.get('days_to_keep'))
+ @$el.datepicker('setDate', @model?.get('days_to_keep') or 'today')
this
\ No newline at end of file
diff --git a/app/models/concerns/has_volume.rb b/app/models/concerns/has_volume.rb
index 6daac08..9ef68e8 100644
--- a/app/models/concerns/has_volume.rb
+++ b/app/models/concerns/has_volume.rb
@@ -4,7 +4,7 @@ module HasVolume
included do
enum unit: {
- "μL": -6,
+ "µL": -6,
"mL": -3,
'L': 0,
}
@@ -19,8 +19,4 @@ def display_volume
end
end
- def simple_volume
- display_volume ? display_volume.gsub('μ', 'u') : nil
- end
-
end
\ No newline at end of file
diff --git a/app/models/consumable_type.rb b/app/models/consumable_type.rb
index 99cb708..fb08c3c 100644
--- a/app/models/consumable_type.rb
+++ b/app/models/consumable_type.rb
@@ -20,10 +20,6 @@ class ConsumableType < ActiveRecord::Base
"LN2": 5
}
- def simple_storage_condition
- (storage_condition or "").gsub('°', '')
- end
-
def latest_batch
batches.last
end
diff --git a/app/serializers/consumable_label_serializer.rb b/app/serializers/consumable_label_serializer.rb
deleted file mode 100644
index e3210ed..0000000
--- a/app/serializers/consumable_label_serializer.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-class ConsumableLabelSerializer < ActiveModel::Serializer
-
- attributes :label_1
-
- def label_1
- {
- barcode_text: object.barcode,
- reagent_name: object.batch.consumable_type.name,
- batch_no: object.batch.number,
- date: "Use by: #{object.batch.expiry_date}",
- barcode: object.barcode,
- volume: object.simple_volume,
- storage_condition: object.batch.consumable_type.simple_storage_condition,
- }
- end
-
-end
diff --git a/app/serializers/print_job_serializer.rb b/app/serializers/print_job_serializer.rb
deleted file mode 100644
index 51ba3d2..0000000
--- a/app/serializers/print_job_serializer.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-class PrintJobSerializer < ActiveModel::Serializer
-
- attributes :label_template_id, :printer_name, :labels
-
- def label_template_id
- object.label_template_id
- end
-
- def printer_name
- object.printer
- end
-
- def labels
- if object.batch.single_barcode?
- consumables = [object.batch.consumables.first]
- else
- consumables = object.batch.consumables
- end
-
- {
- body: consumables.map { |consumable| ConsumableLabelSerializer.new(consumable).attributes }
- }
- end
-
-end
diff --git a/app/views/api/v2/docs/index.html.erb b/app/views/api/v2/docs/index.html.erb
index 8eeb0a9..4125c0d 100644
--- a/app/views/api/v2/docs/index.html.erb
+++ b/app/views/api/v2/docs/index.html.erb
@@ -461,7 +461,7 @@ sort=-updated_at
"created_at":"2016-04-08T11:19:44.440Z",
"barcode":"RGNT_171",
"volume":"51.8",
- "unit":"μL",
+ "unit":"µL",
"depleted":false
},
"relationships":{
@@ -486,7 +486,7 @@ sort=-updated_at
"created_at":"2016-04-08T11:19:44.446Z",
"barcode":"RGNT_172",
"volume":"51.8",
- "unit":"μL",
+ "unit":"µL",
"depleted":false
},
"relationships":{
@@ -530,7 +530,7 @@ sort=-updated_at
"created_at":"2016-04-08T11:19:44.440Z",
"barcode":"RGNT_171",
"volume":"51.8",
- "unit":"μL",
+ "unit":"µL",
"depleted":false
},
"relationships":{
diff --git a/app/views/batches/_form.html.erb b/app/views/batches/_form.html.erb
index 9782d01..b99381d 100644
--- a/app/views/batches/_form.html.erb
+++ b/app/views/batches/_form.html.erb
@@ -3,7 +3,9 @@
diff --git a/config/api.raml b/config/api.raml
index 317a20e..49c6e4b 100644
--- a/config/api.raml
+++ b/config/api.raml
@@ -402,7 +402,7 @@ resourceTypes:
"created_at":"2016-04-08T11:19:44.440Z",
"barcode":"RGNT_171",
"volume":"51.8",
- "unit":"μL",
+ "unit":"µL",
"depleted":false
},
"relationships":{
@@ -427,7 +427,7 @@ resourceTypes:
"created_at":"2016-04-08T11:19:44.446Z",
"barcode":"RGNT_172",
"volume":"51.8",
- "unit":"μL",
+ "unit":"µL",
"depleted":false
},
"relationships":{
@@ -480,7 +480,7 @@ resourceTypes:
"created_at":"2016-04-08T11:19:44.440Z",
"barcode":"RGNT_171",
"volume":"51.8",
- "unit":"μL",
+ "unit":"µL",
"depleted":false
},
"relationships":{
diff --git a/config/environments/development.rb b/config/environments/development.rb
index a5475de..94a31a7 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -41,4 +41,6 @@
# config.stub_ldap = true
+ # Print My Barcode api base
+ config.x.pmb_api_base = 'http://pmb.dev/api/v1'
end
diff --git a/config/environments/production.rb b/config/environments/production.rb
index 5c1b32e..593dda8 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -76,4 +76,7 @@
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
+
+ # Print My Barcode api base
+ config.x.pmb_api_base = 'http://pmb.prod/api/v1'
end
diff --git a/config/environments/test.rb b/config/environments/test.rb
index 7bb43d5..ec47f54 100644
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -47,4 +47,7 @@
exception_recipients: %w(#{Rails.configuration.mailer['smtp']['recipient']})
}
+ # Print My Barcode api base
+ config.x.pmb_api_base = 'http://pmb.test/api/v1'
+
end
diff --git a/config/initializers/print_my_barcode.rb b/config/initializers/print_my_barcode.rb
new file mode 100644
index 0000000..8142333
--- /dev/null
+++ b/config/initializers/print_my_barcode.rb
@@ -0,0 +1 @@
+PMB::Base.site = Rails.configuration.x.pmb_api_base
\ No newline at end of file
diff --git a/lib/labels.rb b/lib/labels.rb
new file mode 100644
index 0000000..790d8ed
--- /dev/null
+++ b/lib/labels.rb
@@ -0,0 +1,33 @@
+class Labels
+
+ attr_accessor :consumables
+
+ def initialize(batch)
+ @consumables = batch.single_barcode? ? [batch.consumables.first] : batch.consumables
+ end
+
+ def to_h
+ {
+ body: body
+ }
+ end
+
+private
+
+ def body
+ consumables.map do |consumable|
+ {
+ label_1: {
+ barcode_text: consumable.barcode,
+ reagent_name: consumable.batch.consumable_type.name,
+ batch_no: consumable.batch.number,
+ date: "Use by:#{consumable.batch.expiry_date}",
+ barcode: consumable.barcode,
+ volume: consumable.display_volume,
+ storage_condition: consumable.batch.consumable_type.storage_condition,
+ }
+ }
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/lib/print_job.rb b/lib/print_job.rb
index 2474b30..c8b0087 100644
--- a/lib/print_job.rb
+++ b/lib/print_job.rb
@@ -11,6 +11,7 @@ class PrintJob
def printer_label_type_matches
printer_model = Printer.find_by(name: printer)
label_type_model = LabelType.find_by(external_id: label_template_id)
+
if label_type_model.nil? or printer_model.nil?
errors.add(:printer, 'does not exist') if printer_model.nil?
errors.add(:label_template_id, 'does not exist') if label_type_model.nil?
@@ -22,47 +23,25 @@ def printer_label_type_matches
end
end
- def config
- Rails.configuration.print_service
- end
-
def execute!
+ return false unless valid?
+
begin
- if valid?
- @response = RestClient.post config["host"], to_json, content_type: "application/vnd.api+json"
- response_successful?
- else
- return false
- end
- rescue RestClient::Exception => e
- if e.http_code == 422
- JSON.parse(e.response)['errors'].each do |type, err_array|
- err_array.each do |error|
- # Remove the type from the start of the error if it's there.
- errors.add(type, error.sub(/^#{type} /i, ''))
- end
- end
- end
+ PMB::PrintJob.execute(printer_name: printer, label_template_id: label_template_id, labels: labels.to_h)
+ return true
+ ##
+ # PMB doesn't format errors in the way PMB::Client expects, so somewhere within the depths
+ # of PMB::Client it throws a NoMethodError
+ # Also, PMB::Client doesn't give access to the json returned from the service so we can't even
+ # access what went wrong to populate errors
+ # This needs to be modified when PMB has fixed its errors object
+ rescue StandardError => e
return false
end
end
- def to_json
- {
- data: {
- attributes: serializer.attributes
- }
- }.to_json
- end
-
- private
-
- def serializer
- PrintJobSerializer.new(self)
- end
-
- def response_successful?
- @response.code == 200
+ def labels
+ Labels.new(batch)
end
end
\ No newline at end of file
diff --git a/spec/features/batches_spec.rb b/spec/features/batches_spec.rb
index a0e0778..22c8d62 100644
--- a/spec/features/batches_spec.rb
+++ b/spec/features/batches_spec.rb
@@ -65,7 +65,7 @@
end
it 'prints labels for the batch' do
- allow(RestClient).to receive(:post).and_return(OpenStruct.new(:code => 200))
+ allow(PMB::PrintJob).to receive(:execute).and_return(true)
visit batch_path(@batch)
click_button "Print Labels"
@@ -77,8 +77,7 @@
end
it 'tells the user if there\'s and error' do
- exception = RestClient::Exception.new(OpenStruct.new(code: 500))
- allow(RestClient).to receive(:post).and_raise(exception)
+ allow(PMB::PrintJob).to receive(:execute).and_raise(JsonApiClient::Errors::ServerError.new({}))
visit batch_path(@batch)
click_button "Print Labels"
@@ -90,6 +89,7 @@
end
it 'tells the user the error if known' do
+ pending 'Need PMB to be fixed first'
exception = RestClient::Exception.new(OpenStruct.new(code: 422, to_str: '{"errors":{"printer":["Printer does not exist"]}}'))
allow(RestClient).to receive(:post).and_raise(exception)
@@ -185,6 +185,7 @@
create_batch
expect(page).to have_content('errors prohibited this record from being saved')
end
+
end
context 'when a consumable type is selected' do
@@ -204,6 +205,23 @@
end
end
+ context 'when a consumable type is selected that has a days_to_keep of 0' do
+ before do
+ @consumable_type = create(:consumable_type, days_to_keep: 0)
+ end
+
+ let(:select_a_consumable_type) {
+ visit new_batch_path
+ select @consumable_type.name, from: 'Consumable Type'
+ wait_for_ajax
+ }
+
+ it 'sets the expiry date to today', js: true do
+ select_a_consumable_type
+ expect(find_field("Expiry Date").value).to eq(Date.today.to_date.to_s(:default))
+ end
+ end
+
context 'when trying to use a batch that does not exist as an ingredient' do
before do
@@ -228,6 +246,16 @@
expect(page).to have_content("with number 12345 could not be found")
end
+ it 'maintains the selected options' do
+ fill_out_form
+ expect(page).to have_select('Consumable Type', selected: @consumable_type.name)
+ expect(page).to have_select('batch_form[ingredients][][consumable_type_id]', selected: @consumable_type.name)
+ expect(find(:xpath, '//input[@name="batch_form[ingredients][][number]"]').value).to eq('12345')
+ expect(page).to have_select('batch_form[ingredients][][kitchen_id]', selected: @team.name)
+ expect(find_field("Expiry Date").value).to eq(@batch.expiry_date.to_s)
+ expect(find_field("Number of Aliquots").value).to eq("3")
+ end
+
end
context 'when a selected consumable type has ingredients' do
diff --git a/spec/lib/labels_spec.rb b/spec/lib/labels_spec.rb
new file mode 100644
index 0000000..fb92894
--- /dev/null
+++ b/spec/lib/labels_spec.rb
@@ -0,0 +1,52 @@
+require 'rails_helper'
+
+RSpec.describe Labels, type: :model do
+
+ before(:each) { @batch = create(:batch_with_consumables) }
+
+ it 'should serialize a batch into labels' do
+ labels = Labels.new(@batch).to_h
+
+ expect(labels).to be_kind_of(Hash)
+
+ expect(labels[:body]).to be_kind_of(Array)
+ expect(labels[:body].count).to eq(3)
+
+ first_label = labels[:body].first
+ first_consumable = @batch.consumables.first
+
+ expect(first_label[:label_1][:barcode_text]).to eql(first_consumable.barcode)
+ expect(first_label[:label_1][:reagent_name]).to eql(@batch.consumable_type.name)
+ expect(first_label[:label_1][:batch_no]).to eql(@batch.number)
+ expect(first_label[:label_1][:date]).to eql("Use by:#{@batch.expiry_date.to_date}")
+ expect(first_label[:label_1][:barcode]).to eql(first_consumable.barcode)
+ expect(first_label[:label_1][:volume]).to eq("1.1mL")
+ expect(first_label[:label_1][:storage_condition]).to eql('LN2')
+ end
+
+ context 'when all barcodes are identical' do
+
+ it 'should only generate a single label' do
+
+ batch = create(:batch)
+ consumable = create(:consumable)
+ batch.consumables << (1..3).map {|n| consumable.dup}
+
+ expect(batch.consumables[0].barcode).to eq(consumable.barcode)
+ expect(batch.consumables[1].barcode).to eq(consumable.barcode)
+ expect(batch.consumables[2].barcode).to eq(consumable.barcode)
+
+ labels = Labels.new(batch).to_h
+
+ expect(labels[:body]).to be_kind_of(Array)
+ expect(labels[:body].count).to eq(1)
+
+ first_label = labels[:body].first
+ expect(first_label[:label_1][:barcode]).to eql(consumable.barcode)
+ expect(first_label[:label_1][:barcode_text]).to eql(consumable.barcode)
+
+ end
+
+ end
+
+end
\ No newline at end of file
diff --git a/spec/lib/print_job_spec.rb b/spec/lib/print_job_spec.rb
index 17dcb6d..50bfb31 100644
--- a/spec/lib/print_job_spec.rb
+++ b/spec/lib/print_job_spec.rb
@@ -11,83 +11,19 @@
@print_job = PrintJob.new(batch: @batch, printer: printer.name, label_template_id: label_type.external_id)
end
- it "should have a host from config" do
- expect(@print_job.config["host"]).to be_kind_of(String)
- end
-
- it "should serialize a batch into a label" do
- json = JSON.parse(@print_job.to_json, symbolize_names: true)
-
- expect(json[:data]).to be_truthy
- expect(json[:data][:attributes][:printer_name]).to eql('ABC123')
- expect(json[:data][:attributes][:label_template_id]).to eql(1)
-
- labels = json[:data][:attributes][:labels]
- expect(labels[:body]).to be_kind_of(Array)
- expect(labels[:body].count).to eq(3)
-
- first_label = labels[:body].first
- first_consumable = @batch.consumables.first
- expect(first_label[:label_1][:barcode_text]).to eql(first_consumable.barcode)
- expect(first_label[:label_1][:reagent_name]).to eql(@batch.consumable_type.name)
- expect(first_label[:label_1][:batch_no]).to eql(@batch.number)
- expect(first_label[:label_1][:date]).to eql("Use by: #{@batch.expiry_date.to_date}")
- expect(first_label[:label_1][:barcode]).to eql(first_consumable.barcode)
- expect(first_label[:label_1][:volume]).to eq("1.1mL")
- expect(first_label[:label_1][:storage_condition]).to eql('LN2')
- end
-
- it "should serialize a batch with special symbols in storage condition" do
- batch = create(:batch_with_consumables)
- batch.consumable_type.storage_condition = 0
- print_job = PrintJob.new(batch: batch, printer: 'ABC123', label_template_id: 1)
- json = JSON.parse(print_job.to_json, symbolize_names: true)
-
- labels = json[:data][:attributes][:labels]
- expect(labels[:body]).to be_kind_of(Array)
-
- first_label = labels[:body].first
- expect(first_label[:label_1][:storage_condition]).to eql('37C')
- end
-
- it "should serialize a batch with special symbols in storage condition" do
- batch = create(:batch_with_consumables)
- batch.consumable_type.storage_condition = 0
- print_job = PrintJob.new(batch: batch, printer: 'ABC123', label_template_id: 1)
- json = JSON.parse(print_job.to_json, symbolize_names: true)
-
- labels = json[:data][:attributes][:labels]
- expect(labels[:body]).to be_kind_of(Array)
-
- first_label = labels[:body].first
- expect(first_label[:label_1][:storage_condition]).to eql('37C')
- end
-
- it 'should serialize a batch with no storage condition' do
- batch = create(:batch_with_consumables)
- batch.consumable_type.storage_condition = nil
- print_job = PrintJob.new(batch: batch, printer: 'ABC123', label_template_id: 1)
- json = JSON.parse(print_job.to_json, symbolize_names: true)
-
- labels = json[:data][:attributes][:labels]
- expect(labels[:body]).to be_kind_of(Array)
-
- first_label = labels[:body].first
- expect(first_label[:label_1][:storage_condition]).to eql("")
- end
-
it "should return true when a print job executes successfully" do
- allow(RestClient).to receive(:post).and_return(OpenStruct.new(:code => 200))
+ allow(PMB::PrintJob).to receive(:execute).and_return(true)
expect(@print_job.execute!).to eq(true)
end
it "should return false when a print job fails" do
- exception = RestClient::Exception.new(OpenStruct.new(code: 500))
- allow(RestClient).to receive(:post).and_raise(exception)
+ allow(PMB::PrintJob).to receive(:execute).and_raise(JsonApiClient::Errors::ServerError.new({}))
expect(@print_job.execute!).to eq(false)
end
+ # Keeping this test in because it needs to be re-enabled once PMB has been fixed
it 'should populate errors when a 422 is thrown' do
+ pending 'Need PMB to be fixed'
exception = RestClient::Exception.new(OpenStruct.new(code: 422, to_str: '{"errors":{"printer":["Printer does not exist"]}}'))
allow(RestClient).to receive(:post).and_raise(exception)
expect(@print_job.execute!).to eq(false)
@@ -121,24 +57,4 @@
expect(print_job.errors.to_a).to include("Label template does not exist")
end
- it 'should only generate a single label if all barcodes are identical' do
- batch = create(:batch)
- consumable = create(:consumable)
- batch.consumables << (1..3).map {|n| consumable.dup}
-
- expect(batch.consumables[0].barcode).to eq(consumable.barcode)
- expect(batch.consumables[1].barcode).to eq(consumable.barcode)
- expect(batch.consumables[2].barcode).to eq(consumable.barcode)
-
- print_job = PrintJob.new(batch: batch, printer: @print_job.printer, label_template_id: @print_job.label_template_id)
- json = JSON.parse(print_job.to_json, symbolize_names: true)
-
- labels = json[:data][:attributes][:labels]
- expect(labels[:body]).to be_kind_of(Array)
- expect(labels[:body].count).to eq(1)
-
- first_label = labels[:body].first
- expect(first_label[:label_1][:barcode]).to eql(consumable.barcode)
- expect(first_label[:label_1][:barcode_text]).to eql(consumable.barcode)
- end
end
\ No newline at end of file
diff --git a/spec/models/consumable_spec.rb b/spec/models/consumable_spec.rb
index 5f9bbcc..5c687e2 100644
--- a/spec/models/consumable_spec.rb
+++ b/spec/models/consumable_spec.rb
@@ -16,15 +16,11 @@
end
it "should have a display volume" do
- expect(build(:consumable, volume: 100, unit: 'μL').display_volume).to eql('100μL')
- end
-
- it "should have a simple volume" do
- expect(build(:consumable, volume: 100, unit: 'μL').simple_volume).to eql('100uL')
+ expect(build(:consumable, volume: 100, unit: 'µL').display_volume).to eql('100µL')
end
it "should show fractional volume when given one" do
- expect(build(:consumable, volume: 100.05, unit: 'μL').display_volume).to eql('100.05μL')
+ expect(build(:consumable, volume: 100.05, unit: 'µL').display_volume).to eql('100.05µL')
end
it "should not be valid without a volume" do
diff --git a/spec/models/consumable_type_spec.rb b/spec/models/consumable_type_spec.rb
index f290290..0829452 100644
--- a/spec/models/consumable_type_spec.rb
+++ b/spec/models/consumable_type_spec.rb
@@ -45,8 +45,4 @@
expect(build(:consumable_type)).to respond_to(:audits)
end
- it "should simplify storage condition" do
- expect(build(:consumable_type, storage_condition: 0).simple_storage_condition).to eql('37C')
- end
-
end