effective_orders 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/effective_orders/version.rb +1 -1
- metadata +10 -258
- data/spec/controllers/admin/orders_controller_spec.rb +0 -243
- data/spec/controllers/carts_controller_spec.rb +0 -143
- data/spec/controllers/ccbill_orders_controller_spec.rb +0 -103
- data/spec/controllers/moneris_orders_controller_spec.rb +0 -133
- data/spec/controllers/orders_controller_spec.rb +0 -500
- data/spec/controllers/stripe_orders_controller_spec.rb +0 -128
- data/spec/controllers/webhooks_controller_spec.rb +0 -170
- data/spec/dummy/README.rdoc +0 -8
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/models/product.rb +0 -9
- data/spec/dummy/app/models/product_with_float_price.rb +0 -9
- data/spec/dummy/app/models/user.rb +0 -11
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -32
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -37
- data/spec/dummy/config/environments/production.rb +0 -80
- data/spec/dummy/config/environments/test.rb +0 -36
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/devise.rb +0 -254
- data/spec/dummy/config/initializers/effective_addresses.rb +0 -15
- data/spec/dummy/config/initializers/effective_orders.rb +0 -269
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/simple_form.rb +0 -189
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/routes.rb +0 -3
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/db/schema.rb +0 -158
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -164
- data/spec/dummy/log/test.log +0 -60
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/fixtures/stripe_webhooks/invoice.payment_succeeded.without_renewals.json +0 -76
- data/spec/helpers/effective_orders_helper_spec.rb +0 -21
- data/spec/models/acts_as_purchasable_spec.rb +0 -75
- data/spec/models/customer_spec.rb +0 -72
- data/spec/models/factories_spec.rb +0 -35
- data/spec/models/order_item_spec.rb +0 -35
- data/spec/models/order_spec.rb +0 -445
- data/spec/models/stripe_charge_spec.rb +0 -39
- data/spec/models/subscription_spec.rb +0 -103
- data/spec/spec_helper.rb +0 -46
- data/spec/support/factories.rb +0 -139
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# # Attributes
|
4
|
-
describe Effective::Providers::StripeCharge do
|
5
|
-
let(:order) { FactoryGirl.create(:order_with_subscription) }
|
6
|
-
let(:charge) { Effective::Providers::StripeCharge.new(order) }
|
7
|
-
|
8
|
-
before { StripeMock.start }
|
9
|
-
after { StripeMock.stop }
|
10
|
-
|
11
|
-
it 'can be initialized with an order' do
|
12
|
-
charge = Effective::Providers::StripeCharge.new(order)
|
13
|
-
charge.order.should eq order
|
14
|
-
charge.effective_order_id.should eq order.to_param
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'can be initialized without an order' do
|
18
|
-
charge = Effective::Providers::StripeCharge.new(:token => 'tok_123', :effective_order_id => 3)
|
19
|
-
charge.token.should eq 'tok_123'
|
20
|
-
charge.effective_order_id.should eq 3
|
21
|
-
charge.order.nil?.should eq true
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'performs validations' do
|
25
|
-
charge = Effective::Providers::StripeCharge.new()
|
26
|
-
charge.valid?.should eq false
|
27
|
-
charge.errors[:token].present?.should eq true
|
28
|
-
charge.errors[:effective_order_id].present?.should eq true
|
29
|
-
end
|
30
|
-
|
31
|
-
it '#order_items returns all OrderItems where the purchasable is not a Subscription' do
|
32
|
-
charge.order_items.all? { |oi| oi.purchasable_type != 'Effective::Subscription'}.should eq true
|
33
|
-
end
|
34
|
-
|
35
|
-
it '#subscriptions returns all Subscriptions (not order items)' do
|
36
|
-
charge.subscriptions.all? { |oi| oi.kind_of?(Effective::Subscription) }.should eq true
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# # Attributes
|
4
|
-
describe Effective::Subscription do
|
5
|
-
let(:subscription) { FactoryGirl.create(:subscription) }
|
6
|
-
|
7
|
-
before { StripeMock.start }
|
8
|
-
after { StripeMock.stop }
|
9
|
-
|
10
|
-
describe '#stripe_plan' do
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#stripe_plan_id=' do
|
15
|
-
it 'assigns the stripe_plan_id' do
|
16
|
-
subscription.stripe_plan_id = 'Plan 9'
|
17
|
-
subscription.stripe_plan_id.should eq 'Plan 9'
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'rejects an invalid stripe_plan' do
|
21
|
-
subscription.stripe_plan.present?.should eq true # From the Factory
|
22
|
-
|
23
|
-
subscription.stripe_plan_id = 'Plan 9' # Set it to an Invalid plan
|
24
|
-
subscription.stripe_plan_id.should eq 'Plan 9'
|
25
|
-
|
26
|
-
subscription.stripe_plan.should eq nil
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'sets the stripe plan' do
|
30
|
-
subscription = Effective::Subscription.new()
|
31
|
-
|
32
|
-
plan = ::Stripe::Plan.create(:id => 'stripe_plan', :name => 'Stripe Plan', :amount => 1000, :currency => 'USD', :interval => 'month')
|
33
|
-
subscription.stripe_plan_id = plan.id
|
34
|
-
subscription.stripe_plan.id.should eq plan.id
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '#stripe_coupon_id=' do
|
39
|
-
it 'assigns the stripe_coupon_id' do
|
40
|
-
subscription.stripe_coupon_id = 'Plan 9'
|
41
|
-
subscription.stripe_coupon_id.should eq 'Plan 9'
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'rejects an invalid stripe_coupon' do
|
45
|
-
subscription.stripe_coupon.present?.should eq true # From the Factory
|
46
|
-
|
47
|
-
subscription.stripe_coupon_id = 'Plan 9' # Set it to an Invalid plan
|
48
|
-
subscription.stripe_coupon_id.should eq 'Plan 9'
|
49
|
-
|
50
|
-
subscription.stripe_coupon.should eq nil
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'sets the stripe coupon' do
|
54
|
-
subscription = Effective::Subscription.new()
|
55
|
-
|
56
|
-
coupon = FactoryGirl.create(:stripe_coupon)
|
57
|
-
subscription.stripe_coupon_id = coupon.id
|
58
|
-
subscription.stripe_coupon.id.should eq coupon.id
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe '#assign_price_and_title' do
|
63
|
-
it 'assigns the price and title as per the stripe plan and coupon' do
|
64
|
-
subscription = Effective::Subscription.new()
|
65
|
-
|
66
|
-
plan = ::Stripe::Plan.create(:id => 'stripe_plan', :name => 'Stripe Plan', :amount => 1000, :currency => 'USD', :interval => 'month')
|
67
|
-
|
68
|
-
subscription.stripe_plan_id = plan.id
|
69
|
-
|
70
|
-
subscription.price.should eq plan.amount
|
71
|
-
subscription.title.include?(plan.name).should eq true
|
72
|
-
subscription.title.include?(plan.interval).should eq true
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'assigns the price and title as per the stripe plan and coupon amount off' do
|
76
|
-
subscription = Effective::Subscription.new()
|
77
|
-
|
78
|
-
plan = ::Stripe::Plan.create(:id => 'stripe_plan', :name => 'Stripe Plan', :amount => 1000, :currency => 'USD', :interval => 'month')
|
79
|
-
coupon = FactoryGirl.create(:stripe_coupon, :percent_off => 25)
|
80
|
-
|
81
|
-
subscription.stripe_plan_id = plan.id
|
82
|
-
subscription.stripe_coupon_id = coupon.id
|
83
|
-
|
84
|
-
subscription.price.should eq (plan.amount * (coupon.percent_off.to_i / 100.0)).round(0).to_i
|
85
|
-
subscription.title.include?('25% off').should eq true
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'assigns the price and title as per the stripe plan and coupon percent off' do
|
89
|
-
subscription = Effective::Subscription.new()
|
90
|
-
|
91
|
-
plan = ::Stripe::Plan.create(:id => 'stripe_plan', :name => 'Stripe Plan', :amount => 1000, :currency => 'USD', :interval => 'month')
|
92
|
-
coupon = FactoryGirl.create(:stripe_coupon, :percent_off => nil, :amount_off => 100)
|
93
|
-
|
94
|
-
subscription.stripe_plan_id = plan.id
|
95
|
-
subscription.stripe_coupon_id = coupon.id
|
96
|
-
|
97
|
-
subscription.price.should eq plan.amount - coupon.amount_off
|
98
|
-
subscription.title.include?('$1.00 off').should eq true
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
ENV["RAILS_ENV"] ||= 'test'
|
2
|
-
|
3
|
-
require File.expand_path("../dummy/config/environment", __FILE__)
|
4
|
-
|
5
|
-
require 'rspec/rails'
|
6
|
-
require 'factory_girl_rails'
|
7
|
-
require 'stripe_mock'
|
8
|
-
require 'pry'
|
9
|
-
require 'shoulda-matchers'
|
10
|
-
|
11
|
-
# Requires supporting ruby files with custom matchers and macros, etc,
|
12
|
-
# in spec/support/ and its subdirectories.
|
13
|
-
Dir[Rails.root.join("../../spec/support/**/*.rb")].each {|f| require f }
|
14
|
-
|
15
|
-
RSpec.configure do |config|
|
16
|
-
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
17
|
-
|
18
|
-
config.include Devise::Test::ControllerHelpers, :type => :controller
|
19
|
-
config.include Shoulda::Matchers::ActiveModel, :type => :model
|
20
|
-
|
21
|
-
Rails.logger.level = 4 # Output only minimal stuff to test.log
|
22
|
-
|
23
|
-
config.use_transactional_fixtures = true # Make this false to once again use DatabaseCleaner
|
24
|
-
config.order = 'random'
|
25
|
-
end
|
26
|
-
|
27
|
-
class ActiveRecord::Base
|
28
|
-
mattr_accessor :shared_connection
|
29
|
-
@@shared_connection = nil
|
30
|
-
|
31
|
-
def self.connection
|
32
|
-
@@shared_connection || retrieve_connection
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# Forces all threads to share the same connection. This works on
|
37
|
-
# Capybara because it starts the web server in a thread.
|
38
|
-
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
|
39
|
-
|
40
|
-
|
41
|
-
# To set up this gem for testing:
|
42
|
-
# spec/dummy> ln -s ../../spec spec
|
43
|
-
#
|
44
|
-
# spec/dummy> rails generate effective_orders:install
|
45
|
-
# spec/dummy> rake db:migrate
|
46
|
-
# spec/dummy> rake db:test:prepare
|
data/spec/support/factories.rb
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
require 'factory_girl'
|
2
|
-
|
3
|
-
FactoryGirl.define do
|
4
|
-
factory :address, class: Effective::Address do
|
5
|
-
category 'billing'
|
6
|
-
full_name 'Peter Pan'
|
7
|
-
sequence(:address1) { |n| "1234#{n} Fake Street" }
|
8
|
-
city 'A canadian city'
|
9
|
-
state_code ['AB', 'BC', 'MB', 'NB', 'NL', 'NT', 'NS', 'ON', 'PE', 'QC', 'SK', 'YT', 'NU'].sample
|
10
|
-
country_code 'CA'
|
11
|
-
postal_code 'T5T2T1'
|
12
|
-
end
|
13
|
-
|
14
|
-
factory :product do # This only exists in the dummy/ app
|
15
|
-
sequence(:title) { |n| "Product #{n}" }
|
16
|
-
|
17
|
-
price 1000
|
18
|
-
tax_exempt false
|
19
|
-
end
|
20
|
-
|
21
|
-
factory :product_with_float_price do # This only exists in the dummy/ app
|
22
|
-
sequence(:title) { |n| "Product #{n}" }
|
23
|
-
|
24
|
-
price 10.00
|
25
|
-
tax_exempt false
|
26
|
-
end
|
27
|
-
|
28
|
-
factory :user do # This only exists in the dummy/ app
|
29
|
-
sequence(:email) { |n| "user_#{n}@effective_orders.test"}
|
30
|
-
|
31
|
-
password '12345678'
|
32
|
-
|
33
|
-
after(:build) { |user| user.skip_confirmation! if user.respond_to?(:skip_confirmation!) }
|
34
|
-
end
|
35
|
-
|
36
|
-
factory :customer, class: Effective::Customer do
|
37
|
-
association :user
|
38
|
-
end
|
39
|
-
|
40
|
-
factory :subscription, class: Effective::Subscription do
|
41
|
-
association :customer
|
42
|
-
|
43
|
-
before(:create) do |subscription|
|
44
|
-
stripe_plan = Stripe::Plan.create(id: "stripe_plan_#{subscription.object_id}", name: 'Stripe Plan', amount: 1000, currency: 'USD', interval: 'month')
|
45
|
-
stripe_coupon = FactoryGirl.create(:stripe_coupon)
|
46
|
-
|
47
|
-
subscription.stripe_plan_id = stripe_plan.id
|
48
|
-
subscription.stripe_coupon_id = stripe_coupon.id
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
factory :cart, class: Effective::Cart do
|
53
|
-
association :user
|
54
|
-
cart_items_count 0
|
55
|
-
|
56
|
-
before(:create) do |cart|
|
57
|
-
3.times { cart.cart_items << FactoryGirl.build(:cart_item, cart: cart) }
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
factory :cart_item, class: Effective::CartItem do
|
62
|
-
association :purchasable, factory: :product
|
63
|
-
association :cart, factory: :cart
|
64
|
-
|
65
|
-
quantity 1
|
66
|
-
end
|
67
|
-
|
68
|
-
factory :cart_with_subscription, class: Effective::Cart do
|
69
|
-
association :user
|
70
|
-
|
71
|
-
before(:create) do |cart|
|
72
|
-
cart.cart_items << FactoryGirl.create(:cart_item, cart: cart)
|
73
|
-
cart.cart_items << FactoryGirl.create(:cart_item, cart: cart, purchasable: FactoryGirl.create(:subscription))
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
factory :cart_with_items, class: Effective::Cart do
|
78
|
-
association :user
|
79
|
-
|
80
|
-
before(:create) do |cart|
|
81
|
-
3.times { cart.cart_items << FactoryGirl.create(:cart_item, cart: cart) }
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
factory :order, class: Effective::Order do
|
86
|
-
association :user
|
87
|
-
|
88
|
-
before(:create) do |order|
|
89
|
-
order.billing_address = FactoryGirl.build(:address, addressable: order)
|
90
|
-
order.shipping_address = FactoryGirl.build(:address, addressable: order)
|
91
|
-
|
92
|
-
3.times { order.order_items << FactoryGirl.create(:order_item, order: order) }
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
factory :order_with_subscription, class: Effective::Order do
|
97
|
-
association :user
|
98
|
-
|
99
|
-
before(:create) do |order|
|
100
|
-
order.billing_address = FactoryGirl.build(:address, addressable: order)
|
101
|
-
order.shipping_address = FactoryGirl.build(:address, addressable: order)
|
102
|
-
|
103
|
-
order.order_items << FactoryGirl.create(:order_item, order: order)
|
104
|
-
order.order_items << FactoryGirl.create(:order_item, purchasable: FactoryGirl.create(:subscription), order: order)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
factory :order_item, class: Effective::OrderItem do
|
109
|
-
association :purchasable, factory: :product
|
110
|
-
association :order, factory: :order
|
111
|
-
|
112
|
-
sequence(:title) { |n| "Order Item #{n}" }
|
113
|
-
quantity 1
|
114
|
-
price 1000
|
115
|
-
tax_exempt false
|
116
|
-
end
|
117
|
-
|
118
|
-
factory :purchased_order, parent: :order do
|
119
|
-
payment_provider 'admin'
|
120
|
-
payment_card 'unknown'
|
121
|
-
|
122
|
-
after(:create) { |order| order.purchase! }
|
123
|
-
end
|
124
|
-
|
125
|
-
factory :declined_order, parent: :order do
|
126
|
-
payment_provider 'admin'
|
127
|
-
|
128
|
-
after(:create) { |order| order.decline! }
|
129
|
-
end
|
130
|
-
|
131
|
-
factory :pending_order, parent: :order do
|
132
|
-
purchase_state 'pending'
|
133
|
-
end
|
134
|
-
|
135
|
-
factory :stripe_coupon, class: Stripe::Coupon do
|
136
|
-
to_create {|c| c.save}
|
137
|
-
duration 'once'
|
138
|
-
end
|
139
|
-
end
|