tang 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -3
  3. data/app/controllers/tang/account/application_controller.rb +2 -4
  4. data/app/controllers/tang/account/cards_controller.rb +11 -8
  5. data/app/controllers/tang/account/coupons_controller.rb +1 -1
  6. data/app/controllers/tang/account/receipts_controller.rb +10 -4
  7. data/app/controllers/tang/account/subscriptions_controller.rb +11 -8
  8. data/app/controllers/tang/admin/application_controller.rb +4 -4
  9. data/app/controllers/tang/admin/coupons_controller.rb +18 -14
  10. data/app/controllers/tang/admin/customers_controller.rb +16 -16
  11. data/app/controllers/tang/admin/dashboard_controller.rb +1 -1
  12. data/app/controllers/tang/admin/invoices_controller.rb +6 -6
  13. data/app/controllers/tang/admin/payments_controller.rb +9 -9
  14. data/app/controllers/tang/admin/plans_controller.rb +21 -19
  15. data/app/controllers/tang/admin/search_controller.rb +15 -14
  16. data/app/controllers/tang/admin/subscriptions_controller.rb +16 -17
  17. data/app/controllers/tang/plans_controller.rb +1 -1
  18. data/app/helpers/tang/application_helper.rb +22 -28
  19. data/app/jobs/tang/import_charges_job.rb +4 -8
  20. data/app/jobs/tang/import_coupons_job.rb +3 -3
  21. data/app/jobs/tang/import_customers_job.rb +15 -13
  22. data/app/jobs/tang/import_invoices_job.rb +7 -7
  23. data/app/jobs/tang/import_plans_job.rb +4 -6
  24. data/app/jobs/tang/import_subscriptions_job.rb +4 -4
  25. data/app/mailers/application_mailer.rb +1 -1
  26. data/app/mailers/tang/stripe_mailer.rb +8 -9
  27. data/app/mailers/tang/subscription_mailer.rb +4 -1
  28. data/app/models/concerns/tang/customer.rb +32 -32
  29. data/app/models/tang/card.rb +7 -8
  30. data/app/models/tang/charge.rb +28 -50
  31. data/app/models/tang/coupon.rb +27 -25
  32. data/app/models/tang/invoice.rb +16 -17
  33. data/app/models/tang/invoice_item.rb +16 -18
  34. data/app/models/tang/plan.rb +31 -16
  35. data/app/models/tang/subscription.rb +34 -42
  36. data/app/services/tang/apply_customer_discount.rb +2 -2
  37. data/app/services/tang/apply_subscription_discount.rb +2 -2
  38. data/app/services/tang/cancel_subscription.rb +2 -2
  39. data/app/services/tang/change_subscription.rb +4 -4
  40. data/app/services/tang/create_coupon.rb +3 -5
  41. data/app/services/tang/create_invoice.rb +2 -2
  42. data/app/services/tang/create_plan.rb +9 -8
  43. data/app/services/tang/create_subscription.rb +18 -15
  44. data/app/services/tang/delete_card.rb +3 -3
  45. data/app/services/tang/delete_coupon.rb +3 -3
  46. data/app/services/tang/delete_customer.rb +2 -2
  47. data/app/services/tang/delete_plan.rb +2 -2
  48. data/app/services/tang/fail_invoice.rb +5 -6
  49. data/app/services/tang/pay_invoice.rb +2 -3
  50. data/app/services/tang/refresh_invoice_pdf.rb +9 -0
  51. data/app/services/tang/remove_customer_discount.rb +2 -2
  52. data/app/services/tang/remove_subscription_discount.rb +3 -3
  53. data/app/services/tang/save_card.rb +8 -9
  54. data/app/services/tang/update_coupon.rb +3 -5
  55. data/app/services/tang/update_customer.rb +4 -4
  56. data/app/services/tang/update_plan.rb +3 -5
  57. data/app/services/tang/update_subscription.rb +3 -5
  58. data/app/validators/future_validator.rb +4 -4
  59. data/app/views/tang/account/cards/show.html.erb +1 -1
  60. data/app/views/tang/account/receipts/_receipt.html.erb +1 -1
  61. data/app/views/tang/account/subscriptions/show.html.erb +14 -3
  62. data/app/views/tang/admin/coupons/show.html.erb +1 -1
  63. data/app/views/tang/admin/customers/show.html.erb +2 -2
  64. data/app/views/tang/admin/plans/show.html.erb +1 -1
  65. data/app/views/tang/admin/subscriptions/show.html.erb +2 -2
  66. data/app/views/tang/plans/index.html.erb +1 -1
  67. data/config/initializers/stripe.rb +2 -2
  68. data/config/initializers/stripe_event.rb +38 -33
  69. data/config/routes.rb +3 -1
  70. data/db/migrate/20160928154410_create_versions.rb +4 -4
  71. data/db/migrate/20160928161623_create_tang_stripe_webhooks.rb +1 -1
  72. data/db/migrate/20160928173328_create_tang_plans.rb +1 -1
  73. data/db/migrate/20160929152510_create_tang_coupons.rb +1 -1
  74. data/db/migrate/20160929152541_add_customer_fields.rb +1 -1
  75. data/db/migrate/20160929171640_create_tang_subscriptions.rb +2 -2
  76. data/db/migrate/20160929174251_create_tang_cards.rb +1 -1
  77. data/db/migrate/20161003035434_create_tang_invoices.rb +1 -1
  78. data/db/migrate/20161114181651_create_tang_invoice_items.rb +1 -1
  79. data/db/migrate/20161115201106_create_tang_charges.rb +1 -1
  80. data/db/migrate/20170523122759_add_group_to_plans.rb +1 -1
  81. data/db/migrate/20170701162853_add_stripe_indexes.rb +1 -1
  82. data/db/migrate/20170731010913_add_subscription_indexes.rb +1 -1
  83. data/db/migrate/20200827001523_add_invoice_pdf_to_invoices.rb +1 -1
  84. data/db/migrate/20230530172604_add_enable_customer_emails.rb +6 -0
  85. data/lib/generators/tang/install_generator.rb +1 -1
  86. data/lib/generators/templates/create_tang.rb +2 -2
  87. data/lib/tang/engine.rb +1 -1
  88. data/lib/tang/version.rb +1 -1
  89. data/lib/tang.rb +6 -6
  90. data/lib/tasks/cucumber.rake +50 -51
  91. data/lib/tasks/tang_tasks.rake +3 -3
  92. metadata +42 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bea3d8985d70c63421fda5fde41fb7319a8472598aa8545d99d9345008bff20b
4
- data.tar.gz: 34579da07b32d7464b6cd2bf8cfe12ff2605c055eafeb13093277e48d615e91f
3
+ metadata.gz: f6c00e737bbd192088ebffd71f41793412c58ccaf3c71365c08c5e5d024346ab
4
+ data.tar.gz: '00954182108869f7fdbedab739d8a5ea51794279b4881bac6518e9b66c79f02c'
5
5
  SHA512:
6
- metadata.gz: 8a53b31ff88b6fe827a49e6978d041af87120969e99174a8b8b5bbf7b1f68ad9d358aa9ecc764519d5bec92d17a22dc27e4ce34681a5b295b47a9d5a40a7a8df
7
- data.tar.gz: 31f717a5b0a44ea6a33e7a6284c69686c3bbbc18ca425036ae43d05f3321c7380004b1c180a4efb717fc3c463b23bd6bc12fad7d1395ab5b543c17c0e206abb9
6
+ metadata.gz: 9616e9c1b253806fdc536fcb58f6f9f3afa3d848dca7ae945a04afc288df3cc8bb549faee196ff098d83f67942f102f5342a55da2bc04d6c045424dad9cab27f
7
+ data.tar.gz: 3cd81024f490c012b331131b4e6b8377714df41799883b7ace034603b2434083b35b719fb61e31404e72d2375a33d2542a81bc5a8d72292d574cdae0f23a0509
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
- APP_RAKEFILE = File.expand_path("../spec/tang_app/Rakefile", __FILE__)
17
+ APP_RAKEFILE = File.expand_path('../spec/tang_app/Rakefile', __FILE__)
18
18
  load 'rails/tasks/engine.rake'
19
19
 
20
20
  load 'rails/tasks/statistics.rake'
@@ -26,7 +26,7 @@ load './lib/tasks/tang_tasks.rake'
26
26
  begin
27
27
  require 'rspec/core/rake_task'
28
28
  RSpec::Core::RakeTask.new(spec: 'app:db:test:prepare')
29
- task :cucumber => 'app:cucumber'
29
+ task cucumber: 'app:cucumber'
30
30
  task default: [:spec, :cucumber]
31
31
  rescue LoadError
32
32
  puts 'rspec/core/rake_task not required'
@@ -53,5 +53,5 @@ namespace :rails do
53
53
  Dir.chdir('spec/tang_app') do
54
54
  system('rails c')
55
55
  end
56
- end
56
+ end
57
57
  end
@@ -3,12 +3,10 @@ module Tang
3
3
  before_action :ensure_customer
4
4
 
5
5
  def ensure_customer
6
- authenticate_user! if self.respond_to?(:authenticate_user!)
6
+ authenticate_user! if respond_to?(:authenticate_user!)
7
7
  @current_customer = current_user
8
8
  end
9
9
 
10
- def current_customer
11
- @current_customer
12
- end
10
+ attr_reader :current_customer
13
11
  end
14
12
  end
@@ -1,13 +1,13 @@
1
- require_dependency "tang/application_controller"
1
+ require_dependency 'tang/application_controller'
2
2
 
3
3
  module Tang
4
4
  class Account::CardsController < Account::ApplicationController
5
5
  before_action :set_card, only: [:show, :destroy]
6
6
 
7
7
  def show
8
- @can_delete_card = current_customer.stripe_id.present? &&
9
- current_customer.subscription.nil? &&
10
- @card.present?
8
+ @can_delete_card = current_customer.stripe_id.present? &&
9
+ current_customer.subscription.nil? &&
10
+ @card.present?
11
11
  end
12
12
 
13
13
  def new
@@ -44,17 +44,20 @@ module Tang
44
44
 
45
45
  def destroy
46
46
  if current_customer.subscription.nil?
47
- @card.destroy
48
- redirect_to account_card_url, notice: 'Card was successfully removed.'
47
+ if @card.present?
48
+ @card.destroy
49
+ redirect_to account_card_url, notice: 'Card was successfully removed.'
50
+ else
51
+ redirect_to account_card_url, notice: 'We could not find a card to remove.'
52
+ end
49
53
  else
50
- redirect_to account_card_url, notice: 'You cannot remove your card with an active subscription.'
54
+ redirect_to account_card_url, notice: 'You cannot remove your card with an active subscription.'
51
55
  end
52
56
  end
53
57
 
54
58
  private
55
59
 
56
60
  def set_card
57
- logger.debug "SET CARD CALLED"
58
61
  @card = current_customer.card
59
62
  end
60
63
  end
@@ -1,4 +1,4 @@
1
- require_dependency "tang/application_controller"
1
+ require_dependency 'tang/application_controller'
2
2
 
3
3
  module Tang
4
4
  class Account::CouponsController < Account::ApplicationController
@@ -1,11 +1,17 @@
1
- require_dependency "tang/application_controller"
1
+ require_dependency 'tang/application_controller'
2
2
 
3
3
  module Tang
4
4
  class Account::ReceiptsController < Account::ApplicationController
5
5
  def index
6
- @invoices = current_customer.invoices.
7
- paginate(page: params[:page]).
8
- order(date: :desc)
6
+ @invoices = current_customer.invoices
7
+ .paginate(page: params[:page])
8
+ .order(date: :desc)
9
+ end
10
+
11
+ def download
12
+ invoice = Invoice.find(params[:id])
13
+ invoice = RefreshInvoicePdf.call(invoice)
14
+ redirect_to invoice.invoice_pdf
9
15
  end
10
16
  end
11
17
  end
@@ -1,20 +1,20 @@
1
- require_dependency "tang/application_controller"
1
+ require_dependency 'tang/application_controller'
2
2
 
3
3
  module Tang
4
4
  class Account::SubscriptionsController < Account::ApplicationController
5
5
  before_action :set_subscription, only: [:show, :edit, :update, :destroy]
6
6
 
7
7
  def show
8
- if !current_customer.stripe_enabled?
9
- render :not_stripe and return
10
- end
8
+ render :not_stripe and return unless current_customer.stripe_enabled?
11
9
 
12
10
  @plans = Plan.where(interval: 'month').order(:order)
13
11
 
14
12
  if @subscription.present? && @subscription.plan.present?
15
- @next_plan = @plans.where("tang_plans.order > ?", @subscription.plan.order).first
16
- @previous_plan = @plans.where("tang_plans.order < ?", @subscription.plan.order).last
13
+ puts "subscription present and plan present"
14
+ @next_plan = @plans.where('tang_plans.order > ?', @subscription.plan.order).first
15
+ @previous_plan = @plans.where('tang_plans.order < ?', @subscription.plan.order).last
17
16
  else
17
+ puts "subscription not present or plan not present"
18
18
  @next_plan = @plans.first
19
19
  @previous_plan = nil
20
20
  end
@@ -31,6 +31,7 @@ module Tang
31
31
  end
32
32
 
33
33
  def create
34
+ # TODO: check how it's possible to get here without a stripe_token
34
35
  plan = Plan.find(subscription_params[:plan])
35
36
  @subscription = CreateSubscription.call(
36
37
  plan,
@@ -61,8 +62,9 @@ module Tang
61
62
  redirect_to account_subscription_path, notice: 'Subscription was successfully changed.'
62
63
  else
63
64
  @plans = Plan.order(:order)
64
- @next_plan = @plans.where("tang_plans.order > ?", @subscription.plan.order).first
65
- @previous_plan = @plans.where("tang_plans.order < ?", @subscription.plan.order).last
65
+ @next_plan = @plans.where('tang_plans.order > ?', @subscription.plan.order).first
66
+ @previous_plan = @plans.where('tang_plans.order < ?', @subscription.plan.order).last
67
+ @receipts = current_customer.charges.order(created: :desc).limit(5)
66
68
  render :show
67
69
  end
68
70
  end
@@ -77,6 +79,7 @@ module Tang
77
79
 
78
80
  def set_subscription
79
81
  @subscription = current_customer.subscription
82
+ puts "set_subscription: #{@subscription}"
80
83
  end
81
84
 
82
85
  def subscription_params
@@ -5,10 +5,10 @@ module Tang
5
5
  layout Tang.admin_layout
6
6
 
7
7
  def ensure_admin
8
- authenticate_user! if self.respond_to?(:authenticate_user!)
9
- unless current_user.present? && current_user.respond_to?(:admin?) && current_user.admin?
10
- redirect_to Tang.unauthorized_url, alert: 'You do not have access to that.'
11
- end
8
+ authenticate_user! if respond_to?(:authenticate_user!)
9
+ return if current_user.present? && current_user.respond_to?(:admin?) && current_user.admin?
10
+
11
+ redirect_to Tang.unauthorized_url, alert: 'You do not have access to that.'
12
12
  end
13
13
  end
14
14
  end
@@ -1,4 +1,4 @@
1
- require_dependency "tang/application_controller"
1
+ require_dependency 'tang/application_controller'
2
2
 
3
3
  module Tang
4
4
  class Admin::CouponsController < Admin::ApplicationController
@@ -6,14 +6,13 @@ module Tang
6
6
 
7
7
  # GET /coupons
8
8
  def index
9
- @coupons = Coupon.all.
10
- paginate(page: params[:page]).
11
- order(:stripe_id)
9
+ @coupons = Coupon.all
10
+ .paginate(page: params[:page])
11
+ .order(:stripe_id)
12
12
  end
13
13
 
14
14
  # GET /coupons/1
15
- def show
16
- end
15
+ def show; end
17
16
 
18
17
  # GET /coupons/new
19
18
  def new
@@ -38,14 +37,19 @@ module Tang
38
37
  end
39
38
 
40
39
  private
41
- # Use callbacks to share common setup or constraints between actions.
42
- def set_coupon
43
- @coupon = Coupon.find(params[:id])
44
- end
45
40
 
46
- # Only allow a trusted parameter "white list" through.
47
- def coupon_params
48
- params.require(:coupon).permit(:stripe_id, :duration, :amount_off, :currency, :duration_in_months, :max_redemptions, :percent_off, :redeem_by)
49
- end
41
+ # Use callbacks to share common setup or constraints between actions.
42
+ def set_coupon
43
+ @coupon = Coupon.find(params[:id])
44
+ end
45
+
46
+ # Only allow a trusted parameter "white list" through.
47
+ def coupon_params
48
+ params.require(:coupon)
49
+ .permit(
50
+ :stripe_id, :duration, :amount_off, :currency,
51
+ :duration_in_months, :max_redemptions, :percent_off, :redeem_by
52
+ )
53
+ end
50
54
  end
51
55
  end
@@ -1,4 +1,4 @@
1
- require_dependency "tang/application_controller"
1
+ require_dependency 'tang/application_controller'
2
2
 
3
3
  module Tang
4
4
  class Admin::CustomersController < Admin::ApplicationController
@@ -6,18 +6,17 @@ module Tang
6
6
 
7
7
  # GET /customers
8
8
  def index
9
- @customers = Tang.customer_class.where.not(stripe_id: nil).
10
- paginate(page: params[:page]).
11
- order(:email)
9
+ @customers = Tang.customer_class
10
+ .where.not(stripe_id: nil)
11
+ .paginate(page: params[:page])
12
+ .order(:email)
12
13
  end
13
14
 
14
15
  # GET /customers/1
15
- def show
16
- end
16
+ def show; end
17
17
 
18
18
  # GET /customers/1/edit
19
- def edit
20
- end
19
+ def edit; end
21
20
 
22
21
  # PATCH/PUT /customers/1
23
22
  def update
@@ -53,14 +52,15 @@ module Tang
53
52
  end
54
53
 
55
54
  private
56
- # Use callbacks to share common setup or constraints between actions.
57
- def set_customer
58
- @customer = Tang.customer_class.find(params[:id])
59
- end
60
55
 
61
- # Only allow a trusted parameter "white list" through.
62
- def customer_params
63
- params.require(Tang.customer_class.to_s.downcase).permit(:email, :account_balance)
64
- end
56
+ # Use callbacks to share common setup or constraints between actions.
57
+ def set_customer
58
+ @customer = Tang.customer_class.find(params[:id])
59
+ end
60
+
61
+ # Only allow a trusted parameter "white list" through.
62
+ def customer_params
63
+ params.require(Tang.customer_class.to_s.downcase).permit(:email, :account_balance)
64
+ end
65
65
  end
66
66
  end
@@ -1,4 +1,4 @@
1
- require_dependency "tang/application_controller"
1
+ require_dependency 'tang/application_controller'
2
2
 
3
3
  module Tang
4
4
  class Admin::DashboardController < Admin::ApplicationController
@@ -1,15 +1,15 @@
1
- require_dependency "tang/application_controller"
1
+ require_dependency 'tang/application_controller'
2
2
 
3
3
  module Tang
4
4
  class Admin::InvoicesController < Admin::ApplicationController
5
5
  before_action :set_invoice, only: [:show]
6
6
 
7
- def show
8
- end
7
+ def show; end
9
8
 
10
9
  private
11
- def set_invoice
12
- @invoice = Invoice.find(params[:id])
13
- end
10
+
11
+ def set_invoice
12
+ @invoice = Invoice.find(params[:id])
13
+ end
14
14
  end
15
15
  end
@@ -1,21 +1,21 @@
1
- require_dependency "tang/application_controller"
1
+ require_dependency 'tang/application_controller'
2
2
 
3
3
  module Tang
4
4
  class Admin::PaymentsController < Admin::ApplicationController
5
5
  before_action :set_payment, only: [:show]
6
6
 
7
7
  def index
8
- @payments = Tang::Charge.all.
9
- paginate(page: params[:page]).
10
- order(created: :desc)
8
+ @payments = Tang::Charge.all
9
+ .paginate(page: params[:page])
10
+ .order(created: :desc)
11
11
  end
12
12
 
13
- def show
14
- end
13
+ def show; end
15
14
 
16
15
  private
17
- def set_payment
18
- @payment = Charge.find(params[:id])
19
- end
16
+
17
+ def set_payment
18
+ @payment = Charge.find(params[:id])
19
+ end
20
20
  end
21
21
  end
@@ -1,4 +1,4 @@
1
- require_dependency "tang/application_controller"
1
+ require_dependency 'tang/application_controller'
2
2
 
3
3
  module Tang
4
4
  class Admin::PlansController < Admin::ApplicationController
@@ -6,14 +6,13 @@ module Tang
6
6
 
7
7
  # GET /plans
8
8
  def index
9
- @plans = Plan.all.
10
- paginate(page: params[:page]).
11
- order(:name)
9
+ @plans = Plan.all
10
+ .paginate(page: params[:page])
11
+ .order(:name)
12
12
  end
13
13
 
14
14
  # GET /plans/1
15
- def show
16
- end
15
+ def show; end
17
16
 
18
17
  # GET /plans/new
19
18
  def new
@@ -21,8 +20,7 @@ module Tang
21
20
  end
22
21
 
23
22
  # GET /plans/1/edit
24
- def edit
25
- end
23
+ def edit; end
26
24
 
27
25
  # POST /plans
28
26
  def create
@@ -51,18 +49,22 @@ module Tang
51
49
  end
52
50
 
53
51
  private
54
- # Use callbacks to share common setup or constraints between actions.
55
- def set_plan
56
- @plan = Plan.find(params[:id])
57
- end
58
52
 
59
- # Only allow a trusted parameter "white list" through.
60
- def plan_create_params
61
- params.require(:plan).permit(:stripe_id, :amount, :currency, :interval, :interval_count, :name, :statement_descriptor, :trial_period_days, :order, :highlight, :features, :description, :group)
62
- end
53
+ # Use callbacks to share common setup or constraints between actions.
54
+ def set_plan
55
+ @plan = Plan.find(params[:id])
56
+ end
63
57
 
64
- def plan_update_params
65
- params.require(:plan).permit(:name, :order, :highlight, :features, :description, :group)
66
- end
58
+ # Only allow a trusted parameter "white list" through.
59
+ def plan_create_params
60
+ params.require(:plan).permit(
61
+ :stripe_id, :amount, :currency, :interval, :interval_count, :name,
62
+ :statement_descriptor, :trial_period_days, :order, :highlight, :features, :description, :group
63
+ )
64
+ end
65
+
66
+ def plan_update_params
67
+ params.require(:plan).permit(:name, :order, :highlight, :features, :description, :group)
68
+ end
67
69
  end
68
70
  end
@@ -1,4 +1,4 @@
1
- require_dependency "tang/application_controller"
1
+ require_dependency 'tang/application_controller'
2
2
 
3
3
  module Tang
4
4
  class Admin::SearchController < Admin::ApplicationController
@@ -18,41 +18,42 @@ module Tang
18
18
  private
19
19
 
20
20
  def search_charges
21
- return Charge.search(@query)
21
+ Charge.search(@query)
22
22
  end
23
23
 
24
24
  def search_customers
25
- return Customer.search(@query)
25
+ Customer.search(@query)
26
26
  end
27
27
 
28
28
  def search_plans
29
29
  plans = Plan.none
30
30
  if @query.present?
31
31
  q = "%#{@query.downcase}%"
32
- plans = Plan.where("lower(tang_plans.stripe_id) like ? or lower(tang_plans.name) like ?",
33
- q, q).
34
- distinct
32
+ plans = Plan.where('lower(tang_plans.stripe_id) like ? or lower(tang_plans.name) like ?',
33
+ q,
34
+ q)
35
+ .distinct
35
36
  end
36
- return plans
37
+ plans
37
38
  end
38
39
 
39
40
  def search_coupons
40
41
  coupons = Coupon.none
41
42
  if @query.present?
42
43
  q = "%#{@query.downcase}%"
43
- coupons = Coupon.where("lower(tang_coupons.stripe_id) like ?",
44
- q).
45
- distinct
44
+ coupons = Coupon.where('lower(tang_coupons.stripe_id) like ?',
45
+ q)
46
+ .distinct
46
47
  end
47
- return coupons
48
+ coupons
48
49
  end
49
50
 
50
51
  def search_invoices
51
- return Invoice.search(@query)
52
+ Invoice.search(@query)
52
53
  end
53
54
 
54
55
  def search_invoice_items
55
- return InvoiceItem.search(@query)
56
+ InvoiceItem.search(@query)
56
57
  end
57
58
  end
58
- end
59
+ end
@@ -1,4 +1,4 @@
1
- require_dependency "tang/application_controller"
1
+ require_dependency 'tang/application_controller'
2
2
 
3
3
  module Tang
4
4
  class Admin::SubscriptionsController < Admin::ApplicationController
@@ -6,19 +6,17 @@ module Tang
6
6
 
7
7
  # GET /subscriptions
8
8
  def index
9
- @subscriptions = Subscription.includes(:customer).
10
- where.not(status: :canceled).
11
- paginate(page: params[:page]).
12
- order("#{Customer.table_name}.email")
9
+ @subscriptions = Subscription.includes(:customer)
10
+ .where.not(status: :canceled)
11
+ .paginate(page: params[:page])
12
+ .order("#{Customer.table_name}.email")
13
13
  end
14
14
 
15
15
  # GET /subscriptions/1
16
- def show
17
- end
16
+ def show; end
18
17
 
19
18
  # GET /subscriptions/1/edit
20
- def edit
21
- end
19
+ def edit; end
22
20
 
23
21
  # PATCH/PUT /subscriptions/1
24
22
  def update
@@ -60,14 +58,15 @@ module Tang
60
58
  end
61
59
 
62
60
  private
63
- # Use callbacks to share common setup or constraints between actions.
64
- def set_subscription
65
- @subscription = Subscription.find(params[:id])
66
- end
67
61
 
68
- # Only allow a trusted parameter "white list" through.
69
- def subscription_params
70
- params.require(:subscription).permit(:plan_id, :quantity, :trial_end)
71
- end
62
+ # Use callbacks to share common setup or constraints between actions.
63
+ def set_subscription
64
+ @subscription = Subscription.find(params[:id])
65
+ end
66
+
67
+ # Only allow a trusted parameter "white list" through.
68
+ def subscription_params
69
+ params.require(:subscription).permit(:plan_id, :quantity, :trial_end)
70
+ end
72
71
  end
73
72
  end
@@ -1,4 +1,4 @@
1
- require_dependency "tang/application_controller"
1
+ require_dependency 'tang/application_controller'
2
2
 
3
3
  module Tang
4
4
  class PlansController < ApplicationController
@@ -2,11 +2,6 @@ require 'will_paginate/view_helpers/action_view'
2
2
 
3
3
  module Tang
4
4
  module ApplicationHelper
5
-
6
- # def created_date(date)
7
- # date.strftime('%Y/%m/%d')
8
- # end
9
-
10
5
  def created_datetime(date)
11
6
  date.strftime('%Y/%m/%d %H:%M')
12
7
  end
@@ -39,28 +34,24 @@ module Tang
39
34
  end
40
35
 
41
36
  def will_paginate(collection_or_options = nil, options = {})
42
- if collection_or_options.is_a? Hash
43
- options, collection_or_options = collection_or_options, nil
44
- end
45
- unless options[:renderer]
46
- options = options.merge renderer: BootstrapLinkRenderer
47
- end
37
+ options, collection_or_options = collection_or_options, nil if collection_or_options.is_a? Hash
38
+ options = options.merge renderer: BootstrapLinkRenderer unless options[:renderer]
48
39
  super(*[collection_or_options, options].compact)
49
40
  end
50
41
 
51
42
  class BootstrapLinkRenderer < WillPaginate::ActionView::LinkRenderer
52
- ELLIPSIS = "&hellip;"
43
+ ELLIPSIS = '&hellip;'.freeze
53
44
 
54
45
  def to_html
55
46
  list_items = pagination.map do |item|
56
47
  case item
57
- when Fixnum
58
- page_number(item)
59
- else
60
- send(item)
48
+ when Integer
49
+ page_number(item)
50
+ else
51
+ send(item)
61
52
  end
62
53
  end.join(@options[:link_separator])
63
- tag("ul", list_items, class: ul_class)
54
+ tag('ul', list_items, class: ul_class)
64
55
  end
65
56
 
66
57
  def container_attributes
@@ -73,41 +64,44 @@ module Tang
73
64
  link_options = @options[:link_options] || {}
74
65
 
75
66
  if page == current_page
76
- tag("li", tag('span', page.to_s + ' <span class="sr-only">(current)</span>', class: 'page-link'), class: "page-item active")
67
+ tag(
68
+ 'li',
69
+ tag('span', "#{page} <span class=\"sr-only\">(current)</span>", class: 'page-link'),
70
+ class: 'page-item active'
71
+ )
77
72
  else
78
- tag("li", link(page, page, link_options.merge(rel: rel_value(page), class: 'page-link')), class: 'page-item')
73
+ tag('li', link(page, page, link_options.merge(rel: rel_value(page), class: 'page-link')), class: 'page-item')
79
74
  end
80
75
  end
81
76
 
82
77
  def previous_or_next_page(page, text, classname)
83
78
  link_options = @options[:link_options] || {}
84
79
  if page
85
- tag("li", link(text, page, link_options.merge(class: 'page-link')), class: "%s page-item" % classname)
80
+ tag('li', link(text, page, link_options.merge(class: 'page-link')), class: format('%s page-item', classname))
86
81
  else
87
- tag("li", tag('span', text, class: 'page-link'), class: "%s page-item disabled" % classname)
82
+ tag('li', tag('span', text, class: 'page-link'), class: format('%s page-item disabled', classname))
88
83
  end
89
84
  end
90
85
 
91
86
  def gap
92
- tag("li", tag("span", ELLIPSIS), class: "page-item disabled")
87
+ tag('li', tag('span', ELLIPSIS), class: 'page-item disabled')
93
88
  end
94
89
 
95
90
  def previous_page
96
91
  @options[:previous_label] = '<span aria-hidden="true">&laquo;</span><span class="sr-only">Previous</span>'
97
- num = @collection.current_page > 1 && @collection.current_page - 1
98
- previous_or_next_page(num, @options[:previous_label], "prev")
92
+ num = @collection.current_page > 1 && (@collection.current_page - 1)
93
+ previous_or_next_page(num, @options[:previous_label], 'prev')
99
94
  end
100
95
 
101
96
  def next_page
102
97
  @options[:next_label] = '<span aria-hidden="true">&raquo;</span><span class="sr-only">Next</span>'
103
- num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
104
- previous_or_next_page(num, @options[:next_label], "next")
98
+ num = @collection.current_page < @collection.total_pages && (@collection.current_page + 1)
99
+ previous_or_next_page(num, @options[:next_label], 'next')
105
100
  end
106
101
 
107
102
  def ul_class
108
- [@options[:class]].compact.join(" ")
103
+ [@options[:class]].compact.join(' ')
109
104
  end
110
105
  end
111
-
112
106
  end
113
107
  end