From 5a4f2fe47dc86a452d88b5c7a12bc439e77316fe Mon Sep 17 00:00:00 2001 From: Jeff Dutil Date: Mon, 19 Nov 2012 06:45:08 -0500 Subject: [PATCH] Fixes broken specs except for a couple relying on open spree pull requests. --- .gitignore | 1 + .../javascripts/store/spree_paypal_express.js | 1 + .../admin/spree_paypal_express.css | 3 +++ .../store/spree_paypal_express.css | 3 +++ .../spree/checkout_controller_decorator.rb | 14 ++++++------ .../add_paypal_details.html.erb.deface | 2 -- .../checkout/payment/_paypalexpress.html.erb | 2 +- .../payment/_paypalexpressuk.html.erb | 2 +- .../shared/paypal_express_confirm.html.erb | 2 +- spec/controllers/checkout_controller_spec.rb | 22 ++++++++----------- .../paypal_express_base_spec.rb | 11 +++++----- spec/requests/paypal_express_spec.rb | 7 +++--- spec/spec_helper.rb | 1 + spree_paypal_express.gemspec | 1 + 14 files changed, 37 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 8224e5d..984d1de 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ spec/test_app spec/dummy .rvmrc +.sass-cache .bundle Gemfile.lock diff --git a/app/assets/javascripts/store/spree_paypal_express.js b/app/assets/javascripts/store/spree_paypal_express.js index e69de29..d5cb5c7 100644 --- a/app/assets/javascripts/store/spree_paypal_express.js +++ b/app/assets/javascripts/store/spree_paypal_express.js @@ -0,0 +1 @@ +//= require store/spree_core diff --git a/app/assets/stylesheets/admin/spree_paypal_express.css b/app/assets/stylesheets/admin/spree_paypal_express.css index e69de29..21ef02a 100644 --- a/app/assets/stylesheets/admin/spree_paypal_express.css +++ b/app/assets/stylesheets/admin/spree_paypal_express.css @@ -0,0 +1,3 @@ +/* + *= require admin/spree_core +*/ diff --git a/app/assets/stylesheets/store/spree_paypal_express.css b/app/assets/stylesheets/store/spree_paypal_express.css index e69de29..94dbe33 100644 --- a/app/assets/stylesheets/store/spree_paypal_express.css +++ b/app/assets/stylesheets/store/spree_paypal_express.css @@ -0,0 +1,3 @@ +/* + *= require store/spree_core +*/ diff --git a/app/controllers/spree/checkout_controller_decorator.rb b/app/controllers/spree/checkout_controller_decorator.rb index 66a7cad..ad4b723 100644 --- a/app/controllers/spree/checkout_controller_decorator.rb +++ b/app/controllers/spree/checkout_controller_decorator.rb @@ -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) diff --git a/app/overrides/spree/shared/_order_details/add_paypal_details.html.erb.deface b/app/overrides/spree/shared/_order_details/add_paypal_details.html.erb.deface index 6f67dfe..0261682 100644 --- a/app/overrides/spree/shared/_order_details/add_paypal_details.html.erb.deface +++ b/app/overrides/spree/shared/_order_details/add_paypal_details.html.erb.deface @@ -12,5 +12,3 @@ <%= order.payment.source.email %> <% end %> - - diff --git a/app/views/spree/checkout/payment/_paypalexpress.html.erb b/app/views/spree/checkout/payment/_paypalexpress.html.erb index 237d24b..e84aa95 100644 --- a/app/views/spree/checkout/payment/_paypalexpress.html.erb +++ b/app/views/spree/checkout/payment/_paypalexpress.html.erb @@ -1 +1 @@ - + diff --git a/app/views/spree/checkout/payment/_paypalexpressuk.html.erb b/app/views/spree/checkout/payment/_paypalexpressuk.html.erb index 237d24b..e84aa95 100644 --- a/app/views/spree/checkout/payment/_paypalexpressuk.html.erb +++ b/app/views/spree/checkout/payment/_paypalexpressuk.html.erb @@ -1 +1 @@ - + diff --git a/app/views/spree/shared/paypal_express_confirm.html.erb b/app/views/spree/shared/paypal_express_confirm.html.erb index 2956f44..290ebfa 100644 --- a/app/views/spree/shared/paypal_express_confirm.html.erb +++ b/app/views/spree/shared/paypal_express_confirm.html.erb @@ -20,4 +20,4 @@ - \ No newline at end of file + diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index e177044..fe46ecf 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -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 diff --git a/spec/models/billing_integration/paypal_express_base_spec.rb b/spec/models/billing_integration/paypal_express_base_spec.rb index d58b5c4..518d9f8 100644 --- a/spec/models/billing_integration/paypal_express_base_spec.rb +++ b/spec/models/billing_integration/paypal_express_base_spec.rb @@ -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) diff --git a/spec/requests/paypal_express_spec.rb b/spec/requests/paypal_express_spec.rb index 3d78ef3..79c8fd8 100644 --- a/spec/requests/paypal_express_spec.rb +++ b/spec/requests/paypal_express_spec.rb @@ -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/ diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8253134..6edc76a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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" diff --git a/spree_paypal_express.gemspec b/spree_paypal_express.gemspec index db0000c..a0285db 100644 --- a/spree_paypal_express.gemspec +++ b/spree_paypal_express.gemspec @@ -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