Module: ActiveRecord::Extension::CachedColumn::Etest

Defined in:
lib/vex/active_record/cached_column/etest.rb

Defined Under Namespace

Classes: X

Instance Method Summary collapse

Instance Method Details

#setupObject



2
3
4
# File 'lib/vex/active_record/cached_column/etest.rb', line 2

def setup
  require "timecop"
end

#test_bigger_w_paramsObject



81
82
83
84
85
# File 'lib/vex/active_record/cached_column/etest.rb', line 81

def test_bigger_w_params
  $something = 0
  x = X.create!
  assert_equal("ActiveRecord::Extension::CachedColumn::Etest::X", x.bigger_w_param)
end

#test_somethingObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vex/active_record/cached_column/etest.rb', line 28

def test_something
  $something = 0
  x = X.create!
  assert_equal(0, $something)
  assert_equal("something-big", x.something)
  assert_equal(1, $something)
  assert_equal("something-big", x.something)
  assert_equal(1, $something)

  Timecop.travel(360.seconds) do
    assert_equal(1, $something)
    assert_equal("something-big", x.something)
    assert_equal(2, $something)
  end
end

#test_time_to_liveObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/vex/active_record/cached_column/etest.rb', line 60

def test_time_to_live
  $something = 0
  x = X.create!
  assert_equal(0, $something)
  assert_equal("something-bigger", x.bigger)
  assert_equal(1, $something)

  Timecop.travel(Time.now + 6.minutes) do
    assert_equal(1, $something)
    assert_equal("something-bigger", x.bigger)
    assert_equal(1, $something)
  end

  Timecop.travel(Time.now + 25.hours) do
    assert_equal(1, $something)
    assert_equal("something-bigger", x.bigger)
    assert_equal(2, $something)
  end
end

#test_w_new_recordObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vex/active_record/cached_column/etest.rb', line 44

def test_w_new_record
  $something = 0
  x = X.new
  assert_equal(0, $something)
  assert_equal("something-big", x.something)
  assert_equal(1, $something)
  assert_equal("something-big", x.something)
  assert_equal(1, $something)

  Timecop.travel(360.seconds) do
    assert_equal(1, $something)
    assert_equal("something-big", x.something)
    assert_equal(2, $something)
  end
end