New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expire Carts after 300 seconds #104 #105
base: master
Are you sure you want to change the base?
Conversation
app/models/cart.rb
Outdated
end | ||
|
||
def expired? | ||
DateTime.now > expires_at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use DateTime.now without zone. Use one of Time.zone.now, DateTime.current, DateTime.now.in_time_zone, DateTime.now.utc, DateTime.now.getlocal, DateTime.now.iso8601, DateTime.now.jisx0301, DateTime.now.rfc3339, DateTime.now.to_i, DateTime.now.to_f instead.
app/models/cart.rb
Outdated
def total_price | ||
cart_items.map(&:total_price).reduce(:+) | ||
end | ||
|
||
def expires_at | ||
(updated_at || DateTime.now) + EXPIRE_AFTER.seconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use DateTime.now without zone. Use one of Time.zone.now, DateTime.current, DateTime.now.in_time_zone, DateTime.now.utc, DateTime.now.getlocal, DateTime.now.iso8601, DateTime.now.jisx0301, DateTime.now.rfc3339, DateTime.now.to_i, DateTime.now.to_f instead.
@@ -3,7 +3,7 @@ class ResolveCartAndUser | |||
|
|||
def call | |||
begin | |||
context.cart = Cart.find_by_id!(context.cart_id) | |||
context.cart = Cart.unexpired.find_by_id!(context.cart_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use find_by! instead of dynamic find_by_id!.
@@ -11,7 +11,7 @@ | |||
} | |||
|
|||
describe '#show' do | |||
before {User.find_by_id(1) || create(:user, id: 1)} | |||
before {User.find_by(id: 1) || create(:user, id: 1)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space missing inside {.
Space missing inside }.
@@ -32,7 +32,7 @@ | |||
before {get :index} | |||
|
|||
context 'when there are products' do | |||
before {(1..3).each {|y| Product.find_by_id(y) || create(:product, id: y)}} | |||
before {(1..3).each {|y| Product.find_by(id: y) || create(:product, id: y)}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space missing inside {.
Space between { and | missing.
Space missing inside }.
Line is too long. [82/80]
@@ -11,7 +11,7 @@ | |||
} | |||
|
|||
describe '#show' do | |||
before {Product.find_by_id(1) || create(:product, id: 1)} | |||
before {Product.find_by(id: 1) || create(:product, id: 1)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space missing inside {.
Space missing inside }.
@@ -11,7 +11,7 @@ | |||
} | |||
|
|||
describe '#show' do | |||
before {Cart.find_by_id(1) || create(:cart, id: 1)} | |||
before {Cart.find_by(id: 1) || create(:cart, id: 1)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space missing inside {.
Space missing inside }.
1d674c9
to
43f4d07
Compare
After Cart expiry reserved products are released, expired Carts are read-only.