Skip to content

Commit 9e41917

Browse files
author
Olexii Kasianenko
committed
fix(kit_creation): update item visibility and value during kit creation
1 parent 3e45d92 commit 9e41917

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

app/services/kit_create_service.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ def call
4343
unless item_creation_result.success?
4444
raise item_creation_result.error
4545
end
46+
kit.items.update_all(visible_to_partners: kit.visible_to_partners)
47+
kit.items.each do |item|
48+
item.update!(value_in_dollars: kit.value_in_dollars)
49+
end
4650
rescue StandardError => e
4751
errors.add(:base, e.message)
4852
raise ActiveRecord::Rollback

spec/system/kit_system_spec.rb

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,36 @@
3333
})
3434
end
3535

36-
it "can create a new kit as a user with the proper quantity" do
37-
visit new_kit_path
38-
kit_traits = attributes_for(:kit)
39-
40-
fill_in "Name", with: kit_traits[:name]
41-
find(:css, '#kit_value_in_dollars').set('10.10')
42-
43-
item = Item.last
44-
quantity_per_kit = 5
45-
select item.name, from: "kit_line_items_attributes_0_item_id"
46-
find(:css, '#kit_line_items_attributes_0_quantity').set(quantity_per_kit)
36+
context "kit creation" do
37+
let(:kit_traits) { attributes_for(:kit) }
38+
let(:item) { Item.last }
39+
let(:quantity_per_kit) { 5 }
40+
let(:value_in_dollars) { 10.10 }
4741

48-
click_button "Save"
42+
before do
43+
visit new_kit_path
44+
fill_in "Name", with: kit_traits[:name]
45+
find(:css, '#visible_to_partners').set(false)
46+
find(:css, '#kit_value_in_dollars').set(value_in_dollars)
47+
select item.name, from: "kit_line_items_attributes_0_item_id"
48+
find(:css, '#kit_line_items_attributes_0_quantity').set(quantity_per_kit)
49+
end
4950

50-
expect(page.find(".alert")).to have_content "Kit created successfully"
51-
expect(page).to have_content(kit_traits[:name])
52-
expect(page).to have_content("#{quantity_per_kit} #{item.name}")
51+
subject { click_button "Save" }
52+
53+
it "can create a new kit as a user with the proper quantity" do
54+
expect {
55+
subject
56+
expect(page.find(".alert")).to have_content "Kit created successfully"
57+
expect(page).to have_content(kit_traits[:name])
58+
expect(page).to have_content("#{quantity_per_kit} #{item.name}")
59+
expect(Kit.last.name).to eq(kit_traits[:name])
60+
expect(Kit.last.visible_to_partners).to eq(false)
61+
expect(Kit.last.value_in_dollars).to eq(value_in_dollars)
62+
expect(item.reload.visible_to_partners).to eq(false)
63+
expect(item.reload.value_in_dollars).to eq(value_in_dollars)
64+
}.to change(Kit, :count).by(1)
65+
end
5366
end
5467

5568
it "can add items correctly" do

0 commit comments

Comments
 (0)