Merge branch 'add-capture-order-shortcut-deface'

Conflicts:
	spec/support/request/authentication_workflow.rb
This commit is contained in:
Rohan Mitchell
2013-07-23 16:55:33 +10:00
5 changed files with 84 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
# When a user fires an event, take them back to where they came from
# Responder: http://guides.spreecommerce.com/developer/logic.html#overriding-controller-action-responses
Spree::Admin::PaymentsController.class_eval do
respond_override :fire => { :html => { :success => lambda {
redirect_to request.referer # Keeps any filter and sort prefs
} } }
end

View File

@@ -0,0 +1,23 @@
Deface::Override.new(:virtual_path => "spree/admin/orders/index",
:name => "add_capture_order_shortcut",
:insert_bottom => "[data-hook='admin_orders_index_row_actions']",
:partial => 'spree/admin/orders/capture'
)
#Resize columns to fit new button (note: this may break with a new version of spree)
Deface::Override.new(:virtual_path => "spree/admin/orders/index",
:name => "add_capture_order_shortcut_first_column",
:set_attributes => "#listing_orders colgroup col:first-child",
:attributes => {:style => "width: 12%"} #was 16%
)
Deface::Override.new(:virtual_path => "spree/admin/orders/index",
:name => "add_capture_order_shortcut_last_column",
:set_attributes => "#listing_orders colgroup col:last-child",
:attributes => {:style => "width: 12%"} #was 8%
)
#And align actions column (not spree standard, but looks better IMO)
Deface::Override.new(:virtual_path => "spree/admin/orders/index",
:name => "add_capture_order_shortcut_align",
:set_attributes => "[data-hook='admin_orders_index_row_actions']",
:attributes => {:class => "actions", :style => "text-align:left;"} #removes 'align-center' class
)

View File

@@ -0,0 +1,5 @@
-# copied from backend/app/views/spree/admin/payments/_list.html.erb
- if order.payments.present?
- order.payments.last.actions.grep(/^capture$/).each do |action|
= link_to_with_icon "icon-#{action}", t(action), fire_admin_order_payment_path(order, order.payments.last, :e => action), :method => :put, :no_text => true, :data => {:action => action}

View File

@@ -102,6 +102,14 @@ FactoryGirl.define do
after(:create) { |c| c.set_preference(:per_kg, 0.5); c.save! }
end
factory :order_with_totals_and_distributor, :parent => :order do #possibly called :order_with_line_items in newer Spree
# Ensure order has a distributor set
distributor { create(:distributor_enterprise) }
after(:create) do |order|
p = create(:simple_product, :distributors => [order.distributor])
FactoryGirl.create(:line_item, :order => order, :product => p)
end
end
end

View File

@@ -0,0 +1,40 @@
require "spec_helper"
feature %q{
As a payment administrator
I want to capture multiple payments quickly from the one page
} do
include AuthenticationWorkflow
include WebHelper
background do
@user = create(:user)
@order = create(:order_with_totals_and_distributor, :user => @user, :state => 'complete', :payment_state => 'balance_due')
# ensure order has a payment to capture
create :check_payment, order: @order, amount: @order.amount
@order.finalize!
end
context "managing orders" do
scenario "capture multiple payments from the orders index page" do
# d.cook: could also test for an order that has had payment voided, then a new check payment created but not yet captured. But it's not critical and I know it works anyway.
login_to_admin_section
click_link 'Orders'
current_path.should == spree.admin_orders_path
# click the 'capture' link for the order
page.find("[data-action=capture][href*=#{@order.number}]").click
flash_message.should == "Payment Updated"
# check the order was captured
@order.reload
@order.payment_state.should == "paid"
# we should still be on the same page
current_path.should == spree.admin_orders_path
end
end
end