Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thegcat
Copy link
Collaborator

@thegcat thegcat commented Jun 16, 2017

After Cart expiry reserved products are released, expired Carts are read-only.

end

def expired?
DateTime.now > expires_at

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.

def total_price
cart_items.map(&:total_price).reduce(:+)
end

def expires_at
(updated_at || DateTime.now) + EXPIRE_AFTER.seconds

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)

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)}

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)}}

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)}

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)}

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 }.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants