dupe 1.0.1 → 1.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dupe/active_resource_extensions.rb +7 -9
- data/lib/dupe/dupe.rb +13 -7
- data/lib/dupe/hash_pruner.rb +6 -2
- data/lib/dupe/mock.rb +10 -7
- data/spec/lib_specs/active_resource_extensions_spec.rb +320 -133
- data/spec/lib_specs/dupe_spec.rb +273 -186
- data/spec/lib_specs/mock_definitions_spec.rb +101 -40
- data/spec/lib_specs/mock_spec.rb +300 -124
- data/spec/lib_specs/network_spec.rb +32 -8
- metadata +38 -62
@@ -1,58 +1,119 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Mock Definition Methods" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
describe "Get" do
|
9
|
-
it "should require a url pattern that is a regex" do
|
10
|
-
proc { Get() }.should raise_error(ArgumentError)
|
11
|
-
proc { Get 'not a regexp' }.should raise_error(ArgumentError)
|
12
|
-
proc { Get %r{/some_url} }.should_not raise_error
|
4
|
+
describe "using xml" do
|
5
|
+
before do
|
6
|
+
Dupe.format = ActiveResource::Formats::XmlFormat
|
7
|
+
Dupe.reset
|
13
8
|
end
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
describe "Get" do
|
11
|
+
it "should require a url pattern that is a regex" do
|
12
|
+
proc { Get() }.should raise_error(ArgumentError)
|
13
|
+
proc { Get 'not a regexp' }.should raise_error(ArgumentError)
|
14
|
+
proc { Get %r{/some_url} }.should_not raise_error
|
15
|
+
end
|
20
16
|
|
21
|
-
|
22
|
-
Dupe.
|
17
|
+
it "should create and return a Dupe::Network::Mock of type :get" do
|
18
|
+
Dupe.network.mocks[:get].should be_empty
|
19
|
+
@book = Dupe.create :book, :label => 'rooby'
|
20
|
+
Dupe.network.mocks[:get].should_not be_empty
|
21
|
+
Dupe.network.mocks[:get].length.should == 2
|
22
|
+
|
23
|
+
mock = Get %r{/books/([^&]+)\.xml} do |label|
|
24
|
+
Dupe.find(:book) {|b| b.label == label}
|
25
|
+
end
|
26
|
+
|
27
|
+
Dupe.network.mocks[:get].length.should == 3
|
28
|
+
Dupe.network.mocks[:get].last.should == mock
|
29
|
+
Dupe.network.mocks[:get].last.url_pattern.should == %r{/books/([^&]+)\.xml}
|
30
|
+
book = Dupe.find(:book)
|
31
|
+
Dupe.network.request(:get, '/books/rooby.xml').should == book.make_safe.to_xml(:root => 'book')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "Post" do
|
36
|
+
it "should require a url pattern that is a regex" do
|
37
|
+
proc { Post() }.should raise_error(ArgumentError)
|
38
|
+
proc { Post 'not a regexp' }.should raise_error(ArgumentError)
|
39
|
+
proc { Post %r{/some_url} }.should_not raise_error
|
23
40
|
end
|
24
41
|
|
25
|
-
Dupe
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
42
|
+
it "should create and return a Dupe::Network::Mock of type :post" do
|
43
|
+
@book = Dupe.create :book, :label => 'rooby'
|
44
|
+
Dupe.network.mocks[:post].should_not be_empty
|
45
|
+
Dupe.network.mocks[:post].length.should == 1
|
46
|
+
|
47
|
+
mock = Post %r{/books\.xml} do |post_data|
|
48
|
+
Dupe.create(:book, post_data)
|
49
|
+
end
|
50
|
+
|
51
|
+
Dupe.network.mocks[:post].length.should == 2
|
52
|
+
Dupe.network.mocks[:post].first.should == mock
|
53
|
+
Dupe.network.mocks[:post].first.url_pattern.should == %r{/books\.xml}
|
54
|
+
book_post = Dupe.create(:book, {:title => "Rooby", :label => "rooby"})
|
55
|
+
book_post.delete(:id)
|
56
|
+
book_response = Dupe.create(:book, {:title => "Rooby", :label => "rooby"})
|
57
|
+
Dupe.network.request(:post, '/books.xml', book_post).should == [Dupe.find(:book) {|b| b.id == 4}.make_safe.to_xml(:root => 'book'), "/books/4.xml"]
|
58
|
+
end
|
30
59
|
end
|
31
60
|
end
|
32
|
-
|
33
|
-
describe "
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
proc { Post %r{/some_url} }.should_not raise_error
|
61
|
+
|
62
|
+
describe "using json" do
|
63
|
+
before do
|
64
|
+
Dupe.format = ActiveResource::Formats::JsonFormat
|
65
|
+
Dupe.reset
|
38
66
|
end
|
39
67
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
68
|
+
describe "Get" do
|
69
|
+
it "should require a url pattern that is a regex" do
|
70
|
+
proc { Get() }.should raise_error(ArgumentError)
|
71
|
+
proc { Get 'not a regexp' }.should raise_error(ArgumentError)
|
72
|
+
proc { Get %r{/some_url} }.should_not raise_error
|
73
|
+
end
|
44
74
|
|
45
|
-
|
46
|
-
Dupe.
|
75
|
+
it "should create and return a Dupe::Network::Mock of type :get" do
|
76
|
+
Dupe.network.mocks[:get].should be_empty
|
77
|
+
@book = Dupe.create :book, :label => 'rooby'
|
78
|
+
Dupe.network.mocks[:get].should_not be_empty
|
79
|
+
Dupe.network.mocks[:get].length.should == 2
|
80
|
+
|
81
|
+
mock = Get %r{/books/([^&]+)\.json} do |label|
|
82
|
+
Dupe.find(:book) {|b| b.label == label}
|
83
|
+
end
|
84
|
+
|
85
|
+
Dupe.network.mocks[:get].length.should == 3
|
86
|
+
Dupe.network.mocks[:get].last.should == mock
|
87
|
+
Dupe.network.mocks[:get].last.url_pattern.should == %r{/books/([^&]+)\.json}
|
88
|
+
book = Dupe.find(:book)
|
89
|
+
Dupe.network.request(:get, '/books/rooby.json').should == book.make_safe.to_json(:root => 'book')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "Post" do
|
94
|
+
it "should require a url pattern that is a regex" do
|
95
|
+
proc { Post() }.should raise_error(ArgumentError)
|
96
|
+
proc { Post 'not a regexp' }.should raise_error(ArgumentError)
|
97
|
+
proc { Post %r{/some_url} }.should_not raise_error
|
47
98
|
end
|
48
99
|
|
49
|
-
Dupe
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
100
|
+
it "should create and return a Dupe::Network::Mock of type :post" do
|
101
|
+
@book = Dupe.create :book, :label => 'rooby'
|
102
|
+
Dupe.network.mocks[:post].should_not be_empty
|
103
|
+
Dupe.network.mocks[:post].length.should == 1
|
104
|
+
|
105
|
+
mock = Post %r{/books\.json} do |post_data|
|
106
|
+
Dupe.create(:book, post_data)
|
107
|
+
end
|
108
|
+
|
109
|
+
Dupe.network.mocks[:post].length.should == 2
|
110
|
+
Dupe.network.mocks[:post].first.should == mock
|
111
|
+
Dupe.network.mocks[:post].first.url_pattern.should == %r{/books\.json}
|
112
|
+
book_post = Dupe.create(:book, {:title => "Rooby", :label => "rooby"})
|
113
|
+
book_post.delete(:id)
|
114
|
+
book_response = Dupe.create(:book, {:title => "Rooby", :label => "rooby"})
|
115
|
+
Dupe.network.request(:post, '/books.json', book_post).should == [Dupe.find(:book) {|b| b.id == 4}.make_safe.to_json(:root => 'book'), "/books/4.json"]
|
116
|
+
end
|
56
117
|
end
|
57
118
|
end
|
58
119
|
end
|
data/spec/lib_specs/mock_spec.rb
CHANGED
@@ -34,160 +34,336 @@ describe Dupe::Network::Mock do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
describe Dupe::Network::GetMock do
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
37
|
+
describe "using xml" do
|
38
|
+
before do
|
39
|
+
Dupe.reset
|
40
|
+
Dupe.format = ActiveResource::Formats::XmlFormat
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "mocked_response" do
|
44
|
+
describe "on a mock object whose response returns a Dupe.find with actual results" do
|
45
|
+
it "should convert the response result to xml" do
|
46
|
+
url_pattern = %r{/books/(\d+)\.xml}
|
47
|
+
response = proc {|id| Dupe.find(:book) {|b| b.id == id.to_i}}
|
48
|
+
book = Dupe.create :book
|
49
|
+
mock = Dupe::Network::GetMock.new url_pattern, response
|
50
|
+
mock.mocked_response('/books/1.xml').should == book.to_xml(:root => 'book')
|
51
|
+
|
52
|
+
proc { mock.mocked_response('/books/2.xml') }.should raise_error(Dupe::Network::GetMock::ResourceNotFoundError)
|
53
|
+
|
54
|
+
Dupe.define :author
|
55
|
+
mock = Dupe::Network::GetMock.new %r{/authors\.xml$}, proc {Dupe.find :authors}
|
56
|
+
mock.mocked_response('/authors.xml').should == [].to_xml(:root => 'results')
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should add a request to the Dupe::Network#log" do
|
60
|
+
url_pattern = %r{/books/([a-zA-Z0-9-]+)\.xml}
|
61
|
+
response = proc {|label| Dupe.find(:book) {|b| b.label == label}}
|
62
|
+
book = Dupe.create :book, :label => 'rooby'
|
63
|
+
mock = Dupe::Network::GetMock.new url_pattern, response
|
64
|
+
Dupe.network.log.requests.length.should == 0
|
65
|
+
mock.mocked_response('/books/rooby.xml')
|
66
|
+
Dupe.network.log.requests.length.should == 1
|
67
|
+
end
|
55
68
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
69
|
+
|
70
|
+
describe "on a mock object whose response returns nil" do
|
71
|
+
it "should raise an error" do
|
72
|
+
url_pattern = %r{/authors/(\d+)\.xml}
|
73
|
+
response = proc { |id| Dupe.find(:author) {|a| a.id == id.to_i}}
|
74
|
+
Dupe.define :author
|
75
|
+
mock = Dupe::Network::GetMock.new url_pattern, response
|
76
|
+
proc {mock.mocked_response('/authors/1.xml')}.should raise_error(Dupe::Network::GetMock::ResourceNotFoundError)
|
77
|
+
end
|
65
78
|
end
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
79
|
+
|
80
|
+
describe "on a mock object whose response returns an empty array" do
|
81
|
+
it "should convert the empty array to an xml array record set with root 'results'" do
|
82
|
+
Dupe.define :author
|
83
|
+
mock = Dupe::Network::GetMock.new %r{/authors\.xml$}, proc {Dupe.find :authors}
|
84
|
+
mock.mocked_response('/authors.xml').should == [].to_xml(:root => 'results')
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should add a request to the Dupe::Network#log" do
|
88
|
+
Dupe.define :author
|
89
|
+
mock = Dupe::Network::GetMock.new %r{/authors\.xml$}, proc {Dupe.find :authors}
|
90
|
+
Dupe.network.log.requests.length.should == 0
|
91
|
+
mock.mocked_response('/authors.xml')
|
92
|
+
Dupe.network.log.requests.length.should == 1
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "on a mock object whose response returns an array of duped records" do
|
97
|
+
it "should convert the array to xml" do
|
98
|
+
Dupe.create :author
|
99
|
+
mock = Dupe::Network::GetMock.new %r{/authors\.xml$}, proc {Dupe.find :authors}
|
100
|
+
mock.mocked_response('/authors.xml').should == Dupe.find(:authors).to_xml(:root => 'authors')
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should add a request to the Dupe::Network#log" do
|
104
|
+
Dupe.create :author
|
105
|
+
mock = Dupe::Network::GetMock.new %r{/authors\.xml$}, proc {Dupe.find :authors}
|
106
|
+
Dupe.network.log.requests.length.should == 0
|
107
|
+
mock.mocked_response('/authors.xml')
|
108
|
+
Dupe.network.log.requests.length.should == 1
|
109
|
+
end
|
75
110
|
end
|
76
111
|
end
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "using json" do
|
115
|
+
before do
|
116
|
+
Dupe.reset
|
117
|
+
Dupe.format = ActiveResource::Formats::JsonFormat
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "mocked_response" do
|
121
|
+
describe "on a mock object whose response returns a Dupe.find with actual results" do
|
122
|
+
it "should convert the response result to json" do
|
123
|
+
url_pattern = %r{/books/(\d+)\.json}
|
124
|
+
response = proc {|id| Dupe.find(:book) {|b| b.id == id.to_i}}
|
125
|
+
book = Dupe.create :book
|
126
|
+
mock = Dupe::Network::GetMock.new url_pattern, response
|
127
|
+
mock.mocked_response('/books/1.json').should == book.to_json(:root => 'book')
|
128
|
+
|
129
|
+
proc { mock.mocked_response('/books/2.json') }.should raise_error(Dupe::Network::GetMock::ResourceNotFoundError)
|
130
|
+
|
131
|
+
Dupe.define :author
|
132
|
+
mock = Dupe::Network::GetMock.new %r{/authors\.json$}, proc {Dupe.find :authors}
|
133
|
+
mock.mocked_response('/authors.json').should == [].to_json(:root => 'results')
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should add a request to the Dupe::Network#log" do
|
137
|
+
url_pattern = %r{/books/([a-zA-Z0-9-]+)\.json}
|
138
|
+
response = proc {|label| Dupe.find(:book) {|b| b.label == label}}
|
139
|
+
book = Dupe.create :book, :label => 'rooby'
|
140
|
+
mock = Dupe::Network::GetMock.new url_pattern, response
|
141
|
+
Dupe.network.log.requests.length.should == 0
|
142
|
+
mock.mocked_response('/books/rooby.json')
|
143
|
+
Dupe.network.log.requests.length.should == 1
|
144
|
+
end
|
83
145
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
146
|
+
|
147
|
+
describe "on a mock object whose response returns nil" do
|
148
|
+
it "should raise an error" do
|
149
|
+
url_pattern = %r{/authors/(\d+)\.json}
|
150
|
+
response = proc { |id| Dupe.find(:author) {|a| a.id == id.to_i}}
|
151
|
+
Dupe.define :author
|
152
|
+
mock = Dupe::Network::GetMock.new url_pattern, response
|
153
|
+
proc {mock.mocked_response('/authors/1.json')}.should raise_error(Dupe::Network::GetMock::ResourceNotFoundError)
|
154
|
+
end
|
91
155
|
end
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
156
|
+
|
157
|
+
describe "on a mock object whose response returns an empty array" do
|
158
|
+
it "should convert the empty array to an json array record set with root 'results'" do
|
159
|
+
Dupe.define :author
|
160
|
+
mock = Dupe::Network::GetMock.new %r{/authors\.json$}, proc {Dupe.find :authors}
|
161
|
+
mock.mocked_response('/authors.json').should == [].to_json(:root => 'results')
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should add a request to the Dupe::Network#log" do
|
165
|
+
Dupe.define :author
|
166
|
+
mock = Dupe::Network::GetMock.new %r{/authors\.json$}, proc {Dupe.find :authors}
|
167
|
+
Dupe.network.log.requests.length.should == 0
|
168
|
+
mock.mocked_response('/authors.json')
|
169
|
+
Dupe.network.log.requests.length.should == 1
|
170
|
+
end
|
99
171
|
end
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
172
|
+
|
173
|
+
describe "on a mock object whose response returns an array of duped records" do
|
174
|
+
it "should convert the array to json" do
|
175
|
+
Dupe.create :author
|
176
|
+
mock = Dupe::Network::GetMock.new %r{/authors\.json$}, proc {Dupe.find :authors}
|
177
|
+
mock.mocked_response('/authors.json').should == Dupe.find(:authors).to_json(:root => 'authors')
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should add a request to the Dupe::Network#log" do
|
181
|
+
Dupe.create :author
|
182
|
+
mock = Dupe::Network::GetMock.new %r{/authors\.json$}, proc {Dupe.find :authors}
|
183
|
+
Dupe.network.log.requests.length.should == 0
|
184
|
+
mock.mocked_response('/authors.json')
|
185
|
+
Dupe.network.log.requests.length.should == 1
|
186
|
+
end
|
107
187
|
end
|
108
188
|
end
|
109
189
|
end
|
110
190
|
end
|
111
191
|
|
112
192
|
describe Dupe::Network::PostMock do
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
193
|
+
describe "using xml" do
|
194
|
+
before do
|
195
|
+
Dupe.reset
|
196
|
+
Dupe.format = ActiveResource::Formats::XmlFormat
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "mocked_response" do
|
200
|
+
describe "on a mock object whose response returns a location of a new record" do
|
201
|
+
it "should convert the new post to xml" do
|
202
|
+
Dupe.define :author
|
203
|
+
mock = Dupe::Network::PostMock.new %r{/authors\.xml$}, proc {|post_data| Dupe.create(:author, post_data)}
|
204
|
+
resp, url = mock.mocked_response('/authors.xml', {:name => "Rachel"})
|
205
|
+
resp.should == Dupe.find(:authors).first.make_safe.to_xml(:root => 'author')
|
206
|
+
url.should == "/authors/1.xml"
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should add a request to the Dupe::Network#log" do
|
210
|
+
Dupe.define :author
|
211
|
+
mock = Dupe::Network::PostMock.new %r{/authors\.xml$}, proc {|post_data| Dupe.create(:author, post_data)}
|
212
|
+
Dupe.network.log.requests.length.should == 0
|
213
|
+
mock.mocked_response('/authors.xml', {:name => "Rachel"})
|
214
|
+
Dupe.network.log.requests.length.should == 1
|
215
|
+
end
|
125
216
|
end
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "using json" do
|
221
|
+
before do
|
222
|
+
Dupe.reset
|
223
|
+
Dupe.format = ActiveResource::Formats::JsonFormat
|
224
|
+
end
|
225
|
+
|
226
|
+
describe "mocked_response" do
|
227
|
+
describe "on a mock object whose response returns a location of a new record" do
|
228
|
+
it "should convert the new post to json" do
|
229
|
+
Dupe.define :author
|
230
|
+
mock = Dupe::Network::PostMock.new %r{/authors\.json$}, proc {|post_data| Dupe.create(:author, post_data)}
|
231
|
+
resp, url = mock.mocked_response('/authors.json', {:name => "Rachel"})
|
232
|
+
resp.should == Dupe.find(:authors).first.make_safe.to_json(:root => 'author')
|
233
|
+
url.should == "/authors/1.json"
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should add a request to the Dupe::Network#log" do
|
237
|
+
Dupe.define :author
|
238
|
+
mock = Dupe::Network::PostMock.new %r{/authors\.json$}, proc {|post_data| Dupe.create(:author, post_data)}
|
239
|
+
Dupe.network.log.requests.length.should == 0
|
240
|
+
mock.mocked_response('/authors.json', {:name => "Rachel"})
|
241
|
+
Dupe.network.log.requests.length.should == 1
|
242
|
+
end
|
133
243
|
end
|
134
244
|
end
|
135
245
|
end
|
136
246
|
end
|
137
247
|
|
138
248
|
describe Dupe::Network::PutMock do
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
249
|
+
describe "using xml" do
|
250
|
+
before do
|
251
|
+
Dupe.reset
|
252
|
+
Dupe.format = ActiveResource::Formats::XmlFormat
|
253
|
+
end
|
254
|
+
|
255
|
+
describe "mocked_response" do
|
256
|
+
describe "on a mock object whose response returns a location of a new record" do
|
257
|
+
before do
|
258
|
+
Dupe.define :author
|
259
|
+
@a = Dupe.create :author, :name => "Matt"
|
260
|
+
@mock = Dupe::Network::PutMock.new %r{/authors/(\d+)\.xml$}, proc {|id, put_data| Dupe.find(:author) {|a| a.id == id.to_i}.merge!(put_data)}
|
261
|
+
end
|
262
|
+
|
263
|
+
it "should convert the put to xml" do
|
264
|
+
resp, url = @mock.mocked_response('/authors/1.xml', {:name => "Rachel"})
|
265
|
+
resp.should == nil
|
266
|
+
@a.name.should == "Rachel"
|
267
|
+
url.should == "/authors/1.xml"
|
268
|
+
end
|
150
269
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
270
|
+
it "should add a request to the Dupe::Network#log" do
|
271
|
+
Dupe.network.log.requests.length.should == 0
|
272
|
+
@mock.mocked_response('/authors/1.xml', {:name => "Rachel"})
|
273
|
+
Dupe.network.log.requests.length.should == 1
|
274
|
+
end
|
156
275
|
end
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
describe "using json" do
|
280
|
+
before do
|
281
|
+
Dupe.reset
|
282
|
+
Dupe.format = ActiveResource::Formats::JsonFormat
|
283
|
+
end
|
284
|
+
|
285
|
+
describe "mocked_response" do
|
286
|
+
describe "on a mock object whose response returns a location of a new record" do
|
287
|
+
before do
|
288
|
+
Dupe.define :author
|
289
|
+
@a = Dupe.create :author, :name => "Matt"
|
290
|
+
@mock = Dupe::Network::PutMock.new %r{/authors/(\d+)\.json$}, proc {|id, put_data| Dupe.find(:author) {|a| a.id == id.to_i}.merge!(put_data)}
|
291
|
+
end
|
292
|
+
|
293
|
+
it "should convert the put to json" do
|
294
|
+
resp, url = @mock.mocked_response('/authors/1.json', {:name => "Rachel"})
|
295
|
+
resp.should == nil
|
296
|
+
@a.name.should == "Rachel"
|
297
|
+
url.should == "/authors/1.json"
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should add a request to the Dupe::Network#log" do
|
301
|
+
Dupe.network.log.requests.length.should == 0
|
302
|
+
@mock.mocked_response('/authors/1.json', {:name => "Rachel"})
|
303
|
+
Dupe.network.log.requests.length.should == 1
|
304
|
+
end
|
162
305
|
end
|
163
306
|
end
|
164
307
|
end
|
165
308
|
end
|
166
309
|
|
167
310
|
describe Dupe::Network::DeleteMock do
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
describe "on a mock object whose response returns a location of a new record" do
|
174
|
-
before do
|
175
|
-
Dupe.define :author
|
176
|
-
@a = Dupe.create :author, :name => "Matt"
|
177
|
-
@mock = Dupe::Network::DeleteMock.new %r{/authors/(\d+)\.xml$}, proc {|id| Dupe.delete(:author) {|a| a.id == id.to_i}}
|
178
|
-
end
|
311
|
+
describe "using xml" do
|
312
|
+
before do
|
313
|
+
Dupe.reset
|
314
|
+
Dupe.format = ActiveResource::Formats::XmlFormat
|
315
|
+
end
|
179
316
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
317
|
+
describe "mocked_response" do
|
318
|
+
describe "on a mock object whose response returns a location of a new record" do
|
319
|
+
before do
|
320
|
+
Dupe.define :author
|
321
|
+
@a = Dupe.create :author, :name => "Matt"
|
322
|
+
@mock = Dupe::Network::DeleteMock.new %r{/authors/(\d+)\.xml$}, proc {|id| Dupe.delete(:author) {|a| a.id == id.to_i}}
|
323
|
+
end
|
324
|
+
|
325
|
+
it "should convert the put to xml" do
|
326
|
+
Dupe.find(:authors).length.should == 1
|
327
|
+
resp = @mock.mocked_response('/authors/1.xml')
|
328
|
+
resp.should == nil
|
329
|
+
Dupe.find(:authors).length.should == 0
|
330
|
+
end
|
331
|
+
|
332
|
+
it "should add a request to the Dupe::Network#log" do
|
333
|
+
Dupe.network.log.requests.length.should == 0
|
334
|
+
@mock.mocked_response('/authors/1.xml')
|
335
|
+
Dupe.network.log.requests.length.should == 1
|
336
|
+
end
|
185
337
|
end
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
describe "using json" do
|
342
|
+
before do
|
343
|
+
Dupe.reset
|
344
|
+
Dupe.format = ActiveResource::Formats::JsonFormat
|
345
|
+
end
|
346
|
+
|
347
|
+
describe "mocked_response" do
|
348
|
+
describe "on a mock object whose response returns a location of a new record" do
|
349
|
+
before do
|
350
|
+
Dupe.define :author
|
351
|
+
@a = Dupe.create :author, :name => "Matt"
|
352
|
+
@mock = Dupe::Network::DeleteMock.new %r{/authors/(\d+)\.json$}, proc {|id| Dupe.delete(:author) {|a| a.id == id.to_i}}
|
353
|
+
end
|
354
|
+
|
355
|
+
it "should convert the put to json" do
|
356
|
+
Dupe.find(:authors).length.should == 1
|
357
|
+
resp = @mock.mocked_response('/authors/1.json')
|
358
|
+
resp.should == nil
|
359
|
+
Dupe.find(:authors).length.should == 0
|
360
|
+
end
|
361
|
+
|
362
|
+
it "should add a request to the Dupe::Network#log" do
|
363
|
+
Dupe.network.log.requests.length.should == 0
|
364
|
+
@mock.mocked_response('/authors/1.json')
|
365
|
+
Dupe.network.log.requests.length.should == 1
|
366
|
+
end
|
191
367
|
end
|
192
368
|
end
|
193
369
|
end
|