Skip to content

Commit ba8aa02

Browse files
committed
Fixing tests for Ruby 1.8
1 parent 748d95c commit ba8aa02

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: ruby
22
rvm:
3+
- 1.8.7
34
- 1.9.3
45
script: bundle exec rake test

test/provider/models.rb

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
class Record
22
attr_accessor :id, :titles, :creator, :tags, :sets, :updated_at, :deleted
3-
4-
def initialize(id,
5-
titles = 'title',
6-
creator = 'creator',
7-
tags = 'tag',
8-
sets = nil,
3+
4+
def initialize(id,
5+
titles = 'title',
6+
creator = 'creator',
7+
tags = 'tag',
8+
sets = nil,
99
deleted = false,
1010
updated_at = Time.now.utc.xmlschema)
11-
11+
1212
@id = id
1313
@titles = titles
1414
@creator = creator
@@ -17,12 +17,12 @@ def initialize(id,
1717
@deleted = deleted
1818
@updated_at = updated_at
1919
end
20-
20+
2121
# Override Object.id
2222
def id
2323
@id
2424
end
25-
25+
2626
def in_set(spec)
2727
if @sets.respond_to?(:each)
2828
@sets.each { |set| return true if set.spec == spec }
@@ -35,26 +35,26 @@ def in_set(spec)
3535

3636
class TestModel < OAI::Provider::Model
3737
include OAI::Provider
38-
38+
3939
def initialize(limit = nil)
4040
super(limit)
4141
@records = []
4242
@sets = []
4343
@earliest = Time.now.utc.xmlschema
4444
end
45-
45+
4646
def earliest
4747
(@records.min {|a,b| a.updated_at <=> b.updated_at }).updated_at.utc.xmlschema
4848
end
49-
49+
5050
def latest
5151
@records.max {|a,b| a.updated_at <=> b.updated_at }.updated_at.utc.xmlschema
5252
end
5353

5454
def sets
5555
@sets
5656
end
57-
57+
5858
def find(selector, opts={})
5959
return nil unless selector
6060

@@ -79,15 +79,15 @@ def find(selector, opts={})
7979
(opts[:from].nil? || rec.updated_at >= opts[:from]) &&
8080
(opts[:until].nil? || rec.updated_at <= opts[:until]))
8181
#else
82-
# ((opts[:set].nil? || rec.in_set(opts[:set])) &&
82+
# ((opts[:set].nil? || rec.in_set(opts[:set])) &&
8383
# (opts[:from].nil? || rec.updated_at >= opts[:from]) &&
8484
# (opts[:until].nil? || rec.updated_at <= opts[:until]))
8585
#end
8686
end
8787

8888
if @limit && records.size > @limit
8989
@groups = generate_chunks(records, @limit)
90-
return PartialResult.new(@groups[0],
90+
return PartialResult.new(@groups[0],
9191
ResumptionToken.new(opts.merge({:last => 1})))
9292
end
9393
return records
@@ -102,25 +102,25 @@ def find(selector, opts={})
102102
nil
103103
end
104104
end
105-
105+
106106
def generate_chunks(records, limit)
107107
groups = []
108108
records.each_slice(limit) do |group|
109109
groups << group
110110
end
111111
groups
112112
end
113-
113+
114114
def generate_records(number, timestamp = Time.now.utc.xmlschema, sets = [], deleted = false)
115115
@earliest = timestamp.dup if @earliest.nil? || timestamp.to_s < @earliest.to_s
116116
@earliest = timestamp.dup if @earliest.nil?
117-
117+
118118
# Add any sets we don't already have
119119
sets = [sets] unless sets.respond_to?(:each)
120120
sets.each do |set|
121121
@sets << set unless @sets.include?(set)
122-
end
123-
122+
end
123+
124124
# Generate some records
125125
number.times do |id|
126126
rec = Record.new(@records.size, "title_#{id}", "creator_#{id}", "tag_#{id}")
@@ -130,11 +130,11 @@ def generate_records(number, timestamp = Time.now.utc.xmlschema, sets = [], dele
130130
@records << rec
131131
end
132132
end
133-
133+
134134
end
135135

136136
class SimpleModel < TestModel
137-
137+
138138
def initialize
139139
super
140140
# Create a couple of sets
@@ -156,7 +156,7 @@ def initialize
156156
end
157157

158158
class BigModel < TestModel
159-
159+
160160
def initialize(limit = nil)
161161
super(limit)
162162
generate_records(100, Time.parse("October 2 2000"))
@@ -165,7 +165,7 @@ def initialize(limit = nil)
165165
generate_records(100, Time.parse("January 2 2001"))
166166
generate_records(100, Time.parse("February 2 2001"))
167167
end
168-
168+
169169
end
170170

171171
class MappedModel < TestModel
@@ -179,15 +179,15 @@ def initialize
179179

180180
generate_records(5, Time.parse("dec 1 2006"), set_one)
181181
end
182-
182+
183183
def map_oai_dc
184184
{:title => :creator, :creator => :titles, :subject => :tags}
185185
end
186186

187187
end
188188

189189
class ComplexModel < TestModel
190-
190+
191191
def initialize(limit = nil)
192192
super(limit)
193193
# Create a couple of sets
@@ -225,20 +225,22 @@ def initialize(limit = nil)
225225
generate_records(50, Time.parse("June 2 1998"), [set_one, set_one_two], true)
226226
generate_records(50, Time.parse("October 10 1998"), [set_three, set_three_four], true)
227227
generate_records(250, Time.parse("July 2 2002"), [set_two, set_one_two])
228-
228+
229229
generate_records(250, Time.parse("September 15 2004"), [set_three, set_three_four])
230230
generate_records(50, Time.parse("October 10 2004"), [set_three, set_three_four], true)
231231
generate_records(250, Time.parse("December 25 2005"), [set_four, set_three_four])
232232
end
233-
233+
234234
def about record
235-
<<-eos
236-
<oai_dc:dc
235+
xml = <<-eos
236+
<oai_dc:dc
237237
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
238238
xmlns:dc="http://purl.org/dc/elements/1.1/">
239239
<dc:publisher>Ruby OAI test data</dc:publisher>
240240
</oai_dc:dc>
241241
eos
242+
# Removes new-lines and formatting, which is a problem with Ruby 1.8.x
243+
xml.gsub(/\s+/, ' ')
242244
end
243245
end
244246

0 commit comments

Comments
 (0)