From 2c1ca15393ec12e5c72773918e03813a9c9935c7 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 29 May 2014 15:37:19 +1000 Subject: [PATCH 01/17] Some tweaks to visual stuff --- app/views/shop/products/_form.html.haml | 2 +- app/views/shop/products/_master.html.haml | 2 +- app/views/shop/products/_summary.html.haml | 2 +- app/views/shop/products/_variants.html.haml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/shop/products/_form.html.haml b/app/views/shop/products/_form.html.haml index 5a3af9684e..6212ef746d 100644 --- a/app/views/shop/products/_form.html.haml +++ b/app/views/shop/products/_form.html.haml @@ -21,7 +21,7 @@ %div{"bo-if" => "hasVariants"} = render partial: "shop/products/variants" - .variant.row{"bo-if" => "!hasVariants"} + .variants.row{"bo-if" => "!hasVariants"} = render partial: "shop/products/master" .row diff --git a/app/views/shop/products/_master.html.haml b/app/views/shop/products/_master.html.haml index 7398912bda..bd8a8cd3de 100644 --- a/app/views/shop/products/_master.html.haml +++ b/app/views/shop/products/_master.html.haml @@ -1,4 +1,4 @@ -.small-1.column +.small-1.columns %span.bulk{"bo-if" => "product.group_buy"} bulk   diff --git a/app/views/shop/products/_summary.html.haml b/app/views/shop/products/_summary.html.haml index e41c6ef440..22ce416336 100644 --- a/app/views/shop/products/_summary.html.haml +++ b/app/views/shop/products/_summary.html.haml @@ -1,5 +1,5 @@ .row.summary - .small-1.column + .small-1.columns %img{"bo-src" => "product.master.images[0].small_url"} .small-4.columns.summary-header diff --git a/app/views/shop/products/_variants.html.haml b/app/views/shop/products/_variants.html.haml index 14ff8eff24..6751f8c62c 100644 --- a/app/views/shop/products/_variants.html.haml +++ b/app/views/shop/products/_variants.html.haml @@ -1,7 +1,7 @@ .row.variants{bindonce: true, "ng-repeat" => "variant in product.variants"} - .small-1.column + .small-1.columns %span.bulk{"bo-if" => "product.group_buy"} bulk   From c0cb9857cc04e1090be97bda557d39b0562fdfbb Mon Sep 17 00:00:00 2001 From: summerscope Date: Thu, 29 May 2014 16:42:05 +1000 Subject: [PATCH 02/17] Style and template adjustments to shopfront top of page to get content hierarchy looking right. Removed change location link as new menu system supercedes this. --- app/assets/stylesheets/darkswarm/shop.css.sass | 17 +++++++++-------- app/views/shop/show.html.haml | 13 +++++++++---- app/views/shopping_shared/_details.html.haml | 5 ++--- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/assets/stylesheets/darkswarm/shop.css.sass b/app/assets/stylesheets/darkswarm/shop.css.sass index 0c2972367a..a23458b941 100644 --- a/app/assets/stylesheets/darkswarm/shop.css.sass +++ b/app/assets/stylesheets/darkswarm/shop.css.sass @@ -27,7 +27,6 @@ margin-right: 12px location font-family: "AvenirBla_IE", "AvenirBla" - padding-right: 16px @media all and (max-width: 768px) location, location + small display: block @@ -58,21 +57,23 @@ @media all and (max-width: 768px) font-size: 1.2em select - width: 280px + width: inherit display: inline-block vackground: transparent - border-width: 2px - border-color: #666666 + border-width: 1px + border-color: #999 + color: #666 font-size: 1em margin-bottom: 0 - padding: 8px 0px 8px 12px + padding: 8px 20px 8px 12px @media all and (max-width: 768px) font-size: 1.2em - width: 180px + // width: 180px closing - font-size: 0.875em + color: black + font-size: 1.5em display: block - padding-top: 14px + padding-bottom: 20px products display: block diff --git a/app/views/shop/show.html.haml b/app/views/shop/show.html.haml index d4b36a5e29..ad0080edae 100644 --- a/app/views/shop/show.html.haml +++ b/app/views/shop/show.html.haml @@ -2,15 +2,20 @@ - content_for :order_cycle_form do %div{"ng-controller" => "OrderCycleChangeCtrl"} - %strong.avenir Ready for + %closing{"ng-if" => "OrderCycle.selected()"} + Next order closing + %strong {{ OrderCycle.orders_close_at() | date_in_words }} + + %span Ready for pickup + + / Will this label should be a variable to reflect pickup or delivery as appropriate + %select.avenir#order_cycle_id{"ng-model" => "order_cycle.order_cycle_id", "ng-change" => "changeOrderCycle()", "ng-options" => "oc.id as oc.time for oc in #{@order_cycles.map {|oc| {time: pickup_time(oc), id: oc.id}}.to_json}", "popover-placement" => "bottom", "popover" => "When do you want to get your order?", "popover-trigger" => "openTrigger"} - %closing{"ng-if" => "OrderCycle.selected()"} - Orders close - %strong {{ OrderCycle.orders_close_at() | date_in_words }} + = render partial: "shopping_shared/details" diff --git a/app/views/shopping_shared/_details.html.haml b/app/views/shopping_shared/_details.html.haml index 37edfa3c16..8a1692ebb1 100644 --- a/app/views/shopping_shared/_details.html.haml +++ b/app/views/shopping_shared/_details.html.haml @@ -4,11 +4,10 @@ %distributor.details.row #distributor_title %img.left{src: current_distributor.logo.url(:thumb)} - %h4 + %h3 = current_distributor.name %location= current_distributor.address.city - %small - %a{href: "/"} Change location + / Will this needs to be a drop-down to choose either pick-up point or delivery once shipping methods are implemented = render partial: "shopping_shared/order_cycles" From 1a47a7486e62cd743ec77c57ba3066d940ca6e4b Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 30 May 2014 11:58:22 +1000 Subject: [PATCH 03/17] Automatically closing the accordion if the form is already valid --- .../checkout/accordion_controller.js.coffee | 7 ++- .../checkout/details_controller.js.coffee | 9 +--- .../services/checkout_form_state.js.coffee | 2 +- .../admin/orders_controller_decorator.rb | 3 +- .../accordion_controller_spec.js.coffee | 43 ++++++++++++++----- 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee index b6f533e751..38f41c6f6b 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout/accordion_controller.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.controller "AccordionCtrl", ($scope, storage) -> +Darkswarm.controller "AccordionCtrl", ($scope, storage, $timeout) -> $scope.accordion = details: true shipping: false @@ -9,3 +9,8 @@ Darkswarm.controller "AccordionCtrl", ($scope, storage) -> $scope.show = (name)-> $scope.accordion[name] = true + $timeout => + if $scope.checkout.$valid + for k, v of $scope.accordion + $scope.accordion[k] = false + diff --git a/app/assets/javascripts/darkswarm/controllers/checkout/details_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout/details_controller.js.coffee index c9d559a0d0..8153c24f92 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout/details_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout/details_controller.js.coffee @@ -1,5 +1,6 @@ Darkswarm.controller "DetailsCtrl", ($scope) -> angular.extend(this, new FieldsetMixin($scope)) + $scope.name = "details" $scope.nextPanel = "billing" @@ -11,11 +12,3 @@ Darkswarm.controller "DetailsCtrl", ($scope) -> $scope.fullName = -> [$scope.order.bill_address.firstname ? null, $scope.order.bill_address.lastname ? null].join(" ").trim() - - - #$scope.$watch -> - #$scope.detailsValid() - #, (valid)-> - #if valid - #$scope.show("billing") - diff --git a/app/assets/javascripts/darkswarm/services/checkout_form_state.js.coffee b/app/assets/javascripts/darkswarm/services/checkout_form_state.js.coffee index 9d68efba64..6fedb6b3c6 100644 --- a/app/assets/javascripts/darkswarm/services/checkout_form_state.js.coffee +++ b/app/assets/javascripts/darkswarm/services/checkout_form_state.js.coffee @@ -1,3 +1,3 @@ Darkswarm.factory 'CheckoutFormState', ()-> - # Just a singleton place to store data about the form statr + # Just a singleton place to store data about the form state new class CheckoutFormState diff --git a/app/controllers/spree/admin/orders_controller_decorator.rb b/app/controllers/spree/admin/orders_controller_decorator.rb index 51c7acba09..27d9a36943 100644 --- a/app/controllers/spree/admin/orders_controller_decorator.rb +++ b/app/controllers/spree/admin/orders_controller_decorator.rb @@ -15,11 +15,10 @@ Spree::Admin::OrdersController.class_eval do per(params[:per_page] || Spree::Config[:orders_per_page]) } } } - private def load_spree_api_key current_user.generate_spree_api_key! unless spree_current_user.spree_api_key @spree_api_key = spree_current_user.spree_api_key end -end \ No newline at end of file +end diff --git a/spec/javascripts/unit/darkswarm/controllers/checkout/accordion_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/checkout/accordion_controller_spec.js.coffee index 1c0c199351..d35fb93e86 100644 --- a/spec/javascripts/unit/darkswarm/controllers/checkout/accordion_controller_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/controllers/checkout/accordion_controller_spec.js.coffee @@ -1,19 +1,40 @@ describe "AccordionCtrl", -> ctrl = null - scope = scope + scope = null beforeEach -> module "Darkswarm" localStorage.clear() - inject ($controller, $rootScope) -> - scope = $rootScope.$new() - scope.order = - id: 129 - ctrl = $controller 'AccordionCtrl', {$scope: scope} - it "defaults the details accordion to visible", -> - expect(scope.accordion.details).toEqual true + describe "loading incomplete form", -> + beforeEach -> + inject ($controller, $rootScope) -> + scope = $rootScope.$new() + scope.order = + id: 129 + ctrl = $controller 'AccordionCtrl', {$scope: scope} - it "changes accordion", -> - scope.show "shipping" - expect(scope.accordion["shipping"]).toEqual true + it "defaults the details accordion to visible", -> + expect(scope.accordion.details).toEqual true + + it "changes accordion", -> + scope.show "shipping" + expect(scope.accordion["shipping"]).toEqual true + + describe "loading complete form", -> + beforeEach -> + inject ($controller, $rootScope) -> + scope = $rootScope.$new() + scope.checkout = + $valid: true + scope.order = + id: 129 + ctrl = $controller 'AccordionCtrl', {$scope: scope} + + it "automatically closes all sections if the entire form is valid", -> + waitsFor -> + (scope.accordion.details and + scope.accordion.shipping and + scope.accordion.payment and + scope.accordion.billing) == false + , "the accordion to close", 100 From db131af5e7625e21accf1a297cce34189435455d Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 30 May 2014 12:00:28 +1000 Subject: [PATCH 04/17] Patching a class hook --- app/views/checkout/_billing.html.haml | 2 +- app/views/checkout/_payment.html.haml | 2 +- app/views/checkout/_shipping.html.haml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/checkout/_billing.html.haml b/app/views/checkout/_billing.html.haml index dc48eadbe2..f8129d32c9 100644 --- a/app/views/checkout/_billing.html.haml +++ b/app/views/checkout/_billing.html.haml @@ -1,7 +1,7 @@ %fieldset#billing %ng-form{"ng-controller" => "BillingCtrl", name: "billing"} - %h5{"ng-class" => "{valid: billing.$valid, dirty: details.$dirty}"} + %h5{"ng-class" => "{valid: billing.$valid, dirty: billing.$dirty}"} %span.right %label.label.round.alert %i.fi-x diff --git a/app/views/checkout/_payment.html.haml b/app/views/checkout/_payment.html.haml index 195ae9e42a..e972ebfcf1 100644 --- a/app/views/checkout/_payment.html.haml +++ b/app/views/checkout/_payment.html.haml @@ -1,7 +1,7 @@ %fieldset#payment %ng-form{"ng-controller" => "PaymentCtrl", name: "payment"} - %h5{"ng-class" => "{valid: payment.$valid, dirty: details.$dirty}"} + %h5{"ng-class" => "{valid: payment.$valid, dirty: payment.$dirty}"} %span.right %label.label.round.alert %i.fi-x diff --git a/app/views/checkout/_shipping.html.haml b/app/views/checkout/_shipping.html.haml index dfa69d43c5..215ea8ed61 100644 --- a/app/views/checkout/_shipping.html.haml +++ b/app/views/checkout/_shipping.html.haml @@ -1,7 +1,7 @@ %fieldset#shipping %ng-form{"ng-controller" => "ShippingCtrl", name: "shipping"} - %h5{"ng-class" => "{valid: shipping.$valid, dirty: details.$dirty}"} + %h5{"ng-class" => "{valid: shipping.$valid, dirty: shipping.$dirty}"} %span.right %label.label.round.alert %i.fi-x From 206c947ea5669e9ba9577e7b1b4c65055588ca59 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 30 May 2014 12:20:18 +1000 Subject: [PATCH 05/17] Tweaking test --- spec/features/consumer/shopping/shopping_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index 9946be2f5b..b1b905fe82 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -67,7 +67,7 @@ feature "As a consumer I want to shop with a distributor", js: true do select "frogs", :from => "order_cycle_id" page.should have_selector "products" - page.should have_content "Orders close in 2 days" + page.should have_content "Next order closing in 2 days" Spree::Order.last.order_cycle.should == oc1 page.should have_content product.name end From 368fbd2383f013b74b21804a97681529a3bb5362 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 30 May 2014 12:52:14 +1000 Subject: [PATCH 06/17] Patching up admin redirects to be MOAR UNIVERSAL --- app/controllers/application_controller.rb | 5 +++++ .../spree/admin/base_controller_decorator.rb | 12 ++++++++++++ .../spree/admin/overview_controller_decorator.rb | 13 +------------ .../spree/admin/base_controller_spec.rb | 15 +++++++++++++++ 4 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 spec/controllers/spree/admin/base_controller_spec.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b9e46d3237..a19f92c918 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,6 +4,11 @@ class ApplicationController < ActionController::Base include EnterprisesHelper + def redirect_to(options = {}, response_status = {}) + ::Rails.logger.error("Redirected by #{caller(1).first rescue "unknown"}") + super(options, response_status) + end + def after_sign_in_path_for(resource) if request.referer and referer_path = URI(request.referer).path [main_app.checkout_path].include?(referer_path) ? referer_path : root_path diff --git a/app/controllers/spree/admin/base_controller_decorator.rb b/app/controllers/spree/admin/base_controller_decorator.rb index df7076345f..7199ca4dec 100644 --- a/app/controllers/spree/admin/base_controller_decorator.rb +++ b/app/controllers/spree/admin/base_controller_decorator.rb @@ -11,4 +11,16 @@ Spree::Admin::BaseController.class_eval do authorize! :admin, record authorize! action, record end + + # This is in Spree::Core::ControllerHelpers::Auth + # But you can't easily reopen modules in Ruby + def unauthorized + if try_spree_current_user + flash[:error] = t(:authorization_failure) + redirect_to '/unauthorized' + else + store_location + redirect_to root_path(anchor: "login?after_login=#{request.env['PATH_INFO']}") + end + end end diff --git a/app/controllers/spree/admin/overview_controller_decorator.rb b/app/controllers/spree/admin/overview_controller_decorator.rb index a6142d26c0..a2288dab88 100644 --- a/app/controllers/spree/admin/overview_controller_decorator.rb +++ b/app/controllers/spree/admin/overview_controller_decorator.rb @@ -4,16 +4,5 @@ Spree::Admin::OverviewController.class_eval do @product_count = Spree::Product.active.managed_by(spree_current_user).count @order_cycle_count = OrderCycle.active.managed_by(spree_current_user).count end - - # This is in Spree::Core::ControllerHelpers::Auth - # But you can't easily reopen modules in Ruby - def unauthorized - if try_spree_current_user - flash[:error] = t(:authorization_failure) - redirect_to '/unauthorized' - else - store_location - redirect_to root_path(anchor: "login?after_login=#{spree.admin_path}") - end - end end + diff --git a/spec/controllers/spree/admin/base_controller_spec.rb b/spec/controllers/spree/admin/base_controller_spec.rb new file mode 100644 index 0000000000..0657929739 --- /dev/null +++ b/spec/controllers/spree/admin/base_controller_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe Spree::Admin::BaseController do + controller(Spree::Admin::BaseController) do + def index + before_filter :unauthorized + render text: "" + end + end + + it "redirects to Angular login" do + get :index + response.should redirect_to root_path(anchor: "login?after_login=#{spree.admin_path}") + end +end From 638d6d2ac0238e54d7dd421822a561dd563fb650 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 30 May 2014 12:58:58 +1000 Subject: [PATCH 07/17] Moving around the authentication specs --- spec/features/admin/authentication_spec.rb | 17 +++++++++++++++++ spec/features/consumer/authentication_spec.rb | 9 --------- 2 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 spec/features/admin/authentication_spec.rb diff --git a/spec/features/admin/authentication_spec.rb b/spec/features/admin/authentication_spec.rb new file mode 100644 index 0000000000..6dd62bdc73 --- /dev/null +++ b/spec/features/admin/authentication_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +feature "Authentication", js: true do + include UIComponentHelper + describe "logging into admin" do + let(:user) { create(:user, password: "password", password_confirmation: "password") } + end + + scenario "logging into admin redirects home, then back to admin" do + visit spree.admin_path + fill_in "Email", with: user.email + fill_in "Password", with: user.password + click_login_button + page.should have_content "Dashboard" + current_path.should == spree.admin_path + end +end diff --git a/spec/features/consumer/authentication_spec.rb b/spec/features/consumer/authentication_spec.rb index 76e4a20877..8853a07c3d 100644 --- a/spec/features/consumer/authentication_spec.rb +++ b/spec/features/consumer/authentication_spec.rb @@ -14,15 +14,6 @@ feature "Authentication", js: true do page.should have_content "Select a producer from the list below" current_path.should == producers_path end - - scenario "logging into admin redirects home, then back to admin" do - visit spree.admin_path - fill_in "Email", with: user.email - fill_in "Password", with: user.password - click_login_button - page.should have_content "Dashboard" - current_path.should == spree.admin_path - end end describe "Loggin in from the home page" do From 2b0bdc69cd90a7919c03be0db008f7fe7ad60536 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 30 May 2014 13:01:16 +1000 Subject: [PATCH 08/17] Fixing a scope issue --- spec/features/admin/authentication_spec.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spec/features/admin/authentication_spec.rb b/spec/features/admin/authentication_spec.rb index 6dd62bdc73..c4768e5eed 100644 --- a/spec/features/admin/authentication_spec.rb +++ b/spec/features/admin/authentication_spec.rb @@ -2,9 +2,7 @@ require 'spec_helper' feature "Authentication", js: true do include UIComponentHelper - describe "logging into admin" do - let(:user) { create(:user, password: "password", password_confirmation: "password") } - end + let(:user) { create(:user, password: "password", password_confirmation: "password") } scenario "logging into admin redirects home, then back to admin" do visit spree.admin_path From 20873b6e452ffc7df2362c121f7b8fef264e87bf Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 30 May 2014 14:21:21 +1000 Subject: [PATCH 09/17] Patching a minor regression spec --- spec/controllers/spree/admin/base_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/spree/admin/base_controller_spec.rb b/spec/controllers/spree/admin/base_controller_spec.rb index 0657929739..0985d733a7 100644 --- a/spec/controllers/spree/admin/base_controller_spec.rb +++ b/spec/controllers/spree/admin/base_controller_spec.rb @@ -10,6 +10,6 @@ describe Spree::Admin::BaseController do it "redirects to Angular login" do get :index - response.should redirect_to root_path(anchor: "login?after_login=#{spree.admin_path}") + response.should redirect_to root_path(anchor: "login?after_login=/anonymous") end end From 1c31ac56eab6de96a2d9658a72b825fe2ea2b5ab Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 22 May 2014 15:49:10 +1000 Subject: [PATCH 10/17] Adding primary taxon field to product Conflicts: db/migrate/20140522044009_add_primary_taxon_to_products.rb --- app/models/enterprise.rb | 1 + app/models/spree/classification_decorator.rb | 10 ++++++++++ app/models/spree/product_decorator.rb | 13 ++++++++----- ...0140522044009_add_primary_taxon_to_products.rb | 3 +++ db/schema.rb | 3 ++- spec/factories.rb | 7 +++++++ spec/models/spree/classification_spec.rb | 15 +++++++++++++++ spec/models/spree/product_spec.rb | 11 +++++++++-- 8 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 app/models/spree/classification_decorator.rb create mode 100644 spec/models/spree/classification_spec.rb diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index dd40744492..6ae33634ee 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -15,6 +15,7 @@ class Enterprise < ActiveRecord::Base has_and_belongs_to_many :payment_methods, join_table: 'distributors_payment_methods', class_name: 'Spree::PaymentMethod', foreign_key: 'distributor_id' has_and_belongs_to_many :shipping_methods, join_table: 'distributors_shipping_methods', class_name: 'Spree::ShippingMethod', foreign_key: 'distributor_id' + delegate :latitude, :longitude, :city, :state_name, :to => :address accepts_nested_attributes_for :address diff --git a/app/models/spree/classification_decorator.rb b/app/models/spree/classification_decorator.rb new file mode 100644 index 0000000000..7e34e6890e --- /dev/null +++ b/app/models/spree/classification_decorator.rb @@ -0,0 +1,10 @@ +Spree::Classification.class_eval do + before_destroy :dont_destroy_if_primary_taxon + + def dont_destroy_if_primary_taxon + if product.primary_taxon == taxon + errors.add :base, "Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted" + return false + end + end +end diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 0140586668..1fff7ea1a8 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -6,6 +6,7 @@ Spree::Product.class_eval do belongs_to :supplier, :class_name => 'Enterprise' + belongs_to :primary_taxon, class_name: 'Spree::Taxon' has_many :product_distributions, :dependent => :destroy has_many :distributors, :through => :product_distributions @@ -13,9 +14,10 @@ Spree::Product.class_eval do accepts_nested_attributes_for :product_distributions, :allow_destroy => true delegate_belongs_to :master, :unit_value, :unit_description - attr_accessible :supplier_id, :distributor_ids, :product_distributions_attributes, :group_buy, :group_buy_unit_size, :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value, :unit_description, :notes + attr_accessible :supplier_id, :primary_taxon_id, :distributor_ids, :product_distributions_attributes, :group_buy, :group_buy_unit_size, :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value, :unit_description, :notes validates_presence_of :supplier + validates_presence_of :primary_taxon validates_presence_of :variant_unit, if: :has_variants? validates_presence_of :variant_unit_scale, @@ -25,6 +27,7 @@ Spree::Product.class_eval do after_initialize :set_available_on_to_now, :if => :new_record? after_save :update_units + before_save :add_primary_taxon_to_taxons # -- Joins @@ -124,10 +127,6 @@ Spree::Product.class_eval do order_cycle.variants_distributed_by(distributor).where(product_id: self) end - def primary_taxon - self.taxons.order.first - end - # Build a product distribution for each distributor def build_product_distributions_for_user user Enterprise.is_distributor.managed_by(user).each do |distributor| @@ -163,6 +162,10 @@ Spree::Product.class_eval do end end + def add_primary_taxon_to_taxons + taxons << primary_taxon unless taxons.find_by_id(primary_taxon) + end + def self.all_variant_unit_option_types Spree::OptionType.where('name LIKE ?', 'unit_%%') end diff --git a/db/migrate/20140522044009_add_primary_taxon_to_products.rb b/db/migrate/20140522044009_add_primary_taxon_to_products.rb index f6ff3cfe96..7b14b42f5e 100644 --- a/db/migrate/20140522044009_add_primary_taxon_to_products.rb +++ b/db/migrate/20140522044009_add_primary_taxon_to_products.rb @@ -1,7 +1,10 @@ class AddPrimaryTaxonToProducts < ActiveRecord::Migration def change add_column :spree_products, :primary_taxon_id, :integer +<<<<<<< HEAD add_index :spree_products, :primary_taxon_id add_foreign_key :spree_products, :spree_taxons, column: :primary_taxon_id +======= +>>>>>>> fd1e7eb... Adding primary taxon field to product end end diff --git a/db/schema.rb b/db/schema.rb index 77df8baf75..69e79c2829 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140522015012) do +ActiveRecord::Schema.define(:version => 20140522044009) do create_table "adjustment_metadata", :force => true do |t| t.integer "adjustment_id" @@ -681,6 +681,7 @@ ActiveRecord::Schema.define(:version => 20140522015012) do t.float "variant_unit_scale" t.string "variant_unit_name" t.text "notes" + t.integer "primary_taxon_id" end add_index "spree_products", ["available_on"], :name => "index_products_on_available_on" diff --git a/spec/factories.rb b/spec/factories.rb index 6da7824d47..394112125a 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -2,6 +2,9 @@ require 'ffaker' require 'spree/core/testing_support/factories' FactoryGirl.define do + factory :classification, class: Spree::Classification do + end + factory :order_cycle, :parent => :simple_order_cycle do coordinator_fees { [create(:enterprise_fee, enterprise: coordinator)] } @@ -150,6 +153,9 @@ end FactoryGirl.modify do + factory :product do + primary_taxon { Spree::Taxon.first || FactoryGirl.create(:taxon) } + end factory :simple_product do # Fix product factory name sequence with Kernel.rand so it is not interpreted as a Spree::Product method # Pull request: https://github.com/spree/spree/pull/1964 @@ -157,6 +163,7 @@ FactoryGirl.modify do sequence(:name) { |n| "Product ##{n} - #{Kernel.rand(9999)}" } supplier { Enterprise.is_primary_producer.first || FactoryGirl.create(:supplier_enterprise) } + primary_taxon { Spree::Taxon.first || FactoryGirl.create(:taxon) } on_hand 3 variant_unit 'weight' diff --git a/spec/models/spree/classification_spec.rb b/spec/models/spree/classification_spec.rb new file mode 100644 index 0000000000..f26f6da0c0 --- /dev/null +++ b/spec/models/spree/classification_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +module Spree + describe Classification do + let(:product) { create(:simple_product) } + let(:taxon) { create(:taxon) } + let(:classification) { create(:classification, taxon: taxon, product: product) } + + it "won't destroy if classification is the primary taxon" do + product.primary_taxon = taxon + classification.destroy.should be_false + classification.errors.messages[:base].should == ["Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted"] + end + end +end diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index a5333b6d11..8d04d690b0 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -5,6 +5,7 @@ module Spree describe "associations" do it { should belong_to(:supplier) } + it { should belong_to(:primary_taxon) } it { should have_many(:product_distributions) } end @@ -13,6 +14,12 @@ module Spree create(:product).should be_valid end + it "requires a primary taxon" do + product = create(:simple_product) + product.primary_taxon = nil + product.should_not be_valid + end + it "requires a supplier" do product = create(:simple_product) product.supplier = nil @@ -565,10 +572,10 @@ module Spree describe "Taxons" do let(:taxon1) { create(:taxon) } let(:taxon2) { create(:taxon) } - let(:product) { create(:simple_product, taxons: [taxon1, taxon2]) } + let(:product) { create(:simple_product) } it "returns the first taxon as the primary taxon" do - product.primary_taxon.should == taxon1 + product.taxons.should == [product.primary_taxon] end end end From b736145552989c13cfc3c43b5c519b832ab8d288 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 22 May 2014 16:13:47 +1000 Subject: [PATCH 11/17] Adding primary taxon to admin forms Conflicts: db/migrate/20140522044009_add_primary_taxon_to_products.rb spec/features/admin/products_spec.rb --- .../products/_form/add_notes_field.html.haml.deface | 1 - .../20140522044009_add_primary_taxon_to_products.rb | 5 +++++ db/schema.rb | 2 ++ spec/features/admin/products_spec.rb | 12 ++++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface b/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface index dadebd01d4..dcc7937d6b 100644 --- a/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface +++ b/app/overrides/spree/admin/products/_form/add_notes_field.html.haml.deface @@ -4,4 +4,3 @@ = f.label :notes, t(:notes) = f.text_area :notes, { :class => 'fullwidth', rows: 5 } = f.error_message_on :notes - diff --git a/db/migrate/20140522044009_add_primary_taxon_to_products.rb b/db/migrate/20140522044009_add_primary_taxon_to_products.rb index 7b14b42f5e..fb7b9b3160 100644 --- a/db/migrate/20140522044009_add_primary_taxon_to_products.rb +++ b/db/migrate/20140522044009_add_primary_taxon_to_products.rb @@ -1,10 +1,15 @@ class AddPrimaryTaxonToProducts < ActiveRecord::Migration def change add_column :spree_products, :primary_taxon_id, :integer +<<<<<<< HEAD <<<<<<< HEAD add_index :spree_products, :primary_taxon_id add_foreign_key :spree_products, :spree_taxons, column: :primary_taxon_id ======= >>>>>>> fd1e7eb... Adding primary taxon field to product +======= + add_index :spree_products, :primary_taxon_id + add_foreign_key :spree_products, :spree_taxons, column: :primary_taxon_id +>>>>>>> 110a6f2... Adding primary taxon to admin forms end end diff --git a/db/schema.rb b/db/schema.rb index 69e79c2829..6005fd7cb5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -689,6 +689,7 @@ ActiveRecord::Schema.define(:version => 20140522044009) do add_index "spree_products", ["name"], :name => "index_products_on_name" add_index "spree_products", ["permalink"], :name => "index_products_on_permalink" add_index "spree_products", ["permalink"], :name => "permalink_idx_unique", :unique => true + add_index "spree_products", ["primary_taxon_id"], :name => "index_spree_products_on_primary_taxon_id" create_table "spree_products_promotion_rules", :id => false, :force => true do |t| t.integer "product_id" @@ -1093,6 +1094,7 @@ ActiveRecord::Schema.define(:version => 20140522044009) do add_foreign_key "spree_products", "enterprises", name: "spree_products_supplier_id_fk", column: "supplier_id" add_foreign_key "spree_products", "spree_shipping_categories", name: "spree_products_shipping_category_id_fk", column: "shipping_category_id" add_foreign_key "spree_products", "spree_tax_categories", name: "spree_products_tax_category_id_fk", column: "tax_category_id" + add_foreign_key "spree_products", "spree_taxons", name: "spree_products_primary_taxon_id_fk", column: "primary_taxon_id" add_foreign_key "spree_products_promotion_rules", "spree_products", name: "spree_products_promotion_rules_product_id_fk", column: "product_id" add_foreign_key "spree_products_promotion_rules", "spree_promotion_rules", name: "spree_products_promotion_rules_promotion_rule_id_fk", column: "promotion_rule_id" diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb index efe531224d..184dd4a7c4 100644 --- a/spec/features/admin/products_spec.rb +++ b/spec/features/admin/products_spec.rb @@ -6,6 +6,7 @@ feature %q{ } do include AuthenticationWorkflow include WebHelper + let!(:taxon) { create(:taxon) } background do @supplier = create(:supplier_enterprise, :name => 'New supplier') @@ -22,6 +23,7 @@ feature %q{ fill_in 'product_name', with: 'A new product !!!' fill_in 'product_price', with: '19.99' + select taxon.name, from: "product_primary_taxon_id" select 'New supplier', from: 'product_supplier_id' click_button 'Create' @@ -43,6 +45,8 @@ feature %q{ product.reload product.distributors.sort.should == [@distributors[0], @distributors[2]].sort + + product.product_distributions.map { |pd| pd.enterprise_fee }.sort.should == [@enterprise_fees[0], @enterprise_fees[2]].sort end @@ -53,6 +57,13 @@ feature %q{ visit spree.edit_admin_product_path(product) +<<<<<<< HEAD +======= + fill_in 'product_name', :with => 'A new product !!!' + fill_in 'product_price', :with => '19.99' + select taxon.name, from: "product_primary_taxon_id" + select 'New supplier', :from => 'product_supplier_id' +>>>>>>> 110a6f2... Adding primary taxon to admin forms choose 'product_group_buy_1' fill_in 'Group buy unit size', :with => '10' @@ -96,6 +107,7 @@ feature %q{ page.should have_selector('#product_supplier_id') select 'Another Supplier', :from => 'product_supplier_id' + select taxon.name, from: "product_primary_taxon_id" # Should only have suppliers listed which the user can manage within "#product_supplier_id" do From a979334f2a2ce46fb3a7e4f048cd3f98e174f3f7 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 23 May 2014 16:01:24 +1000 Subject: [PATCH 12/17] Adding primary taxon --- app/overrides/add_primary_taxon_to_admin_product.rb | 4 ++++ app/overrides/add_primary_taxon_to_admin_product_new.rb | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 app/overrides/add_primary_taxon_to_admin_product.rb create mode 100644 app/overrides/add_primary_taxon_to_admin_product_new.rb diff --git a/app/overrides/add_primary_taxon_to_admin_product.rb b/app/overrides/add_primary_taxon_to_admin_product.rb new file mode 100644 index 0000000000..9f7c5edde5 --- /dev/null +++ b/app/overrides/add_primary_taxon_to_admin_product.rb @@ -0,0 +1,4 @@ +Deface::Override.new(:virtual_path => "spree/admin/products/_form", + :insert_top => "[data-hook='admin_product_form_right']", + :partial => "spree/admin/products/primary_taxon_form", + :name => "add_primary_taxon_to_admin_product") diff --git a/app/overrides/add_primary_taxon_to_admin_product_new.rb b/app/overrides/add_primary_taxon_to_admin_product_new.rb new file mode 100644 index 0000000000..e5c9d24e7f --- /dev/null +++ b/app/overrides/add_primary_taxon_to_admin_product_new.rb @@ -0,0 +1,4 @@ +Deface::Override.new(:virtual_path => "spree/admin/products/new", + :insert_before => "[data-hook='new_product_attrs']", + :partial => "spree/admin/products/primary_taxon_form", + :name => "add_primary_taxon_to_admin_product_new") From a7340df6a567fc4a1a55d15e4bfbdbb1e584eb78 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 30 May 2014 14:45:27 +1000 Subject: [PATCH 13/17] Removing some dud test content --- spec/features/admin/products_spec.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb index 184dd4a7c4..3714a0e91f 100644 --- a/spec/features/admin/products_spec.rb +++ b/spec/features/admin/products_spec.rb @@ -57,13 +57,6 @@ feature %q{ visit spree.edit_admin_product_path(product) -<<<<<<< HEAD -======= - fill_in 'product_name', :with => 'A new product !!!' - fill_in 'product_price', :with => '19.99' - select taxon.name, from: "product_primary_taxon_id" - select 'New supplier', :from => 'product_supplier_id' ->>>>>>> 110a6f2... Adding primary taxon to admin forms choose 'product_group_buy_1' fill_in 'Group buy unit size', :with => '10' From 7304e24591e1906f810968b7d5d3332985938355 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 30 May 2014 14:47:53 +1000 Subject: [PATCH 14/17] Switching the image dimensions --- app/models/enterprise.rb | 2 +- app/models/enterprise_group.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 6ae33634ee..7c54bb1f10 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -20,7 +20,7 @@ class Enterprise < ActiveRecord::Base accepts_nested_attributes_for :address has_attached_file :logo, :styles => { :medium => "300x300>", :thumb => "100x100>" } - has_attached_file :promo_image, :styles => { :large => "260x1200#", :thumb => "100x100>" } + has_attached_file :promo_image, :styles => { :large => "1200x260#", :thumb => "100x100>" } validates_presence_of :name validates_presence_of :address diff --git a/app/models/enterprise_group.rb b/app/models/enterprise_group.rb index 1cea76db72..a06612a064 100644 --- a/app/models/enterprise_group.rb +++ b/app/models/enterprise_group.rb @@ -9,7 +9,7 @@ class EnterpriseGroup < ActiveRecord::Base attr_accessible :name, :description, :long_description, :on_front_page, :enterprise_ids attr_accessible :promo_image - has_attached_file :promo_image, styles: {large: "260x1200#"} + has_attached_file :promo_image, styles: {large: "1200x260#"} validates_attachment_content_type :promo_image, :content_type => /\Aimage\/.*\Z/ attr_accessible :logo From be640fd856dfbabd856df9d9a9017d671ba821f4 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 30 May 2014 15:02:47 +1000 Subject: [PATCH 15/17] Patching a spec and naming something --- app/views/shopping_shared/_tabs.html.haml | 2 +- spec/features/admin/bulk_product_update_spec.rb | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/views/shopping_shared/_tabs.html.haml b/app/views/shopping_shared/_tabs.html.haml index 3a29a12e6c..a5320a7ec5 100644 --- a/app/views/shopping_shared/_tabs.html.haml +++ b/app/views/shopping_shared/_tabs.html.haml @@ -1,7 +1,7 @@ #tabs{"ng-controller" => "TabsCtrl"} .row %tabset - - for name, heading in { about: "About Us", + - for name, heading in { about: "About #{current_distributor.name}", producers: "Producers", groups: "Groups", contact: "Contact"} diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index d89280df80..0e15fbd2f4 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -223,20 +223,19 @@ feature %q{ scenario "creating a new product" do s = FactoryGirl.create(:supplier_enterprise) d = FactoryGirl.create(:distributor_enterprise) + taxon = create(:taxon) login_to_admin_section visit '/admin/products/bulk_edit' - #save_screenshot "/Users/willmarshall/Desktop/foo.png" - #save_and_open_page find("a", text: "NEW PRODUCT").click - page.should have_content 'NEW PRODUCT' fill_in 'product_name', :with => 'Big Bag Of Apples' select(s.name, :from => 'product_supplier_id') fill_in 'product_price', :with => '10.00' + select taxon.name, from: 'product_primary_taxon_id' click_button 'Create' URI.parse(current_url).path.should == '/admin/products/bulk_edit' From 3ddd7c31e89fa1d615fbde6cae5d5a1cf527b972 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 30 May 2014 15:08:16 +1000 Subject: [PATCH 16/17] Patching which image is rendered --- app/views/admin/enterprises/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/enterprises/_form.html.haml b/app/views/admin/enterprises/_form.html.haml index 161f43d34d..06fe94ebf4 100644 --- a/app/views/admin/enterprises/_form.html.haml +++ b/app/views/admin/enterprises/_form.html.haml @@ -177,5 +177,5 @@ %a What's this? .omega.eight.columns - = image_tag @object.promo_image.url if @object.promo_image.present? + = image_tag @object.promo_image(:large) if @object.promo_image.present? = f.file_field :promo_image From de9319f0025ce9eb5ad58e2d0fb15e51a7248635 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 30 May 2014 15:23:42 +1000 Subject: [PATCH 17/17] Auto-aligning BEFORE resizing --- config/initializers/paperclip.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb index c40b9a4130..5dd5c644b4 100644 --- a/config/initializers/paperclip.rb +++ b/config/initializers/paperclip.rb @@ -1,3 +1,3 @@ -Paperclip::Attachment.default_options[:convert_options] = { +Paperclip::Attachment.default_options[:source_file_options] = { all: "-auto-orient" }