Intermittent fail hunting

This commit is contained in:
Rob Harrington
2016-05-27 15:04:43 +10:00
parent a1c7a44fa0
commit 6dd05ca4da
3 changed files with 27 additions and 19 deletions

View File

@@ -24,10 +24,9 @@ Spree::Taxon.class_eval do
joins(:products => :supplier).
select('spree_taxons.*, enterprises.id AS enterprise_id').
each do |t|
taxons[t.enterprise_id.to_i] ||= Set.new
taxons[t.enterprise_id.to_i] << t.id
end
taxons[t.enterprise_id.to_i] ||= Set.new
taxons[t.enterprise_id.to_i] << t.id
end
taxons
end
@@ -43,10 +42,9 @@ Spree::Taxon.class_eval do
where('o_exchanges.incoming = ?', false).
select('spree_taxons.*, o_exchanges.receiver_id AS enterprise_id').
each do |t|
taxons[t.enterprise_id.to_i] ||= Set.new
taxons[t.enterprise_id.to_i] << t.id
end
taxons[t.enterprise_id.to_i] ||= Set.new
taxons[t.enterprise_id.to_i] << t.id
end
taxons
end

View File

@@ -44,10 +44,11 @@ feature "Registration", js: true do
# Choosing a type
expect(page).to have_content 'Last step to add My Awesome Enterprise!'
click_link 'producer-panel'
click_link_and_ensure('producer-panel', lambda { page.has_content? '#producer-panel.selected' } )
click_button 'Create Profile'
# Enterprise should be created
# save_screenshot '/Users/rob/Desktop/ss.png' unless page.has_content? "Nice one!"
expect(page).to have_content 'Nice one!'
e = Enterprise.find_by_name('My Awesome Enterprise')
expect(e.address.address1).to eq "123 Abc Street"
@@ -129,4 +130,14 @@ feature "Registration", js: true do
end
end
end
def click_link_and_ensure(link_text, check)
# Buttons appear to be unresponsive for a while, so keep clicking them until content appears
using_wait_time 0.5 do
10.times do
click_link link_text
break if check.call
end
end
end
end

View File

@@ -3,21 +3,20 @@ require 'spec_helper'
module Spree
describe Taxon do
let(:e) { create(:supplier_enterprise) }
let(:t0) { p1.taxons.order('id ASC').first }
let(:t1) { create(:taxon) }
let(:t2) { create(:taxon) }
let!(:t1) { create(:taxon) }
let!(:t2) { create(:taxon) }
describe "callbacks" do
let(:product) { create(:simple_product, taxons: [t1]) }
let!(:p2) { create(:simple_product, taxons: [t1]) }
it "refreshes the products cache on save" do
expect(OpenFoodNetwork::ProductsCache).to receive(:product_changed).with(product)
expect(OpenFoodNetwork::ProductsCache).to receive(:product_changed).with(p2)
t1.name = 'asdf'
t1.save
end
it "refreshes the products cache on destroy" do
expect(OpenFoodNetwork::ProductsCache).to receive(:product_changed).with(product)
expect(OpenFoodNetwork::ProductsCache).to receive(:product_changed).with(p2)
t1.destroy
end
end
@@ -26,17 +25,17 @@ module Spree
let!(:p1) { create(:simple_product, supplier: e, taxons: [t1, t2]) }
it "finds taxons" do
Taxon.supplied_taxons.should == {e.id => Set.new([t0.id, t1.id, t2.id])}
Taxon.supplied_taxons.should == {e.id => Set.new(p1.taxons.map(&:id))}
end
end
describe "finding all distributed taxons" do
let!(:oc) { create(:simple_order_cycle, distributors: [e], variants: [p1.master]) }
let(:s) { create(:supplier_enterprise) }
let(:p1) { create(:simple_product, supplier: s, taxons: [t1, t2]) }
let!(:s) { create(:supplier_enterprise) }
let!(:p1) { create(:simple_product, supplier: s, taxons: [t1, t2]) }
it "finds taxons" do
Taxon.distributed_taxons.should == {e.id => Set.new([t0.id, t1.id, t2.id])}
Taxon.distributed_taxons.should == {e.id => Set.new(p1.taxons.map(&:id))}
end
end
end