Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 0 updates #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
source 'https://rubygems.org'

gem 'spree', '~> 1.2.0'
gem 'spree_auth_devise', '~> 1.2.0'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', "~> 3.2"
gem 'coffee-rails', "~> 3.2"
end
gem 'spree', github: 'spree/spree', branch: '2-0-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-0-stable'

gemspec
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require 'rake/testtask'
require 'rake/packagetask'
require 'rubygems/package_task'
require 'rspec/core/rake_task'
require 'spree/core/testing_support/common_rake'
require 'spree/testing_support/common_rake'

RSpec::Core::RakeTask.new

Expand Down
3 changes: 2 additions & 1 deletion Versionfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# "1.2.x" => { :branch => "master"}
"2.0.x" => { :branch => "master"}
"1.2.x" => { :ref => "a459bf2098c40855c35ffd786fc12fc2983bf7aa" }
"1.1.x" => { :branch => "spree-1-1-stable"}
"1.0.x" => { :branch => "spree-1-0-stable"}
"0.70.x" => { :branch => "spree-0-70-stable"}
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/store/spree_reuse_credit_card.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $(document).on('click', '#use_existing_card_no', function () {

$("[data-hook=card_number]").show();
$("[data-hook=card_expiration]").show();
$("[data-hook=cart_code]").show(); // unfortunately this is a typo in spree (cart v card)
$("[data-hook=card_code]").show();

restoreContinueButton();

Expand Down Expand Up @@ -97,7 +97,7 @@ function useExistingCardsInit() {

$("[data-hook=card_number]").hide();
$("[data-hook=card_expiration]").hide();
$("[data-hook=cart_code]").hide(); // unfortunately this is a typo in spree (cart v card)
$("[data-hook=card_code]").hide();

disableContinueButton();
}
Expand Down
4 changes: 2 additions & 2 deletions app/views/spree/checkout/payment/_existing_cards.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= content_for :head do %>
<%= javascript_tag do -%>
<%== "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %>
var original_button_text = "<%= t(:save_and_continue) %>";
var original_button_text = "<%= Spree.t(:save_and_continue) %>";
<% end -%>
<% end %>

Expand Down Expand Up @@ -50,7 +50,7 @@
<td><%= card.year %></td>
<td><%= radio_button_tag "existing_card", card.id, (@cards.size ==1) %></td> <%# if we only have 1 saved card, autoselect %>
<td>
<%= link_to (image_tag("admin/icons/delete.png") + t(:delete)),
<%= link_to Spree.t(:delete),
spree.credit_card_url(card),
:remote => true, :method => :delete,
:confirm => 'Are you sure?' %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/spree/users/_card_admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<div id='card_notice'></div>

<h2>Credit Cards on File</h2>
<h3>Credit Cards on File</h3>

<p class="field">
<table class="existing-credit-card-list" style="width:545px;">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module SpreeReuseCreditCard
module Generators
class InstallGenerator < Rails::Generators::Base
class_option :auto_run_migrations, :type => :boolean, :default => false

def add_javascripts
append_file "app/assets/javascripts/store/all.js", "//= require store/spree_reuse_credit_card\n"
Expand All @@ -17,12 +18,12 @@ def add_migrations
end

def run_migrations
res = ask "Would you like to run the migrations now? [Y/n]"
if res == "" || res.downcase == "y"
run 'bundle exec rake db:migrate'
else
puts "Skipping rake db:migrate, don't forget to run it!"
end
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
if run_migrations
run 'bundle exec rake db:migrate'
else
puts 'Skipping rake db:migrate, don\'t forget to run it!'
end
end
end
end
Expand Down
39 changes: 8 additions & 31 deletions spec/factories/order_factory.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,22 @@
FactoryGirl.define do

factory :order_in_address_state, :parent => :order do
after_build { |order|
order.line_items << Factory(:line_item, :order => order)
after(:build) { |order|
order.line_items << FactoryGirl.create(:line_item)
}

after_create { |order|
after(:create) { |order|
order.next!
}
end

factory :order_in_delivery_state, :parent => :order_in_address_state do
after_create { |order| order.next! }
end

factory :order_in_payment_state, :parent => :order_in_delivery_state do
after_create { |order|
order.next!
}
end

factory :order_in_confirm_state, :parent => :order_in_payment_state do
after_create do |order|
after(:create) { |order|
create(:state, :country => create(:country))
create(:shipping_method)
create(:stock_location)
order.next!
end
end

factory :order_in_complete_state, :parent => :order_in_confirm_state do
after_create { |order| order.next! && order.finalize! }
}
end



# factory :order_in_payment_state, :parent => :order do
# after_create { |order|
# # order.line_items << Factory(:line_item, :order => order)
#
# order.next!
# order.next!
# order.next!
#
# }
# end
end
95 changes: 60 additions & 35 deletions spec/features/pay_with_credit_cards_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
require 'spec_helper'

describe "PayWithCreditCards" do
describe "PayWithCreditCards", :js => true do

describe "GET /checkout/payment" do

let (:user) { Factory(:user) }

before(:each) do
@bogus_payment_method = Factory(:bogus_payment_method, :display_on => :front_end)
Factory(:payment_method, :display_on => :front_end)
let!(:country) { create(:country) }
let!(:state) { create(:state, :country => country) }
let!(:shipping_method) { create(:shipping_method) }
let!(:stock_location) { create(:stock_location) }
let!(:mug) { create(:product, :name => "RoR Mug") }
let (:user) { create(:user) }

shipping_method = Factory(:shipping_method)
Spree::ShippingMethod.stub(:all_available) { [shipping_method] }
before(:each) do
@bogus_payment_method = create(:bogus_payment_method, :display_on => :front_end)
create(:payment_method, :display_on => :front_end)

sign_in_as!(user)
end
Expand All @@ -19,10 +22,6 @@
subject { page }

before do
Factory(:product)
Factory(:country)
Factory(:state)

Spree::CreditCard.all.map(&:destroy)

visit spree.products_path
Expand Down Expand Up @@ -79,31 +78,57 @@
context "existing cards" do
before(:each) do

# set up existing payments with this credit card
@credit_card = Factory(:credit_card, :gateway_payment_profile_id => 'FAKE_GATEWAY_ID')
# # set up existing payments with this credit card
# @credit_card = create(:credit_card, :gateway_payment_profile_id => 'FAKE_GATEWAY_ID')
#
# order = create(:order_in_delivery_state, :user => user)
# order.update! # set order.total
#
# # go to payment state
# order.next
# order.state.should eq('payment')
#
# # add a payment
# payment = create(:payment, :order => order, :source => @credit_card, :amount => order.total, :payment_method => @bogus_payment_method)
#
# # go to confirm
# order.next
# order.state.should eq('confirm')
#
# # go to complete
# order.next
# order.state.should eq('complete')
#
# # capture payment
# order.payment.capture!
# order.update!
# order.should_not be_outstanding_balance

order = Factory(:order_in_delivery_state, :user => user)
order.update! # set order.total
visit spree.products_path

# go to payment state
order.next
order.state.should eq('payment')
find(:xpath, "//div[@class='product-image']/a").click
click_button 'Add To Cart'
click_button 'Checkout'
fill_in 'order_bill_address_attributes_firstname', :with => 'Jeff'
fill_in 'order_bill_address_attributes_lastname', :with => 'Squires'
fill_in 'order_bill_address_attributes_address1', :with => '123 Foo St'
fill_in 'order_bill_address_attributes_city', :with => 'Fooville'
select 'Alabama', :from => 'order_bill_address_attributes_state_id'
fill_in 'order_bill_address_attributes_zipcode', :with => '12345'
fill_in 'order_bill_address_attributes_phone', :with => '123-123-1234'
check "Use Billing Address"

# add a payment
payment = Factory(:payment, :order => order, :source => @credit_card, :amount => order.total, :payment_method => @bogus_payment_method)
click_button 'Save and Continue'
click_button "Save and Continue"

# go to confirm
order.next
order.state.should eq('confirm')
fill_in "Card Number", :with => '4111111111111111'
fill_in "Card Code", :with => '111'

# go to complete
order.next
order.state.should eq('complete')
click_button "Save and Continue"
click_button "Place Order"
page.should have_content('Your order has been processed successfully')

# capture payment
order.payment.capture!
order.update!
order.should_not be_outstanding_balance
@credit_card = Spree::Payment.last.source
end

it "allows an existing credit card to be chosen from list and used for a purchase" do
Expand All @@ -116,8 +141,7 @@
fill_in 'order_bill_address_attributes_lastname', :with => 'Squires'
fill_in 'order_bill_address_attributes_address1', :with => '123 Foo St'
fill_in 'order_bill_address_attributes_city', :with => 'Fooville'
fill_in 'order_bill_address_attributes_state_name',:with => 'Alabama'

select 'Alabama', :from => 'order_bill_address_attributes_state_id'
fill_in 'order_bill_address_attributes_zipcode', :with => '12345'
fill_in 'order_bill_address_attributes_phone', :with => '123-123-1234'
check "Use Billing Address"
Expand All @@ -126,15 +150,16 @@

click_button 'Save and Continue'

page.should have_xpath("//table[@class='existing-credit-card-list']/tbody/tr", :text => @credit_card.last_digits) #, :count => x)
sleep 10
page.should have_xpath("//table[@class='existing-credit-card-list']/tbody/tr", :text => @credit_card.last_digits)
choose 'existing_card'

click_button 'Save and Continue'

page.should have_content "Ending in #{@credit_card.last_digits}"
end

it 'allows selecting a different payment method', :js => true do
it 'allows selecting a different payment method' do
visit spree.products_path

find(:xpath, "//div[@class='product-image']/a").click
Expand Down
14 changes: 7 additions & 7 deletions spec/lib/card_reuse_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@
end

context 'with a valid user' do
let(:user) { mock(:user) }
let(:user) { double(:user) }

context 'with payments' do
let(:reuseable_source) {
mock(:reuseable_source).tap do |source|
double(:reuseable_source).tap do |source|
fixture.stub(:valid_for_reuse?).with(source).and_return(true)
end
}

let(:non_reuseable_source) {
mock(:non_reuseable_source).tap do |source|
double(:non_reuseable_source).tap do |source|
fixture.stub(:valid_for_reuse?).with(source).and_return(false)
end
}

let(:first_reusable_payment) {
mock(:first_reusable_payment).tap do |payment|
double(:first_reusable_payment).tap do |payment|
payment.stub(:source).and_return(reuseable_source)
end
}

let(:second_reusable_payment) {
mock(:second_reusable_payment).tap do |payment|
double(:second_reusable_payment).tap do |payment|
payment.stub(:source).and_return(reuseable_source)
end
}

let(:non_reusable_payment) {
mock(:non_reusable_payment).tap do |payment|
double(:non_reusable_payment).tap do |payment|
payment.stub(:source).and_return(non_reuseable_source)
end
}
Expand Down Expand Up @@ -74,7 +74,7 @@

describe '#valid_for_resuse' do
let(:source) {
mock(:source).tap do |s|
double(:source).tap do |s|
s.stub(:gateway_payment_profile_id).and_return('gateway_payment_profile_id')
s.stub(:gateway_customer_profile_id).and_return('gateway_customer_profile_id')
s.stub(:deleted?).and_return(false)
Expand Down
11 changes: 5 additions & 6 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require File.expand_path("../dummy/config/environment.rb", __FILE__)
require 'rspec/rails'
require 'database_cleaner'
require 'spree/core/url_helpers'
require 'ffaker'

require 'factory_girl'
Expand All @@ -18,9 +17,9 @@
# in spec/support/ and its subdirectories.
Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f }

require 'spree/core/testing_support/fixtures'
require 'spree/core/testing_support/factories'
require 'spree/core/testing_support/controller_requests'
require 'spree/testing_support/factories'
require 'spree/testing_support/controller_requests'
require 'spree/testing_support/url_helpers'

RSpec.configure do |config|
# ## Mock Framework
Expand All @@ -41,8 +40,8 @@
config.use_transactional_fixtures = false

config.include FactoryGirl::Syntax::Methods
config.include Spree::Core::UrlHelpers
config.include Spree::Core::TestingSupport::ControllerRequests, :type => :controller
config.include Spree::TestingSupport::UrlHelpers
config.include Spree::TestingSupport::ControllerRequests, :type => :controller
config.include Devise::TestHelpers, :type => :controller
config.include Rack::Test::Methods, :type => :requests
end
Loading