Skip to content

Commit 2439f6d

Browse files
committed
update activerecord tests to use sanitized sql and table prefixes where appropriate
1 parent 8bf712a commit 2439f6d

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed

test/activerecord_provider/tc_activerecord_wrapper.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,50 @@ def test_sql_conditions_from_date
55
input = "2005-12-25"
66
expected = input.dup
77
sql_template, sql_opts = sql_conditions(from: input)
8-
assert_equal "updated_at >= :from", sql_template
8+
assert_equal "dc_fields.updated_at >= :from", sql_template
99
assert_equal expected, sql_opts[:from]
1010
sql_template, sql_opts = sql_conditions(from: Date.strptime(input, "%Y-%m-%d"))
11-
assert_equal "updated_at >= :from", sql_template
11+
assert_equal "dc_fields.updated_at >= :from", sql_template
1212
assert_equal expected, sql_opts[:from]
1313
end
1414

1515
def test_sql_conditions_from_time
1616
input = "2005-12-25T00:00:00Z"
1717
expected = "2005-12-25 00:00:00"
1818
sql_template, sql_opts = sql_conditions(from: input)
19-
assert_equal "updated_at >= :from", sql_template
19+
assert_equal "dc_fields.updated_at >= :from", sql_template
2020
assert_equal expected, sql_opts[:from]
2121
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
22+
assert_equal "dc_fields.updated_at >= :from", sql_template
2323
assert_equal expected, sql_opts[:from]
2424
end
2525

2626
def test_sql_conditions_until_date
2727
input = "2005-12-25"
2828
expected = "2005-12-26"
2929
sql_template, sql_opts = sql_conditions(until: input)
30-
assert_equal "updated_at < :until", sql_template
30+
assert_equal "dc_fields.updated_at < :until", sql_template
3131
assert_equal expected, sql_opts[:until]
3232
sql_template, sql_opts = sql_conditions(until: Date.strptime(input, "%Y-%m-%d"))
33-
assert_equal "updated_at < :until", sql_template
33+
assert_equal "dc_fields.updated_at < :until", sql_template
3434
assert_equal expected, sql_opts[:until]
3535
end
3636

3737
def test_sql_conditions_until_time
3838
input = "2005-12-25T00:00:00Z"
3939
expected = "2005-12-25 00:00:01"
4040
sql_template, sql_opts = sql_conditions(until: input)
41-
assert_equal "updated_at < :until", sql_template
41+
assert_equal "dc_fields.updated_at < :until", sql_template
4242
assert_equal expected, sql_opts[:until]
4343
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
44+
assert_equal "dc_fields.updated_at < :until", sql_template
4545
assert_equal expected, sql_opts[:until]
4646
end
4747

4848
def test_sql_conditions_both
4949
input = "2005-12-25"
5050
sql_template, sql_opts = sql_conditions(from: input, until: input)
51-
assert_equal "updated_at >= :from AND updated_at < :until", sql_template
51+
assert_equal "dc_fields.updated_at >= :from AND dc_fields.updated_at < :until", sql_template
5252
end
5353

5454
def setup

test/activerecord_provider/tc_ar_provider.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ def test_deleted
8181

8282
def test_from
8383
first_id = DCField.order("id asc").first.id
84-
DCField.where("id < #{first_id + 90}").update_all(updated_at: Time.parse("January 1 2005"))
84+
DCField.where("dc_fields.id < #{first_id + 90}").update_all(updated_at: Time.parse("January 1 2005"))
8585

86-
DCField.where("id < #{first_id + 10}").update_all(updated_at: Time.parse("June 1 2005"))
86+
DCField.where("dc_fields.id < #{first_id + 10}").update_all(updated_at: Time.parse("June 1 2005"))
8787

8888

8989
from_param = Time.parse("January 1 2006").getutc.iso8601
@@ -92,7 +92,7 @@ def test_from
9292
@provider.list_records(
9393
:metadata_prefix => 'oai_dc', :from => from_param)
9494
)
95-
assert_equal DCField.where(["updated_at >= ?", from_param]).size,
95+
assert_equal DCField.where(["dc_fields.updated_at >= ?", from_param]).size,
9696
doc.elements['OAI-PMH/ListRecords'].size
9797

9898
doc = REXML::Document.new(
@@ -103,8 +103,8 @@ def test_from
103103
end
104104

105105
def test_until
106-
first_id = DCField.order("id asc").first.id
107-
DCField.where("id < #{first_id + 10}").update_all(updated_at: Time.parse("June 1 2005"))
106+
first_id = DCField.order(id: :asc).first.id
107+
DCField.where("dc_fields.id < ?", first_id + 10).update_all(updated_at: Time.parse("June 1 2005"))
108108

109109
doc = REXML::Document.new(
110110
@provider.list_records(
@@ -114,10 +114,10 @@ def test_until
114114
end
115115

116116
def test_from_and_until
117-
first_id = DCField.order("id asc").first.id
117+
first_id = DCField.order(id: :asc).first.id
118118
DCField.update_all(updated_at: Time.parse("June 1 2005"))
119-
DCField.where("id < #{first_id + 50}").update_all(updated_at: Time.parse("June 15 2005"))
120-
DCField.where("id < #{first_id + 10}").update_all(updated_at: Time.parse("June 30 2005"))
119+
DCField.where("dc_fields.id < ?", first_id + 50).update_all(updated_at: Time.parse("June 15 2005"))
120+
DCField.where("dc_fields.id < ?", first_id + 10).update_all(updated_at: Time.parse("June 30 2005"))
121121

122122
doc = REXML::Document.new(
123123
@provider.list_records(
@@ -129,8 +129,8 @@ def test_from_and_until
129129
end
130130

131131
def test_bad_until_raises_exception
132-
DCField.order('id asc').limit(10).update_all(updated_at: 1.year.ago)
133-
DCField.order('id desc').limit(10).update_all(updated_at: 1.year.from_now)
132+
DCField.order(id: :asc).limit(10).update_all(updated_at: 1.year.ago)
133+
DCField.order(id: :desc).limit(10).update_all(updated_at: 1.year.from_now)
134134
badTimes = [
135135
'junk',
136136
'February 92nd, 2015']
@@ -142,8 +142,8 @@ def test_bad_until_raises_exception
142142
end
143143

144144
def test_bad_from_raises_exception
145-
DCField.order('id asc').limit(10).update_all(updated_at: 1.year.ago)
146-
DCField.order('id desc').limit(10).update_all(updated_at: 1.year.from_now)
145+
DCField.order(id: :asc).limit(10).update_all(updated_at: 1.year.ago)
146+
DCField.order(id: :desc).limit(10).update_all(updated_at: 1.year.from_now)
147147

148148
badTimes = [
149149
'junk',

test/activerecord_provider/tc_ar_sets_provider.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ def define_sets
5151
set_ab = DCSet.create(:name => "Set A:B", :spec => "A:B")
5252

5353
next_id = 0
54-
DCField.limit(10).order("id asc").each do |record|
54+
DCField.limit(10).order(id: :asc).each do |record|
5555
set_a.dc_fields << record
5656
next_id = record.id
5757
end
5858

59-
DCField.where("id > #{next_id}").limit(10).order("id asc").each do |record|
59+
DCField.where("dc_fields.id > ?", next_id).limit(10).order(id: :asc).each do |record|
6060
set_b.dc_fields << record
6161
next_id = record.id
6262
end
6363

64-
DCField.where("id > #{next_id}").limit(10).order("id asc").each do |record|
64+
DCField.where("dc_fields.id > ?", next_id).limit(10).order(id: :asc).each do |record|
6565
set_ab.dc_fields << record
6666
next_id = record.id
6767
end
6868

69-
DCField.where("id > #{next_id}").limit(10).order("id asc").each do |record|
69+
DCField.where("dc_fields.id > ?", next_id).limit(10).order(id: :asc).each do |record|
7070
set_a.dc_fields << record
7171
set_c.dc_fields << record
7272
next_id = record.id
@@ -117,25 +117,25 @@ def setup
117117
def define_sets
118118
next_id = 0
119119

120-
ExclusiveSetDCField.limit(10).order("id asc").each do |record|
120+
ExclusiveSetDCField.limit(10).order(id: :asc).each do |record|
121121
record.set = "A"
122122
record.save!
123123
next_id = record.id
124124
end
125125

126-
ExclusiveSetDCField.where("id > #{next_id}").limit(10).order("id asc").each do |record|
126+
ExclusiveSetDCField.where("id > ?", next_id).limit(10).order(id: :asc).each do |record|
127127
record.set = "B"
128128
record.save!
129129
next_id = record.id
130130
end
131131

132-
ExclusiveSetDCField.where("id > #{next_id}").limit(10).order("id asc").each do |record|
132+
ExclusiveSetDCField.where("id > ?", next_id).limit(10).order(id: :asc).each do |record|
133133
record.set = "A:B"
134134
record.save!
135135
next_id = record.id
136136
end
137137

138-
ExclusiveSetDCField.where("id > #{next_id}").limit(10).order("id asc").each do |record|
138+
ExclusiveSetDCField.where("id > ?", next_id).limit(10).order(id: :asc).each do |record|
139139
record.set = "A"
140140
record.save!
141141
next_id = record.id

test/activerecord_provider/tc_caching_paging_provider.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def test_full_harvest
2323
end
2424

2525
def test_from_and_until
26-
first_id = DCField.order("id asc").first.id
27-
DCField.where("id <= #{first_id + 25}").update_all(updated_at: Time.parse("September 15 2005"))
28-
DCField.where("id < #{first_id + 50} and id > #{first_id + 25}").update_all(updated_at: Time.parse("November 1 2005"))
26+
first_id = DCField.order(id: :asc).first.id
27+
DCField.where("dc_fields.id <= ?", first_id + 25).update_all(updated_at: Time.parse("September 15 2005"))
28+
DCField.where(["dc_fields.id < ? and dc_fields.id > ?", first_id + 50, first_id + 25]).update_all(updated_at: Time.parse("November 1 2005"))
2929

3030
# Should return 50 records broken into 2 groups of 25.
3131
doc = Document.new(

test/activerecord_provider/tc_simple_paging_provider.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ def test_non_integer_identifiers_resumption
4343

4444
def test_from_and_until
4545
first_id = DCField.order("id asc").first.id
46-
DCField.where("id < #{first_id + 25}").update_all(updated_at: Time.parse("September 15 2005"))
47-
DCField.where("id <= #{first_id + 50} and id > #{first_id + 25}").update_all(updated_at: Time.parse("November 1 2005"))
46+
DCField.where("dc_fields.id < ?", first_id + 25).update_all(updated_at: Time.parse("September 15 2005"))
47+
DCField.where(["dc_fields.id <= ? and dc_fields.id > ?", first_id + 50, first_id + 25]).update_all(updated_at: Time.parse("November 1 2005"))
4848

49-
total = DCField.where(["updated_at >= ? AND updated_at <= ?", Time.parse("September 1 2005"), Time.parse("November 30 2005")]).count
49+
total = DCField.where(["dc_fields.updated_at >= ? AND dc_fields.updated_at <= ?", Time.parse("September 1 2005"), Time.parse("November 30 2005")]).count
5050

5151
# Should return 50 records broken into 2 groups of 25.
5252
doc = Document.new(

0 commit comments

Comments
 (0)