Merge branch 'master' into redesign

Conflicts:
	app/assets/javascripts/templates/product_modal.html.haml
This commit is contained in:
Rohan Mitchell
2015-05-13 09:53:20 +10:00
42 changed files with 557 additions and 114 deletions

View File

@@ -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

View File

@@ -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]

View File

@@ -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

View File

@@ -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)) }

View File

@@ -0,0 +1,128 @@
require 'spec_helper'
module Spree
describe Payment do
describe "available actions" do
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
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
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
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