Skip to content

Commit

Permalink
Custom Automatic Checkout Time per Owner
Browse files Browse the repository at this point in the history
  • Loading branch information
salimhb committed Aug 28, 2020
1 parent 0e29d2c commit feb013d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/models/concerns/rails_admin_config/for_owner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module ForOwner

included do
rails_admin do
fields :id, :email, :created_at, :name, :companies, :affiliate, :can_use_for_free, :trial_ends_at, :block_at, :frontend, :stripe_subscription_id, :stripe_customer_id
fields :id, :email, :created_at, :name, :companies, :affiliate, :can_use_for_free, :trial_ends_at, :block_at, :frontend, :stripe_subscription_id, :stripe_customer_id, :auto_checkout_minutes

field :stripe_subscription_status do
read_only true
Expand All @@ -13,7 +13,7 @@ module ForOwner
field :api_token do
read_only true
end

list do
scopes [:all, :affiliate, :with_stripe_data]
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class Ticket < ApplicationRecord
delegate :name, to: :area, prefix: :area

def schedule_auto_checkout_job
AutoCheckoutTicketJob.set(wait: AUTO_CHECKOUT_AFTER).perform_later(id)
AutoCheckoutTicketJob.set(wait: company.owner.auto_checkout_minutes.try(:minutes) || AUTO_CHECKOUT_AFTER).perform_later(id)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAutoCheckoutMinutesToOwners < ActiveRecord::Migration[6.0]
def change
add_column :owners, :auto_checkout_minutes, :integer
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_08_27_142840) do
ActiveRecord::Schema.define(version: 2020_08_28_192134) do

# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
Expand Down Expand Up @@ -102,6 +102,7 @@
t.datetime "block_at"
t.bigint "frontend_id"
t.string "api_token"
t.integer "auto_checkout_minutes"
t.index ["confirmation_token"], name: "index_owners_on_confirmation_token", unique: true
t.index ["email"], name: "index_owners_on_email", unique: true
t.index ["frontend_id"], name: "index_owners_on_frontend_id"
Expand Down
9 changes: 8 additions & 1 deletion spec/requests/tickets_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
expect(JSON.parse(response.body)).not_to be_empty
end

it { is_expected.to have_enqueued_job(AutoCheckoutTicketJob) }
# Using 1 second tolerence as noted in https://github.com/rspec/rspec-rails/issues/2333#issuecomment-628790743
# Alternative: user Timecop
it { is_expected.to have_enqueued_job(AutoCheckoutTicketJob).at(a_value_within(1.seconds).of(4.hours.from_now)) }

it 'uses auto_checkout_minutes from owner' do
area.company.owner.update_attribute(:auto_checkout_minutes, 720)
is_expected.to have_enqueued_job(AutoCheckoutTicketJob).at(a_value_within(1.seconds).of(12.hours.from_now))
end
end

context 'PATCH update' do
Expand Down

0 comments on commit feb013d

Please sign in to comment.