Skip to content

Commit 463db0f

Browse files
committed
test ActiveRecordWrapper#sql_conditions for from/until
- verifies #52 fixed
1 parent 4acd9d4 commit 463db0f

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
require 'test_helper_ar_provider'
2+
3+
class ActiveRecordWrapperTest < TransactionalTestCase
4+
def test_sql_conditions_from_date
5+
input = "2005-12-25"
6+
expected = input.dup
7+
sql_template, sql_opts = sql_conditions(from: input)
8+
assert_equal "updated_at >= :from", sql_template
9+
assert_equal expected, sql_opts[:from]
10+
sql_template, sql_opts = sql_conditions(from: Date.strptime(input, "%Y-%m-%d"))
11+
assert_equal "updated_at >= :from", sql_template
12+
assert_equal expected, sql_opts[:from]
13+
end
14+
15+
def test_sql_conditions_from_time
16+
input = "2005-12-25T00:00:00Z"
17+
expected = "2005-12-25 00:00:00"
18+
sql_template, sql_opts = sql_conditions(from: input)
19+
assert_equal "updated_at >= :from", sql_template
20+
assert_equal expected, sql_opts[:from]
21+
sql_template, sql_opts = sql_conditions(from: Time.strptime(input, "%Y-%m-%dT%H:%M:%S%Z"))
22+
assert_equal "updated_at >= :from", sql_template
23+
assert_equal expected, sql_opts[:from]
24+
end
25+
26+
def test_sql_conditions_until_date
27+
input = "2005-12-25"
28+
expected = "2005-12-26"
29+
sql_template, sql_opts = sql_conditions(until: input)
30+
assert_equal "updated_at < :until", sql_template
31+
assert_equal expected, sql_opts[:until]
32+
sql_template, sql_opts = sql_conditions(until: Date.strptime(input, "%Y-%m-%d"))
33+
assert_equal "updated_at < :until", sql_template
34+
assert_equal expected, sql_opts[:until]
35+
end
36+
37+
def test_sql_conditions_until_time
38+
input = "2005-12-25T00:00:00Z"
39+
expected = "2005-12-25 00:00:01"
40+
sql_template, sql_opts = sql_conditions(until: input)
41+
assert_equal "updated_at < :until", sql_template
42+
assert_equal expected, sql_opts[:until]
43+
sql_template, sql_opts = sql_conditions(until: Time.strptime(input, "%Y-%m-%dT%H:%M:%S%Z"))
44+
assert_equal "updated_at < :until", sql_template
45+
assert_equal expected, sql_opts[:until]
46+
end
47+
48+
def test_sql_conditions_both
49+
input = "2005-12-25"
50+
sql_template, sql_opts = sql_conditions(from: input, until: input)
51+
assert_equal "updated_at >= :from AND updated_at < :until", sql_template
52+
end
53+
54+
def setup
55+
@wrapper = OAI::Provider::ActiveRecordWrapper.new(DCField)
56+
end
57+
58+
def sql_conditions(opts)
59+
@wrapper.send :sql_conditions, opts
60+
end
61+
end
62+
63+

0 commit comments

Comments
 (0)