Fixes broken specs except for a couple relying on open spree pull requests.

This commit is contained in:
Jeff Dutil 2012-11-19 06:45:08 -05:00
parent ca60407d5d
commit 5a4f2fe47d
14 changed files with 37 additions and 35 deletions

1
.gitignore vendored
View File

@ -3,5 +3,6 @@
spec/test_app
spec/dummy
.rvmrc
.sass-cache
.bundle
Gemfile.lock

View File

@ -0,0 +1 @@
//= require store/spree_core

View File

@ -0,0 +1,3 @@
/*
*= require admin/spree_core
*/

View File

@ -0,0 +1,3 @@
/*
*= require store/spree_core
*/

View File

@ -28,7 +28,7 @@ module Spree
def paypal_payment
load_order
opts = all_opts(@order,params[:payment_method_id], 'payment')
opts = all_opts(@order, params[:payment_method_id], 'payment')
unless payment_method.preferred_cart_checkout
opts.merge!(address_options(@order))
else
@ -266,7 +266,7 @@ module Spree
{:currency => payment_method.preferred_currency, :allow_guest_checkout => payment_method.preferred_allow_guest_checkout }
end
def order_opts(order, payment_method, stage)
def order_opts(order, payment_method_id, stage)
items = order.line_items.map do |item|
price = (item.price * 100).to_i # convert for gateway
{ :name => item.variant.product.name,
@ -297,7 +297,7 @@ module Spree
credits_total = credits.map {|i| i[:amount] * i[:quantity] }.sum
end
unless @order.payment_method.preferred_cart_checkout
unless order.payment_method.preferred_cart_checkout
order_total = (order.total * 100).to_i
shipping_total = (order.ship_total*100).to_i
else
@ -306,7 +306,7 @@ module Spree
shipping_total = (shipping_cost).to_i
end
opts = { :return_url => paypal_confirm_order_checkout_url(order, :payment_method_id => payment_method),
opts = { :return_url => paypal_confirm_order_checkout_url(order, :payment_method_id => payment_method_id),
:cancel_return_url => edit_order_checkout_url(order, :state => :payment),
:order_id => order.number,
:custom => order.number,
@ -326,7 +326,7 @@ module Spree
#hack to add float rounding difference in as handling fee - prevents PayPal from rejecting orders
#because the integer totals are different from the float based total. This is temporary and will be
#removed once Spree's currency values are persisted as integers (normally only 1c)
if @order.payment_method.preferred_cart_checkout
if order.payment_method.preferred_cart_checkout
opts[:handling] = 0
else
opts[:handling] = (order.total*100).to_i - opts.slice(:subtotal, :tax, :shipping).values.sum
@ -381,8 +381,8 @@ module Spree
end
end
def all_opts(order, payment_method, stage=nil)
opts = fixed_opts.merge(order_opts(order, payment_method, stage)).merge(paypal_site_opts)
def all_opts(order, payment_method_id, stage=nil)
opts = fixed_opts.merge(order_opts(order, payment_method_id, stage)).merge(paypal_site_opts)
if stage == "payment"
opts.merge! flat_rate_shipping_and_handling_options(order, stage)

View File

@ -12,5 +12,3 @@
<%= order.payment.source.email %>
</span>
<% end %>

View File

@ -1 +1 @@
<INPUT TYPE="image" src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" align="left" style="margin-right:7px;"/>
<INPUT TYPE="image" id="ppx" src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" align="left" style="margin-right:7px;"/>

View File

@ -1 +1 @@
<INPUT TYPE="image" src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" align="left" style="margin-right:7px;"/>
<INPUT TYPE="image" id="ppx" src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" align="left" style="margin-right:7px;"/>

View File

@ -20,4 +20,4 @@
</div>
</div>
</div>
</div>

View File

@ -8,8 +8,7 @@ module Spree
let(:shipping_method) { FactoryGirl.create(:shipping_method, :zone => Spree::Zone.find_by_name('North America')) }
let(:order_total) { (order.total * 100).to_i }
let(:gateway_provider) { mock(ActiveMerchant::Billing::PaypalExpressGateway) }
let(:paypal_gateway) { mock(BillingIntegration::PaypalExpress, :id => 123, :preferred_review => false, :preferred_no_shipping => true, :provider => gateway_provider, :preferred_currency => "US", :preferred_allow_guest_checkout => true
) }
let(:paypal_gateway) { mock(BillingIntegration::PaypalExpress, :id => 123, :payment_profiles_supported? => false, :preferred_cart_checkout => false, :preferred_review => false, :preferred_no_shipping => true, :provider => gateway_provider, :preferred_currency => "US", :preferred_allow_guest_checkout => true ) }
let(:details_for_response) { mock(ActiveMerchant::Billing::PaypalExpressResponse, :success? => true,
:params => {"payer" => order.user.email, "payer_id" => "FWRVKNRRZ3WUC"}, :address => {}) }
@ -19,11 +18,9 @@ module Spree
:avs_result => "F",
:to_yaml => "fake") }
before do
Spree::Auth::Config.set(:registration_step => false)
controller.stub(:current_order => order, :check_authorization => true, :spree_current_user => order.user)
order.stub(:checkout_allowed? => true, :completed? => false)
order.stub(:checkout_allowed? => true, :completed? => false, :payment_method => paypal_gateway)
order.update!
end
@ -34,8 +31,8 @@ module Spree
assert_routing("/orders/#{order.number}/checkout/paypal_confirm", {:controller => "checkout", :action => "paypal_confirm", :order_id => order.number })
end
context "paypal_checkout" do
#feature not implemented
context "paypal_checkout from cart" do
pending 'feature not implemented'
end
context "paypal_payment without auto_capture" do
@ -44,7 +41,7 @@ module Spree
before { Spree::Config.set(:auto_capture => false) }
it "should setup an authorize transaction and redirect to sandbox" do
PaymentMethod.should_receive(:find).at_least(1).with('123').and_return(paypal_gateway)
Spree::PaymentMethod.should_receive(:find).at_least(1).with('123').and_return(paypal_gateway)
gateway_provider.should_receive(:redirect_url_for).with(token, {:review => false}).and_return redirect_url
paypal_gateway.provider.should_receive(:setup_authorization).with(order_total, anything()).and_return(mock(:success? => true, :token => token))
@ -62,7 +59,7 @@ module Spree
before { Spree::Config.set(:auto_capture => true) }
it "should setup a purchase transaction and redirect to sandbox" do
PaymentMethod.should_receive(:find).at_least(1).with("123").and_return(paypal_gateway)
Spree::PaymentMethod.should_receive(:find).at_least(1).with("123").and_return(paypal_gateway)
gateway_provider.should_receive(:redirect_url_for).with(token, {:review => false}).and_return redirect_url
paypal_gateway.provider.should_receive(:setup_purchase).with(order_total, anything()).and_return(mock(:success? => true, :token => token))
@ -76,7 +73,7 @@ module Spree
context "paypal_confirm" do
before do
PaymentMethod.should_receive(:find).at_least(1).with("123").and_return(paypal_gateway)
Spree::PaymentMethod.should_receive(:find).at_least(1).with("123").and_return(paypal_gateway)
order.stub!(:payment_method).and_return paypal_gateway
end
@ -175,8 +172,8 @@ module Spree
:to_yaml => "fake") }
before do
PaymentMethod.should_receive(:find).at_least(1).with("123").and_return(paypal_gateway)
PaypalAccount.should_receive(:find_by_payer_id).with("FWRVKNRRZ3WUC").and_return(paypal_account)
Spree::PaymentMethod.should_receive(:find).at_least(1).with("123").and_return(paypal_gateway)
Spree::PaypalAccount.should_receive(:find_by_payer_id).with("FWRVKNRRZ3WUC").and_return(paypal_account)
end
context "with auto_capture" do
@ -298,7 +295,6 @@ module Spree
order_total #need here so variable is set before credit is created.
order.adjustments.create(:label => "Credit", :amount => -1)
order.update!
opts = controller.send(:order_opts, order, paypal_gateway.id, 'payment')
opts.class.should == Hash

View File

@ -38,7 +38,7 @@ describe Spree::BillingIntegration::PaypalExpressBase do
:avs_result => { 'code' => 'avs-code' })
end
let(:failed_response) { mock('gateway_response', :success? => false) }
let(:failed_response) { mock('failure_response', :success? => false) }
before(:each) do
# So it doesn't create log entries every time a processing method is called
@ -51,7 +51,7 @@ describe Spree::BillingIntegration::PaypalExpressBase do
context "when payment_profiles_supported = true" do
before { gateway.stub :payment_profiles_supported? => true }
context "if sucessful" do
context "if successful" do
before do
provider.should_receive(:capture).with(amount_in_cents, '123', :currency => 'EUR').and_return(success_response)
end
@ -62,7 +62,7 @@ describe Spree::BillingIntegration::PaypalExpressBase do
end
end
context "if unsucessful" do
context "if unsuccessful" do
before do
gateway.should_receive(:capture).with(payment, account, anything).and_return(failed_response)
end
@ -80,7 +80,7 @@ describe Spree::BillingIntegration::PaypalExpressBase do
gateway.stub :payment_profiles_supported? => false
end
context "if sucessful" do
context "if successful" do
before do
provider.should_receive(:capture).with(amount_in_cents, '123', anything).and_return(success_response)
end
@ -91,7 +91,7 @@ describe Spree::BillingIntegration::PaypalExpressBase do
end
end
context "if unsucessful" do
context "if unsuccessful" do
before do
provider.should_receive(:capture).with(amount_in_cents, '123', anything).and_return(failed_response)
end
@ -110,7 +110,6 @@ describe Spree::BillingIntegration::PaypalExpressBase do
context "when payment_profiles_supported = true" do
before { gateway.stub :payment_profiles_supported? => true }
it "should receive correct params" do
provider.should_receive(:credit).with(1000, '123', :currency => 'EUR').and_return(success_response)
payment.credit!(10.0)

View File

@ -5,7 +5,6 @@ describe "Paypal Express checkout" do
FactoryGirl.create(:shipping_method, :zone => Spree::Zone.find_by_name('North America'))
FactoryGirl.create(:payment_method, :environment => 'test')
@product = FactoryGirl.create(:product, :name => "RoR Mug")
sign_in_as! FactoryGirl.create(:user)
FactoryGirl.create(:ppx)
end
@ -16,23 +15,23 @@ describe "Paypal Express checkout" do
visit spree.product_path(@product)
click_button "Add To Cart"
click_link "Checkout"
click_button "Checkout"
str_addr = "bill_address"
select "United States", :from => "order_#{str_addr}_attributes_country_id"
['firstname', 'lastname', 'address1', 'city', 'zipcode', 'phone'].each do |field|
fill_in "order_#{str_addr}_attributes_#{field}", :with => "#{address.send(field)}"
end
select "#{address.state.name}", :from => "order_#{str_addr}_attributes_state_id"
check "order_use_billing"
fill_in 'order[email]', :with => 'spree@example.com'
click_button "Save and Continue"
#delivery
click_button "Save and Continue"
choose "Paypal"
page.should have_selector('a#ppx')
page.should have_selector('input#ppx')
click_button "Save and Continue"
current_path.should match /\A\/orders\/[A-Z][0-9]{9}\/checkout\/paypal_payment\z/

View File

@ -22,6 +22,7 @@ end
require 'ffaker'
RSpec.configure do |config|
config.color = true
config.mock_with :rspec
config.fixture_path = "#{::Rails.root}/spec/fixtures"

View File

@ -19,5 +19,6 @@ Gem::Specification.new do |s|
s.add_development_dependency 'factory_girl', '~> 3.5.0'
s.add_development_dependency 'ffaker'
s.add_development_dependency 'rspec-rails', '~> 2.11.0'
s.add_development_dependency 'sass-rails'
s.add_development_dependency 'sqlite3'
end