rack-test-rest 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,7 +56,9 @@ module Rack
56
56
  assert_content_type_is_json
57
57
 
58
58
  if @rack_test_rest[:location]
59
- assert last_response.original_headers["Location"] =~ @rack_test_rest[:location]
59
+ assert last_response.original_headers["Location"] =~ @rack_test_rest[:location],
60
+ "Response location header '%s' does not match RegExp '%s'" %
61
+ [last_response.original_headers["Location"], @rack_test_rest[:location]]
60
62
  end
61
63
 
62
64
  end
@@ -123,28 +125,30 @@ module Rack
123
125
  end
124
126
  end
125
127
 
126
- def paginate_resource(params={})
128
+ def paginate_resource(opts={})
127
129
 
128
- count = params[:count] ? params[:count] : 512
129
- max = params[:max_length] ? params[:max_length] : 100
130
+ count = opts[:count] ? opts[:count] : 512
131
+ max = opts[:max_length] ? opts[:max_length] : 100
132
+ existing_resource_count = opts[:existing_resource_count] || 0
130
133
 
131
134
  #populate the DB
132
135
  0.upto(count - 1) do |id|
133
- if params.has_key?(:do_create) && params[:do_create] == false
136
+ if opts[:do_create] == false
134
137
  yield(id)
135
138
  else
136
139
  create_resource(yield(id))
137
140
  end
138
141
  end
139
142
 
143
+ total = count + existing_resource_count
140
144
  retrieved = 0
141
145
  offset = 0
142
146
 
143
- while retrieved < count
147
+ while retrieved < total
144
148
  # Get a random number from 1-100
145
149
  length = rand(max - 1) + 1
146
150
 
147
- expected_length = (length > (count - retrieved)) ? (count - retrieved) : length
151
+ expected_length = (length > (total - retrieved)) ? (total - retrieved) : length
148
152
 
149
153
  if @rack_test_rest[:debug]
150
154
  puts "Requesting offset='#{offset}', length='#{length}'"
@@ -158,9 +162,9 @@ module Rack
158
162
  assert_equal(expected_length, pg_resp[@rack_test_rest[:resource]].count)
159
163
 
160
164
  puts "Found #{pg_resp["query"]["found"]} records" if @rack_test_rest[:debug]
161
- assert_equal(count, pg_resp["query"]["found"])
165
+ assert_equal(total, pg_resp["query"]["found"])
162
166
 
163
- assert_equal(count, pg_resp["query"]["total"])
167
+ assert_equal(total, pg_resp["query"]["total"])
164
168
  assert_equal(expected_length, pg_resp["query"]["length"])
165
169
  assert_equal(offset, pg_resp["query"]["offset"])
166
170
 
@@ -1,7 +1,7 @@
1
1
  module Rack
2
2
  module Test
3
3
  module Rest
4
- VERSION = '0.5.1'
4
+ VERSION = '0.6.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-test-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-05 00:00:00.000000000 Z
12
+ date: 2013-09-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -58,7 +58,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
58
  version: '0'
59
59
  segments:
60
60
  - 0
61
- hash: 1945334664000681698
61
+ hash: -3995603219145648516
62
62
  required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements: