From f1a8011e1334d27ae917576ee1ae60c352c2604f Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 23 Apr 2015 10:02:32 +1000 Subject: [PATCH 01/41] Documentation of Variant.full_name The code was confusing for all developers here. Maybe a bit of doco helps. --- app/models/spree/variant_decorator.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index 86a0b5fd69..03543793b2 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -74,6 +74,12 @@ Spree::Variant.class_eval do self.option_values.destroy ovs end + # Used like "product.name - full_name". If called like this, a product with + # name "Bread" would be displayed as one of these: + # Bread - 1kg # if display_name blank + # Bread - Spelt Sourdough, 1kg # if display_name is "Spelt Sourdough, 1kg" + # Bread - 1kg Spelt Sourdough # if unit_to_display is "1kg Spelt Sourdough" + # Bread - Spelt Sourdough (1kg) # if display_name is "Spelt Sourdough" and unit_to_display is "1kg" def full_name return unit_to_display if display_name.blank? return display_name if display_name.downcase.include? unit_to_display.downcase From 3412bc25bf06f522bec22ba57802f3fe25a77164 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 23 Apr 2015 10:17:01 +1000 Subject: [PATCH 02/41] Edit Orders: more variant info in variant search Displaying variant's full name and the producer's name. --- .../spree/admin/variants/_autocomplete.js.erb | 33 ++++++++++++++++++ app/views/spree/admin/variants/search.rabl | 34 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 app/views/spree/admin/variants/_autocomplete.js.erb create mode 100644 app/views/spree/admin/variants/search.rabl diff --git a/app/views/spree/admin/variants/_autocomplete.js.erb b/app/views/spree/admin/variants/_autocomplete.js.erb new file mode 100644 index 0000000000..7b52c0a716 --- /dev/null +++ b/app/views/spree/admin/variants/_autocomplete.js.erb @@ -0,0 +1,33 @@ + diff --git a/app/views/spree/admin/variants/search.rabl b/app/views/spree/admin/variants/search.rabl new file mode 100644 index 0000000000..afd3f39ce6 --- /dev/null +++ b/app/views/spree/admin/variants/search.rabl @@ -0,0 +1,34 @@ +# +# overriding spree/core/app/views/spree/admin/variants/search.rabl +# +collection @variants +attributes :sku, :options_text, :count_on_hand, :id, :cost_price + +node(:name) do |v| + # TODO: when products must have a unit, full_name will always be present + variant_specific = v.full_name + if variant_specific.present? + "#{v.name} - #{v.full_name}" + else + v.name + end +end + +node(:full_name) do |v| + v.full_name +end + +node(:producer_name) do |v| + v.product.supplier.name +end + +child(:images => :images) do + attributes :mini_url +end + +child(:option_values => :option_values) do + child(:option_type => :option_type) do + attributes :name, :presentation + end + attributes :name, :presentation +end From a937fd3c614a7e547976ab732192ca8cfe91b9c0 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 23 Apr 2015 11:37:10 +1000 Subject: [PATCH 03/41] Using variant overrides in variant seach on order edit page --- .../spree/admin/variants_controller_decorator.rb | 13 ++++++++----- .../spree/admin/variants_controller_spec.rb | 7 +++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/controllers/spree/admin/variants_controller_decorator.rb b/app/controllers/spree/admin/variants_controller_decorator.rb index acb55327ae..539ce83183 100644 --- a/app/controllers/spree/admin/variants_controller_decorator.rb +++ b/app/controllers/spree/admin/variants_controller_decorator.rb @@ -6,15 +6,18 @@ Spree::Admin::VariantsController.class_eval do @variants = Spree::Variant.ransack(search_params.merge(:m => 'or')).result - if params[:distributor_id].present? - distributor = Enterprise.find params[:distributor_id] - @variants = @variants.in_distributor(distributor) - end - if params[:order_cycle_id].present? order_cycle = OrderCycle.find params[:order_cycle_id] @variants = @variants.in_order_cycle(order_cycle) end + + if params[:distributor_id].present? + distributor = Enterprise.find params[:distributor_id] + @variants = @variants.in_distributor(distributor) + # Perform scoping after all filtering is done. + # Filtering could be a problem on scoped variants. + @variants.each { |v| v.scope_to_hub(distributor) } + end end def destroy diff --git a/spec/controllers/spree/admin/variants_controller_spec.rb b/spec/controllers/spree/admin/variants_controller_spec.rb index 9c6d77194d..22972a7301 100644 --- a/spec/controllers/spree/admin/variants_controller_spec.rb +++ b/spec/controllers/spree/admin/variants_controller_spec.rb @@ -8,6 +8,7 @@ module Spree describe "search action" do let!(:p1) { create(:simple_product, name: 'Product 1') } let!(:p2) { create(:simple_product, name: 'Product 2') } + let!(:vo) { create(:variant_override, variant: p1.master, hub: d, count_on_hand: 44) } let!(:d) { create(:distributor_enterprise) } let!(:oc) { create(:simple_order_cycle, distributors: [d], variants: [p1.master]) } @@ -16,6 +17,12 @@ module Spree assigns(:variants).should == [p1.master] end + it "applies variant overrides" do + spree_get :search, q: 'Prod', distributor_id: d.id.to_s + assigns(:variants).should == [p1.master] + assigns(:variants).first.count_on_hand.should == 44 + end + it "filters by order cycle" do spree_get :search, q: 'Prod', order_cycle_id: oc.id.to_s assigns(:variants).should == [p1.master] From 355221a2739abf4395969c4bead043809d91e4f4 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 24 Apr 2015 12:32:45 +1000 Subject: [PATCH 04/41] Adding customer name to order edit page heading --- .../shared/_order_tabs/add_customer_name.html.haml.deface | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 app/overrides/spree/admin/shared/_order_tabs/add_customer_name.html.haml.deface diff --git a/app/overrides/spree/admin/shared/_order_tabs/add_customer_name.html.haml.deface b/app/overrides/spree/admin/shared/_order_tabs/add_customer_name.html.haml.deface new file mode 100644 index 0000000000..f8ce05079c --- /dev/null +++ b/app/overrides/spree/admin/shared/_order_tabs/add_customer_name.html.haml.deface @@ -0,0 +1,5 @@ +/ insert_after "code[erb-silent]:contains('content_for :page_title')" + += @order.bill_address.firstname += @order.bill_address.lastname +\- From f94a5a975a4a8e489adc6a84a7ed07743fca622b Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 24 Apr 2015 15:31:45 +1000 Subject: [PATCH 05/41] Edit Order: resend button uses new pretty template. --- .../spree/admin/orders_controller_decorator.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/controllers/spree/admin/orders_controller_decorator.rb b/app/controllers/spree/admin/orders_controller_decorator.rb index 3e3c255ab3..ceba6d9bde 100644 --- a/app/controllers/spree/admin/orders_controller_decorator.rb +++ b/app/controllers/spree/admin/orders_controller_decorator.rb @@ -17,4 +17,13 @@ Spree::Admin::OrdersController.class_eval do page(params[:page]). per(params[:per_page] || Spree::Config[:orders_per_page]) } } } + + # Overwrite to use confirm_email_for_customer instead of confirm_email. + # This uses a new template. See mailers/spree/order_mailer_decorator.rb. + def resend + Spree::OrderMailer.confirm_email_for_customer(@order.id, true).deliver + flash[:success] = t(:order_email_resent) + + respond_with(@order) { |format| format.html { redirect_to :back } } + end end From 2b0f867ed831e83d6155d0e730b4c8b2df17731d Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 29 Apr 2015 11:42:35 +1000 Subject: [PATCH 06/41] new order method ready_to_ship? --- app/models/spree/order_decorator.rb | 5 +++ spec/models/spree/order_spec.rb | 53 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index d5e18c3d9b..f109f730d8 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -198,6 +198,11 @@ Spree::Order.class_eval do end end + # Does this order have shipments that can be shipped? + def ready_to_ship? + self.shipments.any?{|s| s.can_ship?} + end + def available_shipping_methods(display_on = nil) Spree::ShippingMethod.all_available(self, display_on) end diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 3c70c2243c..ecc19f5493 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -186,6 +186,59 @@ describe Spree::Order do end end + describe "an order without shipping method" do + let(:order) { create(:order) } + + it "cannot be shipped" do + order.ready_to_ship?.should == false + end + end + + describe "an unpaid order with a shipment" do + let(:order) { create(:order, shipping_method: shipping_method) } + let(:shipping_method) { create(:shipping_method) } + + before do + order.create_shipment! + order.reload + order.state = 'complete' + order.shipment.update!(order) + end + + it "cannot be shipped" do + order.ready_to_ship?.should == false + end + end + + describe "a paid order without a shipment" do + let(:order) { create(:order) } + + before do + order.payment_state = 'paid' + order.state = 'complete' + end + + it "cannot be shipped" do + order.ready_to_ship?.should == false + end + end + + describe "a paid order with a shipment" do + let(:order) { create(:order, shipping_method: shipping_method) } + let(:shipping_method) { create(:shipping_method) } + + before do + order.create_shipment! + order.payment_state = 'paid' + order.state = 'complete' + order.shipment.update!(order) + end + + it "can be shipped" do + order.ready_to_ship?.should == true + end + end + describe "getting the shipping tax" do let(:order) { create(:order, shipping_method: shipping_method) } let(:shipping_method) { create(:shipping_method, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 50.0)) } From 1268108877f8169af117edbb36723de87d8e8f3d Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 29 Apr 2015 12:03:11 +1000 Subject: [PATCH 07/41] handle ship event on order --- app/models/spree/order_decorator.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index f109f730d8..0dc6977965 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -203,6 +203,13 @@ Spree::Order.class_eval do self.shipments.any?{|s| s.can_ship?} end + # Ship all pending orders + def ship + self.shipments.each do |s| + s.ship if s.can_ship? + end + end + def available_shipping_methods(display_on = nil) Spree::ShippingMethod.all_available(self, display_on) end From 8511bd19ced2b2d6f02ae574e8893cf2ac732728 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 29 Apr 2015 12:03:49 +1000 Subject: [PATCH 08/41] add ship button to order edit page --- .../spree/admin/orders/edit/add_ship_button.html.haml.deface | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 app/overrides/spree/admin/orders/edit/add_ship_button.html.haml.deface diff --git a/app/overrides/spree/admin/orders/edit/add_ship_button.html.haml.deface b/app/overrides/spree/admin/orders/edit/add_ship_button.html.haml.deface new file mode 100644 index 0000000000..47fbdea70a --- /dev/null +++ b/app/overrides/spree/admin/orders/edit/add_ship_button.html.haml.deface @@ -0,0 +1,3 @@ +/ insert_before "code[erb-loud]:contains('button_link_to t(:resend)')" +- if @order.ready_to_ship? + %li= button_link_to t(:ship), fire_admin_order_url(@order, :e => 'ship'), :method => :put, :data => { :confirm => t(:are_you_sure) } From e82a3a9d82057151273e5890c74a0b4bf11d0f78 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 29 Apr 2015 12:30:05 +1000 Subject: [PATCH 09/41] add ship button to admin order index page --- .../admin/orders/index/add_ship_shortcut.html.haml.deface | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 app/overrides/spree/admin/orders/index/add_ship_shortcut.html.haml.deface diff --git a/app/overrides/spree/admin/orders/index/add_ship_shortcut.html.haml.deface b/app/overrides/spree/admin/orders/index/add_ship_shortcut.html.haml.deface new file mode 100644 index 0000000000..cf0b2b0abb --- /dev/null +++ b/app/overrides/spree/admin/orders/index/add_ship_shortcut.html.haml.deface @@ -0,0 +1,6 @@ +/ insert_bottom "[data-hook='admin_orders_index_row_actions']" +-# See also: app/overrides/add_capture_order_shortcut.rb + +- if order.ready_to_ship? + - # copied from backend/app/views/spree/admin/payments/_list.html.erb + = link_to_with_icon "icon-road", t(:ship), fire_admin_order_url(order, :e => 'ship'), :method => :put, :no_text => true, :data => {:action => 'ship', :confirm => t(:are_you_sure)} From 2e66a082eb84d0f8111bff465dab5db08993bc07 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 29 Apr 2015 14:14:18 +1000 Subject: [PATCH 10/41] add customer notes to admin order index page --- .../orders/index/add_special_instructions.html.haml.deface | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 app/overrides/spree/admin/orders/index/add_special_instructions.html.haml.deface diff --git a/app/overrides/spree/admin/orders/index/add_special_instructions.html.haml.deface b/app/overrides/spree/admin/orders/index/add_special_instructions.html.haml.deface new file mode 100644 index 0000000000..75a2bc4689 --- /dev/null +++ b/app/overrides/spree/admin/orders/index/add_special_instructions.html.haml.deface @@ -0,0 +1,6 @@ +/ insert_bottom "[data-hook='admin_orders_index_rows'] td:nth-child(3)" + +- if order.special_instructions.present? + %br + %span{class: "icon-warning-sign with-tip", title: order.special_instructions} + notes From ecf635e080e475ad617c969211ce03574d5d404c Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 29 Apr 2015 14:28:20 +1000 Subject: [PATCH 11/41] handle missing bill_address on admin order page --- .../shared/_order_tabs/add_customer_name.html.haml.deface | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/overrides/spree/admin/shared/_order_tabs/add_customer_name.html.haml.deface b/app/overrides/spree/admin/shared/_order_tabs/add_customer_name.html.haml.deface index f8ce05079c..2e3780460e 100644 --- a/app/overrides/spree/admin/shared/_order_tabs/add_customer_name.html.haml.deface +++ b/app/overrides/spree/admin/shared/_order_tabs/add_customer_name.html.haml.deface @@ -1,5 +1,6 @@ / insert_after "code[erb-silent]:contains('content_for :page_title')" -= @order.bill_address.firstname -= @order.bill_address.lastname -\- +- if @order.bill_address.present? + = @order.bill_address.firstname + = @order.bill_address.lastname + \- From f4df227ef02d2f9c6712926957fd614a0f6f1d92 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 30 Apr 2015 13:54:27 +1000 Subject: [PATCH 12/41] Buildkite should now support Fuubar --- script/ci/run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/ci/run_tests.sh b/script/ci/run_tests.sh index 189875f1e1..5539935a8b 100755 --- a/script/ci/run_tests.sh +++ b/script/ci/run_tests.sh @@ -16,4 +16,4 @@ echo "--- Loading test database" bundle exec rake db:test:load echo "--- Running tests" -bundle exec rspec spec --format progress +bundle exec rspec spec From b09ae550c8773212f14f4c3920eedf08a4a81b55 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 30 Apr 2015 10:52:29 +1000 Subject: [PATCH 13/41] Add spec for payment actions --- spec/models/spree/payment_spec.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 spec/models/spree/payment_spec.rb diff --git a/spec/models/spree/payment_spec.rb b/spec/models/spree/payment_spec.rb new file mode 100644 index 0000000000..0962bdbf98 --- /dev/null +++ b/spec/models/spree/payment_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +module Spree + describe Payment do + describe "available actions" do + let(:payment) { create(:payment, source: create(:credit_card)) } + + context "for most gateways" do + it "can capture and void" do + payment.actions.sort.should == %w(capture void).sort + end + + describe "when a payment has been taken" do + before do + payment.stub(:state) { 'completed' } + payment.stub(:order) { double(:order, payment_state: 'credit_owed') } + end + + it "can void and credit" do + payment.actions.sort.should == %w(void credit).sort + end + end + end + end + end +end From 8184a7c7b2f4d9d9b4ae726eb65dce16321073c9 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 30 Apr 2015 13:45:44 +1000 Subject: [PATCH 14/41] Pin payments can't void or credit, but they can refund --- app/models/spree/payment_decorator.rb | 15 +++++++++++++++ spec/models/spree/payment_spec.rb | 26 ++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 app/models/spree/payment_decorator.rb diff --git a/app/models/spree/payment_decorator.rb b/app/models/spree/payment_decorator.rb new file mode 100644 index 0000000000..5095ae57e9 --- /dev/null +++ b/app/models/spree/payment_decorator.rb @@ -0,0 +1,15 @@ +module Spree + Payment.class_eval do + # Pin payments lacks void and credit methods, but it does have refund + # Here we swap credit out for refund and remove void as a possible action + def actions_with_pin_payment_adaptations + actions = actions_without_pin_payment_adaptations + if payment_method.is_a? Gateway::Pin + actions << 'refund' if actions.include? 'credit' + actions.reject! { |a| ['credit', 'void'].include? a } + end + actions + end + alias_method_chain :actions, :pin_payment_adaptations + end +end diff --git a/spec/models/spree/payment_spec.rb b/spec/models/spree/payment_spec.rb index 0962bdbf98..04cf7b4c6f 100644 --- a/spec/models/spree/payment_spec.rb +++ b/spec/models/spree/payment_spec.rb @@ -3,9 +3,9 @@ require 'spec_helper' module Spree describe Payment do describe "available actions" do - let(:payment) { create(:payment, source: create(:credit_card)) } - context "for most gateways" do + let(:payment) { create(:payment, source: create(:credit_card)) } + it "can capture and void" do payment.actions.sort.should == %w(capture void).sort end @@ -21,6 +21,28 @@ module Spree end end end + + context "for Pin Payments" do + let(:d) { create(:distributor_enterprise) } + let(:pin) { Gateway::Pin.create! name: 'pin', distributor_ids: [d.id]} + let(:payment) { create(:payment, source: create(:credit_card), payment_method: pin) } + + it "does not void" do + payment.actions.should_not include 'void' + end + + describe "when a payment has been taken" do + before do + payment.stub(:state) { 'completed' } + payment.stub(:order) { double(:order, payment_state: 'credit_owed') } + end + + it "can refund instead of crediting" do + payment.actions.should_not include 'credit' + payment.actions.should include 'refund' + end + end + end end end end From b498c2863292dbbb57818355f836b67c69bc1335 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 30 Apr 2015 15:38:01 +1000 Subject: [PATCH 15/41] Payments can be refunded --- app/models/spree/payment_decorator.rb | 37 +++++++++++++ spec/models/spree/payment_spec.rb | 80 +++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) diff --git a/app/models/spree/payment_decorator.rb b/app/models/spree/payment_decorator.rb index 5095ae57e9..1a80f0269f 100644 --- a/app/models/spree/payment_decorator.rb +++ b/app/models/spree/payment_decorator.rb @@ -11,5 +11,42 @@ module Spree actions end alias_method_chain :actions, :pin_payment_adaptations + + + def refund!(refund_amount=nil) + protect_from_connection_error do + check_environment + + refund_amount = calculate_refund_amount(refund_amount) + + if payment_method.payment_profiles_supported? + response = payment_method.refund((refund_amount * 100).round, source, response_code, gateway_options) + else + response = payment_method.refund((refund_amount * 100).round, response_code, gateway_options) + end + + record_response(response) + + if response.success? + self.class.create({ :order => order, + :source => self, + :payment_method => payment_method, + :amount => refund_amount.abs * -1, + :response_code => response.authorization, + :state => 'completed' }, :without_protection => true) + else + gateway_error(response) + end + end + end + + + private + + def calculate_refund_amount(refund_amount=nil) + refund_amount ||= credit_allowed >= order.outstanding_balance.abs ? order.outstanding_balance.abs : credit_allowed.abs + refund_amount.to_f + end + end end diff --git a/spec/models/spree/payment_spec.rb b/spec/models/spree/payment_spec.rb index 04cf7b4c6f..8a781e7700 100644 --- a/spec/models/spree/payment_spec.rb +++ b/spec/models/spree/payment_spec.rb @@ -44,5 +44,85 @@ module Spree end end end + + describe "refunding" do + let(:payment) { create(:payment) } + let(:success) { double(:success? => true, authorization: 'abc123') } + let(:failure) { double(:success? => false) } + + it "always checks the environment" do + payment.payment_method.stub(:refund) { success } + payment.should_receive(:check_environment) + payment.refund! + end + + describe "calculating refund amount" do + it "returns the parameter amount when given" do + payment.send(:calculate_refund_amount, 123).should === 123.0 + end + + it "refunds up to the value of the payment when the outstanding balance is larger" do + payment.stub(:credit_allowed) { 123 } + payment.stub(:order) { double(:order, outstanding_balance: 1000) } + payment.send(:calculate_refund_amount).should == 123 + end + + it "refunds up to the outstanding balance of the order when the payment is larger" do + payment.stub(:credit_allowed) { 1000 } + payment.stub(:order) { double(:order, outstanding_balance: 123) } + payment.send(:calculate_refund_amount).should == 123 + end + end + + describe "performing refunds" do + before do + payment.stub(:calculate_refund_amount) { 123 } + payment.payment_method.should_receive(:refund).and_return(success) + end + + it "performs the refund without payment profiles" do + payment.payment_method.stub(:payment_profiles_supported?) { false } + payment.refund! + end + + it "performs the refund with payment profiles" do + payment.payment_method.stub(:payment_profiles_supported?) { true } + payment.refund! + end + end + + it "records the response" do + payment.stub(:calculate_refund_amount) { 123 } + payment.payment_method.stub(:refund).and_return(success) + payment.should_receive(:record_response).with(success) + payment.refund! + end + + it "records a payment on success" do + payment.stub(:calculate_refund_amount) { 123 } + payment.payment_method.stub(:refund).and_return(success) + payment.stub(:record_response) + + expect do + payment.refund! + end.to change(Payment, :count).by(1) + + p = Payment.last + p.order.should == payment.order + p.source.should == payment + p.payment_method.should == payment.payment_method + p.amount.should == -123 + p.response_code.should == success.authorization + p.state.should == 'completed' + end + + it "logs the error on failure" do + payment.stub(:calculate_refund_amount) { 123 } + payment.payment_method.stub(:refund).and_return(failure) + payment.stub(:record_response) + payment.should_receive(:gateway_error).with(failure) + payment.refund! + end + end end end From 0b652a2113fe69787a569874ff3bc43ed3a63c10 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 30 Apr 2015 15:38:12 +1000 Subject: [PATCH 16/41] Add refund icon --- app/assets/stylesheets/admin/icons.css.scss | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 app/assets/stylesheets/admin/icons.css.scss diff --git a/app/assets/stylesheets/admin/icons.css.scss b/app/assets/stylesheets/admin/icons.css.scss new file mode 100644 index 0000000000..e7737ce8e9 --- /dev/null +++ b/app/assets/stylesheets/admin/icons.css.scss @@ -0,0 +1,3 @@ +@import 'plugins/font-awesome'; + +.icon-refund:before { @extend .icon-ok:before } From 2c7a5c06565a638a5c7d9053ead00fc97303c005 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 30 Apr 2015 15:38:17 +1000 Subject: [PATCH 17/41] Update Spree - fixes bug where Payment#method_missing depends on #provider already called. --- Gemfile.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 17dbfdf8c5..1b62201120 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,7 +23,7 @@ GIT GIT remote: git://github.com/openfoodfoundation/spree.git - revision: 4e0075b07acb56864aca89eee3d9670136176c23 + revision: afcc23e489eb604a3e2651598a7c8364e2acc7b3 branch: 1-3-stable specs: spree (1.3.6.beta) @@ -123,7 +123,7 @@ GEM active_link_to (1.0.0) active_model_serializers (0.8.1) activemodel (>= 3.0) - activemerchant (1.46.0) + activemerchant (1.48.0) activesupport (>= 3.2.14, < 5.0.0) builder (>= 2.1.2, < 4.0.0) i18n (>= 0.6.9) @@ -181,7 +181,7 @@ GEM climate_control (0.0.3) activesupport (>= 3.0) cliver (0.3.2) - cocaine (0.5.5) + cocaine (0.5.7) climate_control (>= 0.0.3, < 1.0) coderay (1.0.9) coffee-rails (3.2.2) @@ -191,7 +191,7 @@ GEM coffee-script-source execjs coffee-script-source (1.3.3) - colorize (0.7.5) + colorize (0.7.7) columnize (0.3.6) comfortable_mexican_sofa (1.6.24) active_link_to (~> 1.0.0) @@ -496,7 +496,7 @@ GEM sprockets (>= 2.0.0) turn (0.8.3) ansi - tzinfo (0.3.43) + tzinfo (0.3.44) uglifier (1.2.4) execjs (>= 0.3.0) multi_json (>= 1.0.2) From 5efc0a511063384abd362ac4dd8120ae5fffd05a Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 30 Apr 2015 16:29:51 +1000 Subject: [PATCH 18/41] quick fix: update fees after updating order --- .../admin/orders_controller_decorator.rb | 11 +++++++ .../spree/admin/orders_controller_spec.rb | 30 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 spec/controllers/spree/admin/orders_controller_spec.rb diff --git a/app/controllers/spree/admin/orders_controller_decorator.rb b/app/controllers/spree/admin/orders_controller_decorator.rb index ceba6d9bde..42e7068afc 100644 --- a/app/controllers/spree/admin/orders_controller_decorator.rb +++ b/app/controllers/spree/admin/orders_controller_decorator.rb @@ -9,6 +9,13 @@ Spree::Admin::OrdersController.class_eval do # in an auth failure as the @order object is nil for collection actions before_filter :check_authorization, :except => :bulk_management + # After updating an order, the fees should be updated as well + # Currently, adding or deleting line items does not trigger updating the + # fees! This is a quick fix for that. + # TODO: update fees when adding/removing line items + # instead of the update_distribution_charge method. + after_filter :update_distribution_charge, :only => :update + respond_override :index => { :html => { :success => lambda { # Filter orders to only show those distributed by current user (or all for admin user) @@ -26,4 +33,8 @@ Spree::Admin::OrdersController.class_eval do respond_with(@order) { |format| format.html { redirect_to :back } } end + + def update_distribution_charge + @order.update_distribution_charge! + end end diff --git a/spec/controllers/spree/admin/orders_controller_spec.rb b/spec/controllers/spree/admin/orders_controller_spec.rb new file mode 100644 index 0000000000..5724732c50 --- /dev/null +++ b/spec/controllers/spree/admin/orders_controller_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe Spree::Admin::OrdersController do + let!(:order) { create(:order) } + + context "updating an order with line items" do + let(:line_item) { create(:line_item) } + before { login_as_admin } + + it "updates distribution charges" do + order.line_items << line_item + order.save + Spree::Order.any_instance.should_receive(:update_distribution_charge!) + spree_put :update, { + id: order, + order: { + number: order.number, + distributor_id: order.distributor_id, + order_cycle_id: order.order_cycle_id, + line_items_attributes: [ + { + id: line_item.id, + quantity: line_item.quantity + } + ] + } + } + end + end +end From a6cecdcc25af036f5d0645341cddfac67e376054 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 1 May 2015 11:59:52 +1000 Subject: [PATCH 19/41] Display header for Xero invoices report --- .../admin/reports_controller_decorator.rb | 26 ++++++++++++++----- .../admin/reports/xero_invoices.html.haml | 13 ++++++++++ config/routes.rb | 1 + lib/open_food_network/xero_invoices_report.rb | 15 +++++++++++ spec/features/admin/reports_spec.rb | 25 ++++++++++++++++++ 5 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 app/views/spree/admin/reports/xero_invoices.html.haml create mode 100644 lib/open_food_network/xero_invoices_report.rb diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index f148456813..aed798827e 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -7,6 +7,7 @@ require 'open_food_network/customers_report' require 'open_food_network/users_and_enterprises_report' require 'open_food_network/order_cycle_management_report' require 'open_food_network/sales_tax_report' +require 'open_food_network/xero_invoices_report' Spree::Admin::ReportsController.class_eval do @@ -14,10 +15,10 @@ Spree::Admin::ReportsController.class_eval do REPORT_TYPES = { orders_and_fulfillment: [ - ['Order Cycle Supplier Totals',:order_cycle_supplier_totals], - ['Order Cycle Supplier Totals by Distributor',:order_cycle_supplier_totals_by_distributor], - ['Order Cycle Distributor Totals by Supplier',:order_cycle_distributor_totals_by_supplier], - ['Order Cycle Customer Totals',:order_cycle_customer_totals] + ['Order Cycle Supplier Totals', :order_cycle_supplier_totals], + ['Order Cycle Supplier Totals by Distributor', :order_cycle_supplier_totals_by_distributor], + ['Order Cycle Distributor Totals by Supplier', :order_cycle_distributor_totals_by_supplier], + ['Order Cycle Customer Totals', :order_cycle_customer_totals] ], products_and_inventory: [ ['All products', :all_products], @@ -30,13 +31,16 @@ Spree::Admin::ReportsController.class_eval do order_cycle_management: [ ["Payment Methods Report", :payment_methods], ["Delivery Report", :delivery] + ], + xero_invoices: [ + ["Xero Invoices Report", :xero_invoices] ] } # Fetches user's distributors, suppliers and order_cycles before_filter :load_data, only: [:customers, :products_and_inventory, :order_cycle_management] - # Render a partial for orders and fulfillment description + # Render a partial for various section descriptions respond_override :index => { :html => { :success => lambda { @reports[:orders_and_fulfillment][:description] = render_to_string(partial: 'orders_and_fulfillment_description', layout: false, locals: {report_types: REPORT_TYPES[:orders_and_fulfillment]}).html_safe @@ -672,7 +676,13 @@ Spree::Admin::ReportsController.class_eval do render_report(@report.header, @report.table, params[:csv], "users_and_enterprises_#{timestamp}.csv") end - def render_report (header, table, create_csv, csv_file_name) + def xero_invoices + @report = OpenFoodNetwork::XeroInvoicesReport.new params + render_report(@report.header, @report.table, params[:csv], "xero_invoices_#{timestamp}.csv") + end + + + def render_report(header, table, create_csv, csv_file_name) unless create_csv render :html => table else @@ -709,7 +719,9 @@ Spree::Admin::ReportsController.class_eval do :sales_total => { :name => "Sales Total", :description => "Sales Total For All Orders" }, :users_and_enterprises => { :name => "Users & Enterprises", :description => "Enterprise Ownership & Status" }, :order_cycle_management => {:name => "Order Cycle Management", :description => ''}, - :sales_tax => { :name => "Sales Tax", :description => "Sales Tax For Orders" } + :sales_tax => { :name => "Sales Tax", :description => "Sales Tax For Orders" }, + :xero_invoices => { :name => "Xero invoices", :description => 'Invoices for import into Xero' } + } # Return only reports the user is authorized to view. reports.select { |action| can? action, :report } diff --git a/app/views/spree/admin/reports/xero_invoices.html.haml b/app/views/spree/admin/reports/xero_invoices.html.haml new file mode 100644 index 0000000000..0e9598125a --- /dev/null +++ b/app/views/spree/admin/reports/xero_invoices.html.haml @@ -0,0 +1,13 @@ +%table#listing_invoices.index + %thead + %tr + - @report.header.each do |header| + %th= header + %tbody + - @report.table.each do |row| + %tr + - row.each do |column| + %td= column + - if @report.table.empty? + %tr + %td{:colspan => "2"}= t(:none) diff --git a/config/routes.rb b/config/routes.rb index 4621ee4a35..66805807ce 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -134,6 +134,7 @@ Spree::Core::Engine.routes.prepend do match '/admin/orders/bulk_management' => 'admin/orders#bulk_management', :as => "admin_bulk_order_management" match '/admin/reports/products_and_inventory' => 'admin/reports#products_and_inventory', :as => "products_and_inventory_admin_reports", :via => [:get, :post] match '/admin/reports/customers' => 'admin/reports#customers', :as => "customers_admin_reports", :via => [:get, :post] + match '/admin/reports/xero_invoices' => 'admin/reports#xero_invoices', :as => "xero_invoices_admin_reports", :via => [:get, :post] match '/admin', :to => 'admin/overview#index', :as => :admin match '/admin/payment_methods/show_provider_preferences' => 'admin/payment_methods#show_provider_preferences', :via => :get diff --git a/lib/open_food_network/xero_invoices_report.rb b/lib/open_food_network/xero_invoices_report.rb new file mode 100644 index 0000000000..35c3dac73d --- /dev/null +++ b/lib/open_food_network/xero_invoices_report.rb @@ -0,0 +1,15 @@ +module OpenFoodNetwork + class XeroInvoicesReport + def initialize(params={}) + @params = params + end + + def header + %w(*ContactName EmailAddress POAddressLine1 POAddressLine2 POAddressLine3 POAddressLine4 POCity PORegion POPostalCode POCountry *InvoiceNumber Reference *InvoiceDate *DueDate InventoryItemCode *Description *Quantity *UnitAmount Discount *AccountCode *TaxType TrackingName1 TrackingOption1 TrackingName2 TrackingOption2 Currency BrandingTheme) + end + + def table + [[]] + end + end +end diff --git a/spec/features/admin/reports_spec.rb b/spec/features/admin/reports_spec.rb index b1685be6db..260c1885ce 100644 --- a/spec/features/admin/reports_spec.rb +++ b/spec/features/admin/reports_spec.rb @@ -297,4 +297,29 @@ feature %q{ ].sort end end + + describe "Xero invoices report" do + let!(:enterprise1) { create( :enterprise, owner: create_enterprise_user ) } + let!(:enterprise2) { create( :enterprise, owner: create_enterprise_user ) } + let!(:enterprise3) { create( :enterprise, owner: create_enterprise_user ) } + + before do + enterprise3.enterprise_roles.build( user: enterprise1.owner ).save + + login_to_admin_section + click_link 'Reports' + + click_link 'Xero invoices' + end + + it "shows Xero invoices report" do + rows = find("table#listing_invoices").all("tr") + table = rows.map { |r| r.all("th,td").map { |c| c.text.strip } } + + table.should == [ + %w(*ContactName EmailAddress POAddressLine1 POAddressLine2 POAddressLine3 POAddressLine4 POCity PORegion POPostalCode POCountry *InvoiceNumber Reference *InvoiceDate *DueDate InventoryItemCode *Description *Quantity *UnitAmount Discount *AccountCode *TaxType TrackingName1 TrackingOption1 TrackingName2 TrackingOption2 Currency BrandingTheme), + [] + ] + end + end end From b7bac326bd792932349042398c817f6defccfb1b Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 1 May 2015 12:05:43 +1000 Subject: [PATCH 20/41] admin order edit: re-label update button to "update and recalculate fees" --- .../admin/orders/_form/relabel_update_button.html.haml.deface | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 app/overrides/spree/admin/orders/_form/relabel_update_button.html.haml.deface diff --git a/app/overrides/spree/admin/orders/_form/relabel_update_button.html.haml.deface b/app/overrides/spree/admin/orders/_form/relabel_update_button.html.haml.deface new file mode 100644 index 0000000000..d4d3aefc8d --- /dev/null +++ b/app/overrides/spree/admin/orders/_form/relabel_update_button.html.haml.deface @@ -0,0 +1,3 @@ +/ replace "code[erb-loud]:contains('button t(:update)')" + += button t(:update_and_recalculate_fees), 'icon-refresh' From e6e063670cd90522a0bd57bb3af2167e1007c06a Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 1 May 2015 14:49:34 +1000 Subject: [PATCH 21/41] Allow managers to remove line items from order Managers of an order cycle and the distributor of an order are allowed to remove a line item from the order. --- .../spree/admin/line_items_controller_decorator.rb | 8 ++++++++ app/models/spree/ability_decorator.rb | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 app/controllers/spree/admin/line_items_controller_decorator.rb diff --git a/app/controllers/spree/admin/line_items_controller_decorator.rb b/app/controllers/spree/admin/line_items_controller_decorator.rb new file mode 100644 index 0000000000..ca83baa00b --- /dev/null +++ b/app/controllers/spree/admin/line_items_controller_decorator.rb @@ -0,0 +1,8 @@ +Spree::Admin::LineItemsController.class_eval do + private + + def load_order + @order = Spree::Order.find_by_number!(params[:order_id]) + authorize! :update, @order + end +end diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index e66c03aa72..c6126d7171 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -144,6 +144,9 @@ class AbilityDecorator end can [:admin, :bulk_management], Spree::Order if user.admin? || user.enterprises.any?(&:is_distributor) can [:admin, :create], Spree::LineItem + can [:destroy], Spree::LineItem do |item| + user.admin? || user.enterprises.include?(order.distributor) || user == order.order_cycle.manager + end can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Payment can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Shipment From 03ae740cd6cafe05d9a74bbeaef931e0d3576269 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 1 May 2015 14:55:26 +1000 Subject: [PATCH 22/41] Revert "Display header for Xero invoices report" This reverts commit a6cecdcc25af036f5d0645341cddfac67e376054. --- .../admin/reports_controller_decorator.rb | 26 +++++-------------- .../admin/reports/xero_invoices.html.haml | 13 ---------- config/routes.rb | 1 - lib/open_food_network/xero_invoices_report.rb | 15 ----------- spec/features/admin/reports_spec.rb | 25 ------------------ 5 files changed, 7 insertions(+), 73 deletions(-) delete mode 100644 app/views/spree/admin/reports/xero_invoices.html.haml delete mode 100644 lib/open_food_network/xero_invoices_report.rb diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index aed798827e..f148456813 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -7,7 +7,6 @@ require 'open_food_network/customers_report' require 'open_food_network/users_and_enterprises_report' require 'open_food_network/order_cycle_management_report' require 'open_food_network/sales_tax_report' -require 'open_food_network/xero_invoices_report' Spree::Admin::ReportsController.class_eval do @@ -15,10 +14,10 @@ Spree::Admin::ReportsController.class_eval do REPORT_TYPES = { orders_and_fulfillment: [ - ['Order Cycle Supplier Totals', :order_cycle_supplier_totals], - ['Order Cycle Supplier Totals by Distributor', :order_cycle_supplier_totals_by_distributor], - ['Order Cycle Distributor Totals by Supplier', :order_cycle_distributor_totals_by_supplier], - ['Order Cycle Customer Totals', :order_cycle_customer_totals] + ['Order Cycle Supplier Totals',:order_cycle_supplier_totals], + ['Order Cycle Supplier Totals by Distributor',:order_cycle_supplier_totals_by_distributor], + ['Order Cycle Distributor Totals by Supplier',:order_cycle_distributor_totals_by_supplier], + ['Order Cycle Customer Totals',:order_cycle_customer_totals] ], products_and_inventory: [ ['All products', :all_products], @@ -31,16 +30,13 @@ Spree::Admin::ReportsController.class_eval do order_cycle_management: [ ["Payment Methods Report", :payment_methods], ["Delivery Report", :delivery] - ], - xero_invoices: [ - ["Xero Invoices Report", :xero_invoices] ] } # Fetches user's distributors, suppliers and order_cycles before_filter :load_data, only: [:customers, :products_and_inventory, :order_cycle_management] - # Render a partial for various section descriptions + # Render a partial for orders and fulfillment description respond_override :index => { :html => { :success => lambda { @reports[:orders_and_fulfillment][:description] = render_to_string(partial: 'orders_and_fulfillment_description', layout: false, locals: {report_types: REPORT_TYPES[:orders_and_fulfillment]}).html_safe @@ -676,13 +672,7 @@ Spree::Admin::ReportsController.class_eval do render_report(@report.header, @report.table, params[:csv], "users_and_enterprises_#{timestamp}.csv") end - def xero_invoices - @report = OpenFoodNetwork::XeroInvoicesReport.new params - render_report(@report.header, @report.table, params[:csv], "xero_invoices_#{timestamp}.csv") - end - - - def render_report(header, table, create_csv, csv_file_name) + def render_report (header, table, create_csv, csv_file_name) unless create_csv render :html => table else @@ -719,9 +709,7 @@ Spree::Admin::ReportsController.class_eval do :sales_total => { :name => "Sales Total", :description => "Sales Total For All Orders" }, :users_and_enterprises => { :name => "Users & Enterprises", :description => "Enterprise Ownership & Status" }, :order_cycle_management => {:name => "Order Cycle Management", :description => ''}, - :sales_tax => { :name => "Sales Tax", :description => "Sales Tax For Orders" }, - :xero_invoices => { :name => "Xero invoices", :description => 'Invoices for import into Xero' } - + :sales_tax => { :name => "Sales Tax", :description => "Sales Tax For Orders" } } # Return only reports the user is authorized to view. reports.select { |action| can? action, :report } diff --git a/app/views/spree/admin/reports/xero_invoices.html.haml b/app/views/spree/admin/reports/xero_invoices.html.haml deleted file mode 100644 index 0e9598125a..0000000000 --- a/app/views/spree/admin/reports/xero_invoices.html.haml +++ /dev/null @@ -1,13 +0,0 @@ -%table#listing_invoices.index - %thead - %tr - - @report.header.each do |header| - %th= header - %tbody - - @report.table.each do |row| - %tr - - row.each do |column| - %td= column - - if @report.table.empty? - %tr - %td{:colspan => "2"}= t(:none) diff --git a/config/routes.rb b/config/routes.rb index 66805807ce..4621ee4a35 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -134,7 +134,6 @@ Spree::Core::Engine.routes.prepend do match '/admin/orders/bulk_management' => 'admin/orders#bulk_management', :as => "admin_bulk_order_management" match '/admin/reports/products_and_inventory' => 'admin/reports#products_and_inventory', :as => "products_and_inventory_admin_reports", :via => [:get, :post] match '/admin/reports/customers' => 'admin/reports#customers', :as => "customers_admin_reports", :via => [:get, :post] - match '/admin/reports/xero_invoices' => 'admin/reports#xero_invoices', :as => "xero_invoices_admin_reports", :via => [:get, :post] match '/admin', :to => 'admin/overview#index', :as => :admin match '/admin/payment_methods/show_provider_preferences' => 'admin/payment_methods#show_provider_preferences', :via => :get diff --git a/lib/open_food_network/xero_invoices_report.rb b/lib/open_food_network/xero_invoices_report.rb deleted file mode 100644 index 35c3dac73d..0000000000 --- a/lib/open_food_network/xero_invoices_report.rb +++ /dev/null @@ -1,15 +0,0 @@ -module OpenFoodNetwork - class XeroInvoicesReport - def initialize(params={}) - @params = params - end - - def header - %w(*ContactName EmailAddress POAddressLine1 POAddressLine2 POAddressLine3 POAddressLine4 POCity PORegion POPostalCode POCountry *InvoiceNumber Reference *InvoiceDate *DueDate InventoryItemCode *Description *Quantity *UnitAmount Discount *AccountCode *TaxType TrackingName1 TrackingOption1 TrackingName2 TrackingOption2 Currency BrandingTheme) - end - - def table - [[]] - end - end -end diff --git a/spec/features/admin/reports_spec.rb b/spec/features/admin/reports_spec.rb index 260c1885ce..b1685be6db 100644 --- a/spec/features/admin/reports_spec.rb +++ b/spec/features/admin/reports_spec.rb @@ -297,29 +297,4 @@ feature %q{ ].sort end end - - describe "Xero invoices report" do - let!(:enterprise1) { create( :enterprise, owner: create_enterprise_user ) } - let!(:enterprise2) { create( :enterprise, owner: create_enterprise_user ) } - let!(:enterprise3) { create( :enterprise, owner: create_enterprise_user ) } - - before do - enterprise3.enterprise_roles.build( user: enterprise1.owner ).save - - login_to_admin_section - click_link 'Reports' - - click_link 'Xero invoices' - end - - it "shows Xero invoices report" do - rows = find("table#listing_invoices").all("tr") - table = rows.map { |r| r.all("th,td").map { |c| c.text.strip } } - - table.should == [ - %w(*ContactName EmailAddress POAddressLine1 POAddressLine2 POAddressLine3 POAddressLine4 POCity PORegion POPostalCode POCountry *InvoiceNumber Reference *InvoiceDate *DueDate InventoryItemCode *Description *Quantity *UnitAmount Discount *AccountCode *TaxType TrackingName1 TrackingOption1 TrackingName2 TrackingOption2 Currency BrandingTheme), - [] - ] - end - end end From 11acb3ba59e647cd0457564af0bd701a787db582 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 1 May 2015 15:59:46 +1000 Subject: [PATCH 23/41] Allow to remove adjustments Managers of an order cycle and the distributor of an order are allowed to remove an adjustment from the order. --- app/models/spree/ability_decorator.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index c6126d7171..b8539979c2 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -152,6 +152,19 @@ class AbilityDecorator can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Shipment can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::Adjustment can [:admin, :index, :read, :create, :edit, :update, :fire], Spree::ReturnAuthorization + can [:destroy], Spree::Adjustment do |adjustment| + # Sharing code with destroying a line item. This should be unified and probably applied for other actions as well. + binding.pry + if user.admin? + true + elsif adjustment.adjustable.instance_of? Spree::Order + order = adjustment.adjustable + user.enterprises.include?(order.distributor) || user == order.order_cycle.manager + elsif adjustment.adjustable.instance_of? Spree::LineItem + order = adjustment.adjustable.order + user.enterprises.include?(order.distributor) || user == order.order_cycle.manager + end + end can [:create], OrderCycle From a3664d44483909916dfa2b40fb8e516db739eed8 Mon Sep 17 00:00:00 2001 From: Rick Giner Date: Sun, 3 May 2015 12:51:59 +1000 Subject: [PATCH 24/41] Added bindonce and ng-if improvements to Producers templates --- app/views/producers/_fat.html.haml | 56 +++++++++++++-------------- app/views/producers/_skinny.html.haml | 12 +++--- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/app/views/producers/_fat.html.haml b/app/views/producers/_fat.html.haml index 17304abbe3..a6d6661501 100644 --- a/app/views/producers/_fat.html.haml +++ b/app/views/producers/_fat.html.haml @@ -1,68 +1,68 @@ -.row.active_table_row{"ng-show" => "open()", "ng-click" => "toggle()", "ng-class" => "{'open' : !ofn-i_032-closed-sign()}"} +.row.active_table_row{"ng-if" => "open()", "ng-click" => "toggle()", "ng-class" => "{'open' : !ofn-i_032-closed-sign()}"} .columns.small-12.medium-7.large-7.fat / Will add in long description available once clean up HTML formatting producer.long_description %div{"bo-if" => "producer.description"} %label About us - %img.right.show-for-medium-up{"ng-src" => "{{producer.logo}}" } - %p.text-small - {{ producer.description }} + %img.right.show-for-medium-up{"bo-src" => "producer.logo" } + %p.text-small{ "bo-text" => "producer.description"} %div.show-for-medium-up{"bo-if" => "producer.description.length==0"} %label   .columns.small-12.medium-5.large-5.fat - %div{"ng-if" => "producer.supplied_taxons"} + %div{"bo-if" => "producer.supplied_taxons"} %label Shop for %p.trans-sentence %span.fat-taxons{"ng-repeat" => "taxon in producer.supplied_taxons"} %render-svg{path: "{{taxon.icon}}"} - {{taxon.name}} + %span{"bo-text" => "taxon.name"} %div.show-for-medium-up{"ng-if" => "producer.supplied_taxons.length==0"}   - %div{"ng-if" => "producer.email || producer.website || producer.phone"} + %div{"bo-if" => "producer.email || producer.website || producer.phone"} %label Contact - %p.word-wrap{"ng-if" => "producer.phone"} - Call {{ producer.phone }} + %p.word-wrap{"bo-if" => "producer.phone"} + Call + %span{"bo-text" => "producer.phone"} - %p.word-wrap{"ng-if" => "producer.email"} - %a{"ng-href" => "{{producer.email | stripUrl}}", target: "_blank", mailto: true} - %span.email {{ producer.email | stripUrl }} + %p.word-wrap{"bo-if" => "producer.email"} + %a{"bo-href" => "producer.email | stripUrl", target: "_blank", mailto: true} + %span.email{"bo-bind" => "producer.email | stripUrl"} - %p.word-wrap{"ng-if" => "producer.website"} - %a{"ng-href" => "http://{{producer.website | stripUrl}}", target: "_blank" } - %span {{ producer.website | stripUrl }} + %p.word-wrap{"bo-if" => "producer.website"} + %a{"bo-href-i" => "http://{{producer.website | stripUrl}}", target: "_blank" } + %span{"bo-bind" => "producer.website | stripUrl"} - %div{"ng-if" => "producer.twitter || producer.facebook || producer.linkedin || producer.instagram"} + %div{"bo-if" => "producer.twitter || producer.facebook || producer.linkedin || producer.instagram"} %label Follow .follow-icons{bindonce: true} - %span{"ng-if" => "producer.twitter"} - %a{"ng-href" => "http://twitter.com/{{producer.twitter}}", target: "_blank"} + %span{"bo-if" => "producer.twitter"} + %a{"bo-href-i" => "http://twitter.com/{{producer.twitter}}", target: "_blank"} %i.ofn-i_041-twitter - %span{"ng-if" => "producer.facebook"} - %a{"ng-href" => "http://{{producer.facebook | stripUrl}}", target: "_blank"} + %span{"bo-if" => "producer.facebook"} + %a{"bo-href-i" => "http://{{producer.facebook | stripUrl}}", target: "_blank"} %i.ofn-i_044-facebook - %span{"ng-if" => "producer.linkedin"} - %a{"ng-href" => "http://{{producer.linkedin | stripUrl}}", target: "_blank"} + %span{"bo-if" => "producer.linkedin"} + %a{"bo-href-i" => "http://{{producer.linkedin | stripUrl}}", target: "_blank"} %i.ofn-i_042-linkedin - %span{"ng-if" => "producer.instagram"} - %a{"ng-href" => "http://instagram.com/{{producer.instagram}}", target: "_blank"} + %span{"bo-if" => "producer.instagram"} + %a{"bo-href-i" => "http://instagram.com/{{producer.instagram}}", target: "_blank"} %i.ofn-i_043-instagram -.row.active_table_row.pad-top{"ng-show" => "open()", "bo-if" => "producer.hubs"} +.row.active_table_row.pad-top{"ng-if" => "open()", "bo-if" => "producer.hubs"} .columns.small-12 .row .columns.small-12.fat %div{"bo-if" => "producer.name"} %label Shop for - %span.turquoise {{ producer.name }} + %span.turquoise{"bo-text" => "producer.name"} products at: %div.show-for-medium-up{"bo-if" => "!producer.name"}   @@ -73,6 +73,6 @@ "bo-class" => "{primary: hub.active, secondary: !hub.active}"} %i.ofn-i_033-open-sign{"bo-if" => "hub.active"} %i.ofn-i_032-closed-sign{"bo-if" => "!hub.active"} - .hub-name {{hub.name}} - .button-address {{ [hub.address.city, hub.address.state_name] | printArray }} + .hub-name{"bo-text" => "hub.name"} + .button-address{"bo-bind" => "[hub.address.city, hub.address.state_name] | printArray"} diff --git a/app/views/producers/_skinny.html.haml b/app/views/producers/_skinny.html.haml index aaa59b20e8..49ab0a35be 100644 --- a/app/views/producers/_skinny.html.haml +++ b/app/views/producers/_skinny.html.haml @@ -2,19 +2,19 @@ .columns.small-12.medium-4.large-4.skinny-head %span{"bo-if" => "producer.is_distributor" } %a.is_distributor{"bo-href" => "producer.path" } - %i{ng: {class: "producer.producer_icon_font"}} + %i{bo: {class: "producer.producer_icon_font"}} %span.margin-top - %strong {{ producer.name }} + %strong{"bo-text" => "producer.name"} %span.producer-name{"bo-if" => "!producer.is_distributor" } - %i{ng: {class: "producer.producer_icon_font"}} + %i{bo: {class: "producer.producer_icon_font"}} %span.margin-top - %strong {{ producer.name }} + %strong{"bo-text" => "producer.name"} .columns.small-6.medium-3.large-3 - %span.margin-top {{ producer.address.city }} + %span.margin-top{"bo-text" => "producer.address.city"} .columns.small-4.medium-3.large-4 - %span.margin-top {{ producer.address.state_name | uppercase }} + %span.margin-top{"bo-bind" => "producer.address.state_name | uppercase"} .columns.small-2.medium-2.large-1.text-right %span.margin-top %i{"ng-class" => "{'ofn-i_005-caret-down' : !open(), 'ofn-i_006-caret-up' : open()}"} From 16e9f0545ba52e7ac6d8caf015f636d30680a491 Mon Sep 17 00:00:00 2001 From: Rick Giner Date: Sun, 3 May 2015 14:02:33 +1000 Subject: [PATCH 25/41] bind-once in products --- app/views/shop/products/_summary.html.haml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/views/shop/products/_summary.html.haml b/app/views/shop/products/_summary.html.haml index 392d7ef31d..dec398f80f 100644 --- a/app/views/shop/products/_summary.html.haml +++ b/app/views/shop/products/_summary.html.haml @@ -7,14 +7,13 @@ .small-10.medium-10.large-11.columns.summary-header %h3 %a{"ng-click" => "triggerProductModal()"} - {{ product.name }} + %span{"bo-text" => "product.name"} %i.ofn-i_057-expand %small %em from %span %enterprise-modal - %i.ofn-i_036-producers - {{ enterprise.name }} + %i.ofn-i_036-producers{"bo-text" => "enterprise.name"} .small-2.medium-2.large-1.columns.text-center .taxon-flag %render-svg{path: "{{product.primary_taxon.icon}}"} From 3fc616cdff059a6beb5d8e4bc8add848dc83099b Mon Sep 17 00:00:00 2001 From: Rick Giner Date: Sun, 3 May 2015 14:11:09 +1000 Subject: [PATCH 26/41] bind-once on hubs --- app/views/home/_fat.html.haml | 5 ++--- app/views/home/_skinny.html.haml | 17 +++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/views/home/_fat.html.haml b/app/views/home/_fat.html.haml index b3741e5aec..6796601637 100644 --- a/app/views/home/_fat.html.haml +++ b/app/views/home/_fat.html.haml @@ -5,7 +5,7 @@ .trans-sentence %span.fat-taxons{"ng-repeat" => "taxon in hub.taxons"} %render-svg{path: "{{taxon.icon}}"} - {{taxon.name}} + %span{"bo-text" => "taxon.name"} %div.show-for-medium-up{"bo-if" => "hub.taxons.length==0"}   .columns.small-12.medium-3.large-2.fat @@ -25,7 +25,6 @@ %li{"ng-repeat" => "enterprise in hub.producers"} %enterprise-modal %i.ofn-i_036-producers - %span - {{ enterprise.name }} + %span{"bo-text" => "enterprise.name"} %div.show-for-medium-up{"bo-if" => "hub.producers.length==0"}   diff --git a/app/views/home/_skinny.html.haml b/app/views/home/_skinny.html.haml index aeaae0cae4..cf001371f7 100644 --- a/app/views/home/_skinny.html.haml +++ b/app/views/home/_skinny.html.haml @@ -2,20 +2,21 @@ .columns.small-12.medium-6.large-5.skinny-head %a.hub{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"} - %i{ng: {class: "hub.icon_font"}} - %span.margin-top.hub-name-listing {{ hub.name | truncate:40}} + %i{bo: {class: "hub.icon_font"}} + %span.margin-top.hub-name-listing{"bo-bind" => "hub.name | truncate:40"} .columns.small-4.medium-2.large-2 - %span.margin-top {{ hub.address.city }} + %span.margin-top{"bo-text" => "hub.address.city"} .columns.small-2.medium-1.large-1 - %span.margin-top {{ hub.address.state_name | uppercase }} + %span.margin-top{"bo-bind" => "hub.address.state_name | uppercase"} .columns.small-6.medium-3.large-4.text-right{"bo-if" => "hub.active"} %a.hub.open_closed{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"} %i.ofn-i_033-open-sign %span.margin-top{ bo: { if: "current()" } } %em Shopping here - %span.margin-top{ bo: { if: "!current()" } } {{ hub.orders_close_at | sensible_timeframe }} + %span.margin-top{ bo: { if: "!current()" } } + %span{"bo-bind" => "hub.orders_close_at | sensible_timeframe"} .columns.small-6.medium-3.large-4.text-right{"bo-if" => "!hub.active"} %a.hub.open_closed{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"} @@ -28,12 +29,12 @@ .columns.small-12.medium-6.large-5.skinny-head %a.hub{"ng-click" => "openModal(hub)", "ng-class" => "{primary: hub.active, secondary: !hub.active}"} %i{ng: {class: "hub.icon_font"}} - %span.margin-top.hub-name-listing {{ hub.name | truncate:40}} + %span.margin-top.hub-name-listing{"bo-bind" => "hub.name | truncate:40"} .columns.small-4.medium-2.large-2 - %span.margin-top {{ hub.address.city }} + %span.margin-top{"bo-text" => "hub.address.city"} .columns.small-2.medium-1.large-1 - %span.margin-top {{ hub.address.state_name | uppercase }} + %span.margin-top{"bo-bind" => "hub.address.state_name | uppercase"} .columns.small-6.medium-3.large-4.text-right %span.margin-top{ bo: { if: "!current()" } } From 9c26b3ebb24a5f43c6a288f7b876f1a8fb8bec25 Mon Sep 17 00:00:00 2001 From: Rick Giner Date: Sun, 3 May 2015 14:34:42 +1000 Subject: [PATCH 27/41] bind-once in partials --- .../templates/partials/contact.html.haml | 11 ++++------ .../partials/enterprise_header.html.haml | 12 +++++------ .../templates/partials/follow.html.haml | 20 +++++++++---------- .../templates/partials/hub_actions.html.haml | 6 +++--- .../templates/partials/hub_details.html.haml | 4 ++-- 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/app/assets/javascripts/templates/partials/contact.html.haml b/app/assets/javascripts/templates/partials/contact.html.haml index caa3bc5e65..165fd69d80 100644 --- a/app/assets/javascripts/templates/partials/contact.html.haml +++ b/app/assets/javascripts/templates/partials/contact.html.haml @@ -1,14 +1,11 @@ %div.contact-container{bindonce: true} %div.modal-centered{"bo-if" => "enterprise.email || enterprise.website || enterprise.phone"} %p.modal-header Contact - %p{"ng-if" => "enterprise.phone"} - {{ enterprise.phone }} + %p{"bo-if" => "enterprise.phone", "bo-text" => "enterprise.phone"} %p.word-wrap{"ng-if" => "enterprise.email"} - %a{"ng-href" => "{{enterprise.email | stripUrl}}", target: "_blank", mailto: true} - %span.email - {{ enterprise.email | stripUrl }} + %a{"bo-href" => "enterprise.email | stripUrl", target: "_blank", mailto: true} + %span.email{"bo-bind" => "enterprise.email | stripUrl"} %p.word-wrap{"ng-if" => "enterprise.website"} - %a{"ng-href" => "http://{{enterprise.website | stripUrl}}", target: "_blank" } - {{ enterprise.website | stripUrl }} + %a{"bo-href-i" => "http://{{enterprise.website | stripUrl}}", target: "_blank", "bo-bind" => "enterprise.website | stripUrl"} diff --git a/app/assets/javascripts/templates/partials/enterprise_header.html.haml b/app/assets/javascripts/templates/partials/enterprise_header.html.haml index 27a57ed90b..c0d9d5d9e0 100644 --- a/app/assets/javascripts/templates/partials/enterprise_header.html.haml +++ b/app/assets/javascripts/templates/partials/enterprise_header.html.haml @@ -1,13 +1,13 @@ -.highlight{"ng-class" => "{'is_distributor' : enterprise.is_distributor}"} +.highlight{bindonce: true, "ng-class" => "{'is_distributor' : enterprise.is_distributor}"} .highlight-top.row .small-12.medium-7.large-8.columns %h3{"ng-if" => "enterprise.is_distributor"} - %a{"bo-href" => "enterprise.path", "ofn-empties-cart" => "enterprise", bindonce: true} + %a{"bo-href" => "enterprise.path", "ofn-empties-cart" => "enterprise"} %i{"ng-class" => "enterprise.icon_font"} - %span {{ enterprise.name }} + %span{"bo-text" => "enterprise.name"} %h3{"ng-if" => "!enterprise.is_distributor", "ng-class" => "{'is_producer' : enterprise.is_primary_producer}"} %i{"ng-class" => "enterprise.icon_font"} - %span {{ enterprise.name }} + %span{"bo-text" => "enterprise.name"} .small-12.medium-5.large-4.columns.text-right.small-only-text-left - %p {{ [enterprise.address.city, enterprise.address.state_name] | printArray}} - %img.hero-img{"ng-src" => "{{enterprise.promo_image}}"} + %p{"bo-bind" => "[enterprise.address.city, enterprise.address.state_name] | printArray"} + %img.hero-img{"bo-src" => "enterprise.promo_image"} diff --git a/app/assets/javascripts/templates/partials/follow.html.haml b/app/assets/javascripts/templates/partials/follow.html.haml index 1f7bd5702b..4e2a00086a 100644 --- a/app/assets/javascripts/templates/partials/follow.html.haml +++ b/app/assets/javascripts/templates/partials/follow.html.haml @@ -1,19 +1,19 @@ -%div.modal-centered{"ng-if" => "enterprise.twitter || enterprise.facebook || enterprise.linkedin || enterprise.instagram"} +%div.modal-centered{bindonce: true, "bo-if" => "enterprise.twitter || enterprise.facebook || enterprise.linkedin || enterprise.instagram"} %p.modal-header Follow - .follow-icons{bindonce: true} - %span{"ng-if" => "enterprise.twitter"} - %a{"ng-href" => "http://twitter.com/{{enterprise.twitter}}", target: "_blank"} + .follow-icons + %span{"bo-if" => "enterprise.twitter"} + %a{"bo-href-i" => "http://twitter.com/{{enterprise.twitter}}", target: "_blank"} %i.ofn-i_041-twitter - %span{"ng-if" => "enterprise.facebook"} - %a{"ng-href" => "http://{{enterprise.facebook | stripUrl}}", target: "_blank"} + %span{"bo-if" => "enterprise.facebook"} + %a{"bo-href-i" => "http://{{enterprise.facebook | stripUrl}}", target: "_blank"} %i.ofn-i_044-facebook - %span{"ng-if" => "enterprise.linkedin"} - %a{"ng-href" => "http://{{enterprise.linkedin | stripUrl}}", target: "_blank"} + %span{"bo-if" => "enterprise.linkedin"} + %a{"bo-href-i" => "http://{{enterprise.linkedin | stripUrl}}", target: "_blank"} %i.ofn-i_042-linkedin - %span{"ng-if" => "enterprise.instagram"} - %a{"ng-href" => "http://instagram.com/{{enterprise.instagram}}", target: "_blank"} + %span{"bo-if" => "enterprise.instagram"} + %a{"bo-href-i" => "http://instagram.com/{{enterprise.instagram}}", target: "_blank"} %i.ofn-i_043-instagram diff --git a/app/assets/javascripts/templates/partials/hub_actions.html.haml b/app/assets/javascripts/templates/partials/hub_actions.html.haml index 61e74afb42..f5b451ef3c 100644 --- a/app/assets/javascripts/templates/partials/hub_actions.html.haml +++ b/app/assets/javascripts/templates/partials/hub_actions.html.haml @@ -2,7 +2,7 @@ .cta-container.small-12.columns %label Shop for - %strong {{enterprise.name}} + %strong{"bo-text" => "enterprise.name"} products at: %a.cta-hub{"ng-repeat" => "hub in enterprise.hubs", "bo-href" => "hub.path", @@ -10,7 +10,7 @@ "ofn-empties-cart" => "hub"} %i.ofn-i_033-open-sign{"bo-if" => "hub.active"} %i.ofn-i_032-closed-sign{"bo-if" => "!hub.active"} - .hub-name {{hub.name}} - .button-address {{ hub.address.city }} , {{hub.address.state_name}} + .hub-name{"bo-text" => "hub.name"} + .button-address{"bo-bind" => "[hub.address.city, hub.address.state_name] | printArray"} / %i.ofn-i_007-caret-right diff --git a/app/assets/javascripts/templates/partials/hub_details.html.haml b/app/assets/javascripts/templates/partials/hub_details.html.haml index 815200821a..8be5ceddac 100644 --- a/app/assets/javascripts/templates/partials/hub_details.html.haml +++ b/app/assets/javascripts/templates/partials/hub_details.html.haml @@ -19,6 +19,6 @@ "ofn-empties-cart" => "enterprise"} %i.ofn-i_033-open-sign{"bo-if" => "enterprise.active"} %i.ofn-i_032-closed-sign{"bo-if" => "!enterprise.active"} - .hub-name {{enterprise.name}} - .button-address {{ enterprise.address.city }} , {{enterprise.address.state_name}} + .hub-name{"bo-text" => "enterprise.name"} + .button-address{"bo-bind" => "[enterprise.address.city, enterprise.address.state_name] | printArray"} / %i.ofn-i_007-caret-right From 8fb11defdb1689415ed87305a48c5dc78b40ed42 Mon Sep 17 00:00:00 2001 From: Rick Giner Date: Sun, 3 May 2015 14:41:34 +1000 Subject: [PATCH 28/41] bind-once in groups home page --- app/views/groups/index.html.haml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/views/groups/index.html.haml b/app/views/groups/index.html.haml index 262e188e3c..901cb17ad9 100644 --- a/app/views/groups/index.html.haml +++ b/app/views/groups/index.html.haml @@ -20,13 +20,11 @@ .row.pad-top{bindonce: true} .small-12.medium-6.columns .groups-header - %a{"ng-href" => "/groups/{{group.id}}"} + %a{"bo-href-i" => "/groups/{{group.id}}"} %i.ofn-i_035-groups - %span.group-name - {{ group.name }} + %span.group-name{"bo-text" => "group.name"} .small-3.medium-2.columns - %p - {{ group.state }} + %p{"bo-text" => "group.state"} .small-9.medium-4.columns.groups-icons %p %link-to-service.ofn-i_050-mail-circle{service: '""', ref: 'group.email.split("").reverse().join("")', mailto: true} From 9e70c80d1d29a5088755e75b0b6d7297a58b3262 Mon Sep 17 00:00:00 2001 From: Rick Giner Date: Sun, 3 May 2015 14:48:27 +1000 Subject: [PATCH 29/41] bind-once in product modal --- .../javascripts/templates/product_modal.html.haml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/templates/product_modal.html.haml b/app/assets/javascripts/templates/product_modal.html.haml index bf66bd4aea..3db8035acc 100644 --- a/app/assets/javascripts/templates/product_modal.html.haml +++ b/app/assets/javascripts/templates/product_modal.html.haml @@ -1,10 +1,10 @@ -.row +.row{bindonce: true} .columns.small-12.large-6.product-header - %h3 {{product.name}} + %h3{"bo-text" => "product.name"} %span %em from - %span.avenir {{ enterprise.name }} + %span.avenir{"bo-text" => "enterprise.name"} %br @@ -18,11 +18,11 @@ %div{"ng-if" => "product.description"} %hr - %p.text-small {{product.description}} + %p.text-small{"bo-text" => "product.description"} %hr .columns.small-12.large-6 - %img.product-img{"ng-src" => "{{product.largeImage}}", "ng-if" => "product.largeImage"} - %img.product-img.placeholder{"ng-src" => "/assets/noimage/large.png", "ng-if" => "!product.largeImage"} + %img.product-img{"bo-src" => "product.largeImage", "bo-if" => "product.largeImage"} + %img.product-img.placeholder{"bo-src" => "'/assets/noimage/large.png'", "bo-if" => "!product.largeImage"} %ng-include{src: "'partials/close.html'"} From 368402f115586014fd872d1f60f8a36fc8f5f69e Mon Sep 17 00:00:00 2001 From: Rick Giner Date: Sun, 3 May 2015 15:24:16 +1000 Subject: [PATCH 30/41] Changed selectors' ng-repeat. Using existing variable instead of method call --- app/assets/javascripts/templates/filter_selector.html.haml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/templates/filter_selector.html.haml b/app/assets/javascripts/templates/filter_selector.html.haml index ecd4fb7d6d..c6990c369f 100644 --- a/app/assets/javascripts/templates/filter_selector.html.haml +++ b/app/assets/javascripts/templates/filter_selector.html.haml @@ -1,4 +1,4 @@ -%div{ style: "display: inline-block" } - %active-selector{ ng: { repeat: "selector in selectors()", show: "ifDefined(selector.fits, true)" } } +%div{bindonce:true, style: "display: inline-block" } + %active-selector{ ng: { repeat: "selector in allSelectors", show: "ifDefined(selector.fits, true)" } } %render-svg{path: "{{selector.object.icon}}", ng: { if: "selector.object.icon"} } - %span {{ selector.object.name }} + %span{"bo-text" => "selector.object.name"} From 8788322492d822d9f9a0d9395c01f1411b9ebf6d Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 6 May 2015 11:10:50 +1000 Subject: [PATCH 31/41] Alllowing payments in payment reports to access soft-deleted payment methods --- app/controllers/spree/admin/reports_controller_decorator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index f148456813..92653a5aa9 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -323,7 +323,7 @@ Spree::Admin::ReportsController.class_eval do sort_by: proc { |payment_state| payment_state } }, { group_by: proc { |payment| payment.order.distributor }, sort_by: proc { |distributor| distributor.name } }, - { group_by: proc { |payment| payment.payment_method }, + { group_by: proc { |payment| Spree::PaymentMethod.unscoped { payment.payment_method } }, sort_by: proc { |method| method.name } } ] when "itemised_payment_totals" From ad7e5a45bba0415ef8e700b621ab458b6c7fd6a8 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 6 May 2015 17:58:36 +1000 Subject: [PATCH 32/41] Add updated merge script --- script/ci/merge_branch_to_master.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/script/ci/merge_branch_to_master.sh b/script/ci/merge_branch_to_master.sh index 0bb07b43e2..6a942c2d39 100755 --- a/script/ci/merge_branch_to_master.sh +++ b/script/ci/merge_branch_to_master.sh @@ -7,4 +7,8 @@ echo "--- Verifying branch is based on current master" exit_unless_master_merged echo "--- Pushing branch" -echo git push origin $BUILDKITE_COMMIT:master +git checkout master +git merge origin/master +git merge origin/$BUILDKITE_BRANCH +git push origin master +git checkout origin/$BUILDKITE_BRANCH From f84e704d99711335dad03c295dfe4c8ee397e126 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 6 May 2015 17:59:36 +1000 Subject: [PATCH 33/41] Retry simple push-to-master script --- script/ci/merge_branch_to_master.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/script/ci/merge_branch_to_master.sh b/script/ci/merge_branch_to_master.sh index 6a942c2d39..6e40ed4ef9 100755 --- a/script/ci/merge_branch_to_master.sh +++ b/script/ci/merge_branch_to_master.sh @@ -7,8 +7,4 @@ echo "--- Verifying branch is based on current master" exit_unless_master_merged echo "--- Pushing branch" -git checkout master -git merge origin/master -git merge origin/$BUILDKITE_BRANCH -git push origin master -git checkout origin/$BUILDKITE_BRANCH +git push origin $BUILDKITE_COMMIT:master From 485eee4bddae4d4f9251eba618b913d11945f75a Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 6 May 2015 18:07:50 +1000 Subject: [PATCH 34/41] Deploy scripts display their output --- script/ci/push_to_production.sh | 4 +++- script/ci/push_to_staging.sh | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/script/ci/push_to_production.sh b/script/ci/push_to_production.sh index b731b538ca..8a8d4bf318 100755 --- a/script/ci/push_to_production.sh +++ b/script/ci/push_to_production.sh @@ -12,4 +12,6 @@ echo "--- Saving baseline data for staging" ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/ci/save_staging_baseline.sh $BUILDKITE_COMMIT" echo "--- Pushing to production" -[[ $(git push production $BUILDKITE_COMMIT:master --force 2>&1) =~ "Done" ]] +output=$(git push production $BUILDKITE_COMMIT:master --force 2>&1) +echo $output +[[ $output =~ "Done" ]] diff --git a/script/ci/push_to_staging.sh b/script/ci/push_to_staging.sh index 582f500a76..0a5a11235a 100755 --- a/script/ci/push_to_staging.sh +++ b/script/ci/push_to_staging.sh @@ -16,4 +16,6 @@ echo "--- Loading baseline data" ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/ci/load_staging_baseline.sh" echo "--- Pushing to staging" -[[ $(git push staging2 $BUILDKITE_COMMIT:master --force 2>&1) =~ "Done" ]] +output=$(git push staging2 $BUILDKITE_COMMIT:master --force 2>&1) +echo $output +[[ $output =~ "Done" ]] From 7b4130972b576890e845bfd4e4246c7f09632264 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 6 May 2015 18:12:17 +1000 Subject: [PATCH 35/41] Fix first feature spec sometimes timing out --- spec/features/admin/authentication_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/features/admin/authentication_spec.rb b/spec/features/admin/authentication_spec.rb index 059963fd70..8473551c99 100644 --- a/spec/features/admin/authentication_spec.rb +++ b/spec/features/admin/authentication_spec.rb @@ -10,15 +10,15 @@ feature "Authentication", js: true do scenario "logging into admin redirects home, then back to admin" do # This is the first admin spec, so give a little extra load time for slow systems - Capybara.using_wait_time(60) do + Capybara.using_wait_time(120) do visit spree.admin_path - end - 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 + 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 scenario "viewing my account" do From 3dee29cd124f72b7ce802c4cbfa10aea041be7ec Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 6 May 2015 19:37:21 +1000 Subject: [PATCH 36/41] Remove build badge - master branch is always green --- README.markdown | 1 - 1 file changed, 1 deletion(-) diff --git a/README.markdown b/README.markdown index f43856daf6..b9aaf8193c 100644 --- a/README.markdown +++ b/README.markdown @@ -1,4 +1,3 @@ -[![Build status](https://badge.buildkite.com/e18473fffac95ed2735ca75700673bd301cac5cffc64de821a.svg?branch=master)](https://buildkite.com/open-food-foundation/open-food-network) [![Code Climate](https://codeclimate.com/github/openfoodfoundation/openfoodnetwork.png)](https://codeclimate.com/github/openfoodfoundation/openfoodnetwork) # Open Food Network From d109e898d281d5add8882d88e0988298cfbed3ae Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 6 May 2015 19:38:20 +1000 Subject: [PATCH 37/41] Preserve newlines when displaying deploy script output --- script/ci/push_to_production.sh | 2 +- script/ci/push_to_staging.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/script/ci/push_to_production.sh b/script/ci/push_to_production.sh index 8a8d4bf318..1666368e08 100755 --- a/script/ci/push_to_production.sh +++ b/script/ci/push_to_production.sh @@ -13,5 +13,5 @@ ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/ci/save_stag echo "--- Pushing to production" output=$(git push production $BUILDKITE_COMMIT:master --force 2>&1) -echo $output +echo "$output" [[ $output =~ "Done" ]] diff --git a/script/ci/push_to_staging.sh b/script/ci/push_to_staging.sh index 0a5a11235a..a38cda0c1b 100755 --- a/script/ci/push_to_staging.sh +++ b/script/ci/push_to_staging.sh @@ -17,5 +17,5 @@ ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/ci/load_stag echo "--- Pushing to staging" output=$(git push staging2 $BUILDKITE_COMMIT:master --force 2>&1) -echo $output +echo "$output" [[ $output =~ "Done" ]] From 6d33dc5070db0f20d205e8ffcc4158741986f2a7 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 6 May 2015 19:41:36 +1000 Subject: [PATCH 38/41] Add script to merge master into the current branch if required before running specs --- script/ci/includes.sh | 7 +++++++ script/ci/merge_master_into_branch.sh | 12 ++++++++++++ 2 files changed, 19 insertions(+) create mode 100755 script/ci/merge_master_into_branch.sh diff --git a/script/ci/includes.sh b/script/ci/includes.sh index ee59a732d7..d7619f7d23 100644 --- a/script/ci/includes.sh +++ b/script/ci/includes.sh @@ -12,6 +12,13 @@ function exit_unless_master_merged { fi } +function succeed_if_master_merged { + if [[ `git branch -a --merged origin/$BUILDKITE_BRANCH` == *origin/master* ]]; then + echo "This branch already has the current master merged." + exit 0 + fi +} + function drop_and_recreate_database { # Adapted from: http://stackoverflow.com/questions/12924466/capistrano-with-postgresql-error-database-is-being-accessed-by-other-users psql -U openfoodweb postgres < Date: Wed, 6 May 2015 19:50:06 +1000 Subject: [PATCH 39/41] Add debugging to merge script --- script/ci/merge_branch_to_master.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/ci/merge_branch_to_master.sh b/script/ci/merge_branch_to_master.sh index 6e40ed4ef9..3eaae17d56 100755 --- a/script/ci/merge_branch_to_master.sh +++ b/script/ci/merge_branch_to_master.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -ex source ./script/ci/includes.sh echo "--- Verifying branch is based on current master" From 50d2ddc05f68c3965793a21c64a30a4ce664c4fd Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 6 May 2015 20:00:50 +1000 Subject: [PATCH 40/41] Add progress comments --- script/ci/merge_master_into_branch.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/script/ci/merge_master_into_branch.sh b/script/ci/merge_master_into_branch.sh index ebbafd865c..a5e05c7759 100755 --- a/script/ci/merge_master_into_branch.sh +++ b/script/ci/merge_master_into_branch.sh @@ -3,8 +3,10 @@ set -e source ./script/ci/includes.sh +echo "--- Checking if master has already been merged" succeed_if_master_merged +echo "--- Merging master into this branch" git checkout $BUILDKITE_BRANCH git merge origin/$BUILDKITE_BRANCH git merge origin/master -m "Auto-merge from CI [skip ci]" From bd6bac887455b30545e610e306739be545d8ebd0 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 6 May 2015 20:02:03 +1000 Subject: [PATCH 41/41] Display deployment output in real time This reverts commit 485eee4bddae4d4f9251eba618b913d11945f75a. --- script/ci/push_to_production.sh | 6 ++---- script/ci/push_to_staging.sh | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/script/ci/push_to_production.sh b/script/ci/push_to_production.sh index 1666368e08..00ade0af07 100755 --- a/script/ci/push_to_production.sh +++ b/script/ci/push_to_production.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -ex # Add production git remote if required PROD_TEST=`git remote | grep -s 'production' || true` @@ -12,6 +12,4 @@ echo "--- Saving baseline data for staging" ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/ci/save_staging_baseline.sh $BUILDKITE_COMMIT" echo "--- Pushing to production" -output=$(git push production $BUILDKITE_COMMIT:master --force 2>&1) -echo "$output" -[[ $output =~ "Done" ]] +[[ $(git push production $BUILDKITE_COMMIT:master --force 2>&1) =~ "Done" ]] diff --git a/script/ci/push_to_staging.sh b/script/ci/push_to_staging.sh index a38cda0c1b..c634ca53a4 100755 --- a/script/ci/push_to_staging.sh +++ b/script/ci/push_to_staging.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -ex source ./script/ci/includes.sh # Add staging git remote if required @@ -16,6 +16,4 @@ echo "--- Loading baseline data" ssh ofn-staging2 "/home/openfoodweb/apps/openfoodweb/current/script/ci/load_staging_baseline.sh" echo "--- Pushing to staging" -output=$(git push staging2 $BUILDKITE_COMMIT:master --force 2>&1) -echo "$output" -[[ $output =~ "Done" ]] +[[ $(git push staging2 $BUILDKITE_COMMIT:master --force 2>&1) =~ "Done" ]]