Skip to content

Commit

Permalink
DRY up specs
Browse files Browse the repository at this point in the history
  • Loading branch information
alepore committed Jul 3, 2015
1 parent f21c708 commit 45640c5
Showing 1 changed file with 51 additions and 63 deletions.
114 changes: 51 additions & 63 deletions spec/features/paypal_spec.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
describe "PayPal", :js => true do
let!(:product) { FactoryGirl.create(:product, :name => 'iPad') }
describe "PayPal", js: true do
let!(:product) { FactoryGirl.create(:product, name: 'iPad') }

before do
@gateway = Spree::Gateway::PayPalExpress.create!({
:preferred_login => "pp_api1.ryanbigg.com",
:preferred_password => "1383066713",
:preferred_signature => "An5ns1Kso7MWUdW4ErQKJJJ4qi4-Ar-LpzhMJL0cu8TjM8Z2e1ykVg5B",
:name => "PayPal",
:active => true
preferred_login: "pp_api1.ryanbigg.com",
preferred_password: "1383066713",
preferred_signature: "An5ns1Kso7MWUdW4ErQKJJJ4qi4-Ar-LpzhMJL0cu8TjM8Z2e1ykVg5B",
name: "PayPal",
active: true
})
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
fill_in :order_bill_address_attributes_firstname, with: "Test"
fill_in :order_bill_address_attributes_lastname, with: "User"
fill_in :order_bill_address_attributes_address1, with: "1 User Lane"
# City, State and ZIP must all match for PayPal to be happy
fill_in :order_bill_address_attributes_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 :order_bill_address_attributes_zipcode, with: "35005"
fill_in :order_bill_address_attributes_phone, with: "555-123-4567"
end

def switch_to_paypal_login
Expand All @@ -36,8 +34,8 @@ def switch_to_paypal_login

def login_to_paypal
within("#loginForm") do
fill_in "Email", :with => "[email protected]"
fill_in "Password", :with => "thequickbrownfox"
fill_in "Email", with: "[email protected]"
fill_in "Password", with: "thequickbrownfox"
click_button "Log in to PayPal"
end
end
Expand All @@ -47,15 +45,23 @@ def within_transaction_cart(&block)
within(".transctionCartDetails") { block.call }
end

xit "pays for an order successfully" do
def add_to_cart(product)
visit spree.root_path
click_link 'iPad'
click_link product.name
click_button 'Add To Cart'
click_button 'Checkout'
end

def fill_in_guest
within("#guest_checkout") do
fill_in "Email", :with => "[email protected]"
fill_in "Email", with: "[email protected]"
click_button 'Continue'
end
end

xit "pays for an order successfully" do
add_to_cart(product)
click_button 'Checkout'
fill_in_guest
fill_in_billing
click_button "Save and Continue"
# Delivery step doesn't require any action
Expand All @@ -75,12 +81,10 @@ def within_transaction_cart(&block)
end

xit "passes user details to PayPal" do
visit spree.root_path
click_link 'iPad'
click_button 'Add To Cart'
add_to_cart(product)
click_button 'Checkout'
within("#guest_checkout") do
fill_in "Email", :with => "[email protected]"
fill_in "Email", with: "[email protected]"
click_button 'Continue'
end
fill_in_billing
Expand All @@ -101,23 +105,18 @@ def within_transaction_cart(&block)
end

xit "includes adjustments in PayPal summary" do
visit spree.root_path
click_link 'iPad'
click_button 'Add To Cart'
add_to_cart(product)
# TODO: Is there a better way to find this current order?
order = Spree::Order.last
order.adjustments.create!(:amount => -5, :label => "$5 off")
order.adjustments.create!(:amount => 10, :label => "$10 on")
order.adjustments.create!(amount: -5, label: "$5 off")
order.adjustments.create!(amount: 10, label: "$10 on")
visit '/cart'
within("#cart_adjustments") do
page.should have_content("$5 off")
page.should have_content("$10 on")
end
click_button 'Checkout'
within("#guest_checkout") do
fill_in "Email", :with => "[email protected]"
click_button 'Continue'
end
fill_in_guest
fill_in_billing
click_button "Save and Continue"
# Delivery step doesn't require any action
Expand Down Expand Up @@ -148,14 +147,12 @@ def within_transaction_cart(&block)
let(:promotion) { Spree::Promotion.create(name: "10% off") }
before do
calculator = Spree::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10)
action = Spree::Promotion::Actions::CreateItemAdjustments.create(:calculator => calculator)
action = Spree::Promotion::Actions::CreateItemAdjustments.create(calculator: calculator)
promotion.actions << action
end

xit "includes line item adjustments in PayPal summary" do
visit spree.root_path
click_link 'iPad'
click_button 'Add To Cart'
add_to_cart(product)
# TODO: Is there a better way to find this current order?
order = Spree::Order.last
order.line_item_adjustments.count.should == 1
Expand All @@ -166,7 +163,7 @@ def within_transaction_cart(&block)
end
click_button 'Checkout'
within("#guest_checkout") do
fill_in "Email", :with => "[email protected]"
fill_in "Email", with: "[email protected]"
click_button 'Continue'
end
fill_in_billing
Expand All @@ -190,23 +187,18 @@ def within_transaction_cart(&block)

# Regression test for #10
context "will skip $0 items" do
let!(:product2) { FactoryGirl.create(:product, :name => 'iPod') }
let!(:product2) { FactoryGirl.create(:product, name: 'iPod') }

xit 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_to_cart(product)
add_to_cart(product2)

# TODO: Is there a better way to find this current order?
order = Spree::Order.last
order.line_items.last.update_attribute(:price, 0)
click_button 'Checkout'
within("#guest_checkout") do
fill_in "Email", :with => "[email protected]"
fill_in "Email", with: "[email protected]"
click_button 'Continue'
end
fill_in_billing
Expand Down Expand Up @@ -245,15 +237,13 @@ def within_transaction_cart(&block)
end

xit do
visit spree.root_path
click_link 'iPad'
click_button 'Add To Cart'
add_to_cart(product)
# 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!")
order.adjustments.create!(amount: -order.line_items.last.price, label: "FREE iPad ZOMG!")
click_button 'Checkout'
within("#guest_checkout") do
fill_in "Email", :with => "[email protected]"
fill_in "Email", with: "[email protected]"
click_button 'Continue'
end
fill_in_billing
Expand All @@ -279,12 +269,10 @@ def within_transaction_cart(&block)
end

specify do
visit spree.root_path
click_link 'iPad'
click_button 'Add To Cart'
add_to_cart(product)
click_button 'Checkout'
within("#guest_checkout") do
fill_in "Email", :with => "[email protected]"
fill_in "Email", with: "[email protected]"
click_button 'Continue'
end
fill_in_billing
Expand All @@ -306,7 +294,7 @@ def within_transaction_cart(&block)
click_button 'Add To Cart'
click_button 'Checkout'
within("#guest_checkout") do
fill_in "Email", :with => "[email protected]"
fill_in "Email", with: "[email protected]"
click_button 'Continue'
end
fill_in_billing
Expand Down Expand Up @@ -346,7 +334,7 @@ def within_transaction_cart(&block)
xit "can refund payments partially" do
payment = Spree::Payment.last
# Take a dollar off, which should cause refund type to be...
fill_in "Amount", :with => payment.amount - 1
fill_in "Amount", with: payment.amount - 1
click_button "Refund"
page.should have_content("PayPal refund successful")

Expand All @@ -359,7 +347,7 @@ def within_transaction_cart(&block)
end

xit "errors when given an invalid refund amount" do
fill_in "Amount", :with => "lol"
fill_in "Amount", with: "lol"
click_button "Refund"
page.should have_content("PayPal refund unsuccessful (The partial refund amount is not valid)")
end
Expand Down

0 comments on commit 45640c5

Please sign in to comment.