From 58e0b95cf6aa10aaa4f1e71cca2be8da78f8213e Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 19 Aug 2016 12:06:19 +1000 Subject: [PATCH] Show property badges on shops --- app/serializers/api/enterprise_serializer.rb | 10 ++++++++ app/views/home/_fat.html.haml | 10 +++++--- spec/features/consumer/shops_spec.rb | 26 +++++++++++++++++++- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index a742b91d63..f68c8be679 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -22,6 +22,7 @@ end class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer attributes :orders_close_at, :active has_many :supplied_properties, serializer: Api::PropertySerializer + has_many :distributed_properties, serializer: Api::PropertySerializer def orders_close_at options[:data].earliest_closing_times[object.id] @@ -38,6 +39,15 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer OpenFoodNetwork::PropertyMerge.merge product_properties, producer_properties end + + def distributed_properties + # This results in 3 queries per enterprise + product_properties = Spree::Property.sold_by(object) + ids = ProducerProperty.sold_by(object).pluck(:property_id) + producer_properties = Spree::Property.where(id: ids) + + OpenFoodNetwork::PropertyMerge.merge product_properties, producer_properties + end end class Api::CachedEnterpriseSerializer < ActiveModel::Serializer diff --git a/app/views/home/_fat.html.haml b/app/views/home/_fat.html.haml index 4e90771cc1..d5703f84d8 100644 --- a/app/views/home/_fat.html.haml +++ b/app/views/home/_fat.html.haml @@ -4,9 +4,13 @@ %label = t :hubs_buy .trans-sentence - %span.fat-taxons{"ng-repeat" => "taxon in hub.taxons"} - %render-svg{path: "{{taxon.icon}}"} - %span{"ng-bind" => "::taxon.name"} + %div + %span.fat-taxons{"ng-repeat" => "taxon in hub.taxons"} + %render-svg{path: "{{taxon.icon}}"} + %span{"ng-bind" => "::taxon.name"} + %div + %span.fat-properties{"ng-repeat" => "property in hub.distributed_properties"} + %span{"ng-bind" => "property.presentation"} %div.show-for-medium-up{"ng-if" => "::hub.taxons.length==0"}   .columns.small-12.medium-3.large-2.fat diff --git a/spec/features/consumer/shops_spec.rb b/spec/features/consumer/shops_spec.rb index adbbf05f9a..2a65a73aef 100644 --- a/spec/features/consumer/shops_spec.rb +++ b/spec/features/consumer/shops_spec.rb @@ -56,12 +56,36 @@ feature 'Shops', js: true do expect(page).to have_current_path enterprise_shop_path(distributor) end + describe "property badges" do + let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), variants: [product.variants.first]) } + let(:product) { create(:simple_product, supplier: producer) } + + before do + product.set_property 'Local', 'XYZ 123' + end + + it "shows property badges" do + # Given a shop with a product with a property + # And the product's producer has a producer property + + # When I go to the shops path + visit shops_path + + # And I open the shop + expand_active_table_node distributor.name + + # Then I should see both properties + expect(page).to have_content 'Local' # Product property + expect(page).to have_content 'Organic' # Producer property + end + end + 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 + it "shows hub producer modals" do expand_active_table_node distributor.name expect(page).to have_content producer.name open_enterprise_modal producer