-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from jbeast/pmb-client-integration
Integrated with PMB Client gem
- Loading branch information
Showing
15 changed files
with
136 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,4 +41,6 @@ | |
|
||
# config.stub_ldap = true | ||
|
||
# Print My Barcode api base | ||
config.x.pmb_api_base = 'http://pmb.dev/api/v1' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PMB::Base.site = Rails.configuration.x.pmb_api_base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.