From fa0cc6f2c82abcf36032a10ed370ade52a98ae50 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 15 Jun 2016 10:10:40 +1000 Subject: [PATCH 1/8] Add spec for filtering producers by taxon --- spec/features/consumer/producers_spec.rb | 57 +++++++++++++++++++----- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/spec/features/consumer/producers_spec.rb b/spec/features/consumer/producers_spec.rb index 8a26eaf026..20676c7dbc 100644 --- a/spec/features/consumer/producers_spec.rb +++ b/spec/features/consumer/producers_spec.rb @@ -5,22 +5,43 @@ feature %q{ I want to see a list of producers So that I can shop at hubs distributing their products }, js: true do + include WebHelper include UIComponentHelper - let!(:producer) { create(:supplier_enterprise) } - let!(:invisible_producer) { create(:supplier_enterprise, visible: false) } - let(:taxon) { create(:taxon) } - let!(:product) { create(:simple_product, supplier: producer, taxons: [taxon]) } - let(:shop) { create(:distributor_enterprise) } - let!(:er) { create(:enterprise_relationship, parent: shop, child: producer) } - before do - visit producers_path + let!(:producer1) { create(:supplier_enterprise) } + let!(:producer2) { create(:supplier_enterprise) } + let!(:invisible_producer) { create(:supplier_enterprise, visible: false) } + + let(:taxon_fruit) { create(:taxon, name: 'Fruit') } + let(:taxon_veg) { create(:taxon, name: 'Vegetables') } + + let!(:product1) { create(:simple_product, supplier: producer1, taxons: [taxon_fruit]) } + let!(:product2) { create(:simple_product, supplier: producer2, taxons: [taxon_veg]) } + + let(:shop) { create(:distributor_enterprise) } + let!(:er) { create(:enterprise_relationship, parent: shop, child: producer1) } + + before { visit producers_path } + + it "filters by taxon" do + toggle_filters + + toggle_filter 'Vegetables' + + page.should_not have_content producer1.name + page.should have_content producer2.name + + toggle_filter 'Vegetables' + toggle_filter 'Fruit' + + page.should have_content producer1.name + page.should_not have_content producer2.name end it "shows all producers with expandable details" do - page.should have_content producer.name - expand_active_table_node producer.name - page.should have_content producer.supplied_taxons.first.name.split.map(&:capitalize).join(' ') + page.should have_content producer1.name + expand_active_table_node producer1.name + page.should have_content producer1.supplied_taxons.first.name.split.map(&:capitalize).join(' ') end it "doesn't show invisible producers" do @@ -28,7 +49,19 @@ feature %q{ end it "links to places to buy produce" do - expand_active_table_node producer.name + expand_active_table_node producer1.name page.should have_link shop.name end + + + private + + def toggle_filters + find('a.filterbtn').click + end + + def toggle_filter(name) + page.find('span', text: name).click + end + end From 4338f632f6af67534f9c28ca09012c538108c894 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 16 Jun 2016 10:43:53 +1000 Subject: [PATCH 2/8] Add scope: Spree::Property.applied_by --- app/models/spree/property_decorator.rb | 6 ++++++ spec/models/spree/property_spec.rb | 30 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/app/models/spree/property_decorator.rb b/app/models/spree/property_decorator.rb index 5b8e53338c..f6eaefc75f 100644 --- a/app/models/spree/property_decorator.rb +++ b/app/models/spree/property_decorator.rb @@ -1,5 +1,11 @@ module Spree Property.class_eval do + scope :applied_by, ->(enterprise) { + select('DISTINCT spree_properties.*'). + joins(:product_properties). + where('spree_product_properties.product_id IN (?)', enterprise.supplied_product_ids) + } + after_save :refresh_products_cache # When a Property is destroyed, dependent-destroy will destroy all ProductProperties, diff --git a/spec/models/spree/property_spec.rb b/spec/models/spree/property_spec.rb index a86513b5a9..6867b9de1f 100644 --- a/spec/models/spree/property_spec.rb +++ b/spec/models/spree/property_spec.rb @@ -2,6 +2,36 @@ require 'spec_helper' module Spree describe Property do + describe "scopes" do + describe ".applied_by" do + let(:producer) { create(:supplier_enterprise) } + let(:producer_other) { create(:supplier_enterprise) } + let(:product) { create(:simple_product, supplier: producer) } + let(:product_other_producer) { create(:simple_product, supplier: producer_other) } + let(:product_other_property) { create(:simple_product, supplier: producer) } + let(:property) { product.properties.last } + let(:property_other) { product_other_producer.properties.last } + + before do + product.set_property 'Organic', 'NASAA 12345' + product_other_property.set_property 'Organic', 'NASAA 12345' + product_other_producer.set_property 'Biodynamic', 'ASDF 1234' + end + + it "returns properties applied to supplied products" do + expect(Spree::Property.applied_by(producer)).to eq [property] + end + + it "doesn't return properties not applied" do + expect(Spree::Property.applied_by(producer)).not_to include property_other + end + + it "doesn't return duplicates" do + expect(Spree::Property.applied_by(producer).to_a.count).to eq 1 + end + end + end + describe "callbacks" do let(:property) { product_property.property } let(:product) { product_property.product } From aae1689a27a082c111e93ed43e3810eef848d9d7 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 16 Jun 2016 11:00:20 +1000 Subject: [PATCH 3/8] Show product properties on producers page --- .../darkswarm/producer_node.css.sass | 17 +++++++---------- .../stylesheets/darkswarm/taxons.css.sass | 4 ++-- app/serializers/api/enterprise_serializer.rb | 7 ++++++- app/serializers/api/property_serializer.rb | 2 +- app/views/producers/_fat.html.haml | 6 ++++++ spec/features/consumer/producers_spec.rb | 11 +++++++++-- 6 files changed, 31 insertions(+), 16 deletions(-) diff --git a/app/assets/stylesheets/darkswarm/producer_node.css.sass b/app/assets/stylesheets/darkswarm/producer_node.css.sass index 7bac2dde6d..78209845c5 100644 --- a/app/assets/stylesheets/darkswarm/producer_node.css.sass +++ b/app/assets/stylesheets/darkswarm/producer_node.css.sass @@ -5,7 +5,7 @@ .active_table .active_table_node // Header row - @media all and (max-width: 640px) + @media all and (max-width: 640px) .skinny-head background-color: $clr-turquoise-light @include border-radius-mixed(0.5em, 0.5em, 0, 0) @@ -16,7 +16,7 @@ .follow-icons &, & * font-size: 1.5rem - + // Producer icons i.ofn-i_059-producer, i.ofn-i_060-producer-reversed @@ -41,11 +41,11 @@ &:hover, &:focus, &:active &.secondary color: #666 - .hub-name, .button-address + .hub-name, .button-address border-bottom: 1px solid #999 &.primary color: $clr-brick-bright - .hub-name, .button-address + .hub-name, .button-address border-bottom: 1px solid $clr-brick-bright p.word-wrap @@ -53,7 +53,7 @@ &:last-child margin-bottom: 1rem - .fat-taxons + .fat-taxons, .fat-properties background-color: $clr-turquoise-light .producer-name @@ -72,7 +72,7 @@ max-height: 160px width: auto &.left - padding: 0.25rem 1rem 0.25rem 0 + padding: 0.25rem 1rem 0.25rem 0 &.right padding: 0.25rem 0.5rem 0.25rem 2rem @@ -87,10 +87,7 @@ &.closed .active_table_row.closed border: 1px solid transparent - @media all and (max-width: 640px) + @media all and (max-width: 640px) border-color: $clr-turquoise-light &:hover, &:active, &:focus border-color: $clr-turquoise - - - diff --git a/app/assets/stylesheets/darkswarm/taxons.css.sass b/app/assets/stylesheets/darkswarm/taxons.css.sass index 4f23a8bc3a..1d1e5b652f 100644 --- a/app/assets/stylesheets/darkswarm/taxons.css.sass +++ b/app/assets/stylesheets/darkswarm/taxons.css.sass @@ -1,7 +1,7 @@ @import branding @import mixins -.fat-taxons +.fat-taxons, .fat-properties display: inline-block line-height: 1 margin-right: 0.5rem @@ -29,7 +29,7 @@ svg path fill: $disabled-dark - + .product-header render-svg svg diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index 3210c1d2af..b0f4438e90 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -47,7 +47,7 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer attributes :taxons, :supplied_taxons has_one :address, serializer: Api::AddressSerializer - + has_many :properties, serializer: Api::PropertySerializer def taxons ids_to_objs options[:data].distributed_taxons[object.id] @@ -57,6 +57,11 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer ids_to_objs options[:data].supplied_taxons[object.id] end + def properties + # This results in 2 queries per enterprise + Spree::Property.applied_by(object) + end + def pickup services = options[:data].shipping_method_services[object.id] services ? services[:pickup] : false diff --git a/app/serializers/api/property_serializer.rb b/app/serializers/api/property_serializer.rb index ce04480d30..7da4fce990 100644 --- a/app/serializers/api/property_serializer.rb +++ b/app/serializers/api/property_serializer.rb @@ -1,3 +1,3 @@ class Api::PropertySerializer < ActiveModel::Serializer - + attributes :id, :name, :presentation end diff --git a/app/views/producers/_fat.html.haml b/app/views/producers/_fat.html.haml index 6b665b4f34..0fc082b361 100644 --- a/app/views/producers/_fat.html.haml +++ b/app/views/producers/_fat.html.haml @@ -20,6 +20,12 @@ %render-svg{path: "{{taxon.icon}}"} %span{"ng-bind" => "::taxon.name"} + %div + %label Product properties + %p.trans-sentence + %span.fat-properties{"ng-repeat" => "property in producer.properties"} + %span{"ng-bind" => "property.presentation"} + %div.show-for-medium-up{"ng-if" => "producer.supplied_taxons.length==0"}   diff --git a/spec/features/consumer/producers_spec.rb b/spec/features/consumer/producers_spec.rb index 20676c7dbc..4f3b4f7067 100644 --- a/spec/features/consumer/producers_spec.rb +++ b/spec/features/consumer/producers_spec.rb @@ -21,7 +21,13 @@ feature %q{ let(:shop) { create(:distributor_enterprise) } let!(:er) { create(:enterprise_relationship, parent: shop, child: producer1) } - before { visit producers_path } + before do + product1.set_property 'Organic', 'NASAA 12345' + product2.set_property 'Biodynamic', 'ABC123' + + visit producers_path + end + it "filters by taxon" do toggle_filters @@ -41,7 +47,8 @@ feature %q{ it "shows all producers with expandable details" do page.should have_content producer1.name expand_active_table_node producer1.name - page.should have_content producer1.supplied_taxons.first.name.split.map(&:capitalize).join(' ') + page.should have_content 'Fruit' + page.should have_content 'Organic' end it "doesn't show invisible producers" do From 58379a5e28a0a6b1e71696d9a8a2d591f6d4cd2e Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 17 Jun 2016 11:14:39 +1000 Subject: [PATCH 4/8] Extract property merging to lib class --- app/models/spree/product_decorator.rb | 7 ++---- lib/open_food_network/property_merge.rb | 18 +++++++++++++ spec/factories.rb | 6 +++++ .../open_food_network/property_merge_spec.rb | 25 +++++++++++++++++++ spec/models/spree/product_spec.rb | 2 +- 5 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 lib/open_food_network/property_merge.rb create mode 100644 spec/lib/open_food_network/property_merge_spec.rb diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index e6acd440c7..f8c177ceac 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -1,4 +1,5 @@ require 'open_food_network/permalink_generator' +require 'open_food_network/property_merge' Spree::Product.class_eval do include PermalinkGenerator @@ -128,11 +129,7 @@ Spree::Product.class_eval do ps = product_properties.all if inherits_properties - supplier.producer_properties.each do |producer_property| - unless ps.find { |product_property| product_property.property.presentation == producer_property.property.presentation } - ps << producer_property - end - end + ps = OpenFoodNetwork::PropertyMerge.merge(ps, supplier.producer_properties) end ps. diff --git a/lib/open_food_network/property_merge.rb b/lib/open_food_network/property_merge.rb new file mode 100644 index 0000000000..9c21fb7b0d --- /dev/null +++ b/lib/open_food_network/property_merge.rb @@ -0,0 +1,18 @@ +module OpenFoodNetwork + class PropertyMerge + def self.merge(primary, secondary) + primary + secondary.reject do |secondary_p| + primary.any? do |primary_p| + property_of(primary_p).presentation == property_of(secondary_p).presentation + end + end + end + + + private + + def self.property_of(p) + p.respond_to?(:property) ? p.property : p + end + end +end diff --git a/spec/factories.rb b/spec/factories.rb index 5729d6c12f..06f5dbd879 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -259,6 +259,12 @@ FactoryGirl.define do end end + factory :producer_property, class: ProducerProperty do + value 'abc123' + producer { create(:supplier_enterprise) } + property + end + factory :customer, :class => Customer do email { Faker::Internet.email } enterprise diff --git a/spec/lib/open_food_network/property_merge_spec.rb b/spec/lib/open_food_network/property_merge_spec.rb new file mode 100644 index 0000000000..85f4200ab0 --- /dev/null +++ b/spec/lib/open_food_network/property_merge_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +module OpenFoodNetwork + describe PropertyMerge do + let(:p1a) { create(:property, presentation: 'One') } + let(:p1b) { create(:property, presentation: 'One') } + let(:p2) { create(:property, presentation: 'Two') } + + describe "merging Spree::Properties" do + it "merges properties" do + expect(PropertyMerge.merge([p1a], [p1b, p2])).to eq [p1a, p2] + end + end + + describe "merging ProducerProperties and Spree::ProductProperties" do + let(:pp1a) { create(:product_property, property: p1a) } + let(:pp1b) { create(:producer_property, property: p1b) } + let(:pp2) { create(:producer_property, property: p2) } + + it "merges properties" do + expect(PropertyMerge.merge([pp1a], [pp1b, pp2])).to eq [pp1a, pp2] + end + end + end +end diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 9c2ee6b664..10e67e5900 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -420,7 +420,7 @@ module Spree end end - context "when product has an inherit_properties value set to true" do + context "when product has an inherit_properties value set to false" do let(:supplier) { create(:supplier_enterprise) } let(:product) { create(:simple_product, supplier: supplier, inherits_properties: false) } From 4134cbfc9c3e142070743dc846810d68ee22a1b4 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 17 Jun 2016 11:19:06 +1000 Subject: [PATCH 5/8] Include producer properties on producer listing --- app/serializers/api/enterprise_serializer.rb | 9 +++++++-- spec/features/consumer/producers_spec.rb | 10 +++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index b0f4438e90..127aee1a08 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -1,3 +1,5 @@ +require 'open_food_network/property_merge' + class Api::EnterpriseSerializer < ActiveModel::Serializer # We reference this here because otherwise the serializer complains about its absence Api::IdSerializer @@ -58,8 +60,11 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer end def properties - # This results in 2 queries per enterprise - Spree::Property.applied_by(object) + # This results in 3 queries per enterprise + product_properties = Spree::Property.applied_by(object) + producer_properties = object.properties + + OpenFoodNetwork::PropertyMerge.merge product_properties, producer_properties end def pickup diff --git a/spec/features/consumer/producers_spec.rb b/spec/features/consumer/producers_spec.rb index 4f3b4f7067..634350af18 100644 --- a/spec/features/consumer/producers_spec.rb +++ b/spec/features/consumer/producers_spec.rb @@ -25,6 +25,9 @@ feature %q{ product1.set_property 'Organic', 'NASAA 12345' product2.set_property 'Biodynamic', 'ABC123' + producer1.set_producer_property 'Local', 'Victoria' + producer2.set_producer_property 'Fair Trade', 'FT123' + visit producers_path end @@ -47,8 +50,13 @@ feature %q{ it "shows all producers with expandable details" do page.should have_content producer1.name expand_active_table_node producer1.name + + # -- Taxons page.should have_content 'Fruit' - page.should have_content 'Organic' + + # -- Properties + page.should have_content 'Organic' # Product property + page.should have_content 'Local' # Producer property end it "doesn't show invisible producers" do From a5a00e9cef15e1042b16ee4eb8f725335946dd53 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 17 Jun 2016 11:53:58 +1000 Subject: [PATCH 6/8] Show taxons and properties on producer modal (seen on map, shop producer info) --- .../partials/enterprise_details.html.haml | 28 +++++++------------ spec/features/consumer/shops_spec.rb | 22 +++++++++++---- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/app/assets/javascripts/templates/partials/enterprise_details.html.haml b/app/assets/javascripts/templates/partials/enterprise_details.html.haml index d1d208c5c4..46a37050e2 100644 --- a/app/assets/javascripts/templates/partials/enterprise_details.html.haml +++ b/app/assets/javascripts/templates/partials/enterprise_details.html.haml @@ -1,26 +1,18 @@ .row .small-12.large-8.columns - / TODO: Rob add logic for taxons and properties too: - / %div{"ng-if" => "enterprise.long_description.length > 0 || enterprise.logo"} %div %p.modal-header {{'label_about' | t}} - / TODO: Rob - add in taxons and properties and property pop-overs + %div + %span.filter-shopfront.taxon-selectors + %ul.inline-block + %li{"ng-repeat" => "taxon in enterprise.supplied_taxons"} + %a.button.tiny.disabled{"ng-bind" => "taxon.name"} + + %span.filter-shopfront.property-selectors.pad-top + %ul.inline-block + %li{"ng-repeat" => "property in enterprise.properties"} + %a.button.tiny{"ng-bind" => "property.presentation"} - -# TODO: Add producer taxons and properties here - -# %div - -# %span.filter-shopfront.taxon-selectors - -# %ul.inline-block - -# %li - -# %a.button.tiny.disabled Grains - -# %li - -# %a.button.tiny.disabled Dairy - -# - -# %span.filter-shopfront.property-selectors.pad-top - -# %ul.inline-block - -# %li - -# %a.button.tiny Organic certified - -# / TODO: Rob - need popover, use will's directive or this? http://pineconellc.github.io/angular-foundation/ - -# .about-container.pad-top %img.enterprise-logo{"ng-src" => "{{::enterprise.logo}}", "ng-if" => "::enterprise.logo"} %p.text-small{"ng-bind-html" => "::enterprise.long_description"} diff --git a/spec/features/consumer/shops_spec.rb b/spec/features/consumer/shops_spec.rb index df44955232..8b1a709462 100644 --- a/spec/features/consumer/shops_spec.rb +++ b/spec/features/consumer/shops_spec.rb @@ -13,6 +13,7 @@ feature 'Shops', js: true do let!(:er) { create(:enterprise_relationship, parent: distributor, child: producer) } before do + producer.set_producer_property 'Organic', 'NASAA 12345' visit shops_path end @@ -45,11 +46,22 @@ feature 'Shops', js: true do expect(page).to have_current_path enterprise_shop_path(distributor) end - it "should show hub producer modals" do - expand_active_table_node distributor.name - expect(page).to have_content producer.name - open_enterprise_modal producer - modal_should_be_open_for producer + describe "hub producer modal" do + let!(:product) { create(:simple_product, supplier: producer, taxons: [taxon]) } + let!(:taxon) { create(:taxon, name: 'Fruit') } + let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), variants: [product.variants.first]) } + + it "should show hub producer modals" do + expand_active_table_node distributor.name + expect(page).to have_content producer.name + open_enterprise_modal producer + modal_should_be_open_for producer + + within ".reveal-modal" do + expect(page).to have_content 'Fruit' # Taxon + expect(page).to have_content 'Organic' # Producer property + end + end end def click_link_and_ensure(link_text, check) From 9cc0bb831acecd04d7579456707b8b0fe6b4a7c2 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 17 Jun 2016 17:44:46 +1000 Subject: [PATCH 7/8] Show properties alongside taxons on producer fat view --- .../stylesheets/darkswarm/producer_node.css.sass | 6 +++++- app/views/producers/_fat.html.haml | 16 +++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/darkswarm/producer_node.css.sass b/app/assets/stylesheets/darkswarm/producer_node.css.sass index 78209845c5..24eb0467c2 100644 --- a/app/assets/stylesheets/darkswarm/producer_node.css.sass +++ b/app/assets/stylesheets/darkswarm/producer_node.css.sass @@ -53,9 +53,13 @@ &:last-child margin-bottom: 1rem - .fat-taxons, .fat-properties + .fat-taxons background-color: $clr-turquoise-light + .fat-properties + background-color: $clr-turquoise-ultra-light + border: 1px solid $clr-turquoise-light + .producer-name color: $clr-turquoise diff --git a/app/views/producers/_fat.html.haml b/app/views/producers/_fat.html.haml index 0fc082b361..28ed0c985f 100644 --- a/app/views/producers/_fat.html.haml +++ b/app/views/producers/_fat.html.haml @@ -16,15 +16,13 @@ %label = t :producers_buy %p.trans-sentence - %span.fat-taxons{"ng-repeat" => "taxon in producer.supplied_taxons"} - %render-svg{path: "{{taxon.icon}}"} - %span{"ng-bind" => "::taxon.name"} - - %div - %label Product properties - %p.trans-sentence - %span.fat-properties{"ng-repeat" => "property in producer.properties"} - %span{"ng-bind" => "property.presentation"} + %div + %span.fat-taxons{"ng-repeat" => "taxon in producer.supplied_taxons"} + %render-svg{path: "{{taxon.icon}}"} + %span{"ng-bind" => "::taxon.name"} + %div + %span.fat-properties{"ng-repeat" => "property in producer.properties"} + %span{"ng-bind" => "property.presentation"} %div.show-for-medium-up{"ng-if" => "producer.supplied_taxons.length==0"}   From 78b22c4a823f6a3db72400c417ec09c442938da4 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Wed, 22 Jun 2016 14:54:06 +1000 Subject: [PATCH 8/8] Fix incorrectly aligned columns --- .../orders_and_fulfillments_report.rb | 1 + .../orders_and_fulfillments_report_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/open_food_network/orders_and_fulfillments_report.rb b/lib/open_food_network/orders_and_fulfillments_report.rb index 089838a1b1..b4778a12aa 100644 --- a/lib/open_food_network/orders_and_fulfillments_report.rb +++ b/lib/open_food_network/orders_and_fulfillments_report.rb @@ -216,6 +216,7 @@ module OpenFoodNetwork proc { |line_items| "" }, proc { |line_items| "" }, proc { |line_items| "" }, + proc { |line_items| line_items.all? { |li| li.order.paid? } ? "Yes" : "No" }, proc { |line_items| line_items.first.order.shipping_method.andand.name }, proc { |line_items| rsa.call(line_items) ? 'Y' : 'N' }, diff --git a/spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb b/spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb index 55c8bd1197..f37dcefa02 100644 --- a/spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb +++ b/spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb @@ -93,5 +93,24 @@ module OpenFoodNetwork end end end + + describe "columns are aligned" do + let(:d1) { create(:distributor_enterprise) } + let(:oc1) { create(:simple_order_cycle) } + let(:o1) { create(:order, completed_at: 1.day.ago, order_cycle: oc1, distributor: d1) } + let(:li1) { build(:line_item) } + let(:user) { create(:admin_user)} + + before { o1.line_items << li1 } + + it 'has aligned columsn' do + report_types = ["", "order_cycle_supplier_totals", "order_cycle_supplier_totals_by_distributor", "order_cycle_distributor_totals_by_supplier", "order_cycle_customer_totals"] + + report_types.each do |report_type| + report = OrdersAndFulfillmentsReport.new user, report_type: report_type + report.header.size.should == report.columns.size + end + end + end end end