cirandas.net

ref: master

test/unit/time_scopes.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# encoding: UTF-8
require_relative "../test_helper"

#FIXME Find a way to test with a generic example

class TimeScopesTest < ActiveSupport::TestCase
  should 'fetch profiles older than a specific date' do
    p1 = fast_create(Profile, :created_at => Time.now.in_time_zone)
    p2 = fast_create(Profile, :created_at => Time.now.in_time_zone - 1.day)
    p3 = fast_create(Profile, :created_at => Time.now.in_time_zone - 2.days)
    p4 = fast_create(Profile, :created_at => Time.now.in_time_zone - 3.days)

    profiles = Profile.older_than(p2.created_at)

    assert_not_includes profiles, p1
    assert_not_includes profiles, p2
    assert_includes profiles, p3
    assert_includes profiles, p4
  end

  should 'fetch profiles younger than a specific date' do
    p1 = fast_create(Profile, :created_at => Time.now.in_time_zone)
    p2 = fast_create(Profile, :created_at => Time.now.in_time_zone - 1.day)
    p3 = fast_create(Profile, :created_at => Time.now.in_time_zone - 2.days)
    p4 = fast_create(Profile, :created_at => Time.now.in_time_zone - 3.days)

    profiles = Profile.younger_than(p3.created_at)

    assert_includes profiles, p1
    assert_includes profiles, p2
    assert_not_includes profiles, p3
    assert_not_includes profiles, p4
  end
end