Skip to content

Commit

Permalink
Merge branch 'master' into no-shipping-preference
Browse files Browse the repository at this point in the history
  • Loading branch information
fredjean committed Oct 2, 2014
2 parents 361a31e + 2f540c3 commit 8ce4366
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ Gemfile.lock
tmp
pkg
spec/dummy
rspec.failures
.rvmrc
.idea
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ gem 'sqlite3'
gem 'pg'

group :test do
gem 'yarjuf'
gem 'require_all'
gem 'capybara'
gem 'capybara-screenshot'
gem 'poltergeist'
end

Expand Down
9 changes: 4 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ require 'rake'
require 'rake/testtask'
require 'rake/packagetask'
require 'rubygems/package_task'
require 'rspec/core/rake_task'
require 'spree/testing_support/extension_rake'

desc 'Generates a dummy app for testing'
task :test_app do
Expand All @@ -14,18 +12,19 @@ end

require 'rspec/core'
require 'rspec/core/rake_task'
Rake::Task["spec"].clear
require 'rspec-rerun'
require 'spree/testing_support/extension_rake'

RSpec::Core::RakeTask.new(:spec) do |t|
t.fail_on_error = false
t.rspec_opts = %w[-f JUnit -o results.xml]
end

desc "Run RSpec with code coverage"
task :coverage do
ENV['COVERAGE'] = 'true'
Rake::Task["spec"].execute
end
task :default => :spec
task :default => 'rspec-rerun:spec'


Bundler::GemHelper.install_tasks
98 changes: 74 additions & 24 deletions spec/features/paypal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,24 @@ def fill_in_billing
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")
unless page.has_selector?("#login #email")
find("#loadLogin").click
end
end

def login_to_paypal
within("#loginForm") do
fill_in "Email", :with => "[email protected]"
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

it "pays for an order successfully" do
visit spree.root_path
click_link 'iPad'
Expand All @@ -50,10 +63,8 @@ def switch_to_paypal_login
click_button "Save and Continue"
find("#paypal_button").click
switch_to_paypal_login
fill_in "login_email", :with => "[email protected]"
fill_in "login_password", :with => "thequickbrownfox"
click_button "Log In"
find("#continue_abovefold").click # Because there's TWO continue buttons.
login_to_paypal
click_button "Pay Now"
page.should have_content("Your order has been processed successfully")

Spree::Payment.last.source.transaction_id.should_not be_blank
Expand All @@ -79,16 +90,14 @@ def switch_to_paypal_login
click_button "Save and Continue"
find("#paypal_button").click

page.should have_selector '#billingInfo', text: 'Test User'
page.should have_selector '#billingInfo', text: '1 User Lane'
page.should have_selector '#billingInfo', text: 'Adamsville, AL 35005'
page.should have_selector '#billingInfo', text: 'United States'
page.should have_field 'email', with: '[email protected]'
login_to_paypal
click_button "Pay Now"

# PayPal arbitrarily removes or does not remove the hypenation in phone numbers,
# so our test needs to accept both cases
page.should have_field 'H_PhoneNumberUS'
page.find('#H_PhoneNumberUS').value.gsub('-', '').should == '5551234567'
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'
page.should have_selector '[data-hook=order-bill-address] .adr', text: 'United States'
page.should have_selector '[data-hook=order-bill-address] .tel', text: '555-123-4567'
end
end

Expand All @@ -115,7 +124,22 @@ def switch_to_paypal_login
# Delivery step doesn't require any action
click_button "Save and Continue"
find("#paypal_button").click
within("#miniCart") do

within_transaction_cart do
page.should have_content("$5 off")
page.should have_content("$10 on")
end

login_to_paypal

within_transaction_cart do
page.should have_content("$5 off")
page.should have_content("$10 on")
end

click_button "Pay Now"

within("[data-hook=order_details_adjustments]") do
page.should have_content("$5 off")
page.should have_content("$10 on")
end
Expand All @@ -127,7 +151,7 @@ def switch_to_paypal_login
calculator = Spree::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10)
action = Spree::Promotion::Actions::CreateItemAdjustments.create(:calculator => calculator)
promotion.actions << action
end
end

it "includes line item adjustments in PayPal summary" do

Expand All @@ -152,7 +176,15 @@ def switch_to_paypal_login
# Delivery step doesn't require any action
click_button "Save and Continue"
find("#paypal_button").click
within("#miniCart") do

within_transaction_cart do
page.should have_content("10% off")
end

login_to_paypal
click_button "Pay Now"

within("[data-hook=order_details_price_adjustments]") do
page.should have_content("10% off")
end
end
Expand Down Expand Up @@ -184,10 +216,25 @@ def switch_to_paypal_login
# Delivery step doesn't require any action
click_button "Save and Continue"
find("#paypal_button").click
within("#miniCart") do

within_transaction_cart do
page.should have_content('iPad')
page.should_not have_content('iPod')
end

login_to_paypal

within_transaction_cart do
page.should have_content('iPad')
page.should_not have_content('iPod')
end

click_button "Pay Now"

within("#line-items") do
page.should have_content('iPad')
page.should have_content('iPod')
end
end
end

Expand Down Expand Up @@ -216,8 +263,13 @@ def switch_to_paypal_login
# Delivery step doesn't require any action
click_button "Save and Continue"
find("#paypal_button").click
within("#miniCart") do
page.should have_content('Current purchase')

login_to_paypal

click_button "Pay Now"

within("[data-hook=order_details_adjustments]") do
page.should have_content('FREE iPad ZOMG!')
end
end
end
Expand Down Expand Up @@ -265,10 +317,8 @@ def switch_to_paypal_login
click_button "Save and Continue"
find("#paypal_button").click
switch_to_paypal_login
fill_in "login_email", :with => "[email protected]"
fill_in "login_password", :with => "thequickbrownfox"
click_button "Log In"
find("#continue_abovefold").click # Because there's TWO continue buttons.
login_to_paypal
click_button("Pay Now")
page.should have_content("Your order has been processed successfully")

visit '/admin'
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
require 'pry'
require 'capybara/rspec'
require 'capybara/rails'
require 'capybara-screenshot/rspec'

# To stop these warnings:
# WARN: tilt autoloading 'sass' in a non thread-safe way; explicit require 'sass' suggested.
Expand Down
3 changes: 2 additions & 1 deletion spree_paypal_express.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Gem::Specification.new do |s|
s.add_development_dependency 'database_cleaner', '1.0.1'
s.add_development_dependency 'factory_girl', '~> 4.2'
s.add_development_dependency 'ffaker'
s.add_development_dependency 'rspec-rails', '~> 2.13'
s.add_development_dependency 'rspec-rails', '~> 2.14.0'
s.add_development_dependency 'rspec-rerun'
s.add_development_dependency 'sass-rails', '~> 4.0.2'
s.add_development_dependency 'selenium-webdriver'
s.add_development_dependency 'simplecov'
Expand Down

0 comments on commit 8ce4366

Please sign in to comment.