Skip to content

Commit

Permalink
FIX rename to Item.contained_in_line_items to avoid name conflict, ad…
Browse files Browse the repository at this point in the history
…d rspec
  • Loading branch information
jimmyli97 committed Aug 16, 2024
1 parent 1b2fedc commit 02ce2a3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Item < ApplicationRecord

validate :has_no_line_items, if: -> { kit.blank? }

has_many :line_items, dependent: :destroy
has_many :contained_in_line_items, class_name: "LineItem", dependent: :destroy
has_many :inventory_items, dependent: :destroy
has_many :barcode_items, as: :barcodeable, dependent: :destroy
has_many :storage_locations, through: :inventory_items
Expand Down
2 changes: 1 addition & 1 deletion app/services/historical_trend_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def series
items_with_line_items.each_with_object([]) do |item, array_of_items|
dates = default_dates.deep_dup

item.line_items.each do |line_item|
item.contained_in_line_items.each do |line_item|
month = line_item.created_at.month
index = month_offset.index(month) + 1
dates[index] = dates[index] + line_item.quantity
Expand Down
11 changes: 9 additions & 2 deletions spec/models/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@

let(:organization) { create(:organization) }

describe 'Assocations >' do
describe 'Associations >' do
it { should belong_to(:item_category).optional }
it "should return line items containing the item" do
item = create(:item)
create(:line_item, item: item)
expect(item.contained_in_line_items.count).to eq(1)
end
end
context "Validations >" do
it "requires a unique name" do
Expand All @@ -44,8 +49,10 @@
it { should validate_numericality_of(:on_hand_recommended_quantity).is_greater_than_or_equal_to(0) }

context "Doesn't house a kit >" do
it "ensures associated line_items are empty" do
it "ensures associated itemizable line_items don't exist without invalidating associated line_items" do
item = create(:item)
create(:line_item, item: item)
expect(item).to be_valid
item.line_items << build(:line_item, quantity: 1)
expect(item).not_to be_valid
end
Expand Down

0 comments on commit 02ce2a3

Please sign in to comment.