saasaparilla 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/Gemfile +36 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +39 -0
- data/app/controllers/saasaparilla/admin/plans_controller.rb +87 -0
- data/app/controllers/saasaparilla/admin/subscriptions_controller.rb +34 -0
- data/app/controllers/saasaparilla/admin/transactions_controller.rb +14 -0
- data/app/controllers/saasaparilla/application_controller.rb +4 -0
- data/app/controllers/saasaparilla/billing_history_controller.rb +9 -0
- data/app/controllers/saasaparilla/contact_info_controller.rb +31 -0
- data/app/controllers/saasaparilla/credit_card_controller.rb +41 -0
- data/app/controllers/saasaparilla/invoices_controller.rb +19 -0
- data/app/controllers/saasaparilla/payments_controller.rb +71 -0
- data/app/controllers/saasaparilla/plans_controller.rb +34 -0
- data/app/controllers/saasaparilla/subscription_controller.rb +71 -0
- data/app/helpers/application_helper.rb +3 -0
- data/app/helpers/plans_helper.rb +2 -0
- data/app/helpers/saasaparilla/billing_history_helper.rb +4 -0
- data/app/mailers/saasaparilla/notifier.rb +38 -0
- data/app/models/billing_activity.rb +12 -0
- data/app/models/contact_info.rb +107 -0
- data/app/models/credit_card.rb +109 -0
- data/app/models/invoice.rb +31 -0
- data/app/models/invoice_line_item.rb +3 -0
- data/app/models/payment.rb +39 -0
- data/app/models/plan.rb +36 -0
- data/app/models/subscription.rb +363 -0
- data/app/models/transaction.rb +32 -0
- data/app/views/layouts/saasaparilla.html.haml +9 -0
- data/app/views/saasaparilla/admin/plans/_form.html.haml +45 -0
- data/app/views/saasaparilla/admin/plans/edit.html.erb +4 -0
- data/app/views/saasaparilla/admin/plans/index.html.erb +31 -0
- data/app/views/saasaparilla/admin/plans/new.html.haml +4 -0
- data/app/views/saasaparilla/admin/plans/show.html.haml +20 -0
- data/app/views/saasaparilla/admin/subscriptions/_subscription.html.haml +7 -0
- data/app/views/saasaparilla/admin/subscriptions/index.html.haml +14 -0
- data/app/views/saasaparilla/admin/subscriptions/show.html.haml +52 -0
- data/app/views/saasaparilla/admin/transactions/_transaction.html.haml +6 -0
- data/app/views/saasaparilla/admin/transactions/index.html.haml +16 -0
- data/app/views/saasaparilla/billing_history/_billing_activity.html.haml +10 -0
- data/app/views/saasaparilla/billing_history/show.html.haml +11 -0
- data/app/views/saasaparilla/contact_info/edit.html.haml +8 -0
- data/app/views/saasaparilla/credit_card/edit.html.haml +18 -0
- data/app/views/saasaparilla/invoices/show.html.haml +17 -0
- data/app/views/saasaparilla/notifier/billing_failed.html.haml +5 -0
- data/app/views/saasaparilla/notifier/billing_successful.html.haml +5 -0
- data/app/views/saasaparilla/notifier/invoice_created.html.haml +24 -0
- data/app/views/saasaparilla/notifier/pending_cancellation_notice.html.haml +6 -0
- data/app/views/saasaparilla/notifier/subscription_canceled.html.haml +4 -0
- data/app/views/saasaparilla/notifier/subscription_created.html.haml +5 -0
- data/app/views/saasaparilla/payments/edit.html.haml +10 -0
- data/app/views/saasaparilla/payments/new.html.haml +10 -0
- data/app/views/saasaparilla/payments/show.html.haml +8 -0
- data/app/views/saasaparilla/plans/edit.html.haml +34 -0
- data/app/views/saasaparilla/subscription/_contact_info_form.html.haml +19 -0
- data/app/views/saasaparilla/subscription/_credit_card_form.html.haml +10 -0
- data/app/views/saasaparilla/subscription/new.html.haml +24 -0
- data/app/views/saasaparilla/subscription/show.html.haml +73 -0
- data/autotest/discover.rb +2 -0
- data/config/routes.rb +27 -0
- data/lib/country_select/MIT-LICENSE +20 -0
- data/lib/country_select/README +15 -0
- data/lib/country_select/init.rb +1 -0
- data/lib/country_select/install.rb +2 -0
- data/lib/country_select/lib/country_select.rb +88 -0
- data/lib/country_select/uninstall.rb +1 -0
- data/lib/extensions/action_controller/base.rb +7 -0
- data/lib/extensions/active_record/nested_attributes.rb +36 -0
- data/lib/extensions/active_record/statuses.rb +16 -0
- data/lib/extensions/billable.rb +12 -0
- data/lib/generators/saasaparilla/install/install_generator.rb +29 -0
- data/lib/generators/saasaparilla/install/templates/create_saasaparilla_tables.rb +106 -0
- data/lib/generators/saasaparilla/install/templates/saasaparilla.yml +32 -0
- data/lib/initializers/auth_dot_net.rb +25 -0
- data/lib/initializers/simple_form.rb +77 -0
- data/lib/initializers/time_format.rb +3 -0
- data/lib/saasaparilla.rb +16 -0
- data/lib/saasaparilla/authentication.rb +18 -0
- data/lib/saasaparilla/authorization.rb +26 -0
- data/lib/saasaparilla/engine.rb +30 -0
- data/lib/saasaparilla/version.rb +3 -0
- data/saasaparilla.gemspec +48 -0
- data/spec/.livereload +21 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +11 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/model/user.rb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +46 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/simple_form.rb +77 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/locales/simple_form.en.yml +24 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/config/saasaparilla.yml +32 -0
- data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/index.html +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/jquery.js +8374 -0
- data/spec/dummy/public/javascripts/jquery.min.js +16 -0
- data/spec/dummy/public/javascripts/rails.js +159 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/MIT-LICENSE +20 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/README +32 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/Rakefile +23 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/init.rb +1 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/install.rb +1 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/lib/authorize_net_cim_gateway_test.rb +492 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/lib/authorize_net_gateway_test.rb +133 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/lib/paypal_express_gateway_test.rb +138 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/tasks/activemerchant_testing_tasks.rake +4 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/test/activemerchant_testing_test.rb +8 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/test/test_helper.rb +3 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/uninstall.rb +1 -0
- data/spec/factories/factories.rb +75 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/mailers/notifier_spec.rb +167 -0
- data/spec/models/billing_activity_spec.rb +27 -0
- data/spec/models/contact_info_spec.rb +32 -0
- data/spec/models/credit_card_spec.rb +57 -0
- data/spec/models/invoice_line_item_spec.rb +7 -0
- data/spec/models/invoice_spec.rb +25 -0
- data/spec/models/payment_spec.rb +29 -0
- data/spec/models/plan_spec.rb +16 -0
- data/spec/models/subscription_spec.rb +414 -0
- data/spec/requests/admin_plans_spec.rb +32 -0
- data/spec/requests/admin_subscriptions_spec.rb +31 -0
- data/spec/requests/billing_history_spec.rb +26 -0
- data/spec/requests/contact_info_controller_spec.rb +42 -0
- data/spec/requests/credit_cards_spec.rb +79 -0
- data/spec/requests/invoices_spec.rb +23 -0
- data/spec/requests/payments_spec.rb +89 -0
- data/spec/requests/subscription_plans_spec.rb +34 -0
- data/spec/requests/subscriptions_spec.rb +80 -0
- data/spec/spec_helper.rb +68 -0
- data/spec/spec_helpers/spec_helpers.rb +8 -0
- metadata +611 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include SpecHelpers
|
3
|
+
describe 'Plans' do
|
4
|
+
describe "GET /admin/plans" do
|
5
|
+
it "should display plans" do
|
6
|
+
Factory.create(:plan, :name => "Gold")
|
7
|
+
visit admin_plans_path
|
8
|
+
page.should have_content("Gold")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "POST /admin/plans", :js => "true" do
|
13
|
+
it "should create new plan" do
|
14
|
+
javascript do
|
15
|
+
visit new_admin_plan_path
|
16
|
+
fill_in "plan_name", :with => "Silver"
|
17
|
+
fill_in "Price", :with => "12.99"
|
18
|
+
fill_in "attribute_name", :with => "Testing123"
|
19
|
+
click_link "Add attribute"
|
20
|
+
page.should have_content("Testing123")
|
21
|
+
fill_in 'field_Testing123', :with => 'test'
|
22
|
+
click_button "Create"
|
23
|
+
page.should have_content("Plan was successfully created.")
|
24
|
+
page.should have_content("Silver")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "admin/subscriptions" do
|
4
|
+
before(:each) do
|
5
|
+
@plan = Factory.build(:plan, :name => "Gold", :price => 20)
|
6
|
+
@contact_info = Factory.build(:contact_info)
|
7
|
+
|
8
|
+
@credit_card = Factory.build(:credit_card)
|
9
|
+
@subscription = Factory.build(:subscription, :contact_info => @contact_info, :plan => @plan, :credit_card => @credit_card)
|
10
|
+
@user = Factory.create(:user, :subscription => @subscription)
|
11
|
+
@contact_info2 = Factory.build(:contact_info)
|
12
|
+
|
13
|
+
@credit_card2 = Factory.build(:credit_card)
|
14
|
+
@subscription2 = Factory.build(:subscription, :contact_info => @contact_info2, :plan => @plan, :credit_card => @credit_card2)
|
15
|
+
@user2 = Factory.create(:user, :subscription => @subscription2)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should load index page' do
|
19
|
+
visit admin_subscriptions_path
|
20
|
+
page.should have_content("Subscriptions")
|
21
|
+
page.should have_content("bobjones@123.com")
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should load subscription show path' do
|
25
|
+
visit admin_subscriptions_path
|
26
|
+
click_on("Show Detail")
|
27
|
+
page.should have_content("Subscription Details")
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'BillingHistory' do
|
4
|
+
|
5
|
+
describe 'GET /index' do
|
6
|
+
before(:each) do
|
7
|
+
@billing_activity1 = Factory(:billing_activity, :amount => 13.00, :message => "Thanks for your payment." )
|
8
|
+
@billing_activity2 = Factory(:billing_activity, :amount => 18.00, :message => "Thanks for your payment." )
|
9
|
+
@plan = Factory.build(:plan, :name => "Gold", :price => 20)
|
10
|
+
@contact_info = Factory.build(:contact_info)
|
11
|
+
|
12
|
+
@credit_card = Factory.build(:credit_card)
|
13
|
+
@subscription = Factory(:subscription, :contact_info => @contact_info, :plan => @plan, :credit_card => @credit_card)
|
14
|
+
@user = Factory(:user, :subscription => @subscription)
|
15
|
+
@subscription.billing_activities << @billing_activity1
|
16
|
+
@subscription.billing_activities << @billing_activity2
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should load billing histories page' do
|
20
|
+
visit subscription_billing_history_path
|
21
|
+
page.should have_content "18.00"
|
22
|
+
page.should have_content "Thanks for your payment."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Contact info' do
|
4
|
+
|
5
|
+
describe 'GET /contact' do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@plan = Factory.build(:plan, :name => "Gold", :price => 20)
|
9
|
+
@contact_info = Factory.build(:contact_info)
|
10
|
+
@credit_card = Factory.build(:credit_card)
|
11
|
+
@subscription = Factory.build(:subscription, :contact_info => @contact_info, :plan => @plan, :credit_card => @credit_card)
|
12
|
+
@user = Factory.create(:user, :subscription => @subscription)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should display contact form' do
|
16
|
+
visit edit_subscription_contact_info_path
|
17
|
+
page.should have_content 'Update Billing Contact Info'
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'POST /contact-info' do
|
23
|
+
before(:each) do
|
24
|
+
@plan = Factory.build(:plan, :name => "Gold", :price => 20)
|
25
|
+
@contact_info = Factory.build(:contact_info)
|
26
|
+
|
27
|
+
@credit_card = Factory.build(:credit_card)
|
28
|
+
@subscription = Factory.build(:subscription, :contact_info => @contact_info, :plan => @plan, :credit_card => @credit_card)
|
29
|
+
@user = Factory.create(:user, :subscription => @subscription)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should update contact info' do
|
33
|
+
visit edit_subscription_contact_info_path
|
34
|
+
fill_in "First name", :with => "Ted"
|
35
|
+
click_on("Update Contact Info")
|
36
|
+
page.should have_content("Contact info was successfully updated.")
|
37
|
+
page.should have_content("Ted")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'CreditCard' do
|
4
|
+
|
5
|
+
describe 'GET /credit_card' do
|
6
|
+
before(:each) do
|
7
|
+
|
8
|
+
@plan = Factory.build(:plan, :name => "Gold", :price => 20)
|
9
|
+
@contact_info = Factory.build(:contact_info)
|
10
|
+
|
11
|
+
@credit_card = Factory.build(:credit_card)
|
12
|
+
@subscription = Factory(:subscription, :contact_info => @contact_info, :plan => @plan, :credit_card => @credit_card)
|
13
|
+
@user = Factory(:user, :subscription => @subscription)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should load credit_card path' do
|
17
|
+
visit edit_subscription_credit_card_path
|
18
|
+
page.should have_content(@subscription.credit_card.card_number)
|
19
|
+
page.should have_content(@subscription.credit_card.expiration_date)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'POST /credit_cards' do
|
25
|
+
before(:each) do
|
26
|
+
@plan = Factory.build(:plan, :name => "Gold", :price => 20)
|
27
|
+
@contact_info = Factory.build(:contact_info)
|
28
|
+
|
29
|
+
@credit_card = Factory.build(:credit_card)
|
30
|
+
@subscription = Factory(:subscription, :contact_info => @contact_info, :plan => @plan, :credit_card => @credit_card)
|
31
|
+
@user = Factory(:user, :subscription => @subscription)
|
32
|
+
end
|
33
|
+
it 'should update credit card' do
|
34
|
+
visit edit_subscription_credit_card_path
|
35
|
+
# fill_in "First name", :with => "Bob"
|
36
|
+
# fill_in "Last name", :with => "Herman"
|
37
|
+
fill_in "Card number", :with => "4111111111111111"
|
38
|
+
select 'Visa', :from => "Card type"
|
39
|
+
fill_in "Card verification", :with => "332"
|
40
|
+
select '12', :from => "Expiry month"
|
41
|
+
select (Date.today.year + 1).to_s, :from => "Expiry year"
|
42
|
+
|
43
|
+
click_on("Update Card")
|
44
|
+
page.should have_content("Your credit card was successfully updated.")
|
45
|
+
page.should have_content("12/#{(Date.today.year + 1).to_s}")
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should update credit card' do
|
49
|
+
GATEWAYCIM.success= false
|
50
|
+
visit edit_subscription_credit_card_path
|
51
|
+
# fill_in "First name", :with => "Bob"
|
52
|
+
# fill_in "Last name", :with => "Herman"
|
53
|
+
fill_in "Card number", :with => "4111111111111111"
|
54
|
+
select 'Visa', :from => "Card type"
|
55
|
+
fill_in "Card verification", :with => "332"
|
56
|
+
select '12', :from => "Expiry month"
|
57
|
+
select (Date.today.year + 1).to_s, :from => "Expiry year"
|
58
|
+
|
59
|
+
click_on("Update Card")
|
60
|
+
page.should have_content("The transaction was unsuccessful.")
|
61
|
+
GATEWAYCIM.success= true
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should keep current card the same om error' do
|
65
|
+
visit edit_subscription_credit_card_path
|
66
|
+
|
67
|
+
fill_in "Card number", :with => "425656956545454"
|
68
|
+
select 'Visa', :from => "Card type"
|
69
|
+
select '12', :from => "Expiry month"
|
70
|
+
select (Date.today.year + 1).to_s, :from => "Expiry year"
|
71
|
+
click_on("Update Card")
|
72
|
+
page.should have_content("XXXXXXXXXXXX1111")
|
73
|
+
page.should have_content("10/2011")
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Invoices" do
|
4
|
+
describe 'GET /invoices/:id' do
|
5
|
+
before(:each) do
|
6
|
+
@plan = Factory.build(:plan, :name => "Gold", :price => 20)
|
7
|
+
@contact_info = Factory.build(:contact_info)
|
8
|
+
|
9
|
+
@credit_card = Factory.build(:credit_card)
|
10
|
+
@subscription = Factory(:subscription, :contact_info => @contact_info, :plan => @plan, :credit_card => @credit_card)
|
11
|
+
@user = Factory(:user, :subscription => @subscription)
|
12
|
+
@subscription.invoice!
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Payments' do
|
4
|
+
|
5
|
+
describe 'GET /payments' do
|
6
|
+
|
7
|
+
it 'should not allow payment for an subscription with no balance' do
|
8
|
+
@plan = Factory.build(:plan, :name => "Gold", :price => 20)
|
9
|
+
@contact_info = Factory.build(:contact_info)
|
10
|
+
|
11
|
+
@credit_card = Factory.build(:credit_card)
|
12
|
+
@subscription = Factory(:subscription, :contact_info => @contact_info, :plan => @plan,:credit_card => @credit_card)
|
13
|
+
@user = Factory(:user, :subscription => @subscription)
|
14
|
+
@subscription.balance = 0.0
|
15
|
+
visit new_subscription_payment_path
|
16
|
+
page.should have_content("$0.00")
|
17
|
+
fill_in "Amount", :with => "12.00"
|
18
|
+
click_on "Submit"
|
19
|
+
page.should have_content("cannot be more than your balance")
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should allow payment to be created' do
|
23
|
+
@plan = Factory.build(:plan, :name => "Gold", :price => 20)
|
24
|
+
@contact_info = Factory.build(:contact_info)
|
25
|
+
|
26
|
+
@credit_card = Factory.build(:credit_card)
|
27
|
+
@subscription = Factory(:subscription, :contact_info => @contact_info, :plan => @plan, :credit_card => @credit_card)
|
28
|
+
@user = Factory(:user, :subscription => @subscription)
|
29
|
+
@subscription.update_attributes(:balance => 20.00)
|
30
|
+
visit new_subscription_payment_path
|
31
|
+
page.should have_content("$20.00")
|
32
|
+
fill_in "Amount", :with => 13.00
|
33
|
+
click_on "Submit"
|
34
|
+
page.should have_content("Confirm Payment")
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'POST /payments' do
|
44
|
+
it 'should not allow payment without pending status' do
|
45
|
+
@plan = Factory.build(:plan, :name => "Gold", :price => 20)
|
46
|
+
@contact_info = Factory.build(:contact_info)
|
47
|
+
|
48
|
+
@credit_card = Factory.build(:credit_card)
|
49
|
+
|
50
|
+
@subscription = Factory(:subscription, :contact_info => @contact_info, :plan => @plan, :credit_card => @credit_card)
|
51
|
+
@subscription.update_attributes(:balance => 15)
|
52
|
+
@payment = Factory(:payment, :amount => 12, :subscription => @subscription)
|
53
|
+
@user = Factory(:user, :subscription => @subscription)
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
Payment.skip_callback(:update, :before, :charge_subscription)
|
58
|
+
@payment.update_attributes(:status => "paid")
|
59
|
+
|
60
|
+
|
61
|
+
visit edit_subscription_payment_path(@payment)
|
62
|
+
page.should have_content("Payment has already been paid")
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should allow updated payments that have not been paid' do
|
66
|
+
@plan = Factory.build(:plan, :name => "Gold", :price => 20)
|
67
|
+
@contact_info = Factory.build(:contact_info)
|
68
|
+
|
69
|
+
@credit_card = Factory.build(:credit_card)
|
70
|
+
|
71
|
+
@subscription = Factory(:subscription, :contact_info => @contact_info, :plan => @plan, :credit_card => @credit_card)
|
72
|
+
@subscription.update_attributes(:balance => 15)
|
73
|
+
@payment = Factory(:payment, :amount => 12, :subscription => @subscription)
|
74
|
+
|
75
|
+
|
76
|
+
@user = Factory(:user, :subscription => @subscription)
|
77
|
+
|
78
|
+
visit edit_subscription_payment_path(@payment)
|
79
|
+
page.should have_content("Confirm Payment")
|
80
|
+
|
81
|
+
click_on "Confirm"
|
82
|
+
|
83
|
+
page.should have_content("Thank you, your payment has been processed.")
|
84
|
+
page.should have_content("$12.00")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Plans' do
|
4
|
+
|
5
|
+
describe 'GET /subscriptions/plans' do
|
6
|
+
before(:each) do
|
7
|
+
@plan = Factory(:plan, :name => "Gold", :price => 20)
|
8
|
+
@plan2 = Factory(:plan, :name => "Silver", :price => 10)
|
9
|
+
@contact_info = Factory.build(:contact_info)
|
10
|
+
|
11
|
+
@credit_card = Factory.build(:credit_card)
|
12
|
+
|
13
|
+
@subscription = Factory.build(:subscription, :contact_info => @contact_info, :plan => @plan, :credit_card => @credit_card)
|
14
|
+
|
15
|
+
@user = Factory(:user, :subscription => @subscription)
|
16
|
+
end
|
17
|
+
it 'should not show current plan on downgrade' do
|
18
|
+
visit edit_subscription_plan_path
|
19
|
+
page.should have_content("Silver")
|
20
|
+
|
21
|
+
page.should have_content("You are currently subscribed to this plan")
|
22
|
+
|
23
|
+
end
|
24
|
+
it 'should set downgrade_to_plan on downgrade' do
|
25
|
+
visit edit_subscription_plan_path
|
26
|
+
click_on("Downgrade")
|
27
|
+
page.should have_content("Plan was successfully changed.")
|
28
|
+
@subscription.reload
|
29
|
+
@subscription.plan.should == @plan
|
30
|
+
@subscription.downgrade_to_plan.should == @plan2
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Subscriptions' do
|
4
|
+
|
5
|
+
describe 'Post /subscription' do
|
6
|
+
before(:each) do
|
7
|
+
Factory.create(:user)
|
8
|
+
Factory.create(:plan, :name => "Gold", :price => 4.00)
|
9
|
+
Factory.create(:plan, :name => "Silver")
|
10
|
+
end
|
11
|
+
it "should create a new subscription" do
|
12
|
+
visit new_subscription_path
|
13
|
+
fill_in "subscription_contact_info_attributes_first_name", :with => "Bob"
|
14
|
+
fill_in "subscription_contact_info_attributes_last_name", :with => "Jones"
|
15
|
+
fill_in "Email", :with => "bobjones@123.com"
|
16
|
+
fill_in "Address", :with => "123 fake st"
|
17
|
+
fill_in "City", :with => "seattle"
|
18
|
+
fill_in "State", :with => "wa"
|
19
|
+
fill_in "Zip", :with => "98123"
|
20
|
+
select 'United States', :from => 'Country'
|
21
|
+
fill_in "subscription_contact_info_attributes_phone_area_code", :with => "206"
|
22
|
+
fill_in "subscription_contact_info_attributes_phone_prefix", :with => "123"
|
23
|
+
fill_in "subscription_contact_info_attributes_phone_suffix", :with => "1234"
|
24
|
+
fill_in "Card number", :with => "4111111111111111"
|
25
|
+
select 'Visa', :from => "Card type"
|
26
|
+
fill_in "Card verification", :with => "332"
|
27
|
+
select '10', :from => "Expiry month"
|
28
|
+
select Date.today.year.to_s, :from => "Expiry year"
|
29
|
+
choose 'Gold'
|
30
|
+
click_on 'Create Subscription'
|
31
|
+
page.should have_content("Your subscription was successfully created.")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should fail with declined card" do
|
35
|
+
visit new_subscription_path
|
36
|
+
GATEWAYCIM.success = false
|
37
|
+
fill_in "subscription_contact_info_attributes_first_name", :with => "Bob"
|
38
|
+
fill_in "subscription_contact_info_attributes_last_name", :with => "Jones"
|
39
|
+
fill_in "Email", :with => "bobjones@123.com"
|
40
|
+
fill_in "Address", :with => "123 fake st"
|
41
|
+
fill_in "City", :with => "seattle"
|
42
|
+
fill_in "State", :with => "wa"
|
43
|
+
fill_in "Zip", :with => "98123"
|
44
|
+
select 'United States', :from => 'Country'
|
45
|
+
fill_in "subscription_contact_info_attributes_phone_area_code", :with => "206"
|
46
|
+
fill_in "subscription_contact_info_attributes_phone_prefix", :with => "123"
|
47
|
+
fill_in "subscription_contact_info_attributes_phone_suffix", :with => "1234"
|
48
|
+
fill_in "Card number", :with => "4222222222222"
|
49
|
+
select 'Visa', :from => "Card type"
|
50
|
+
fill_in "Card verification", :with => "332"
|
51
|
+
select '10', :from => "Expiry month"
|
52
|
+
select Date.today.year.to_s, :from => "Expiry year"
|
53
|
+
choose 'Gold'
|
54
|
+
|
55
|
+
click_on 'Create Subscription'
|
56
|
+
page.should have_content("The transaction was unsuccessful.")
|
57
|
+
GATEWAYCIM.success = true
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
end
|
62
|
+
describe 'DELETE /subscription' do
|
63
|
+
|
64
|
+
before(:each) do
|
65
|
+
@plan = Factory.build(:plan, :name => "Gold", :price => 20)
|
66
|
+
@contact_info = Factory.build(:contact_info)
|
67
|
+
@credit_card = Factory.build(:credit_card)
|
68
|
+
@subscription = Factory(:subscription, :contact_info => @contact_info, :plan => @plan, :credit_card => @credit_card)
|
69
|
+
@user = Factory(:user, :subscription => @subscription)
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
it 'should set subscription status to canceled' do
|
74
|
+
visit subscription_path
|
75
|
+
click_on "Cancel Subscription"
|
76
|
+
page.should have_content("Your subscription has been canceled.")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|