Skip to content

Commit

Permalink
Fix flaky specs
Browse files Browse the repository at this point in the history
We are now triggering caching for shipments an line items when we call
`order.contents.add`. This meant that `order.shipments` and
`order.line_items` needed to be reloaded for these specs. Also, the
`order.shipments.reload` that I had added caused flakiness because
in Postgres they would sometimes reload in a random order and then
`shipments.first` and `shipments.last` wouldn't be the expected items.
  • Loading branch information
jordan-brough committed Aug 18, 2016
1 parent cb302fb commit 0ca63c3
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions backend/spec/features/admin/orders/order_details_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
before do
@shipment1 = order.shipments.create(stock_location_id: stock_location.id)
order.contents.add(product.master, 2)
# order.contents.add causes things (like line items & shipments) to get
# cached, and these are going to change during this spec so we go ahead and
# reload now
order.reload
end

context 'as Admin' do
Expand Down Expand Up @@ -185,8 +189,6 @@

expect(page).to have_css('.shipment', count: 2)

order.shipments.reload

expect(order.shipments.count).to eq(2)
expect(order.shipments.last.backordered?).to eq(false)
expect(order.shipments.first.inventory_units_for(product.master).count).to eq(1)
Expand All @@ -201,8 +203,6 @@

expect(page).to have_content("pending package from 'Clarksville'")

order.shipments.reload

expect(order.shipments.count).to eq(1)
expect(order.shipments.last.backordered?).to eq(false)
expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
Expand All @@ -217,8 +217,6 @@

expect(page).to have_content("pending package from 'Clarksville'")

order.shipments.reload

expect(order.shipments.count).to eq(1)
expect(order.shipments.last.backordered?).to eq(false)
expect(order.shipments.first.inventory_units_for(product.master).count).to eq(5)
Expand All @@ -233,8 +231,6 @@

wait_for_ajax

order.shipments.reload

expect(order.shipments.count).to eq(1)
expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
Expand All @@ -248,8 +244,6 @@

wait_for_ajax

order.shipments.reload

expect(order.shipments.count).to eq(1)
expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
Expand Down Expand Up @@ -290,8 +284,6 @@

wait_for_ajax

order.shipments.reload

expect(order.shipments.count).to eq(1)
expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
expect(order.shipments.first.stock_location.id).to eq(stock_location.id)
Expand All @@ -308,8 +300,6 @@

expect(page).to have_content("pending package from 'Clarksville'")

order.shipments.reload

expect(order.shipments.count).to eq(1)
expect(order.shipments.first.inventory_units_for(product.master).count).to eq(2)
expect(order.shipments.first.stock_location.id).to eq(stock_location2.id)
Expand All @@ -320,6 +310,8 @@
context 'multiple items in cart' do
it 'should have no problem splitting if multiple items are in the from shipment' do
order.contents.add(create(:variant), 2)
order.reload

expect(order.shipments.count).to eq(1)
expect(order.shipments.first.manifest.count).to eq(2)

Expand All @@ -328,8 +320,6 @@

expect(page).to have_css('.shipment', count: 2)

order.shipments.reload

expect(order.shipments.count).to eq(2)
expect(order.shipments.last.backordered?).to eq(false)
expect(order.shipments.first.inventory_units_for(product.master).count).to eq(1)
Expand All @@ -341,7 +331,6 @@
context 'removing an item' do
it "removes only the one item" do
@shipment2 = order.shipments.create(stock_location_id: stock_location2.id)
order.line_items.reload # inventory units are outdated
order.line_items[0].inventory_units[0].update!(shipment: @shipment2)
visit spree.edit_admin_order_path(order)

Expand Down Expand Up @@ -371,8 +360,6 @@

expect(page).to have_css("#shipment_#{@shipment2.id}", count: 1)

order.shipments.reload

expect(order.shipments.count).to eq(1)
expect(order.shipments.last.inventory_units_for(product.master).count).to eq(2)
end
Expand All @@ -396,8 +383,6 @@

wait_for_ajax

order.shipments.reload

expect(order.shipments.count).to eq(2)
expect(order.shipments.first.inventory_units_for(product.master).count).to eq(1)
expect(order.shipments.last.inventory_units_for(product.master).count).to eq(1)
Expand All @@ -415,15 +400,14 @@
it 'should split fine if more than one line_item is in the receiving shipment' do
variant2 = create(:variant)
order.contents.add(variant2, 2, shipment: @shipment2)
order.reload

within_row(1) { click_icon 'arrows-h' }
complete_split_to(@shipment2, quantity: 1)

expect(page).not_to have_content(/Move .* to/)
expect(page).to have_css('.shipment', count: 2)

order.shipments.reload

expect(order.shipments.count).to eq(2)
expect(order.shipments.first.inventory_units_for(product.master).count).to eq 1
expect(order.shipments.last.inventory_units_for(product.master).count).to eq 1
Expand Down

0 comments on commit 0ca63c3

Please sign in to comment.