paid_up 0.11.7 → 0.12.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -13
  3. data/.rubocop_todo.yml +7 -0
  4. data/.travis.yml +4 -3
  5. data/Gemfile +29 -24
  6. data/README.md +22 -1
  7. data/Rakefile +6 -5
  8. data/VERSION +1 -1
  9. data/app/controllers/paid_up/paid_up_controller.rb +16 -9
  10. data/app/controllers/paid_up/plans_controller.rb +2 -0
  11. data/app/controllers/paid_up/subscriptions_controller.rb +58 -49
  12. data/app/helpers/paid_up/features_helper.rb +35 -34
  13. data/app/helpers/paid_up/paid_up_helper.rb +10 -8
  14. data/app/helpers/paid_up/plans_helper.rb +75 -55
  15. data/app/helpers/paid_up/subscriptions_helper.rb +17 -13
  16. data/app/models/paid_up/ability.rb +53 -46
  17. data/app/models/paid_up/plan.rb +36 -34
  18. data/app/models/paid_up/plan_feature_setting.rb +2 -0
  19. data/app/models/paid_up/unlimited.rb +2 -0
  20. data/app/views/paid_up/features/_abilities_table.html.haml +1 -45
  21. data/app/views/paid_up/features/_boolean_state.html.haml +6 -0
  22. data/app/views/paid_up/features/_setting_state.html.haml +13 -0
  23. data/app/views/paid_up/subscriptions/index.html.haml +2 -2
  24. data/config/initializers/stripe.rb +2 -0
  25. data/config/locales/en.yml +4 -1
  26. data/config/routes.rb +3 -1
  27. data/lib/generators/paid_up/install/install_generator.rb +4 -1
  28. data/lib/generators/paid_up/install/templates/ability.rb +2 -0
  29. data/lib/generators/paid_up/install/templates/initializer.rb +2 -0
  30. data/lib/generators/paid_up/utils.rb +2 -0
  31. data/lib/paid_up/configuration.rb +4 -2
  32. data/lib/paid_up/engine.rb +2 -0
  33. data/lib/paid_up/extensions/integer.rb +2 -0
  34. data/lib/paid_up/extensions/stripe.rb +2 -0
  35. data/lib/paid_up/feature.rb +10 -7
  36. data/lib/paid_up/feature_setting_type.rb +45 -0
  37. data/lib/paid_up/feature_setting_types/rolify.rb +10 -0
  38. data/lib/paid_up/feature_setting_types/table.rb +7 -0
  39. data/lib/paid_up/localization.rb +2 -0
  40. data/lib/paid_up/mixins/paid_for.rb +59 -47
  41. data/lib/paid_up/mixins/subscriber.rb +45 -101
  42. data/lib/paid_up/railtie.rb +2 -0
  43. data/lib/paid_up/ruby_version_check.rb +15 -0
  44. data/lib/paid_up/subscription.rb +80 -0
  45. data/lib/paid_up/validators/rolify_rows.rb +11 -6
  46. data/lib/paid_up/validators/table_rows.rb +9 -6
  47. data/lib/paid_up/version.rb +2 -0
  48. data/lib/paid_up.rb +8 -0
  49. data/paid_up.gemspec +108 -115
  50. data/spec/controllers/paid_up/plans_spec.rb +2 -0
  51. data/spec/controllers/paid_up/subscriptions_spec.rb +18 -11
  52. data/spec/dummy/Rakefile +2 -0
  53. data/spec/dummy/app/assets/stylesheets/application.css.scss +6 -0
  54. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  55. data/spec/dummy/app/models/ability.rb +2 -0
  56. data/spec/dummy/app/models/doodad.rb +2 -0
  57. data/spec/dummy/app/models/group.rb +2 -0
  58. data/spec/dummy/app/models/post.rb +2 -0
  59. data/spec/dummy/app/models/role.rb +2 -0
  60. data/spec/dummy/app/models/user.rb +2 -0
  61. data/spec/dummy/app/views/layouts/application.html.haml +13 -11
  62. data/spec/dummy/bin/bundle +2 -0
  63. data/spec/dummy/bin/rails +2 -0
  64. data/spec/dummy/bin/rake +2 -0
  65. data/spec/dummy/bin/setup +10 -8
  66. data/spec/dummy/config/application.rb +2 -3
  67. data/spec/dummy/config/boot.rb +2 -0
  68. data/spec/dummy/config/environment.rb +2 -0
  69. data/spec/dummy/config/environments/development.rb +2 -0
  70. data/spec/dummy/config/environments/test.rb +2 -4
  71. data/spec/dummy/config/initializers/assets.rb +2 -0
  72. data/spec/dummy/config/initializers/backtrace_silencers.rb +1 -0
  73. data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
  74. data/spec/dummy/config/initializers/devise.rb +2 -0
  75. data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
  76. data/spec/dummy/config/initializers/inflections.rb +1 -0
  77. data/spec/dummy/config/initializers/mime_types.rb +1 -0
  78. data/spec/dummy/config/initializers/paid_up.rb +10 -16
  79. data/spec/dummy/config/initializers/rolify.rb +2 -0
  80. data/spec/dummy/config/initializers/session_store.rb +2 -0
  81. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
  82. data/spec/dummy/config/routes.rb +2 -0
  83. data/spec/dummy/config.ru +2 -0
  84. data/spec/dummy/db/schema.rb +14 -23
  85. data/spec/dummy/db/seeds.rb +8 -6
  86. data/spec/dummy/db/test.sqlite3 +0 -0
  87. data/spec/dummy/lib/tasks/system.rake +2 -0
  88. data/spec/factories/doodad.rb +2 -0
  89. data/spec/factories/group.rb +2 -0
  90. data/spec/factories/plan.rb +2 -0
  91. data/spec/factories/plan_feature_setting.rb +2 -0
  92. data/spec/factories/post.rb +2 -0
  93. data/spec/factories/user.rb +3 -1
  94. data/spec/models/group_spec.rb +9 -7
  95. data/spec/models/paid_up/feature_spec.rb +2 -0
  96. data/spec/models/paid_up/plan_feature_setting_spec.rb +2 -0
  97. data/spec/models/paid_up/plan_spec.rb +2 -0
  98. data/spec/models/scope_spec.rb +9 -7
  99. data/spec/models/user_spec.rb +60 -58
  100. data/spec/paid_up_spec.rb +2 -0
  101. data/spec/rails_helper.rb +16 -2
  102. data/spec/routing/paid_up/plans_spec.rb +2 -0
  103. data/spec/routing/paid_up/subscription_spec.rb +2 -0
  104. data/spec/spec_helper.rb +2 -0
  105. data/spec/support/controller_macros.rb +2 -0
  106. data/spec/support/factory_girl.rb +2 -0
  107. data/spec/support/loaded_site/features.rb +2 -0
  108. data/spec/support/loaded_site/groups.rb +2 -0
  109. data/spec/support/loaded_site/loaded_site.rb +2 -0
  110. data/spec/support/loaded_site/plans.rb +2 -0
  111. data/spec/support/loaded_site/posts.rb +2 -0
  112. data/spec/support/loaded_site/users.rb +4 -2
  113. data/spec/support/stripe.rb +2 -0
  114. data/spec/views/paid_up/plans_spec.rb +9 -7
  115. data/spec/views/paid_up/subscriptions_spec.rb +20 -19
  116. metadata +124 -90
  117. data/app/views/devise/confirmations/new.html.haml +0 -13
  118. data/app/views/devise/passwords/edit.html.haml +0 -19
  119. data/app/views/devise/passwords/new.html.haml +0 -14
  120. data/app/views/devise/registrations/_new_form.html.haml +0 -23
  121. data/app/views/devise/registrations/edit.html.haml +0 -39
  122. data/app/views/devise/registrations/new.html.haml +0 -11
  123. data/app/views/devise/sessions/_new_form.html.haml +0 -21
  124. data/app/views/devise/sessions/new.html.haml +0 -11
  125. data/app/views/devise/shared/_links.html.haml +0 -14
  126. data/app/views/devise/unlocks/new.html.haml +0 -14
  127. data/app/views/layouts/mailer.html.haml +0 -3
  128. data/app/views/layouts/mailer.text.haml +0 -1
  129. data/app/views/paid_up/subscription_mailer/payment_failed_email.html.haml +0 -0
  130. data/app/views/paid_up/subscription_mailer/payment_failed_email.text.haml +0 -0
  131. data/coverage/.last_run.json +0 -5
  132. data/coverage/.resultset.json +0 -1927
  133. data/spec/dummy/app/views/pages/index.html.haml +0 -1
  134. data/spec/dummy/config/environments/production.rb +0 -83
  135. data/spec/dummy/config/initializers/high_voltage.rb +0 -3
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
  require 'cancan/matchers'
3
5
 
@@ -10,7 +12,7 @@ describe User do
10
12
  end
11
13
 
12
14
  context '#cards' do
13
- subject { professional_subscriber.cards.first }
15
+ subject { prof_subscriber.cards.first }
14
16
  it { should be_a Stripe::Card }
15
17
  end
16
18
 
@@ -67,13 +69,13 @@ describe User do
67
69
 
68
70
  context 'starting from higher subscription' do
69
71
  before do
70
- professional_subscriber.subscribe_to_free_plan
72
+ prof_subscriber.subscribe_to_free_plan
71
73
  end
72
74
  after do
73
75
  token = working_stripe_token no_ads_subscriber
74
- professional_subscriber.subscribe_to_plan professional_plan, token
76
+ prof_subscriber.subscribe_to_plan professional_plan, token
75
77
  end
76
- subject { professional_subscriber.plan }
78
+ subject { prof_subscriber.plan }
77
79
  it { should eq(free_plan) }
78
80
  end
79
81
  end
@@ -90,115 +92,115 @@ describe User do
90
92
  end
91
93
  end
92
94
 
93
- context '#table_rows_remaining' do
95
+ context '#table_setting().rows_remaining' do
94
96
  context 'when using a plan without the feature' do
95
- subject { no_ads_subscriber.table_rows_remaining 'doodads' }
97
+ subject { no_ads_subscriber.table_setting('doodads').rows_remaining }
96
98
  it { should eq 0 }
97
99
  end
98
100
  context 'when subscribed to a plan with the feature limited' do
99
- subject { group_leader_subscriber.table_rows_remaining 'doodads' }
101
+ subject { leader_subscriber.table_setting('doodads').rows_remaining }
100
102
  it { should eq 10 }
101
103
  end
102
104
  context 'when subscribed to a plan with the feature unlimited' do
103
- subject { professional_subscriber.table_rows_remaining 'doodads' }
105
+ subject { prof_subscriber.table_setting('doodads').rows_remaining }
104
106
  it { should eq PaidUp::Unlimited.to_i }
105
107
  end
106
108
  end
107
109
 
108
- context '#table_rows_unlimited?' do
110
+ context '#table_setting().rows_unlimited?' do
109
111
  context 'when using a plan without the feature' do
110
- subject { no_ads_subscriber.table_rows_unlimited? 'doodads' }
112
+ subject { no_ads_subscriber.table_setting('doodads').rows_unlimited? }
111
113
  it { should eq false }
112
114
  end
113
115
  context 'when subscribed to a plan with the feature limited' do
114
- subject { group_leader_subscriber.table_rows_unlimited? 'doodads' }
116
+ subject { leader_subscriber.table_setting('doodads').rows_unlimited? }
115
117
  it { should eq false }
116
118
  end
117
119
  context 'when subscribed to a plan with the feature unlimited' do
118
- subject { professional_subscriber.table_rows_unlimited? 'doodads' }
120
+ subject { prof_subscriber.table_setting('doodads').rows_unlimited? }
119
121
  it { should eq true }
120
122
  end
121
123
  end
122
124
 
123
- context '#table_rows_allowed' do
125
+ context '#table_setting().rows_allowed' do
124
126
  context 'when using a plan without the feature' do
125
- subject { no_ads_subscriber.table_rows_allowed 'doodads' }
127
+ subject { no_ads_subscriber.table_setting('doodads').rows_allowed }
126
128
  it { should eq 0 }
127
129
  end
128
130
  context 'when subscribed to a plan with the feature limited' do
129
- subject { group_leader_subscriber.table_rows_allowed 'doodads' }
131
+ subject { leader_subscriber.table_setting('doodads').rows_allowed }
130
132
  it { should eq 10 }
131
133
  end
132
134
  context 'when subscribed to a plan with the feature unlimited' do
133
- subject { professional_subscriber.table_rows_allowed 'doodads' }
135
+ subject { prof_subscriber.table_setting('doodads').rows_allowed }
134
136
  it { should eq PaidUp::Unlimited.to_i }
135
137
  end
136
138
  end
137
139
 
138
- context '#table_rows' do
140
+ context '#table_setting().rows_count' do
139
141
  context 'when possessing no rows' do
140
- subject { professional_subscriber.table_rows 'doodads' }
142
+ subject { prof_subscriber.table_setting('doodads').rows_count }
141
143
  it { should eq 0 }
142
144
  end
143
145
  context 'when possessing 3 rows' do
144
146
  before do
145
147
  3.times do
146
- professional_subscriber.doodads.create! name: 'Test Doodad'
148
+ prof_subscriber.doodads.create! name: 'Test Doodad'
147
149
  end
148
150
  end
149
- subject { professional_subscriber.table_rows 'doodads' }
151
+ subject { prof_subscriber.table_setting('doodads').rows_count }
150
152
  it { should eq 3 }
151
153
  end
152
154
  end
153
155
 
154
- context '#rolify_rows_remaining' do
156
+ context '#rolify_setting().rows_remaining' do
155
157
  context 'when using a plan without the feature' do
156
- subject { no_ads_subscriber.rolify_rows_remaining 'groups' }
158
+ subject { no_ads_subscriber.rolify_setting('groups').rows_remaining }
157
159
  it { should eq 0 }
158
160
  end
159
161
  context 'when subscribed to a plan with the feature limited' do
160
- subject { group_leader_subscriber.rolify_rows_remaining 'groups' }
162
+ subject { leader_subscriber.rolify_setting('groups').rows_remaining }
161
163
  it { should eq 4 }
162
164
  end
163
165
  context 'when subscribed to a plan with the feature unlimited' do
164
- subject { professional_subscriber.rolify_rows_remaining 'groups' }
166
+ subject { prof_subscriber.rolify_setting('groups').rows_remaining }
165
167
  it { should be > 99_999_999 }
166
168
  end
167
169
  end
168
170
 
169
- context '#rolify_rows_unlimited?' do
171
+ context '#rolify_setting().rows_unlimited?' do
170
172
  context 'when using a plan without the feature' do
171
- subject { no_ads_subscriber.rolify_rows_unlimited? 'groups' }
173
+ subject { no_ads_subscriber.rolify_setting('groups').rows_unlimited? }
172
174
  it { should eq false }
173
175
  end
174
176
  context 'when subscribed to a plan with the feature limited' do
175
- subject { group_leader_subscriber.rolify_rows_unlimited? 'groups' }
177
+ subject { leader_subscriber.rolify_setting('groups').rows_unlimited? }
176
178
  it { should eq false }
177
179
  end
178
180
  context 'when subscribed to a plan with the feature unlimited' do
179
- subject { professional_subscriber.rolify_rows_unlimited? 'groups' }
181
+ subject { prof_subscriber.rolify_setting('groups').rows_unlimited? }
180
182
  it { should eq true }
181
183
  end
182
184
  end
183
185
 
184
- context '#rolify_rows_allowed' do
186
+ context '#rolify_setting().rows_allowed' do
185
187
  context 'when using a plan without the feature' do
186
- subject { no_ads_subscriber.rolify_rows_allowed 'groups' }
188
+ subject { no_ads_subscriber.rolify_setting('groups').rows_allowed }
187
189
  it { should eq 0 }
188
190
  end
189
191
  context 'when subscribed to a plan with the feature limited' do
190
- subject { group_leader_subscriber.rolify_rows_allowed 'groups' }
192
+ subject { leader_subscriber.rolify_setting('groups').rows_allowed }
191
193
  it { should eq 5 }
192
194
  end
193
195
  context 'when subscribed to a plan with the feature unlimited' do
194
- subject { professional_subscriber.rolify_rows_allowed 'groups' }
196
+ subject { prof_subscriber.rolify_setting('groups').rows_allowed }
195
197
  it { should eq PaidUp::Unlimited.to_i }
196
198
  end
197
199
  end
198
200
 
199
- context '#rolify_rows' do
201
+ context '#rolify_setting().rows_count' do
200
202
  context 'when possessing no rows' do
201
- subject { blank_subscriber.rolify_rows 'groups' }
203
+ subject { blank_subscriber.rolify_setting('groups').rows_count }
202
204
  it { should eq 0 }
203
205
  end
204
206
  context 'when possessing 3 rows' do
@@ -211,7 +213,7 @@ describe User do
211
213
  )
212
214
  end
213
215
  end
214
- subject { blank_subscriber.rolify_rows 'groups' }
216
+ subject { blank_subscriber.rolify_setting('groups').rows_count }
215
217
  it { should eq 3 }
216
218
  end
217
219
  end
@@ -227,28 +229,28 @@ describe User do
227
229
  end
228
230
  end
229
231
 
230
- context '#subscription' do
232
+ context '#paid_up_subscription' do
231
233
  context 'when using free plan' do
232
- subject { free_subscriber.subscription }
233
- it { should be_a Stripe::Subscription }
234
+ subject { free_subscriber.paid_up_subscription }
235
+ it { should be_a PaidUp::Subscription }
234
236
  end
235
237
  context 'when subscribed to a plan' do
236
- subject { no_ads_subscriber.subscription }
237
- it { should be_a Stripe::Subscription }
238
+ subject { no_ads_subscriber.paid_up_subscription }
239
+ it { should be_a PaidUp::Subscription }
238
240
  end
239
241
  end
240
242
 
241
- context '#is_subscribed_to?' do
243
+ context '#subscribed_to?' do
242
244
  context 'when using free plan' do
243
- subject { free_subscriber.is_subscribed_to? free_plan }
245
+ subject { free_subscriber.subscribed_to? free_plan }
244
246
  it { should be true }
245
247
  end
246
248
  context 'when true' do
247
- subject { professional_subscriber.is_subscribed_to? professional_plan }
249
+ subject { prof_subscriber.subscribed_to? professional_plan }
248
250
  it { should be true }
249
251
  end
250
252
  context 'when false' do
251
- subject { no_ads_subscriber.is_subscribed_to? professional_plan }
253
+ subject { no_ads_subscriber.subscribed_to? professional_plan }
252
254
  it { should be false }
253
255
  end
254
256
  end
@@ -269,7 +271,7 @@ describe User do
269
271
  it { should be true }
270
272
  end
271
273
  context 'when false' do
272
- subject { professional_subscriber.can_upgrade_to? no_ads_plan }
274
+ subject { prof_subscriber.can_upgrade_to? no_ads_plan }
273
275
  it { should be false }
274
276
  end
275
277
  end
@@ -290,7 +292,7 @@ describe User do
290
292
  it { should be false }
291
293
  end
292
294
  context 'when true' do
293
- subject { professional_subscriber.can_downgrade_to? no_ads_plan }
295
+ subject { prof_subscriber.can_downgrade_to? no_ads_plan }
294
296
  it { should be true }
295
297
  end
296
298
  end
@@ -313,7 +315,7 @@ describe User do
313
315
  describe 'Abilities' do
314
316
  context 'when anonymous' do
315
317
  let(:group) do
316
- FactoryGirl.create(:group, owner: professional_subscriber)
318
+ FactoryGirl.create(:group, owner: prof_subscriber)
317
319
  end
318
320
  let(:user) { nil }
319
321
  subject(:ability) { Ability.new(user) }
@@ -327,7 +329,7 @@ describe User do
327
329
  end
328
330
  context 'when on free plan' do
329
331
  let(:group) do
330
- FactoryGirl.create(:group, owner: professional_subscriber)
332
+ FactoryGirl.create(:group, owner: prof_subscriber)
331
333
  end
332
334
  let(:user) { free_subscriber }
333
335
  subject(:ability) { Ability.new(user) }
@@ -341,16 +343,16 @@ describe User do
341
343
  end
342
344
  context 'when on group plan' do
343
345
  describe 'misc abilities' do
344
- let(:user) { group_leader_subscriber }
346
+ let(:user) { leader_subscriber }
345
347
  subject(:ability) { Ability.new(user) }
346
348
  it { should be_able_to(:use, :ad_free) }
347
349
  end
348
350
  describe 'using groups' do
349
351
  context 'given no groups are owned' do
350
352
  let(:group) do
351
- FactoryGirl.create(:group, owner: group_leader_subscriber)
353
+ FactoryGirl.create(:group, owner: leader_subscriber)
352
354
  end
353
- let(:user) { group_leader_subscriber }
355
+ let(:user) { leader_subscriber }
354
356
  subject(:ability) { Ability.new(user) }
355
357
  it { should be_able_to(:index, group) }
356
358
  it { should be_able_to(:show, group) }
@@ -374,9 +376,9 @@ describe User do
374
376
  describe 'using doodads' do
375
377
  context 'given no doodads are owned' do
376
378
  let(:doodad) do
377
- FactoryGirl.create(:doodad, user: group_leader_subscriber)
379
+ FactoryGirl.create(:doodad, user: leader_subscriber)
378
380
  end
379
- let(:user) { group_leader_subscriber }
381
+ let(:user) { leader_subscriber }
380
382
  subject(:ability) { Ability.new(user) }
381
383
  it { should be_able_to(:index, doodad) }
382
384
  it { should be_able_to(:show, doodad) }
@@ -400,9 +402,9 @@ describe User do
400
402
  describe 'using posts' do
401
403
  context 'given no posts are owned' do
402
404
  let(:post) do
403
- FactoryGirl.create(:post, user: group_leader_subscriber)
405
+ FactoryGirl.create(:post, user: leader_subscriber)
404
406
  end
405
- let(:user) { group_leader_subscriber }
407
+ let(:user) { leader_subscriber }
406
408
  subject(:ability) { Ability.new(user) }
407
409
  it { should be_able_to(:index, post) }
408
410
  it { should be_able_to(:show, post) }
@@ -429,7 +431,7 @@ describe User do
429
431
  let(:group) do
430
432
  FactoryGirl.create(:group, owner: blank_subscriber)
431
433
  end
432
- let(:user) { professional_subscriber }
434
+ let(:user) { prof_subscriber }
433
435
  subject(:ability) { Ability.new(user) }
434
436
  it { should be_able_to(:index, group) }
435
437
  it { should be_able_to(:show, group) }
@@ -441,9 +443,9 @@ describe User do
441
443
  end
442
444
  context 'given one group is owned' do
443
445
  let(:group) do
444
- FactoryGirl.create(:group, owner: professional_subscriber)
446
+ FactoryGirl.create(:group, owner: prof_subscriber)
445
447
  end
446
- let(:user) { professional_subscriber }
448
+ let(:user) { prof_subscriber }
447
449
  subject(:ability) { Ability.new(user) }
448
450
  it { should be_able_to(:index, group) }
449
451
  it { should be_able_to(:show, group) }
data/spec/paid_up_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  describe 'PaidUp' do
data/spec/rails_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'coveralls'
2
4
  Coveralls.wear!
3
5
 
@@ -7,6 +9,7 @@ require 'spec_helper'
7
9
  require File.expand_path('../dummy/config/environment', __FILE__)
8
10
  require 'rspec/rails'
9
11
  # Add additional requires below this line. Rails is not loaded until this point!
12
+ require 'rspec/core/formatters/console_codes'
10
13
  require 'shoulda/matchers'
11
14
  require 'factory_girl_rails'
12
15
  require 'capybara/rspec'
@@ -35,6 +38,10 @@ ActiveRecord::Migrator.migrations_paths = 'spec/dummy/db/migrate'
35
38
  # If you are not using ActiveRecord, you can remove this line.
36
39
  # ActiveRecord::Migration.maintain_test_schema!
37
40
 
41
+ # TODO: Add feature specs
42
+ # TODO: Add helper specs
43
+ # TODO: Remove view specs
44
+
38
45
  RSpec.configure do |config|
39
46
  config.before(:suite) do
40
47
  DatabaseCleaner.strategy = :transaction
@@ -76,8 +83,15 @@ RSpec.configure do |config|
76
83
  config.before(:each) { @routes = PaidUp::Engine.routes }
77
84
  config.include PaidUp::Engine.routes.url_helpers
78
85
 
79
- config.include Devise::TestHelpers, type: :controller
80
- config.include Devise::TestHelpers, type: :view
86
+ config.include Devise::Test::ControllerHelpers, type: :controller
87
+ config.include Devise::Test::ControllerHelpers, type: :view
81
88
  config.include ControllerMacros, type: :controller
82
89
  config.include ControllerMacros, type: :view
83
90
  end
91
+
92
+ Shoulda::Matchers.configure do |config|
93
+ config.integrate do |with|
94
+ with.test_framework :rspec
95
+ with.library :rails
96
+ end
97
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  describe 'PaidUp::Routing' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  describe 'PaidUp::Routing' do
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file was generated by the `rails generate rspec:install` command.
2
4
  # Conventionally, all specs live under a `spec` directory, which RSpec adds
3
5
  # to the `$LOAD_PATH`. The generated `.rspec` file contains
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ControllerMacros
2
4
  def access_anonymous
3
5
  sign_out :user
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.configure do |config|
2
4
  config.include FactoryGirl::Syntax::Methods
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_context 'features' do
2
4
  let!(:ad_free_feature) { PaidUp::Feature.find_by_slug('ad_free') }
3
5
  let!(:groups_feature) { PaidUp::Feature.find_by_slug('groups') }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_context 'groups' do
2
4
  let(:first_group) { Group.find_by_title('First Group') }
3
5
  let(:second_group) { Group.find_by_title('Second Group') }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_context 'loaded site' do
2
4
  include_context 'plans'
3
5
  include_context 'features'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_context 'plans' do
2
4
  let!(:anonymous_plan) { PaidUp::Plan.find_by_stripe_id('anonymous-plan') }
3
5
  let!(:free_plan) { PaidUp::Plan.find_by_stripe_id('free-plan') }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_context 'posts' do
2
4
  let(:first_post) { Post.find_by_title('First Post') }
3
5
  let(:active_post) { Post.find_by_title('Active Post') }
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_context 'users' do
2
4
  let(:free_subscriber) { User.find_by_name('Free Subscriber') }
3
5
  let(:no_ads_subscriber) { User.find_by_name('No Ads Subscriber') }
4
- let(:group_leader_subscriber) { User.find_by_name('Group Leader Subscriber') }
5
- let(:professional_subscriber) { User.find_by_name('Professional Subscriber') }
6
+ let(:leader_subscriber) { User.find_by_name('Group Leader Subscriber') }
7
+ let(:prof_subscriber) { User.find_by_name('Professional Subscriber') }
6
8
  let(:blank_subscriber) { User.find_by_name('Blank Subscriber') }
7
9
  let(:disabling_subscriber) { User.find_by_name('Disabling Subscriber') }
8
10
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_context 'stripe' do
2
4
  let(:default_card_data) do
3
5
  {
@@ -1,13 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe 'paid_up/plans/index' do
4
6
  include_context 'loaded site'
5
7
 
8
+ before do
9
+ view.extend PaidUp::PlansHelper
10
+ view.extend PaidUp::FeaturesHelper
11
+ view.extend BootstrapLeatherHelper
12
+ end
13
+
6
14
  context 'when user is anonymous' do
7
15
  before do
8
- view.extend PaidUp::PlansHelper
9
- view.extend PaidUp::FeaturesHelper
10
-
11
16
  assign(:current_user, access_anonymous)
12
17
  assign(:plans, PaidUp::Plan.subscribable)
13
18
  render
@@ -29,10 +34,7 @@ RSpec.describe 'paid_up/plans/index' do
29
34
 
30
35
  context 'when user is logged in as professional subscriber' do
31
36
  before do
32
- view.extend PaidUp::PlansHelper
33
- view.extend PaidUp::FeaturesHelper
34
-
35
- assign(:current_user, login_subscriber(professional_subscriber))
37
+ assign(:current_user, login_subscriber(prof_subscriber))
36
38
  assign(:plans, PaidUp::Plan.subscribable)
37
39
  render
38
40
  end
@@ -1,13 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails_helper'
2
4
 
3
5
  RSpec.describe 'paid_up/subscriptions/new' do
4
6
  include_context 'loaded site'
7
+
8
+ before do
9
+ view.extend PaidUp::PlansHelper
10
+ view.extend PaidUp::FeaturesHelper
11
+ view.extend BootstrapLeatherHelper
12
+ end
13
+
5
14
  context 'when user is logged in as free customer' do
6
15
  context 'displays a payment form' do
7
16
  before do
8
- view.extend PaidUp::PlansHelper
9
- view.extend PaidUp::FeaturesHelper
10
-
11
17
  assign(:current_user, login_subscriber(free_subscriber))
12
18
  assign(:plan, professional_plan)
13
19
  render
@@ -23,9 +29,6 @@ RSpec.describe 'paid_up/subscriptions/new' do
23
29
  context 'when user is logged in as a paid customer' do
24
30
  context 'displays a payment form' do
25
31
  before do
26
- view.extend PaidUp::PlansHelper
27
- view.extend PaidUp::FeaturesHelper
28
-
29
32
  assign(:current_user, login_subscriber(no_ads_subscriber))
30
33
  assign(:plan, professional_plan)
31
34
  render
@@ -42,26 +45,24 @@ end
42
45
 
43
46
  RSpec.describe 'paid_up/subscriptions/index' do
44
47
  include_context 'loaded site'
48
+
49
+ before do
50
+ view.extend PaidUp::PlansHelper
51
+ view.extend PaidUp::FeaturesHelper
52
+ view.extend BootstrapLeatherHelper
53
+ end
54
+
45
55
  context 'when user is logged in' do
46
56
  context "displays the details of a user's subscriptions" do
47
57
  before do
48
- view.extend PaidUp::PlansHelper
49
- view.extend PaidUp::FeaturesHelper
50
-
51
- assign(:current_user, login_subscriber(group_leader_subscriber))
58
+ assign(:current_user, login_subscriber(leader_subscriber))
52
59
  render
53
60
  end
54
61
  subject { rendered }
55
62
  it { should include 'Group Leader' }
56
- it do
57
- should have_selector 'table.abilities #ad_free_ability .glyphicon-ok'
58
- end
59
- it do
60
- should have_selector 'table.abilities #groups_ability .glyphicon-ok'
61
- end
62
- it do
63
- should have_selector 'table.abilities #doodads_ability .glyphicon-ok'
64
- end
63
+ it { should have_css 'table.abilities #ad_free_ability .glyphicon-ok' }
64
+ it { should have_css 'table.abilities #groups_ability .glyphicon-ok' }
65
+ it { should have_css 'table.abilities #doodads_ability .glyphicon-ok' }
65
66
  end
66
67
  end
67
68
  end