mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Merge branch 'master' into enterprises
Conflicts: app/controllers/enterprises_controller.rb app/views/spree/checkout/_distributor.html.haml db/schema.rb spec/lib/open_food_web/group_buy_report_spec.rb
This commit is contained in:
@@ -36,7 +36,7 @@ module OpenFoodWeb
|
||||
@orders << order2
|
||||
|
||||
@supplier2 = create(:supplier_enterprise)
|
||||
@variant3 = create(:variant)
|
||||
@variant3 = create(:variant, :weight => nil)
|
||||
@variant3.product.supplier = @supplier2
|
||||
@variant3.product.save!
|
||||
product_distribution = create(:product_distribution, :product => @variant3.product, :distributor => distributor, :shipping_method => create(:shipping_method))
|
||||
@@ -82,12 +82,12 @@ module OpenFoodWeb
|
||||
|
||||
table_row_objects = subject.variants_and_quantities
|
||||
|
||||
variant_rows = table_row_objects.select{ |r| r.class == OpenFoodWeb::GroupBuyVariantRow }
|
||||
product_rows = table_row_objects.select{ |r| r.class == OpenFoodWeb::GroupBuyProductRow }
|
||||
variant_rows = table_row_objects.select { |r| r.class == OpenFoodWeb::GroupBuyVariantRow }
|
||||
product_rows = table_row_objects.select { |r| r.class == OpenFoodWeb::GroupBuyProductRow }
|
||||
|
||||
supplier_groups = variant_rows.group_by { |r| r.variant.product.supplier }
|
||||
variant_groups = variant_rows.group_by{ |r| r.variant }
|
||||
product_groups = product_rows.group_by{ |r| r.product }
|
||||
variant_groups = variant_rows.group_by { |r| r.variant }
|
||||
product_groups = product_rows.group_by { |r| r.product }
|
||||
|
||||
supplier_groups.length.should == 2
|
||||
variant_groups.length.should == 3
|
||||
|
||||
152
spec/lib/open_food_web/order_grouper_spec.rb
Normal file
152
spec/lib/open_food_web/order_grouper_spec.rb
Normal file
@@ -0,0 +1,152 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module OpenFoodWeb
|
||||
describe OrderGrouper do
|
||||
|
||||
before(:each) do
|
||||
@items = [1, 2, 3, 4]
|
||||
end
|
||||
|
||||
context "constructing the table" do
|
||||
it "should build a tree then build a table" do
|
||||
rules = [ { group_by: Proc.new { |sentence| sentence.paragraph.chapter }, sort_by: Proc.new { |chapter| chapter.name }, summary_columns: [Proc.new { |is| is.first.paragraph.chapter.name }, Proc.new { |is| "TOTAL" }, Proc.new { |is| "" }, Proc.new { |is| is.sum {|i| i.property1 } } ] },
|
||||
{ group_by: Proc.new { |sentence| sentence.paragraph }, sort_by: Proc.new { |paragraph| paragraph.name } } ]
|
||||
columns = [Proc.new { |is| is.first.paragraph.chapter.name }, Proc.new { |is| is.first.paragraph.name }, Proc.new { |is| is.first.name }, Proc.new { |is| is.sum {|i| i.property1 } }]
|
||||
|
||||
subject = OrderGrouper.new rules, columns
|
||||
|
||||
tree = double(:tree)
|
||||
subject.should_receive(:build_tree).with(@items, rules).and_return(tree)
|
||||
subject.should_receive(:build_table).with(tree)
|
||||
|
||||
subject.table(@items)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "grouping items without rules" do
|
||||
it "returns the original array when no rules are provided" do
|
||||
rules = []
|
||||
column1 = double(:col1)
|
||||
column2 = double(:col2)
|
||||
columns = [column1, column2]
|
||||
subject = OrderGrouper.new rules, columns
|
||||
|
||||
rules.should_receive(:clone).and_return(rules)
|
||||
subject.build_tree(@items, rules).should == @items
|
||||
end
|
||||
end
|
||||
|
||||
context "grouping items with rules" do
|
||||
|
||||
before(:each) do
|
||||
@rule1 = double(:rule1)
|
||||
rule2 = double(:rule2)
|
||||
@rules = [@rule1, rule2]
|
||||
@remaining_rules = [rule2]
|
||||
column1 = double(:col1)
|
||||
column2 = double(:col2)
|
||||
@columns = [column1, column2]
|
||||
end
|
||||
|
||||
it "builds branches by removing a rule from 'rules' and running group_and_sort" do
|
||||
subject = OrderGrouper.new @rules, @columns
|
||||
|
||||
@rules.should_receive(:clone).and_return(@rules)
|
||||
@rules.should_receive(:delete_at).with(0)
|
||||
grouped_tree = double(:grouped_tree)
|
||||
subject.should_receive(:group_and_sort).and_return(grouped_tree)
|
||||
|
||||
subject.build_tree(@items, @rules).should == grouped_tree
|
||||
end
|
||||
|
||||
it "separates the first rule from rules before sending to group_and_sort" do
|
||||
subject = OrderGrouper.new @rules, @columns
|
||||
|
||||
grouped_tree = double(:grouped_tree)
|
||||
subject.should_receive(:group_and_sort).with(@rule1, @rules[1..-1], @items).and_return(grouped_tree)
|
||||
|
||||
subject.build_tree(@items, @rules).should == grouped_tree
|
||||
end
|
||||
|
||||
it "should group, then sort, send each group to build_tree, and return a branch" do
|
||||
summary_columns_object = double(:summary_columns)
|
||||
@rule1.stub(:[]).with(:summary_columns) { summary_columns_object }
|
||||
|
||||
subject = OrderGrouper.new @rules, @columns
|
||||
|
||||
number_of_categories = 3
|
||||
groups = double(:groups)
|
||||
@items.should_receive(:group_by).and_return(groups)
|
||||
sorted_groups = {}
|
||||
1.upto(number_of_categories) { |i| sorted_groups[i] = double(:group, name: "Group "+ i.to_s ) }
|
||||
groups.should_receive(:sort_by).and_return(sorted_groups)
|
||||
group = { group1: 1, group2: 2, group3: 3 }
|
||||
subject.should_receive(:build_tree).exactly(number_of_categories).times.and_return(group)
|
||||
|
||||
group_tree = {}
|
||||
1.upto(number_of_categories) { |i| group_tree[i] = group }
|
||||
1.upto(number_of_categories) { |i| group_tree[i][:summary_row] = summary_columns_object }
|
||||
subject.group_and_sort(@rule1, @remaining_rules, @items).should == group_tree
|
||||
end
|
||||
end
|
||||
|
||||
context "building the table Array" do
|
||||
before(:each) do
|
||||
rule1 = double(:rule1)
|
||||
rule2 = double(:rule2)
|
||||
@rules = [rule1, rule2]
|
||||
@column1 = double(:col1, :call => "Column1")
|
||||
@column2 = double(:col2, :call => "Column2")
|
||||
@columns = [@column1, @column2]
|
||||
|
||||
sumcol1 = double(:sumcol1, :call => "SumColumn1")
|
||||
sumcol2 = double(:sumcol2, :call => "SumColumn2")
|
||||
@sumcols = [sumcol1, sumcol2]
|
||||
|
||||
item1 = double(:item1)
|
||||
item2 = double(:item2)
|
||||
item3 = double(:item3)
|
||||
@items1 = [item1, item2]
|
||||
@items2 = [item2, item3]
|
||||
@items3 = [item3, item1]
|
||||
end
|
||||
it "should return columns when given an Array" do
|
||||
subject = OrderGrouper.new @rules, @columns
|
||||
|
||||
@column1.should_receive(:call)
|
||||
@column2.should_receive(:call)
|
||||
|
||||
subject.build_table(@items1).should == [["Column1", "Column2"]]
|
||||
end
|
||||
|
||||
it "should return a row for each key-value pair when given a Hash" do
|
||||
groups = { items1: @items1, items2: @items2, items3: @items3 }
|
||||
|
||||
subject = OrderGrouper.new @rules, @columns
|
||||
|
||||
#subject.should_receive(:build_table).exactly(2).times
|
||||
|
||||
expected_return = []
|
||||
groups.length.times { expected_return << ["Column1", "Column2"] }
|
||||
subject.build_table(groups).should == expected_return
|
||||
end
|
||||
|
||||
it "should return an extra row when a :summary_row key appears in a given Hash" do
|
||||
groups = { items1: @items1, items2: @items2, items3: @items3, summary_row: { items: { items2: @items2, items3: @items3 }, columns: @sumcols } }
|
||||
|
||||
subject = OrderGrouper.new @rules, @columns
|
||||
|
||||
expected_return = []
|
||||
groups.each do |key, group|
|
||||
if key == :summary_row
|
||||
expected_return << ["SumColumn1", "SumColumn2"]
|
||||
else
|
||||
expected_return << ["Column1", "Column2"]
|
||||
end
|
||||
end
|
||||
subject.build_table(groups).should == expected_return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -49,14 +49,14 @@ feature %q{
|
||||
fill_in 'product_price', :with => '19.99'
|
||||
select 'New supplier', :from => 'product_supplier_id'
|
||||
choose 'product_group_buy_1'
|
||||
fill_in 'Group buy unit size', :with => '10 kg'
|
||||
fill_in 'Group buy unit size', :with => '10'
|
||||
|
||||
click_button 'Create'
|
||||
|
||||
flash_message.should == 'Product "A new product !!!" has been successfully created!'
|
||||
product = Spree::Product.find_by_name('A new product !!!')
|
||||
product.group_buy.should be_true
|
||||
product.group_buy_unit_size.should == '10 kg'
|
||||
product.group_buy_unit_size.should == 10.0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -24,4 +24,28 @@ feature %q{
|
||||
page.should have_content 'Supplier'
|
||||
end
|
||||
|
||||
scenario "bulk co-op report" do
|
||||
login_to_admin_section
|
||||
click_link 'Reports'
|
||||
click_link 'Bulk Co-Op'
|
||||
|
||||
page.should have_content 'Supplier'
|
||||
end
|
||||
|
||||
scenario "payments reports" do
|
||||
login_to_admin_section
|
||||
click_link 'Reports'
|
||||
click_link 'Payment Reports'
|
||||
|
||||
page.should have_content 'Payment State'
|
||||
end
|
||||
|
||||
scenario "order cycle reports" do
|
||||
login_to_admin_section
|
||||
click_link 'Reports'
|
||||
click_link 'Order Cycle Reports'
|
||||
|
||||
page.should have_content 'Supplier'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -22,4 +22,62 @@ feature %q{
|
||||
page.should have_selector 'td', :text => d.name
|
||||
end
|
||||
|
||||
describe "viewing distributor details" do
|
||||
context "without Javascript" do
|
||||
it "displays a holding message when no distributor is selected" do
|
||||
p = create(:product)
|
||||
|
||||
visit spree.product_path p
|
||||
|
||||
page.should have_selector '#product-distributor-details', :text => 'When you select a distributor for your order, their address and pickup times will be displayed here.'
|
||||
end
|
||||
|
||||
it "displays distributor details when one is selected" do
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d])
|
||||
|
||||
visit spree.root_path
|
||||
click_link d.name
|
||||
visit spree.product_path p
|
||||
|
||||
within '#product-distributor-details' do
|
||||
[d.name,
|
||||
d.address.address1,
|
||||
d.address.city,
|
||||
d.address.zipcode,
|
||||
d.address.state_text,
|
||||
d.address.country.name,
|
||||
d.pickup_times,
|
||||
d.next_collection_at,
|
||||
d.contact,
|
||||
d.phone,
|
||||
d.email,
|
||||
d.description,
|
||||
d.website].each do |value|
|
||||
|
||||
page.should have_content value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with Javascript", js: true do
|
||||
it "changes distributor details when the distributor is changed" do
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
d3 = create(:distributor_enterprise)
|
||||
p = create(:product, :distributors => [d1, d2, d3])
|
||||
|
||||
visit spree.product_path p
|
||||
|
||||
[d1, d2, d3].each do |d|
|
||||
select d.name, :from => 'distributor_id'
|
||||
|
||||
within '#product-distributor-details' do
|
||||
page.should have_selector 'h2', :text => d.name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user