|
33 | 33 | }) |
34 | 34 | end |
35 | 35 |
|
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 } |
47 | 41 |
|
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 |
49 | 50 |
|
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 |
53 | 66 | end |
54 | 67 |
|
55 | 68 | it "can add items correctly" do |
|
0 commit comments