Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and tweak barcode tests #4700

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
28 changes: 19 additions & 9 deletions spec/models/barcode_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,29 @@
it "->barcodeable_id shows only barcodes for a specific barcodeable_id" do
global_barcode_item
create(:global_barcode_item, base_item: create(:base_item))
results = BarcodeItem.barcodeable_id(base_item.id)
items = BarcodeItem.barcodeable_id(base_item.id)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This felt more descriptive, and matches what we used in our new/altered tests below.


expect(results.length).to eq(1)
expect(results.first).to eq(global_barcode_item)
expect(items.length).to eq(1)
expect(items.first).to eq(global_barcode_item)
end
it "#by_base_item_partner_key returns barcodes that match the partner key" do
c1 = create(:base_item, partner_key: "foo")
c2 = create(:base_item, partner_key: "bar")
b1 = create(:global_barcode_item, barcodeable: c1)
create(:global_barcode_item, barcodeable: c2)
expect(BarcodeItem.by_base_item_partner_key("foo").first).to eq(b1)
items = BarcodeItem.by_base_item_partner_key("foo")
expect(items).to have_attributes(length: 1)
expect(items.first).to eq(b1)
end
it "#by_item_partner_key returns barcodes that match the partner key" do
b1 = create(:barcode_item) # this will create an item and base item

# explicitly create a base item here so the partner key is different
other_base = create(:base_item, partner_key: "somethingelse")
create(:barcode_item, barcodeable: other_base)
items = BarcodeItem.by_item_partner_key(b1.barcodeable.partner_key)
expect(items).to have_attributes(length: 1)
expect(items.first).to eq(b1)
end
it "->by_value returns the barcode with that value" do
b1 = create(:global_barcode_item, value: "DEADBEEF")
Expand All @@ -78,13 +90,11 @@
end

context "scopes >" do
describe "barcodeable_id" # TODO: Write test
describe "by_item_partner_key" # TODO: Write test
describe "by_base_item_partner_key" # TODO: Write test
describe "by_value" # TODO: Write test
# The following scopes are tested in the filter tests above:
# barcodeable_id, by_base_item_partner_key, by_item_partner_key, by_value
describe "for_csv_export" # TODO: Write test
describe "global" do
it "includes all barcodes, for both base items and regular items" do
it "only includes barcode for base items, since those are available globally" do
create(:global_barcode_item)
expect do
create(:barcode_item)
Expand Down