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

Add tests for inequality with relative times #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 117 additions & 5 deletions test/datetime_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,41 +66,153 @@ def test_less_equals
refute_includes Product.search("created_at <= 2014-05-01"), product
end

def test_hours_ago
def test_hours_ago_less
product = create(:product, created_at: 5.hours.ago)

assert_includes Product.search("created_at < '4 hours ago'"), product
refute_includes Product.search("created_at < '6 hours ago'"), product
end

def test_hours_ago_less
product = create(:product, created_at: 5.hours.ago)

assert_includes Product.search("created_at < '4 hours ago'"), product
refute_includes Product.search("created_at < '6 hours ago'"), product
end

def test_hours_ago_less_equals
product = create(:product, created_at: 5.hours.ago)

assert_includes Product.search("created_at <= '4 hours ago'"), product
refute_includes Product.search("created_at <= '6 hours ago'"), product
end

def test_days_ago
def test_hours_ago_greater
product = create(:product, created_at: 5.hours.ago)

refute_includes Product.search("created_at > '4 hours ago'"), product
assert_includes Product.search("created_at > '6 hours ago'"), product
end

def test_hours_ago_greater_equals
product = create(:product, created_at: 5.hours.ago)

refute_includes Product.search("created_at >= '4 hours ago'"), product
assert_includes Product.search("created_at >= '6 hours ago'"), product
end

def test_days_ago_less
product = create(:product, created_at: 2.days.ago)

assert_includes Product.search("created_at < '1 day ago'"), product
refute_includes Product.search("created_at < '3 days ago'"), product
end

def test_days_ago_less_equals
product = create(:product, created_at: 2.days.ago)

assert_includes Product.search("created_at <= '1 day ago'"), product
refute_includes Product.search("created_at <= '3 days ago'"), product
end

def test_weeks_ago
def test_days_ago_greater
product = create(:product, created_at: 2.days.ago)

refute_includes Product.search("created_at > '1 day ago'"), product
assert_includes Product.search("created_at > '3 days ago'"), product
end

def test_days_ago_greater_equals
product = create(:product, created_at: 2.days.ago)

refute_includes Product.search("created_at >= '1 day ago'"), product
assert_includes Product.search("created_at >= '3 days ago'"), product
end

def test_weeks_ago_less
product = create(:product, created_at: 2.weeks.ago)

assert_includes Product.search("created_at < '1 weeks ago'"), product
refute_includes Product.search("created_at < '3 weeks ago'"), product
end

def test_weeks_ago_less_equals
product = create(:product, created_at: 2.weeks.ago)

assert_includes Product.search("created_at <= '1 weeks ago'"), product
refute_includes Product.search("created_at <= '3 weeks ago'"), product
end

def test_months_ago
def test_weeks_ago_greater
product = create(:product, created_at: 2.weeks.ago)

refute_includes Product.search("created_at > '1 weeks ago'"), product
assert_includes Product.search("created_at > '3 weeks ago'"), product
end

def test_weeks_ago_greater_equals
product = create(:product, created_at: 2.weeks.ago)

refute_includes Product.search("created_at >= '1 weeks ago'"), product
assert_includes Product.search("created_at >= '3 weeks ago'"), product
end

def test_months_ago_less
product = create(:product, created_at: 2.months.ago)

assert_includes Product.search("created_at < '1 months ago'"), product
refute_includes Product.search("created_at < '3 months ago'"), product
end

def test_months_ago_less_equals
product = create(:product, created_at: 2.months.ago)

assert_includes Product.search("created_at <= '1 months ago'"), product
refute_includes Product.search("created_at <= '3 months ago'"), product
end

def test_years_ago
def test_months_ago_greater
product = create(:product, created_at: 2.months.ago)

refute_includes Product.search("created_at > '1 months ago'"), product
assert_includes Product.search("created_at > '3 months ago'"), product
end

def test_months_ago_greater_equals
product = create(:product, created_at: 2.months.ago)

refute_includes Product.search("created_at >= '1 months ago'"), product
assert_includes Product.search("created_at >= '3 months ago'"), product
end

def test_years_ago_less
product = create(:product, created_at: 2.years.ago)

assert_includes Product.search("created_at < '1 years ago'"), product
refute_includes Product.search("created_at < '3 years ago'"), product
end

def test_years_ago_less_equals
product = create(:product, created_at: 2.years.ago)

assert_includes Product.search("created_at <= '1 years ago'"), product
refute_includes Product.search("created_at <= '3 years ago'"), product
end

def test_years_ago_greater
product = create(:product, created_at: 2.years.ago)

refute_includes Product.search("created_at > '1 years ago'"), product
assert_includes Product.search("created_at > '3 years ago'"), product
end

def test_years_ago_greater_equals
product = create(:product, created_at: 2.years.ago)

refute_includes Product.search("created_at >= '1 years ago'"), product
assert_includes Product.search("created_at >= '3 years ago'"), product
end

if DATABASE == "postgres" && ActiveRecord::VERSION::MAJOR >= 7
def test_timestamp_with_zone
product = create(:product, timestamp_with_zone: Time.parse("2014-05-01 12:30:30 CEST"))
Expand Down
Loading