From 99a3eabee8759c45babcaee107ca64b9f8db78fe Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Wed, 1 Oct 2014 11:40:09 -0600 Subject: [PATCH 01/14] Handling addresses between a Spree store and Paypal. The goal of this is to give a store operator the tools needed to be able to place seller protection elibible payments against Paypal. The changes are: * Creating a no_shipping preference to give the store developer a say in whether to send the shipping address. (#113) * Adds the ability to send a shipping address to Paypal (see #113) * Adds the option of displaying the shipping address on the Paypal pages. * Upgrades the Paypal SDK gem * Adds the ability to request a confirmed shipping address from Paypal. * Extracts the confirmed address from the Paypal express checkout details when we are configured to require a confirmed shipping address. --- README.md | 45 +++- app/controllers/spree/paypal_controller.rb | 49 ++-- app/models/spree/gateway/pay_pal_express.rb | 58 +++++ app/models/spree/paypal_express_checkout.rb | 4 +- ...6155949_add_address_to_express_checkout.rb | 5 + spec/features/paypal_spec.rb | 244 ++++++++++++++++-- spec/models/pay_pal_express_spec.rb | 14 +- spree_paypal_express.gemspec | 2 +- 8 files changed, 361 insertions(+), 60 deletions(-) create mode 100644 db/migrate/20141006155949_add_address_to_express_checkout.rb diff --git a/README.md b/README.md index 4ea0faea..654ca49d 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ You will also need a "Personal" account to test the transactions on your site. C #### Spree Setup -In Spree, go to the admin backend, click "Configuration" and then "Payment Methods" and create a new payment method. Select "Spree::Gateway::PayPalExpress" as the provider, and click "Create". Enter the email address, password and signature from the "API Credentials" tab for the **Business** account on PayPal. +In Spree, go to the admin backend, click "Configuration" and then "Payment Methods" and create a new payment method. Select "Spree::Gateway::PayPalExpress" as the provider, and click "Create". Enter the email address, password and signature from the "API Credentials" tab for the **Business** account on PayPal. ### Production setup @@ -56,7 +56,7 @@ This Spree extension supports *some* of those. If your favourite is not here, th ### Solution Type -Determines whether or not a user needs a PayPal account to check out. +Determines whether or not a user needs a PayPal account to check out. ```ruby payment_method.preferred_solution_type = "Mark" @@ -64,7 +64,7 @@ payment_method.preferred_solution_type = "Mark" payment_method.preferred_solution_type = "Sole" ``` -"Mark" if you do want users to have a paypal account, "Sole" otherwise. +"Mark" if you do want users to have a paypal account, "Sole" otherwise. ### Landing Page @@ -88,6 +88,45 @@ payment_method.preferred_logourl = 'http://yoursite.com/images/checkout.jpg' **Must** be an absolute path to the image. +### Displaying Shipping Addresses + +You have the option of displaying the shipping address of an order on +the PayPal pages: + +```ruby +# Displays the shipping address of the order on the Paypal page +payment_method.preferred_no_shipping = '0' + +# Do not display the shipping address on the Paypal page +# This is the default configuration since this matches the pre-existing +# behavior of the gem +payment_method.preferred_no_shipping = '1' + +# Display the shipping address listed in the profile if it is not +# sent along with the order +payment_method.preferred_no_shipping = '2' +``` + +This has no effect on what shipping address is passed to the gateway. + +### Overriding the Shipping Address + +By default PayPay will use the shipping address that it has on file as +the shipping address for an order. + +You can configure the gateway to send up the shipping address associated +with the order through the following configuration: + +```ruby +# Do not override the shipping address on file (default) +payment_method.preferred_address_override = '0' + +# Override the shipping address on file +payment_method.preferred_address_override = '1' +``` + +The shipping address will be sent to the server if configured to do so. + ## Caveats *Caveat venditor* diff --git a/app/controllers/spree/paypal_controller.rb b/app/controllers/spree/paypal_controller.rb index aef1d921..46a85355 100644 --- a/app/controllers/spree/paypal_controller.rb +++ b/app/controllers/spree/paypal_controller.rb @@ -87,17 +87,23 @@ def line_item(item) end def express_checkout_request_details order, items - { :SetExpressCheckoutRequestDetails => { - :InvoiceID => order.number, - :BuyerEmail => order.email, - :ReturnURL => confirm_paypal_url(:payment_method_id => params[:payment_method_id], :utm_nooverride => 1), - :CancelURL => cancel_paypal_url, - :SolutionType => payment_method.preferred_solution.present? ? payment_method.preferred_solution : "Mark", - :LandingPage => payment_method.preferred_landing_page.present? ? payment_method.preferred_landing_page : "Billing", - :cppheaderimage => payment_method.preferred_logourl.present? ? payment_method.preferred_logourl : "", - :NoShipping => 1, - :PaymentDetails => [payment_details(items)] - }} + request_details = { + :InvoiceID => order.number, + :BuyerEmail => order.email, + :ReturnURL => confirm_paypal_url(:payment_method_id => params[:payment_method_id], :utm_nooverride => 1), + :CancelURL => cancel_paypal_url, + :SolutionType => payment_method.preferred_solution.present? ? payment_method.preferred_solution : "Mark", + :LandingPage => payment_method.preferred_landing_page.present? ? payment_method.preferred_landing_page : "Billing", + :cppheaderimage => payment_method.preferred_logourl.present? ? payment_method.preferred_logourl : "", + :NoShipping => payment_method.preferred_no_shipping.present? ? payment_method.preferred_no_shipping : '1', + :PaymentDetails => [payment_details(items)] + } + + # Optional fields without set defaults. + request_details[:AddressOverride] = payment_method.preferred_address_override if payment_method.preferred_address_override.present? + request_details[:ReqConfirmShipping] = payment_method.preferred_req_confirmed_address if payment_method.preferred_req_confirmed_address.present? + + { :SetExpressCheckoutRequestDetails => request_details } end def payment_method @@ -156,15 +162,17 @@ def payment_details items def address_options return {} unless address_required? + address = current_order.use_billing ? current_order.bill_address : current_order.ship_address + { - :Name => current_order.bill_address.try(:full_name), - :Street1 => current_order.bill_address.address1, - :Street2 => current_order.bill_address.address2, - :CityName => current_order.bill_address.city, - :Phone => current_order.bill_address.phone, - :StateOrProvince => current_order.bill_address.state_text, - :Country => current_order.bill_address.country.iso, - :PostalCode => current_order.bill_address.zipcode + :Name => address.try(:full_name), + :Street1 => address.address1, + :Street2 => address.address2, + :CityName => address.city, + :Phone => address.phone, + :StateOrProvince => address.state_text, + :Country => address.country.iso, + :PostalCode => address.zipcode } end @@ -173,7 +181,8 @@ def completion_route(order) end def address_required? - payment_method.preferred_solution.eql?('Sole') + payment_method.preferred_solution.eql?('Sole') \ + || payment_method.preferred_address_override.eql?('1') end end end diff --git a/app/models/spree/gateway/pay_pal_express.rb b/app/models/spree/gateway/pay_pal_express.rb index f9086cb6..3d504e6a 100644 --- a/app/models/spree/gateway/pay_pal_express.rb +++ b/app/models/spree/gateway/pay_pal_express.rb @@ -8,6 +8,28 @@ class Gateway::PayPalExpress < Gateway preference :solution, :string, default: 'Mark' preference :landing_page, :string, default: 'Billing' preference :logourl, :string, default: '' + # Indicates whether to display the shipping address on the paypal checkout + # page. + # + # 0 - Paypal displays the shipping address on the page. + # 1 - Paypal does not display the shipping address on its pages. This is + # the default due to the history of this gem. + # 2 - Paypal will obtain the shipping address from the profile. + preference :no_shipping, :string, default: '1' + + # Allow Address Override + # 0 - Do not override the address stored at PayPal + # 1 - Override the address stored at Paypal + # By default, the shipping address is not overriden on Paypal's site + preference :address_override, :string + + # Whether to require a confirmed address + # 0 - Do not require a confirmed address + # 1 - Require a confirmed address + # + # Paypal recommends that you do not override the address if you are + # requiring a confirmed address for this order. + preference :req_confirmed_address, :string def supports?(source) true @@ -55,6 +77,14 @@ def purchase(amount, express_checkout, gateway_options={}) # This is mainly so we can use it later on to refund the payment if the user wishes. transaction_id = pp_response.do_express_checkout_payment_response_details.payment_info.first.transaction_id express_checkout.update_column(:transaction_id, transaction_id) + + # We need to get a hold of the confirmed address + address = extract_address(pp_details_response) + + if address && address.valid? + express_checkout.update_column(:address_id, address.id) + end + # This is rather hackish, required for payment/processing handle_response code. Class.new do def success?; true; end @@ -99,6 +129,34 @@ def refund(payment, amount) end refund_transaction_response end + + private + + def extract_address(response) + return nil unless self.preferred_req_confirmed_address == '1' + + express_checkout_details = response.get_express_checkout_details_response_details + payment_details = express_checkout_details.PaymentDetails.first + payer_info = express_checkout_details.PayerInfo + ship_to_address = payment_details.ShipToAddress + + return nil unless ship_to_address && payer_info + + if state = Spree::State.find_by_abbr(ship_to_address.state_or_province) + Spree::Address.create( + firstname: payer_info.payer_name.first_name, + last_name: payer_info.payer_name.last_name, + address1: ship_to_address.street1, + address2: ship_to_address.street2, + city: ship_to_address.city_name, + state_id: state.id, + state_name: state.name, + country_id: state.country.id, + zipcode: ship_to_address.postal_code, + phone: ship_to_address.phone || "n/a" + ) + end + end end end diff --git a/app/models/spree/paypal_express_checkout.rb b/app/models/spree/paypal_express_checkout.rb index a29d2614..b40ee5c0 100644 --- a/app/models/spree/paypal_express_checkout.rb +++ b/app/models/spree/paypal_express_checkout.rb @@ -1,4 +1,6 @@ module Spree class PaypalExpressCheckout < ActiveRecord::Base + belongs_to :address, class_name: "Spree::Address" + alias_attribute :confirmed_address, :address end -end \ No newline at end of file +end diff --git a/db/migrate/20141006155949_add_address_to_express_checkout.rb b/db/migrate/20141006155949_add_address_to_express_checkout.rb new file mode 100644 index 00000000..8b3169ff --- /dev/null +++ b/db/migrate/20141006155949_add_address_to_express_checkout.rb @@ -0,0 +1,5 @@ +class AddAddressToExpressCheckout < ActiveRecord::Migration + def change + add_reference :spree_paypal_express_checkouts, :address + end +end diff --git a/spec/features/paypal_spec.rb b/spec/features/paypal_spec.rb index 78540457..636965a2 100644 --- a/spec/features/paypal_spec.rb +++ b/spec/features/paypal_spec.rb @@ -13,6 +13,7 @@ }) FactoryGirl.create(:shipping_method) end + def fill_in_billing within("#billing") do fill_in "First Name", :with => "Test" @@ -27,6 +28,21 @@ def fill_in_billing end end + def fill_in_shipping + uncheck("order[use_billing]") + within("#shipping") do + fill_in "First Name", :with => "Test" + fill_in "Last Name", :with => "User" + fill_in "Street Address", :with => "2 User Lane" + # City, State and ZIP must all match for PayPal to be happy + fill_in "City", :with => "Adamsville" + select "United States of America", :from => "order_ship_address_attributes_country_id" + select "Alabama", :from => "order_ship_address_attributes_state_id" + fill_in "Zip", :with => "35005" + fill_in "Phone", :with => "555-123-4567" + end + end + def switch_to_paypal_login # If you go through a payment once in the sandbox, it remembers your preferred setting. # It defaults to the *wrong* setting for the first time, so we need to have this method. @@ -48,10 +64,14 @@ def within_transaction_cart(&block) within(".transctionCartDetails") { block.call } end - it "pays for an order successfully" do + def add_product_to_cart(product) visit spree.root_path - click_link 'iPad' + click_link product click_button 'Add To Cart' + end + + it "pays for an order successfully" do + add_product_to_cart 'iPad' click_button 'Checkout' within("#guest_checkout") do fill_in "Email", :with => "test@example.com" @@ -76,9 +96,7 @@ def within_transaction_cart(&block) end it "passes user details to PayPal" do - visit spree.root_path - click_link 'iPad' - click_button 'Add To Cart' + add_product_to_cart('iPad') click_button 'Checkout' within("#guest_checkout") do fill_in "Email", :with => "test@example.com" @@ -102,9 +120,7 @@ def within_transaction_cart(&block) end it "includes adjustments in PayPal summary" do - visit spree.root_path - click_link 'iPad' - click_button 'Add To Cart' + add_product_to_cart('iPad') # TODO: Is there a better way to find this current order? order = Spree::Order.last order.adjustments.create!(:amount => -5, :label => "$5 off") @@ -154,10 +170,7 @@ def within_transaction_cart(&block) end it "includes line item adjustments in PayPal summary" do - - visit spree.root_path - click_link 'iPad' - click_button 'Add To Cart' + add_product_to_cart('iPad') # TODO: Is there a better way to find this current order? order = Spree::Order.last order.line_item_adjustments.count.should == 1 @@ -190,18 +203,14 @@ def within_transaction_cart(&block) end end + # Regression test for #10 context "will skip $0 items" do let!(:product2) { FactoryGirl.create(:product, :name => 'iPod') } specify do - visit spree.root_path - click_link 'iPad' - click_button 'Add To Cart' - - visit spree.root_path - click_link 'iPod' - click_button 'Add To Cart' + add_product_to_cart('iPad') + add_product_to_cart('iPod') # TODO: Is there a better way to find this current order? order = Spree::Order.last @@ -247,9 +256,7 @@ def within_transaction_cart(&block) end specify do - visit spree.root_path - click_link 'iPad' - click_button 'Add To Cart' + add_product_to_cart('iPad') # TODO: Is there a better way to find this current order? order = Spree::Order.last order.adjustments.create!(:amount => -order.line_items.last.price, :label => "FREE iPad ZOMG!") @@ -274,6 +281,191 @@ def within_transaction_cart(&block) end end + shared_examples_for :no_shipping do + it "displays the shipping address on file on the paypal page" do + add_product_to_cart('iPad') + click_button 'Checkout' + within('#guest_checkout') do + fill_in "Email", with: "test@example.com" + click_button 'Continue' + end + fill_in_billing + fill_in_shipping + + click_button "Save and Continue" + # Delivery step doesn't require any action + click_button "Save and Continue" + + find("#paypal_button").click + + login_to_paypal + + within("#shippingAddress") do + page.should have_content("Ship to") + end + + click_button "Pay Now" + + page.should have_content("Your order has been processed successfully") + end + end + + context "displays the shipping address on the paypal page" do + before do + @gateway.preferred_no_shipping = '0' + @gateway.save + end + + it_behaves_like :no_shipping + end + + shared_examples_for :no_shipping_displayed do + it "does not show the address by default" do + add_product_to_cart('iPad') + click_button 'Checkout' + within('#guest_checkout') do + fill_in "Email", with: "test@example.com" + click_button 'Continue' + end + fill_in_billing + fill_in_shipping + + click_button "Save and Continue" + # Delivery step doesn't require any action + click_button "Save and Continue" + + find("#paypal_button").click + + login_to_paypal + + page.should have_no_content("Ship To") + + click_button "Pay Now" + + page.should have_content("Your order has been processed successfully") + end + end + + context "requiring confirmed shipping address" do + before do + @gateway.preferred_req_confirmed_address = '1' + @gateway.save + end + + it_behaves_like :no_shipping_displayed + + it "overrides the shipping address on the order with the confirmed one" do + maryland = FactoryGirl.create(:state, name: "Maryland", abbr: "MD") + + add_product_to_cart('iPad') + click_button 'Checkout' + within('#guest_checkout') do + fill_in "Email", with: "test@example.com" + click_button 'Continue' + end + fill_in_billing + fill_in_shipping + + click_button "Save and Continue" + # Delivery step doesn't require any action + click_button "Save and Continue" + + find("#paypal_button").click + + login_to_paypal + + page.should have_no_content("Ship To") + + click_button "Pay Now" + + page.should have_content("Your order has been processed successfully") + + order = Spree::Order.last + express_checkout = order.payments.last.source + + address = express_checkout.address + address.should_not be_nil + + address.address1.should eq("Suite 510") + address.address2.should eq("7735 Old Georgetown Road") + address.city.should eq("Bethesda") + address.state.should eq(maryland) + end + end + + context "displays the shipping address on the paypal page when none is passed" do + before do + @gateway.preferred_no_shipping = '2' + @gateway.save + end + + it_behaves_like :no_shipping + end + + context "default no shipping option" do + it_behaves_like :no_shipping_displayed + end + + context "shipping address override" do + before do + @gateway.preferred_no_shipping = '0' + @gateway.preferred_address_override = '1' + @gateway.save + end + + it "shipping address from order" do + add_product_to_cart('iPad') + click_button 'Checkout' + within('#guest_checkout') do + fill_in "Email", with: "test@example.com" + click_button 'Continue' + end + fill_in_billing + fill_in_shipping + + click_button "Save and Continue" + # Delivery step doesn't require any action + click_button "Save and Continue" + + find("#paypal_button").click + + login_to_paypal + + within("#shippingAddress") do + page.should have_content("2 User Lane") + end + click_button "Pay Now" + + page.should have_content("Your order has been processed successfully") + end + + it "billing address from order" do + add_product_to_cart('iPad') + click_button 'Checkout' + within('#guest_checkout') do + fill_in "Email", with: "test@example.com" + click_button 'Continue' + end + fill_in_billing + + click_button "Save and Continue" + # Delivery step doesn't require any action + click_button "Save and Continue" + + find("#paypal_button").click + + login_to_paypal + + within("#shippingAddress") do + page.should have_content("1 User Lane") + end + + click_button "Pay Now" + + page.should have_content("Your order has been processed successfully") + end + end + context "cannot process a payment with invalid gateway details" do before do @gateway.preferred_login = nil @@ -281,9 +473,7 @@ def within_transaction_cart(&block) end specify do - visit spree.root_path - click_link 'iPad' - click_button 'Add To Cart' + add_product_to_cart('iPad') click_button 'Checkout' within("#guest_checkout") do fill_in "Email", :with => "test@example.com" @@ -303,9 +493,7 @@ def within_transaction_cart(&block) context "refunding payments" do before do - visit spree.root_path - click_link 'iPad' - click_button 'Add To Cart' + add_product_to_cart('iPad') click_button 'Checkout' within("#guest_checkout") do fill_in "Email", :with => "test@example.com" diff --git a/spec/models/pay_pal_express_spec.rb b/spec/models/pay_pal_express_spec.rb index 761bbe26..d94757e1 100644 --- a/spec/models/pay_pal_express_spec.rb +++ b/spec/models/pay_pal_express_spec.rb @@ -22,12 +22,12 @@ }).and_return(pp_details_request = double) pp_details_response = double(:get_express_checkout_details_response_details => - double(:PaymentDetails => { - :OrderTotal => { - :currencyID => "USD", - :value => "10.00" - } - })) + double(:PaymentDetails => { + :OrderTotal => { + :currencyID => "USD", + :value => "10.00" + }, + })) provider.should_receive(:get_express_checkout_details). with(pp_details_request). @@ -53,7 +53,7 @@ # Test for #4 it "fails" do - response = double('pp_response', :success? => false, + response = double('pp_response', :success? => false, :errors => [double('pp_response_error', :long_message => "An error goes here.")]) provider.should_receive(:do_express_checkout_payment).and_return(response) lambda { payment.purchase! }.should raise_error(Spree::Core::GatewayError, "An error goes here.") diff --git a/spree_paypal_express.gemspec b/spree_paypal_express.gemspec index e3e25233..12b31c92 100644 --- a/spree_paypal_express.gemspec +++ b/spree_paypal_express.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |s| s.requirements << 'none' s.add_dependency 'spree_core', '~> 2.4.0.beta' - s.add_dependency 'paypal-sdk-merchant', '1.106.1' + s.add_dependency 'paypal-sdk-merchant', '1.116.0' s.add_development_dependency 'capybara', '~> 2.1' s.add_development_dependency 'coffee-rails' From 8a0aa03aa83f5181ac8392aec8af2d932f75eeb5 Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Wed, 8 Oct 2014 12:05:38 -0600 Subject: [PATCH 02/14] Addressing Paypal's evolving layout. --- spec/features/paypal_spec.rb | 106 ++++++++++++++++++++++++++--------- 1 file changed, 81 insertions(+), 25 deletions(-) diff --git a/spec/features/paypal_spec.rb b/spec/features/paypal_spec.rb index 636965a2..ba08ca35 100644 --- a/spec/features/paypal_spec.rb +++ b/spec/features/paypal_spec.rb @@ -14,6 +14,19 @@ FactoryGirl.create(:shipping_method) end + def paypal_layout + @paypal_layout ||= begin + page.find("body.pagelogin") + :new_layout + end + rescue Capybara::ElementNotFound + if page.has_content?("Internal Server Error") + page.reload + else + @paypal_layout = :old_layout + end + end + def fill_in_billing within("#billing") do fill_in "First Name", :with => "Test" @@ -43,25 +56,58 @@ def fill_in_shipping end end - def switch_to_paypal_login - # If you go through a payment once in the sandbox, it remembers your preferred setting. - # It defaults to the *wrong* setting for the first time, so we need to have this method. - unless page.has_selector?("#login #email") - find("#loadLogin").click + def go_to_paypal + find("#paypal_button").click + + # Paypal keeps going back and forth with their design. The HTML is very + # different between both. + # + # This changes the behavior of the specs to match the layout that Paypal + # returns to us. + if paypal_layout == :new_layout + extend NewPaypal unless respond_to?(:login_to_paypal) + else + extend OldPaypal unless respond_to?(:login_to_paypal) end end - def login_to_paypal - within("#loginForm") do - fill_in "Email", :with => "pp@spreecommerce.com" - fill_in "Password", :with => "thequickbrownfox" - click_button "Log in to PayPal" + module OldPaypal + def login_to_paypal + fill_in "login_email", :with => "pp@spreecommerce.com" + fill_in "login_password", :with => "thequickbrownfox" + click_button "Log In" + end + + def within_transaction_cart(&block) + within("#miniCart") { block.call } + end + + def switch_to_paypal_login + # If you go through a payment once in the sandbox, it remembers your preferred setting. + # It defaults to the *wrong* setting for the first time, so we need to have this method. + unless page.has_selector?("#login #email") + find("#loadLogin").click + end end end - def within_transaction_cart(&block) - find(".transactionDetails").click - within(".transctionCartDetails") { block.call } + module NewPaypal + def login_to_paypal + within("#loginForm") do + fill_in "Email", :with => "pp@spreecommerce.com" + fill_in "Password", :with => "thequickbrownfox" + click_button "Log in to PayPal" + end + end + + def within_transaction_cart(&block) + find(".transactionDetails").click + within(".transctionCartDetails") { block.call } + end + + def switch_to_paypal_login + #NOOP + end end def add_product_to_cart(product) @@ -81,7 +127,9 @@ def add_product_to_cart(product) click_button "Save and Continue" # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + + go_to_paypal + switch_to_paypal_login login_to_paypal click_button "Pay Now" @@ -106,7 +154,8 @@ def add_product_to_cart(product) click_button "Save and Continue" # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + + go_to_paypal login_to_paypal click_button "Pay Now" @@ -139,7 +188,8 @@ def add_product_to_cart(product) click_button "Save and Continue" # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + + go_to_paypal within_transaction_cart do page.should have_content("$5 off") @@ -188,7 +238,8 @@ def add_product_to_cart(product) click_button "Save and Continue" # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + + go_to_paypal within_transaction_cart do page.should have_content("10% off") @@ -224,7 +275,8 @@ def add_product_to_cart(product) click_button "Save and Continue" # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + + go_to_paypal within_transaction_cart do page.should have_content('iPad') @@ -269,7 +321,8 @@ def add_product_to_cart(product) click_button "Save and Continue" # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + + go_to_paypal login_to_paypal @@ -296,7 +349,8 @@ def add_product_to_cart(product) # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + + go_to_paypal login_to_paypal @@ -334,7 +388,7 @@ def add_product_to_cart(product) # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + go_to_paypal login_to_paypal @@ -370,7 +424,7 @@ def add_product_to_cart(product) # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + go_to_paypal login_to_paypal @@ -427,7 +481,7 @@ def add_product_to_cart(product) # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + go_to_paypal login_to_paypal @@ -452,7 +506,7 @@ def add_product_to_cart(product) # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + go_to_paypal login_to_paypal @@ -503,7 +557,9 @@ def add_product_to_cart(product) click_button "Save and Continue" # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + + go_to_paypal + switch_to_paypal_login login_to_paypal click_button("Pay Now") From 6d9a96ecaf260b383a4f16a0121b2256b39d7fc7 Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Wed, 8 Oct 2014 14:23:23 -0600 Subject: [PATCH 03/14] The specs are almost working --- spec/features/paypal_spec.rb | 76 ++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/spec/features/paypal_spec.rb b/spec/features/paypal_spec.rb index ba08ca35..834dfb62 100644 --- a/spec/features/paypal_spec.rb +++ b/spec/features/paypal_spec.rb @@ -15,7 +15,7 @@ end def paypal_layout - @paypal_layout ||= begin + $paypal_layout ||= begin page.find("body.pagelogin") :new_layout end @@ -23,7 +23,7 @@ def paypal_layout if page.has_content?("Internal Server Error") page.reload else - @paypal_layout = :old_layout + $paypal_layout = :old_layout end end @@ -73,6 +73,11 @@ def go_to_paypal module OldPaypal def login_to_paypal + # If you go through a payment once in the sandbox, it remembers your preferred setting. + # It defaults to the *wrong* setting for the first time, so we need to have this method. + unless page.has_selector?("#login_email") + find("#loadLogin").click + end fill_in "login_email", :with => "pp@spreecommerce.com" fill_in "login_password", :with => "thequickbrownfox" click_button "Log In" @@ -82,12 +87,12 @@ def within_transaction_cart(&block) within("#miniCart") { block.call } end - def switch_to_paypal_login - # If you go through a payment once in the sandbox, it remembers your preferred setting. - # It defaults to the *wrong* setting for the first time, so we need to have this method. - unless page.has_selector?("#login #email") - find("#loadLogin").click - end + def click_pay_now + find("#continue_abovefold").click + end + + def ship_to_heading + "Shipping address" end end @@ -105,8 +110,12 @@ def within_transaction_cart(&block) within(".transctionCartDetails") { block.call } end - def switch_to_paypal_login - #NOOP + def click_pay_now + click_button "Pay Now" + end + + def ship_to_heading + "Ship to" end end @@ -127,12 +136,9 @@ def add_product_to_cart(product) click_button "Save and Continue" # Delivery step doesn't require any action click_button "Save and Continue" - go_to_paypal - - switch_to_paypal_login login_to_paypal - click_button "Pay Now" + click_pay_now page.should have_content("Your order has been processed successfully") Spree::Payment.last.source.transaction_id.should_not be_blank @@ -158,8 +164,7 @@ def add_product_to_cart(product) go_to_paypal login_to_paypal - click_button "Pay Now" - + click_pay_now page.should have_selector '[data-hook=order-bill-address] .fn', text: 'Test User' page.should have_selector '[data-hook=order-bill-address] .adr', text: '1 User Lane' page.should have_selector '[data-hook=order-bill-address] .adr', text: 'Adamsville AL 35005' @@ -203,7 +208,7 @@ def add_product_to_cart(product) page.should have_content("$10 on") end - click_button "Pay Now" + click_pay_now within("[data-hook=order_details_adjustments]") do page.should have_content("$5 off") @@ -246,7 +251,7 @@ def add_product_to_cart(product) end login_to_paypal - click_button "Pay Now" + click_pay_now within("[data-hook=order_details_price_adjustments]") do page.should have_content("10% off") @@ -290,7 +295,7 @@ def add_product_to_cart(product) page.should_not have_content('iPod') end - click_button "Pay Now" + click_pay_now within("#line-items") do page.should have_content('iPad') @@ -326,7 +331,7 @@ def add_product_to_cart(product) login_to_paypal - click_button "Pay Now" + click_pay_now within("[data-hook=order_details_adjustments]") do page.should have_content('FREE iPad ZOMG!') @@ -354,11 +359,9 @@ def add_product_to_cart(product) login_to_paypal - within("#shippingAddress") do - page.should have_content("Ship to") - end + page.should have_content(ship_to_heading) - click_button "Pay Now" + click_pay_now page.should have_content("Your order has been processed successfully") end @@ -392,9 +395,9 @@ def add_product_to_cart(product) login_to_paypal - page.should have_no_content("Ship To") + page.should have_no_content(ship_to_heading) - click_button "Pay Now" + click_pay_now page.should have_content("Your order has been processed successfully") end @@ -428,9 +431,9 @@ def add_product_to_cart(product) login_to_paypal - page.should have_no_content("Ship To") + page.should have_no_content(ship_to_heading) - click_button "Pay Now" + click_pay_now page.should have_content("Your order has been processed successfully") @@ -485,10 +488,9 @@ def add_product_to_cart(product) login_to_paypal - within("#shippingAddress") do - page.should have_content("2 User Lane") - end - click_button "Pay Now" + page.should have_content("2 User Lane") + + click_pay_now page.should have_content("Your order has been processed successfully") end @@ -510,11 +512,9 @@ def add_product_to_cart(product) login_to_paypal - within("#shippingAddress") do - page.should have_content("1 User Lane") - end + page.should have_content("1 User Lane") - click_button "Pay Now" + click_pay_now page.should have_content("Your order has been processed successfully") end @@ -559,10 +559,8 @@ def add_product_to_cart(product) click_button "Save and Continue" go_to_paypal - - switch_to_paypal_login login_to_paypal - click_button("Pay Now") + click_pay_now page.should have_content("Your order has been processed successfully") visit '/admin' From 052cca35ebdd41d8f995776584c1605c60aad0c7 Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Wed, 8 Oct 2014 14:36:02 -0600 Subject: [PATCH 04/14] Attempting to speed things up a little bit... --- spec/features/paypal_spec.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/features/paypal_spec.rb b/spec/features/paypal_spec.rb index 834dfb62..ec0885bf 100644 --- a/spec/features/paypal_spec.rb +++ b/spec/features/paypal_spec.rb @@ -64,10 +64,12 @@ def go_to_paypal # # This changes the behavior of the specs to match the layout that Paypal # returns to us. - if paypal_layout == :new_layout - extend NewPaypal unless respond_to?(:login_to_paypal) - else - extend OldPaypal unless respond_to?(:login_to_paypal) + unless respond_to?(:login_to_paypal) + if paypal_layout == :new_layout + self.class.include NewPaypal + else + self.class.include OldPaypal + end end end From d79a828d589555c48cd808090ef37ebd60477dcf Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Wed, 8 Oct 2014 15:54:19 -0600 Subject: [PATCH 05/14] small changes in detecting the layout. --- spec/features/paypal_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/features/paypal_spec.rb b/spec/features/paypal_spec.rb index ec0885bf..3bdb26ec 100644 --- a/spec/features/paypal_spec.rb +++ b/spec/features/paypal_spec.rb @@ -20,8 +20,12 @@ def paypal_layout :new_layout end rescue Capybara::ElementNotFound + retries ||= 0 if page.has_content?("Internal Server Error") + sleep(1) page.reload + retry if retries < 3 + retries += 1 else $paypal_layout = :old_layout end @@ -96,6 +100,8 @@ def click_pay_now def ship_to_heading "Shipping address" end + + end module NewPaypal From 448b0a1f6204379f0b960fb95944abcbf303aa6c Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Thu, 9 Oct 2014 10:02:16 -0600 Subject: [PATCH 06/14] Improving the paypal layout discovery. --- spec/features/paypal_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/features/paypal_spec.rb b/spec/features/paypal_spec.rb index 3bdb26ec..57719d84 100644 --- a/spec/features/paypal_spec.rb +++ b/spec/features/paypal_spec.rb @@ -16,18 +16,18 @@ def paypal_layout $paypal_layout ||= begin - page.find("body.pagelogin") + page.find("body.pagelogin", wait: 2) :new_layout end rescue Capybara::ElementNotFound retries ||= 0 - if page.has_content?("Internal Server Error") + if page.find("body.xptSandbox") + $paypal_layout = :old_layout + else sleep(1) page.reload - retry if retries < 3 retries += 1 - else - $paypal_layout = :old_layout + retry if retries < 3 end end From ba48c84d3113a989a1d967b60447a780dcd031e2 Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Thu, 9 Oct 2014 10:02:49 -0600 Subject: [PATCH 07/14] Making sure that we are not requesting the address for this spec. --- spec/models/pay_pal_express_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/pay_pal_express_spec.rb b/spec/models/pay_pal_express_spec.rb index d94757e1..64f2e29b 100644 --- a/spec/models/pay_pal_express_spec.rb +++ b/spec/models/pay_pal_express_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Spree::Gateway::PayPalExpress do - let(:gateway) { Spree::Gateway::PayPalExpress.create!(name: "PayPalExpress", :environment => Rails.env) } + let(:gateway) { Spree::Gateway::PayPalExpress.create!(name: "PayPalExpress", :environment => Rails.env, preferred_req_confirmed_address: '0') } context "payment purchase" do let(:payment) do From 621641b103dfe27614122ba3d284edfc0bb14dc7 Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Thu, 9 Oct 2014 11:25:18 -0600 Subject: [PATCH 08/14] Setting defaults. --- app/models/spree/gateway/pay_pal_express.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/spree/gateway/pay_pal_express.rb b/app/models/spree/gateway/pay_pal_express.rb index 3d504e6a..293ad8fc 100644 --- a/app/models/spree/gateway/pay_pal_express.rb +++ b/app/models/spree/gateway/pay_pal_express.rb @@ -21,7 +21,7 @@ class Gateway::PayPalExpress < Gateway # 0 - Do not override the address stored at PayPal # 1 - Override the address stored at Paypal # By default, the shipping address is not overriden on Paypal's site - preference :address_override, :string + preference :address_override, :string, default: '0' # Whether to require a confirmed address # 0 - Do not require a confirmed address @@ -29,7 +29,7 @@ class Gateway::PayPalExpress < Gateway # # Paypal recommends that you do not override the address if you are # requiring a confirmed address for this order. - preference :req_confirmed_address, :string + preference :req_confirmed_address, :string, default: '0' def supports?(source) true From 70f958e5d569124b989ed7e87ca11228895ed81d Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Thu, 9 Oct 2014 11:47:30 -0600 Subject: [PATCH 09/14] Moving the Paypal support methods to it's own module. --- spec/features/paypal_spec.rb | 117 ++------------------------------- spec/spec_helper.rb | 1 + spec/support/paypal_support.rb | 116 ++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 113 deletions(-) create mode 100644 spec/support/paypal_support.rb diff --git a/spec/features/paypal_spec.rb b/spec/features/paypal_spec.rb index 57719d84..3d44bf42 100644 --- a/spec/features/paypal_spec.rb +++ b/spec/features/paypal_spec.rb @@ -7,6 +7,10 @@ :preferred_login => "pp_api1.ryanbigg.com", :preferred_password => "1383066713", :preferred_signature => "An5ns1Kso7MWUdW4ErQKJJJ4qi4-Ar-LpzhMJL0cu8TjM8Z2e1ykVg5B", + :preferred_solution => "Mark", + :preferred_address_override => '0', + :preferred_no_shipping => '1', + :preferred_req_confirmed_address => '0', :name => "PayPal", :active => true, :environment => Rails.env @@ -14,119 +18,6 @@ FactoryGirl.create(:shipping_method) end - def paypal_layout - $paypal_layout ||= begin - page.find("body.pagelogin", wait: 2) - :new_layout - end - rescue Capybara::ElementNotFound - retries ||= 0 - if page.find("body.xptSandbox") - $paypal_layout = :old_layout - else - sleep(1) - page.reload - retries += 1 - retry if retries < 3 - end - end - - def fill_in_billing - within("#billing") do - fill_in "First Name", :with => "Test" - fill_in "Last Name", :with => "User" - fill_in "Street Address", :with => "1 User Lane" - # City, State and ZIP must all match for PayPal to be happy - fill_in "City", :with => "Adamsville" - select "United States of America", :from => "order_bill_address_attributes_country_id" - select "Alabama", :from => "order_bill_address_attributes_state_id" - fill_in "Zip", :with => "35005" - fill_in "Phone", :with => "555-123-4567" - end - end - - def fill_in_shipping - uncheck("order[use_billing]") - within("#shipping") do - fill_in "First Name", :with => "Test" - fill_in "Last Name", :with => "User" - fill_in "Street Address", :with => "2 User Lane" - # City, State and ZIP must all match for PayPal to be happy - fill_in "City", :with => "Adamsville" - select "United States of America", :from => "order_ship_address_attributes_country_id" - select "Alabama", :from => "order_ship_address_attributes_state_id" - fill_in "Zip", :with => "35005" - fill_in "Phone", :with => "555-123-4567" - end - end - - def go_to_paypal - find("#paypal_button").click - - # Paypal keeps going back and forth with their design. The HTML is very - # different between both. - # - # This changes the behavior of the specs to match the layout that Paypal - # returns to us. - unless respond_to?(:login_to_paypal) - if paypal_layout == :new_layout - self.class.include NewPaypal - else - self.class.include OldPaypal - end - end - end - - module OldPaypal - def login_to_paypal - # If you go through a payment once in the sandbox, it remembers your preferred setting. - # It defaults to the *wrong* setting for the first time, so we need to have this method. - unless page.has_selector?("#login_email") - find("#loadLogin").click - end - fill_in "login_email", :with => "pp@spreecommerce.com" - fill_in "login_password", :with => "thequickbrownfox" - click_button "Log In" - end - - def within_transaction_cart(&block) - within("#miniCart") { block.call } - end - - def click_pay_now - find("#continue_abovefold").click - end - - def ship_to_heading - "Shipping address" - end - - - end - - module NewPaypal - def login_to_paypal - within("#loginForm") do - fill_in "Email", :with => "pp@spreecommerce.com" - fill_in "Password", :with => "thequickbrownfox" - click_button "Log in to PayPal" - end - end - - def within_transaction_cart(&block) - find(".transactionDetails").click - within(".transctionCartDetails") { block.call } - end - - def click_pay_now - click_button "Pay Now" - end - - def ship_to_heading - "Ship to" - end - end - def add_product_to_cart(product) visit spree.root_path click_link product diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bf989a5c..ef817b16 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -49,6 +49,7 @@ config.include FactoryGirl::Syntax::Methods config.include Spree::TestingSupport::UrlHelpers config.include Spree::TestingSupport::AuthorizationHelpers::Controller + config.include PaypalSupport, type: :feature config.mock_with :rspec config.color = true diff --git a/spec/support/paypal_support.rb b/spec/support/paypal_support.rb new file mode 100644 index 00000000..ee5530a6 --- /dev/null +++ b/spec/support/paypal_support.rb @@ -0,0 +1,116 @@ +module PaypalSupport + def paypal_layout + $paypal_layout ||= begin + page.find("body.pagelogin", wait: 3) + :new_layout + end + rescue Capybara::ElementNotFound + retries ||= 0 + if page.has_css?("body.xptSandbox") + $paypal_layout = :old_layout + elsif page.has_content?("Internal Server Error") + page.reload + retry + else + sleep(1) + page.reload + retries += 1 + retry if retries < 5 + raise "Could not determine the paypal layout" + end + end + + def fill_in_billing + within("#billing") do + fill_in "First Name", :with => "Test" + fill_in "Last Name", :with => "User" + fill_in "Street Address", :with => "1 User Lane" + # City, State and ZIP must all match for PayPal to be happy + fill_in "City", :with => "Adamsville" + select "United States of America", :from => "order_bill_address_attributes_country_id" + select "Alabama", :from => "order_bill_address_attributes_state_id" + fill_in "Zip", :with => "35005" + fill_in "Phone", :with => "555-123-4567" + end + end + + def fill_in_shipping + uncheck("order[use_billing]") + within("#shipping") do + fill_in "First Name", :with => "Test" + fill_in "Last Name", :with => "User" + fill_in "Street Address", :with => "2 User Lane" + # City, State and ZIP must all match for PayPal to be happy + fill_in "City", :with => "Adamsville" + select "United States of America", :from => "order_ship_address_attributes_country_id" + select "Alabama", :from => "order_ship_address_attributes_state_id" + fill_in "Zip", :with => "35005" + fill_in "Phone", :with => "555-123-4567" + end + end + + def go_to_paypal + find("#paypal_button").click + + # Paypal keeps going back and forth with their design. The HTML is very + # different between both. + # + # This changes the behavior of the specs to match the layout that Paypal + # returns to us. + # unless respond_to?(:login_to_paypal) + if paypal_layout == :new_layout + self.class.include NewPaypal + else + self.class.include OldPaypal + end + # end + end + + module OldPaypal + def login_to_paypal + # If you go through a payment once in the sandbox, it remembers your preferred setting. + # It defaults to the *wrong* setting for the first time, so we need to have this method. + unless page.has_selector?("#login_email") + find("#loadLogin").click + end + fill_in "login_email", :with => "pp@spreecommerce.com" + fill_in "login_password", :with => "thequickbrownfox" + click_button "Log In" + end + + def within_transaction_cart(&block) + within("#miniCart") { block.call } + end + + def click_pay_now + find("#continue_abovefold").click + end + + def ship_to_heading + "Shipping address" + end + end + + module NewPaypal + def login_to_paypal + within("#loginForm") do + fill_in "Email", :with => "pp@spreecommerce.com" + fill_in "Password", :with => "thequickbrownfox" + click_button "Log in to PayPal" + end + end + + def within_transaction_cart(&block) + find(".transactionDetails").click + within(".transctionCartDetails") { block.call } + end + + def click_pay_now + click_button "Pay Now" + end + + def ship_to_heading + "Ship to" + end + end +end From e81fddf2818db9c890381408aedb1827c44bd6e9 Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Fri, 10 Oct 2014 14:03:02 -0600 Subject: [PATCH 10/14] Further musing on where things belong... --- spec/features/paypal_spec.rb | 30 ++++++++++++++++++++++++ spec/support/paypal_support.rb | 43 ++++++---------------------------- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/spec/features/paypal_spec.rb b/spec/features/paypal_spec.rb index 3d44bf42..f384ae27 100644 --- a/spec/features/paypal_spec.rb +++ b/spec/features/paypal_spec.rb @@ -18,6 +18,36 @@ FactoryGirl.create(:shipping_method) end + def fill_in_billing + within("#billing") do + fill_in "First Name", :with => "Test" + fill_in "Last Name", :with => "User" + fill_in "Street Address", :with => "1 User Lane" + # City, State and ZIP must all match for PayPal to be happy + fill_in "City", :with => "Adamsville" + select "United States of America", :from => "order_bill_address_attributes_country_id" + select "Alabama", :from => "order_bill_address_attributes_state_id" + fill_in "Zip", :with => "35005" + fill_in "Phone", :with => "555-123-4567" + end + end + + def fill_in_shipping + uncheck("order[use_billing]") + within("#shipping") do + fill_in "First Name", :with => "Test" + fill_in "Last Name", :with => "User" + fill_in "Street Address", :with => "2 User Lane" + # City, State and ZIP must all match for PayPal to be happy + fill_in "City", :with => "Adamsville" + select "United States of America", :from => "order_ship_address_attributes_country_id" + select "Alabama", :from => "order_ship_address_attributes_state_id" + fill_in "Zip", :with => "35005" + fill_in "Phone", :with => "555-123-4567" + end + end + + def add_product_to_cart(product) visit spree.root_path click_link product diff --git a/spec/support/paypal_support.rb b/spec/support/paypal_support.rb index ee5530a6..edeca371 100644 --- a/spec/support/paypal_support.rb +++ b/spec/support/paypal_support.rb @@ -20,35 +20,6 @@ def paypal_layout end end - def fill_in_billing - within("#billing") do - fill_in "First Name", :with => "Test" - fill_in "Last Name", :with => "User" - fill_in "Street Address", :with => "1 User Lane" - # City, State and ZIP must all match for PayPal to be happy - fill_in "City", :with => "Adamsville" - select "United States of America", :from => "order_bill_address_attributes_country_id" - select "Alabama", :from => "order_bill_address_attributes_state_id" - fill_in "Zip", :with => "35005" - fill_in "Phone", :with => "555-123-4567" - end - end - - def fill_in_shipping - uncheck("order[use_billing]") - within("#shipping") do - fill_in "First Name", :with => "Test" - fill_in "Last Name", :with => "User" - fill_in "Street Address", :with => "2 User Lane" - # City, State and ZIP must all match for PayPal to be happy - fill_in "City", :with => "Adamsville" - select "United States of America", :from => "order_ship_address_attributes_country_id" - select "Alabama", :from => "order_ship_address_attributes_state_id" - fill_in "Zip", :with => "35005" - fill_in "Phone", :with => "555-123-4567" - end - end - def go_to_paypal find("#paypal_button").click @@ -57,13 +28,11 @@ def go_to_paypal # # This changes the behavior of the specs to match the layout that Paypal # returns to us. - # unless respond_to?(:login_to_paypal) - if paypal_layout == :new_layout - self.class.include NewPaypal - else - self.class.include OldPaypal - end - # end + if paypal_layout == :new_layout + extend NewPaypal + else + extend OldPaypal + end end module OldPaypal @@ -93,6 +62,8 @@ def ship_to_heading module NewPaypal def login_to_paypal + find("#loginForm") + within("#loginForm") do fill_in "Email", :with => "pp@spreecommerce.com" fill_in "Password", :with => "thequickbrownfox" From 5e18fda9b93c62aa0038ca6dd6f7073fecdfe2ef Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Fri, 10 Oct 2014 15:12:54 -0600 Subject: [PATCH 11/14] Further adjustments on the retry logic --- spec/support/paypal_support.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/support/paypal_support.rb b/spec/support/paypal_support.rb index edeca371..582646a9 100644 --- a/spec/support/paypal_support.rb +++ b/spec/support/paypal_support.rb @@ -1,19 +1,19 @@ module PaypalSupport def paypal_layout - $paypal_layout ||= begin + @paypal_layout ||= begin page.find("body.pagelogin", wait: 3) :new_layout end rescue Capybara::ElementNotFound retries ||= 0 if page.has_css?("body.xptSandbox") - $paypal_layout = :old_layout + @paypal_layout = :old_layout elsif page.has_content?("Internal Server Error") - page.reload + visit current_path retry else sleep(1) - page.reload + visit current_path retries += 1 retry if retries < 5 raise "Could not determine the paypal layout" From a0ea176d59d6ce21ae4b3ae6c46d55b0c3eb6125 Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Mon, 20 Oct 2014 11:10:23 -0600 Subject: [PATCH 12/14] Using TLSv1 for SSL testing. --- spec/spec_helper.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ef817b16..c6b3010d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -33,6 +33,10 @@ require 'capybara/poltergeist' +Capybara.register_driver :poltergeist do |app| + Capybara::Poltergeist::Driver.new(app, + :phantomjs_options => ['--debug=no', '--ignore-ssl-errors=yes', '--ssl-protocol=TLSv1'], :debug => false) +end Capybara.javascript_driver = :poltergeist Capybara.default_wait_time = 15 From ef80f570b9aa25fb53246aaebc16b4b74480bcfa Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Thu, 30 Oct 2014 16:26:58 -0600 Subject: [PATCH 13/14] Addressing SSL and timeouts in tests. --- spec/spec_helper.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c6b3010d..27039294 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -34,11 +34,15 @@ require 'capybara/poltergeist' Capybara.register_driver :poltergeist do |app| - Capybara::Poltergeist::Driver.new(app, - :phantomjs_options => ['--debug=no', '--ignore-ssl-errors=yes', '--ssl-protocol=TLSv1'], :debug => false) + Capybara::Poltergeist::Driver.new( + app, + :phantomjs_options => ['--debug=no', '--ssl-protocol=ANY'], + :timeout => 30, + :debug => false + ) end Capybara.javascript_driver = :poltergeist -Capybara.default_wait_time = 15 +Capybara.default_wait_time = 30 Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f } From 80108fd565db98bb3c0e15622cbce09ced169c96 Mon Sep 17 00:00:00 2001 From: Frederic Jean Date: Thu, 30 Oct 2014 16:53:02 -0600 Subject: [PATCH 14/14] Clean up spacing. Pushing to the branch is the only way I have to retry the specs on travis-ci. --- spec/spec_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 27039294..0bde3e64 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -41,6 +41,7 @@ :debug => false ) end + Capybara.javascript_driver = :poltergeist Capybara.default_wait_time = 30