kronk 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -82,16 +82,6 @@ class TestRequest < Test::Unit::TestCase
82
82
  end
83
83
 
84
84
 
85
- def test_retrieve_file_cache
86
- File.expects(:open).with(Kronk::DEFAULT_CACHE_FILE, "rb").
87
- yields StringIO.new(mock_200_response)
88
-
89
- resp = Kronk::Request.retrieve_file :cache
90
- assert_equal mock_200_response, resp.raw
91
- assert_equal "200", resp.code
92
- end
93
-
94
-
95
85
  def test_retrieve_file_redirect
96
86
  resp2 = Kronk::Request.retrieve_file "test/mocks/200_response.txt"
97
87
  Kronk::Request.expects(:follow_redirect).returns resp2
@@ -0,0 +1,330 @@
1
+ require 'test/test_helper'
2
+
3
+ class TestTransaction < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @data = {
7
+ :key1 => {
8
+ :key1a => [
9
+ "foo",
10
+ "bar",
11
+ "foobar",
12
+ {:findme => "thing"}
13
+ ],
14
+ 'key1b' => "findme"
15
+ },
16
+ 'findme' => [
17
+ 123,
18
+ 456,
19
+ {:findme => 123456}
20
+ ],
21
+ :key2 => "foobar",
22
+ :key3 => {
23
+ :key3a => ["val1", "val2", "val3"]
24
+ }
25
+ }
26
+
27
+ @trans = Kronk::Path::Transaction.new @data
28
+ end
29
+
30
+
31
+ def test_class_run
32
+ block = lambda do |t|
33
+ t.delete "key3/key*/2", "**=thing"
34
+ t.select "**=foo*", "**/findme"
35
+ end
36
+
37
+ assert_equal @trans.run(&block),
38
+ Kronk::Path::Transaction.run(@data, &block)
39
+
40
+ assert_equal @trans.run(:keep_indicies => true, &block),
41
+ Kronk::Path::Transaction.run(@data, :keep_indicies => true, &block)
42
+ end
43
+
44
+
45
+ def test_run
46
+ expected = {
47
+ :key1=>{:key1a=>["foo", "foobar", {}]},
48
+ :key2=>"foobar",
49
+ "findme"=>[123, 456, {:findme=>123456}]
50
+ }
51
+
52
+ result = @trans.run do |t|
53
+ t.delete "key3/key*/2", "**=thing"
54
+ t.select "**=foo*", "**/findme"
55
+ end
56
+
57
+ assert_equal expected, result
58
+ assert_equal @data, @trans.run
59
+
60
+ result2 = @trans.run do |t|
61
+ t.delete "key3/key*/2", "**=thing"
62
+ t.select "**=foo*", "**/findme"
63
+ end
64
+
65
+ assert_equal expected, result2
66
+ end
67
+
68
+
69
+ def test_results
70
+ @trans.clear
71
+ @trans.delete "key3/key*/2", "**=thing"
72
+ @trans.select "**=foo*", "**/findme"
73
+ result = @trans.results
74
+
75
+ expected = {
76
+ :key1=>{:key1a=>["foo", "foobar", {}]},
77
+ :key2=>"foobar",
78
+ "findme"=>[123, 456, {:findme=>123456}]
79
+ }
80
+
81
+ assert_equal expected, result
82
+ end
83
+
84
+
85
+ def test_results_keep_indicies
86
+ @trans.clear
87
+ @trans.delete "key3/key*/2", "**=thing"
88
+ @trans.select "**=foo*", "**/findme"
89
+ result = @trans.results :keep_indicies => true
90
+
91
+ expected = {
92
+ :key1=>{:key1a=>{2=>"foobar", 0=>"foo", 3=>{}}},
93
+ :key2=>"foobar",
94
+ "findme"=>[123, 456, {:findme=>123456}]
95
+ }
96
+
97
+ assert_equal expected, result
98
+ end
99
+
100
+
101
+ def test_remake_arrays_select
102
+ result = @trans.transaction_select @data, "**=foo", "key3/key*/2"
103
+ result = @trans.remake_arrays result
104
+
105
+ expected = {:key1=>{:key1a=>["foo"]}, :key3=>{:key3a=>["val3"]}}
106
+
107
+ assert_equal expected, result
108
+ end
109
+
110
+
111
+ def test_remake_arrays_select_except_modified
112
+ result = @trans.transaction_select @data, "**=foo", "key3/key*/2"
113
+ result = @trans.remake_arrays result, true
114
+
115
+ expected = {:key1=>{:key1a=>{0=>"foo"}}, :key3=>{:key3a=>{2=>"val3"}}}
116
+
117
+ assert_equal expected, result
118
+ end
119
+
120
+
121
+ def test_remake_arrays_select_root
122
+ data_arr = @data.keys.sort{|x,y| x.to_s <=> y.to_s}.map{|k| @data[k]}
123
+
124
+ @trans = Kronk::Path::Transaction.new data_arr
125
+ result = @trans.transaction_select data_arr, "**=foo", "3/key*/2"
126
+ result = @trans.remake_arrays result
127
+
128
+ expected = [{:key1a=>["foo"]}, {:key3a=>["val3"]}]
129
+
130
+ assert_equal expected, result
131
+ end
132
+
133
+
134
+ def test_remake_arrays_select_root_except_modified
135
+ data_arr = @data.keys.sort{|x,y| x.to_s <=> y.to_s}.map{|k| @data[k]}
136
+
137
+ @trans = Kronk::Path::Transaction.new data_arr
138
+ result = @trans.transaction_select data_arr, "**=foo", "3/key*"
139
+ result = @trans.remake_arrays result, true
140
+
141
+ expected = {1=>{:key1a=>{0=>"foo"}}, 3=>{:key3a=>["val1", "val2", "val3"]}}
142
+
143
+ assert_equal expected, result
144
+ end
145
+
146
+
147
+ def test_remake_arrays_delete
148
+ result = @trans.transaction_delete @data, "**=foo", "key3/key*/2"
149
+ result = @trans.remake_arrays result
150
+
151
+ expected = {
152
+ :key1 => {
153
+ :key1a => ["bar", "foobar", {:findme => "thing"}],
154
+ 'key1b' => "findme"
155
+ },
156
+ 'findme' => [123, 456, {:findme => 123456}],
157
+ :key2 => "foobar",
158
+ :key3 => {
159
+ :key3a => ["val1", "val2"]
160
+ }
161
+ }
162
+
163
+ assert_equal expected, result
164
+ end
165
+
166
+
167
+ def test_remake_arrays_delete_except_modified
168
+ result = @trans.transaction_delete @data, "**=foo", "key3/key*/2"
169
+ result = @trans.remake_arrays result, true
170
+
171
+ expected = {
172
+ :key1 => {
173
+ :key1a => {1=>"bar", 2=>"foobar", 3=>{:findme=>"thing"}},
174
+ 'key1b' => "findme"
175
+ },
176
+ 'findme' => [123, 456, {:findme => 123456}],
177
+ :key2 => "foobar",
178
+ :key3 => {
179
+ :key3a => {0=>"val1", 1=>"val2"}
180
+ }
181
+ }
182
+
183
+ assert_equal expected, result
184
+ end
185
+
186
+
187
+ def test_remake_arrays_delete_root
188
+ data_arr = @data.keys.sort{|x,y| x.to_s <=> y.to_s}.map{|k| @data[k]}
189
+
190
+ @trans = Kronk::Path::Transaction.new data_arr
191
+ result = @trans.transaction_delete data_arr, "**=foo", "3/key*/2"
192
+ result = @trans.remake_arrays result
193
+
194
+ expected = [
195
+ [123, 456, {:findme=>123456}],
196
+ {:key1a=>["bar", "foobar", {:findme=>"thing"}], "key1b"=>"findme"},
197
+ "foobar",
198
+ {:key3a=>["val1", "val2"]}
199
+ ]
200
+
201
+ assert_equal expected, result
202
+ end
203
+
204
+
205
+ def test_remake_arrays_delete_root_except_modified
206
+ data_arr = @data.keys.sort{|x,y| x.to_s <=> y.to_s}.map{|k| @data[k]}
207
+
208
+ @trans = Kronk::Path::Transaction.new data_arr
209
+ result = @trans.transaction_delete data_arr, "**=foo", "3/key*/2"
210
+ result = @trans.remake_arrays result, true
211
+
212
+ expected = [
213
+ [123, 456, {:findme=>123456}],
214
+ {:key1a=>{1=>"bar", 2=>"foobar", 3=>{:findme=>"thing"}},
215
+ "key1b"=>"findme"},
216
+ "foobar",
217
+ {:key3a=>{0=>"val1", 1=>"val2"}}
218
+ ]
219
+
220
+ assert_equal expected, result
221
+ end
222
+
223
+
224
+ def test_transaction_select
225
+ result = @trans.transaction_select @data, "**=foo", "key3/key*/2"
226
+ expected = {:key1=>{:key1a=>{0=>"foo"}}, :key3=>{:key3a=>{2=>"val3"}}}
227
+
228
+ assert_equal expected, result
229
+ end
230
+
231
+
232
+ def test_transaction_select_array
233
+ data_arr = @data.keys.sort{|x,y| x.to_s <=> y.to_s}.map{|k| @data[k]}
234
+
235
+ result = @trans.transaction_select data_arr, "**=foo", "3/key*/2"
236
+ expected = {1=>{:key1a=>{0=>"foo"}}, 3=>{:key3a=>{2=>"val3"}}}
237
+
238
+ assert_equal expected, result
239
+ end
240
+
241
+
242
+ def test_transaction_select_empty
243
+ assert_equal @data, @trans.transaction_select(@data)
244
+ end
245
+
246
+
247
+ def test_transaction_delete
248
+ result = @trans.transaction_delete @data, "**=foo", "key3/key*/2"
249
+ expected = {
250
+ :key1 => {
251
+ :key1a => {1 => "bar", 2 => "foobar", 3 => {:findme => "thing"}},
252
+ 'key1b' => "findme"
253
+ },
254
+ 'findme' => [123, 456, {:findme => 123456}],
255
+ :key2 => "foobar",
256
+ :key3 => {
257
+ :key3a => {0 => "val1", 1 => "val2"}
258
+ }
259
+ }
260
+
261
+ assert_equal expected, result
262
+ end
263
+
264
+
265
+ def test_transaction_delete_array
266
+ data_arr = @data.keys.sort{|x,y| x.to_s <=> y.to_s}.map{|k| @data[k]}
267
+
268
+ result = @trans.transaction_delete data_arr, "**=foo", "3/key*/2"
269
+ expected = {
270
+ 0 => [123, 456, {:findme => 123456}],
271
+ 1 => {
272
+ :key1a => {1 => "bar", 2 => "foobar", 3 => {:findme => "thing"}},
273
+ 'key1b' => "findme"
274
+ },
275
+ 2 => "foobar",
276
+ 3 => {:key3a => {0 => "val1", 1 => "val2"}}
277
+ }
278
+
279
+ assert_equal expected, result
280
+ end
281
+
282
+
283
+ def test_transaction_delete_empty
284
+ assert_equal @data, @trans.transaction_delete(@data)
285
+ end
286
+
287
+
288
+ def test_ary_to_hash
289
+ expected = {1 => :a, 0 => :foo, 2 => :b}
290
+ assert_equal expected, @trans.ary_to_hash([:foo, :a, :b])
291
+ end
292
+
293
+
294
+ def test_hash_to_ary
295
+ assert_equal [:foo, :a, :b], @trans.hash_to_ary(1 => :a, 0 => :foo, 2 => :b)
296
+ end
297
+
298
+
299
+ def test_clear
300
+ @trans.instance_variable_get(:@actions)[:foo] = :bar
301
+ @trans.instance_variable_get(:@make_array) << :foobar
302
+
303
+ @trans.clear
304
+
305
+ assert @trans.instance_variable_get(:@actions).empty?
306
+ assert @trans.instance_variable_get(:@make_array).empty?
307
+ end
308
+
309
+
310
+ def test_select
311
+ @trans.select "path1", "path2", "path3"
312
+ assert_equal ["path1", "path2", "path3"],
313
+ @trans.instance_variable_get(:@actions)[:select]
314
+
315
+ @trans.select "path4", "path5"
316
+ assert_equal ["path1", "path2", "path3", "path4", "path5"],
317
+ @trans.instance_variable_get(:@actions)[:select]
318
+ end
319
+
320
+
321
+ def test_delete
322
+ @trans.delete "path1", "path2", "path3"
323
+ assert_equal ["path1", "path2", "path3"],
324
+ @trans.instance_variable_get(:@actions)[:delete]
325
+
326
+ @trans.delete "path4", "path5"
327
+ assert_equal ["path1", "path2", "path3", "path4", "path5"],
328
+ @trans.instance_variable_get(:@actions)[:delete]
329
+ end
330
+ end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kronk
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 1
8
- - 3
9
- - 1
10
- version: 1.3.1
7
+ - 4
8
+ - 0
9
+ version: 1.4.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Jeremie Castagna
@@ -15,7 +14,8 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-06-01 00:00:00 Z
17
+ date: 2011-07-04 00:00:00 -07:00
18
+ default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: plist
@@ -25,7 +25,6 @@ dependencies:
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
- hash: 3
29
28
  segments:
30
29
  - 3
31
30
  - 1
@@ -41,7 +40,6 @@ dependencies:
41
40
  requirements:
42
41
  - - ~>
43
42
  - !ruby/object:Gem::Version
44
- hash: 5
45
43
  segments:
46
44
  - 1
47
45
  - 5
@@ -56,7 +54,6 @@ dependencies:
56
54
  requirements:
57
55
  - - ~>
58
56
  - !ruby/object:Gem::Version
59
- hash: 7
60
57
  segments:
61
58
  - 1
62
59
  - 4
@@ -64,99 +61,65 @@ dependencies:
64
61
  type: :runtime
65
62
  version_requirements: *id003
66
63
  - !ruby/object:Gem::Dependency
67
- name: i18n
64
+ name: cookiejar
68
65
  prerelease: false
69
66
  requirement: &id004 !ruby/object:Gem::Requirement
70
67
  none: false
71
68
  requirements:
72
- - - ">="
69
+ - - ~>
73
70
  - !ruby/object:Gem::Version
74
- hash: 1
75
71
  segments:
76
72
  - 0
77
- - 5
78
- version: "0.5"
73
+ - 3
74
+ - 0
75
+ version: 0.3.0
79
76
  type: :runtime
80
77
  version_requirements: *id004
81
78
  - !ruby/object:Gem::Dependency
82
- name: activesupport
79
+ name: rubyforge
83
80
  prerelease: false
84
81
  requirement: &id005 !ruby/object:Gem::Requirement
85
82
  none: false
86
83
  requirements:
87
84
  - - ">="
88
85
  - !ruby/object:Gem::Version
89
- hash: 15
90
86
  segments:
91
87
  - 2
92
88
  - 0
93
- - 0
94
- version: 2.0.0
95
- type: :runtime
89
+ - 4
90
+ version: 2.0.4
91
+ type: :development
96
92
  version_requirements: *id005
97
- - !ruby/object:Gem::Dependency
98
- name: cookiejar
99
- prerelease: false
100
- requirement: &id006 !ruby/object:Gem::Requirement
101
- none: false
102
- requirements:
103
- - - ~>
104
- - !ruby/object:Gem::Version
105
- hash: 19
106
- segments:
107
- - 0
108
- - 3
109
- - 0
110
- version: 0.3.0
111
- type: :runtime
112
- version_requirements: *id006
113
- - !ruby/object:Gem::Dependency
114
- name: rack
115
- prerelease: false
116
- requirement: &id007 !ruby/object:Gem::Requirement
117
- none: false
118
- requirements:
119
- - - ~>
120
- - !ruby/object:Gem::Version
121
- hash: 15
122
- segments:
123
- - 1
124
- - 0
125
- version: "1.0"
126
- type: :runtime
127
- version_requirements: *id007
128
93
  - !ruby/object:Gem::Dependency
129
94
  name: mocha
130
95
  prerelease: false
131
- requirement: &id008 !ruby/object:Gem::Requirement
96
+ requirement: &id006 !ruby/object:Gem::Requirement
132
97
  none: false
133
98
  requirements:
134
99
  - - ~>
135
100
  - !ruby/object:Gem::Version
136
- hash: 47
137
101
  segments:
138
102
  - 0
139
103
  - 9
140
104
  - 10
141
105
  version: 0.9.10
142
106
  type: :development
143
- version_requirements: *id008
107
+ version_requirements: *id006
144
108
  - !ruby/object:Gem::Dependency
145
109
  name: hoe
146
110
  prerelease: false
147
- requirement: &id009 !ruby/object:Gem::Requirement
111
+ requirement: &id007 !ruby/object:Gem::Requirement
148
112
  none: false
149
113
  requirements:
150
114
  - - ">="
151
115
  - !ruby/object:Gem::Version
152
- hash: 35
153
116
  segments:
154
117
  - 2
155
- - 9
156
- - 4
157
- version: 2.9.4
118
+ - 7
119
+ - 0
120
+ version: 2.7.0
158
121
  type: :development
159
- version_requirements: *id009
122
+ version_requirements: *id007
160
123
  description: |-
161
124
  Kronk runs diffs against data from live and cached http responses.
162
125
  Kronk was made possible by the sponsoring of AT&T Interactive.
@@ -185,6 +148,8 @@ files:
185
148
  - lib/kronk/diff.rb
186
149
  - lib/kronk/diff/ascii_format.rb
187
150
  - lib/kronk/diff/color_format.rb
151
+ - lib/kronk/path.rb
152
+ - lib/kronk/path/transaction.rb
188
153
  - lib/kronk/plist_parser.rb
189
154
  - lib/kronk/request.rb
190
155
  - lib/kronk/response.rb
@@ -210,10 +175,12 @@ files:
210
175
  - test/test_diff.rb
211
176
  - test/test_helper.rb
212
177
  - test/test_kronk.rb
178
+ - test/test_path.rb
213
179
  - test/test_request.rb
214
180
  - test/test_response.rb
181
+ - test/test_transaction.rb
215
182
  - test/test_xml_parser.rb
216
- - .gemtest
183
+ has_rdoc: true
217
184
  homepage: https://github.com/yaksnrainbows/kronk
218
185
  licenses: []
219
186
 
@@ -228,7 +195,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
195
  requirements:
229
196
  - - ">="
230
197
  - !ruby/object:Gem::Version
231
- hash: 3
198
+ hash: 855220484149539505
232
199
  segments:
233
200
  - 0
234
201
  version: "0"
@@ -237,14 +204,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
204
  requirements:
238
205
  - - ">="
239
206
  - !ruby/object:Gem::Version
240
- hash: 3
241
207
  segments:
242
208
  - 0
243
209
  version: "0"
244
210
  requirements: []
245
211
 
246
212
  rubyforge_project: kronk
247
- rubygems_version: 1.8.4
213
+ rubygems_version: 1.3.7
248
214
  signing_key:
249
215
  specification_version: 3
250
216
  summary: Kronk runs diffs against data from live and cached http responses
@@ -256,6 +222,8 @@ test_files:
256
222
  - test/test_helper.rb
257
223
  - test/test_helper_methods.rb
258
224
  - test/test_kronk.rb
225
+ - test/test_path.rb
259
226
  - test/test_request.rb
260
227
  - test/test_response.rb
228
+ - test/test_transaction.rb
261
229
  - test/test_xml_parser.rb