superdupe 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +37 -1
- data/lib/superdupe/active_resource_extensions.rb +2 -1
- data/lib/superdupe/dupe.rb +15 -14
- data/lib/superdupe/mock.rb +6 -2
- data/lib/superdupe/record.rb +7 -1
- data/spec/lib_specs/active_resource_extensions_spec.rb +78 -114
- data/spec/spec_helper.rb +1 -1
- metadata +4 -36
- data/spec/lib_specs/attribute_template_spec.rb +0 -173
- data/spec/lib_specs/database_spec.rb +0 -163
- data/spec/lib_specs/dupe_spec.rb +0 -522
- data/spec/lib_specs/hash_pruner_spec.rb +0 -73
- data/spec/lib_specs/log_spec.rb +0 -78
- data/spec/lib_specs/logged_request_spec.rb +0 -22
- data/spec/lib_specs/mock_definitions_spec.rb +0 -58
- data/spec/lib_specs/mock_spec.rb +0 -194
- data/spec/lib_specs/model_spec.rb +0 -95
- data/spec/lib_specs/network_spec.rb +0 -130
- data/spec/lib_specs/record_spec.rb +0 -70
- data/spec/lib_specs/rest_validation_spec.rb +0 -17
- data/spec/lib_specs/schema_spec.rb +0 -109
- data/spec/lib_specs/sequence_spec.rb +0 -39
- data/spec/lib_specs/string_spec.rb +0 -31
- data/spec/lib_specs/symbol_spec.rb +0 -17
@@ -1,73 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe HashPruner do
|
4
|
-
describe "#prune" do
|
5
|
-
it "should nil out any repeated hashes" do
|
6
|
-
clarke = {:name => "Arthur C. Clarke"}
|
7
|
-
heinlein = {:name => "Robert Heinlein"}
|
8
|
-
sci_fi = {:name => "Science Fiction", :authors => [clarke, heinlein]}
|
9
|
-
clarke[:genre] = sci_fi
|
10
|
-
odyssey = {:name => "2001", :genre => sci_fi, :author => clarke}
|
11
|
-
hoag = {:name => "the unpleasant profession", :genre => sci_fi, :author => heinlein}
|
12
|
-
clarke[:books] = [odyssey]
|
13
|
-
heinlein[:books] = [hoag]
|
14
|
-
|
15
|
-
HashPruner.prune(clarke).should ==
|
16
|
-
{
|
17
|
-
:name=>"Arthur C. Clarke",
|
18
|
-
:genre => {
|
19
|
-
:name => "Science Fiction",
|
20
|
-
:authors => [
|
21
|
-
{
|
22
|
-
:name=>"Arthur C. Clarke"
|
23
|
-
},
|
24
|
-
{
|
25
|
-
:name=>"Robert Heinlein",
|
26
|
-
:books=> [
|
27
|
-
{
|
28
|
-
:name => "the unpleasant profession",
|
29
|
-
:genre => {
|
30
|
-
:name => "Science Fiction"
|
31
|
-
},
|
32
|
-
:author => {
|
33
|
-
:name => "Robert Heinlein"
|
34
|
-
}
|
35
|
-
}
|
36
|
-
]
|
37
|
-
}
|
38
|
-
]
|
39
|
-
},
|
40
|
-
:books=> [
|
41
|
-
{
|
42
|
-
:name => "2001",
|
43
|
-
:genre => {
|
44
|
-
:name => "Science Fiction",
|
45
|
-
:authors => [
|
46
|
-
{
|
47
|
-
:name => "Arthur C. Clarke"
|
48
|
-
},
|
49
|
-
{
|
50
|
-
:name=>"Robert Heinlein",
|
51
|
-
:books=> [
|
52
|
-
{
|
53
|
-
:name => "the unpleasant profession",
|
54
|
-
:genre => {
|
55
|
-
:name => "Science Fiction"
|
56
|
-
},
|
57
|
-
:author => {
|
58
|
-
:name => "Robert Heinlein"
|
59
|
-
}
|
60
|
-
}
|
61
|
-
]
|
62
|
-
}
|
63
|
-
]
|
64
|
-
},
|
65
|
-
:author => {
|
66
|
-
:name => "Arthur C. Clarke"
|
67
|
-
}
|
68
|
-
}
|
69
|
-
]
|
70
|
-
}
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
data/spec/lib_specs/log_spec.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Dupe::Network::Log do
|
4
|
-
before do
|
5
|
-
Dupe.reset
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "##new" do
|
9
|
-
it "should initialize the request entries to an empty array" do
|
10
|
-
log = Dupe::Network::Log.new
|
11
|
-
log.requests.should == []
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "#add_request" do
|
16
|
-
before do
|
17
|
-
@log = Dupe::Network::Log.new
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should require a valid HTTP verb" do
|
21
|
-
proc {
|
22
|
-
@log.add_request :invalid_http_verb, '/some_url'
|
23
|
-
}.should raise_error(Dupe::Network::UnknownRestVerbError)
|
24
|
-
proc {
|
25
|
-
Dupe::Network::VERBS.each do |verb|
|
26
|
-
@log.add_request verb, '/some_url'
|
27
|
-
end
|
28
|
-
}.should_not raise_error
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should require a url" do
|
32
|
-
proc {
|
33
|
-
@log.add_request :get
|
34
|
-
}.should raise_error(ArgumentError)
|
35
|
-
proc {
|
36
|
-
@log.add_request :get, '/a_url'
|
37
|
-
}.should_not raise_error
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should add a Dupe::Network::Log::MockedRequest to requests" do
|
41
|
-
@log.requests.should be_empty
|
42
|
-
path = '/translate?q=hola&from=spanish&to=english'
|
43
|
-
response_body = 'hello'
|
44
|
-
@log.add_request :get, path, response_body
|
45
|
-
@log.requests.should_not be_empty
|
46
|
-
@log.requests.length.should == 1
|
47
|
-
logged_request = @log.requests.first
|
48
|
-
logged_request.should be_kind_of(Dupe::Network::Log::Request)
|
49
|
-
logged_request.verb.should == :get
|
50
|
-
logged_request.path.should == path
|
51
|
-
logged_request.response_body.should == response_body
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "#pretty_print" do
|
56
|
-
before do
|
57
|
-
@log = Dupe::Network::Log.new
|
58
|
-
@log.add_request :get, '/knock-knock', "who's there?"
|
59
|
-
end
|
60
|
-
it "should return a formatted list of mocked requests" do
|
61
|
-
@log.pretty_print.should ==
|
62
|
-
"Logged Requests:\n" +
|
63
|
-
" Request: GET /knock-knock\n" +
|
64
|
-
" Response:\n" +
|
65
|
-
" who's there?\n\n"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "#reset" do
|
70
|
-
it "should clear out all logged requests" do
|
71
|
-
@log = Dupe::Network::Log.new
|
72
|
-
@log.add_request :get, '/knock-knock', "who's there?"
|
73
|
-
@log.requests.should_not be_empty
|
74
|
-
@log.reset
|
75
|
-
@log.requests.should be_empty
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Dupe::Network::Log::Request do
|
4
|
-
describe "##new" do
|
5
|
-
it "should set the verb, url, and response_body" do
|
6
|
-
r = Dupe::Network::Log::Request.new :get, "/knock-knock", "who's there?"
|
7
|
-
r.verb.should == :get
|
8
|
-
r.path.should == "/knock-knock"
|
9
|
-
r.response_body.should == "who's there?"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#pretty_print" do
|
14
|
-
it "should show the request type, request path, and request response" do
|
15
|
-
r = Dupe::Network::Log::Request.new :get, "/knock-knock", "who's there?"
|
16
|
-
r.pretty_print.should ==
|
17
|
-
"Request: GET /knock-knock\n" +
|
18
|
-
"Response:\n" +
|
19
|
-
" who's there?"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe "Mock Definition Methods" do
|
4
|
-
before do
|
5
|
-
Dupe.reset
|
6
|
-
end
|
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
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should create and return a Dupe::Network::Mock of type :get" do
|
16
|
-
Dupe.network.mocks[:get].should be_empty
|
17
|
-
@book = Dupe.create :book, :label => 'rooby'
|
18
|
-
Dupe.network.mocks[:get].should_not be_empty
|
19
|
-
Dupe.network.mocks[:get].length.should == 2
|
20
|
-
|
21
|
-
mock = Get %r{/books/([^&]+)\.xml} do |label|
|
22
|
-
Dupe.find(:book) {|b| b.label == label}
|
23
|
-
end
|
24
|
-
|
25
|
-
Dupe.network.mocks[:get].length.should == 3
|
26
|
-
Dupe.network.mocks[:get].last.should == mock
|
27
|
-
Dupe.network.mocks[:get].last.url_pattern.should == %r{/books/([^&]+)\.xml}
|
28
|
-
book = Dupe.find(:book)
|
29
|
-
Dupe.network.request(:get, '/books/rooby.xml').should == book.to_xml_safe(:root => 'book')
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "Post" do
|
34
|
-
it "should require a url pattern that is a regex" do
|
35
|
-
proc { Post() }.should raise_error(ArgumentError)
|
36
|
-
proc { Post 'not a regexp' }.should raise_error(ArgumentError)
|
37
|
-
proc { Post %r{/some_url} }.should_not raise_error
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should create and return a Dupe::Network::Mock of type :post" do
|
41
|
-
@book = Dupe.create :book, :label => 'rooby'
|
42
|
-
Dupe.network.mocks[:post].should_not be_empty
|
43
|
-
Dupe.network.mocks[:post].length.should == 1
|
44
|
-
|
45
|
-
mock = Post %r{/books\.xml} do |post_data|
|
46
|
-
Dupe.create(:book, post_data)
|
47
|
-
end
|
48
|
-
|
49
|
-
Dupe.network.mocks[:post].length.should == 2
|
50
|
-
Dupe.network.mocks[:post].first.should == mock
|
51
|
-
Dupe.network.mocks[:post].first.url_pattern.should == %r{/books\.xml}
|
52
|
-
book_post = Dupe.create(:book, {:title => "Rooby", :label => "rooby"})
|
53
|
-
book_post.delete(:id)
|
54
|
-
book_response = Dupe.create(:book, {:title => "Rooby", :label => "rooby"})
|
55
|
-
Dupe.network.request(:post, '/books.xml', book_post).should == [Dupe.find(:book) {|b| b.id == 4}.to_xml_safe(:root => 'book'), "/books/4.xml"]
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
data/spec/lib_specs/mock_spec.rb
DELETED
@@ -1,194 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Dupe::Network::Mock do
|
4
|
-
before do
|
5
|
-
Dupe.reset
|
6
|
-
end
|
7
|
-
|
8
|
-
describe "new" do
|
9
|
-
it "should require the url be a kind of regular expression" do
|
10
|
-
proc { Dupe::Network::Mock.new '', proc {} }.should raise_error(
|
11
|
-
ArgumentError,
|
12
|
-
"The URL pattern parameter must be a type of regular expression."
|
13
|
-
)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should set the, @url, and @response parameters accordingly" do
|
17
|
-
url_pattern = /\//
|
18
|
-
response = proc {}
|
19
|
-
mock = Dupe::Network::Mock.new url_pattern, response
|
20
|
-
mock.url_pattern.should == url_pattern
|
21
|
-
mock.response.should == response
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "match?" do
|
26
|
-
it "should determine if a given string matches the mock's url pattern" do
|
27
|
-
url = %r{/blogs/(\d+).xml}
|
28
|
-
response = proc {}
|
29
|
-
mock = Dupe::Network::Mock.new url, response
|
30
|
-
mock.match?('/blogs/1.xml').should == true
|
31
|
-
mock.match?('/bogs/1.xml').should == false
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe Dupe::Network::GetMock do
|
37
|
-
before do
|
38
|
-
Dupe.reset
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "mocked_response" do
|
42
|
-
describe "on a mock object whose response returns a Dupe.find with actual results" do
|
43
|
-
it "should convert the response result to xml" do
|
44
|
-
url_pattern = %r{/books/(\d+)\.xml}
|
45
|
-
response = proc {|id| Dupe.find(:book) {|b| b.id == id.to_i}}
|
46
|
-
book = Dupe.create :book
|
47
|
-
mock = Dupe::Network::GetMock.new url_pattern, response
|
48
|
-
mock.mocked_response('/books/1.xml').should == book.to_xml(:root => 'book')
|
49
|
-
|
50
|
-
proc { mock.mocked_response('/books/2.xml') }.should raise_error(Dupe::Network::GetMock::ResourceNotFoundError)
|
51
|
-
|
52
|
-
Dupe.define :author
|
53
|
-
mock = Dupe::Network::GetMock.new %r{/authors\.xml$}, proc {Dupe.find :authors}
|
54
|
-
mock.mocked_response('/authors.xml').should == [].to_xml(:root => 'results')
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should add a request to the Dupe::Network#log" do
|
58
|
-
url_pattern = %r{/books/([a-zA-Z0-9-]+)\.xml}
|
59
|
-
response = proc {|label| Dupe.find(:book) {|b| b.label == label}}
|
60
|
-
book = Dupe.create :book, :label => 'rooby'
|
61
|
-
mock = Dupe::Network::GetMock.new url_pattern, response
|
62
|
-
Dupe.network.log.requests.length.should == 0
|
63
|
-
mock.mocked_response('/books/rooby.xml')
|
64
|
-
Dupe.network.log.requests.length.should == 1
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "on a mock object whose response returns nil" do
|
69
|
-
it "should raise an error" do
|
70
|
-
url_pattern = %r{/authors/(\d+)\.xml}
|
71
|
-
response = proc { |id| Dupe.find(:author) {|a| a.id == id.to_i}}
|
72
|
-
Dupe.define :author
|
73
|
-
mock = Dupe::Network::GetMock.new url_pattern, response
|
74
|
-
proc {mock.mocked_response('/authors/1.xml')}.should raise_error(Dupe::Network::GetMock::ResourceNotFoundError)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe "on a mock object whose response returns an empty array" do
|
79
|
-
it "should convert the empty array to an xml array record set with root 'results'" do
|
80
|
-
Dupe.define :author
|
81
|
-
mock = Dupe::Network::GetMock.new %r{/authors\.xml$}, proc {Dupe.find :authors}
|
82
|
-
mock.mocked_response('/authors.xml').should == [].to_xml(:root => 'results')
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should add a request to the Dupe::Network#log" do
|
86
|
-
Dupe.define :author
|
87
|
-
mock = Dupe::Network::GetMock.new %r{/authors\.xml$}, proc {Dupe.find :authors}
|
88
|
-
Dupe.network.log.requests.length.should == 0
|
89
|
-
mock.mocked_response('/authors.xml')
|
90
|
-
Dupe.network.log.requests.length.should == 1
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "on a mock object whose response returns an array of duped records" do
|
95
|
-
it "should convert the array to xml" do
|
96
|
-
Dupe.create :author
|
97
|
-
mock = Dupe::Network::GetMock.new %r{/authors\.xml$}, proc {Dupe.find :authors}
|
98
|
-
mock.mocked_response('/authors.xml').should == Dupe.find(:authors).to_xml(:root => 'authors')
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should add a request to the Dupe::Network#log" do
|
102
|
-
Dupe.create :author
|
103
|
-
mock = Dupe::Network::GetMock.new %r{/authors\.xml$}, proc {Dupe.find :authors}
|
104
|
-
Dupe.network.log.requests.length.should == 0
|
105
|
-
mock.mocked_response('/authors.xml')
|
106
|
-
Dupe.network.log.requests.length.should == 1
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe Dupe::Network::PostMock do
|
113
|
-
before do
|
114
|
-
Dupe.reset
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "mocked_response" do
|
118
|
-
describe "on a mock object whose response returns a location of a new record" do
|
119
|
-
it "should convert the new post to xml" do
|
120
|
-
Dupe.define :author
|
121
|
-
mock = Dupe::Network::PostMock.new %r{/authors\.xml$}, proc {|post_data| Dupe.create(:author, post_data)}
|
122
|
-
resp, url = mock.mocked_response('/authors.xml', {:name => "Rachel"})
|
123
|
-
resp.should == Dupe.find(:authors).first.to_xml_safe(:root => 'author')
|
124
|
-
url.should == "/authors/1.xml"
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should add a request to the Dupe::Network#log" do
|
128
|
-
Dupe.define :author
|
129
|
-
mock = Dupe::Network::PostMock.new %r{/authors\.xml$}, proc {|post_data| Dupe.create(:author, post_data)}
|
130
|
-
Dupe.network.log.requests.length.should == 0
|
131
|
-
mock.mocked_response('/authors.xml', {:name => "Rachel"})
|
132
|
-
Dupe.network.log.requests.length.should == 1
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
describe Dupe::Network::PutMock do
|
139
|
-
before do
|
140
|
-
Dupe.reset
|
141
|
-
end
|
142
|
-
|
143
|
-
describe "mocked_response" do
|
144
|
-
describe "on a mock object whose response returns a location of a new record" do
|
145
|
-
before do
|
146
|
-
Dupe.define :author
|
147
|
-
@a = Dupe.create :author, :name => "Matt"
|
148
|
-
@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)}
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should convert the put to xml" do
|
152
|
-
resp, url = @mock.mocked_response('/authors/1.xml', {:name => "Rachel"})
|
153
|
-
resp.should == nil
|
154
|
-
@a.name.should == "Rachel"
|
155
|
-
url.should == "/authors/1.xml"
|
156
|
-
end
|
157
|
-
|
158
|
-
it "should add a request to the Dupe::Network#log" do
|
159
|
-
Dupe.network.log.requests.length.should == 0
|
160
|
-
@mock.mocked_response('/authors/1.xml', {:name => "Rachel"})
|
161
|
-
Dupe.network.log.requests.length.should == 1
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
describe Dupe::Network::DeleteMock do
|
168
|
-
before do
|
169
|
-
Dupe.reset
|
170
|
-
end
|
171
|
-
|
172
|
-
describe "mocked_response" do
|
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
|
179
|
-
|
180
|
-
it "should convert the put to xml" do
|
181
|
-
Dupe.find(:authors).length.should == 1
|
182
|
-
resp = @mock.mocked_response('/authors/1.xml')
|
183
|
-
resp.should == nil
|
184
|
-
Dupe.find(:authors).length.should == 0
|
185
|
-
end
|
186
|
-
|
187
|
-
it "should add a request to the Dupe::Network#log" do
|
188
|
-
Dupe.network.log.requests.length.should == 0
|
189
|
-
@mock.mocked_response('/authors/1.xml')
|
190
|
-
Dupe.network.log.requests.length.should == 1
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Dupe::Model do
|
4
|
-
describe "new" do
|
5
|
-
it "should require a model name" do
|
6
|
-
proc { Dupe::Model.new }.should raise_error(ArgumentError)
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should set the model name to what was passed in during initialization" do
|
10
|
-
m = Dupe::Model.new :book
|
11
|
-
m.name.should == :book
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should initialize an empty schema" do
|
15
|
-
m = Dupe::Model.new :book
|
16
|
-
m.schema.should be_kind_of(Dupe::Model::Schema)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should setup an id_sequence initialized to 0" do
|
20
|
-
m = Dupe::Model.new :book
|
21
|
-
m.id_sequence.current_value.should == 1
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "define" do
|
26
|
-
describe "when passed a proc" do
|
27
|
-
before do
|
28
|
-
@model = Dupe::Model.new :book
|
29
|
-
@definition = proc { |attrs|
|
30
|
-
attrs.author('Anonymous') do |dont_care|
|
31
|
-
'Flying Spaghetti Monster'
|
32
|
-
end
|
33
|
-
}
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should pass that proc off to it's schema" do
|
37
|
-
@model.schema.should_receive(:method_missing).once
|
38
|
-
@model.define @definition
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should result in a schema with the desired attribute templates" do
|
42
|
-
@model.define @definition
|
43
|
-
@model.schema.attribute_templates[:author].name.should == :author
|
44
|
-
@model.schema.attribute_templates[:author].default.should == 'Anonymous'
|
45
|
-
@model.schema.attribute_templates[:author].transformer.call(
|
46
|
-
'dont care'
|
47
|
-
).should == 'Flying Spaghetti Monster'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "create" do
|
53
|
-
before do
|
54
|
-
Dupe.define :book do |attrs|
|
55
|
-
attrs.title 'Untitled'
|
56
|
-
attrs.author 'Anon' do |author|
|
57
|
-
"Author: #{author}"
|
58
|
-
end
|
59
|
-
attrs.after_create do |book|
|
60
|
-
book.label = book.title.downcase.gsub(/\ +/, '-')
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
@book_model = Dupe.models[:book]
|
65
|
-
end
|
66
|
-
|
67
|
-
it "shouldn't require any parameters" do
|
68
|
-
proc {
|
69
|
-
@book_model.create
|
70
|
-
}.should_not raise_error
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should return a Dupe::Database::Record instance with the desired parameters" do
|
74
|
-
book = @book_model.create
|
75
|
-
book.should be_kind_of(Dupe::Database::Record)
|
76
|
-
book.__model__.name.should == :book
|
77
|
-
book.id.should == 1
|
78
|
-
book.title.should == 'Untitled'
|
79
|
-
book.author.should == 'Anon'
|
80
|
-
|
81
|
-
# the callback shouldn't get run until the database record is inserted into the duped 'database'
|
82
|
-
book.label.should == nil
|
83
|
-
|
84
|
-
book = @book_model.create :title => 'Rooby On Rails', :author => 'Matt Parker'
|
85
|
-
book.__model__.name.should == :book
|
86
|
-
book.id.should == 2
|
87
|
-
book.title.should == 'Rooby On Rails'
|
88
|
-
|
89
|
-
# the callback shouldn't get run until the database record is inserted into the duped 'database'
|
90
|
-
book.label.should == nil
|
91
|
-
|
92
|
-
book.author.should == 'Author: Matt Parker'
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
@@ -1,130 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Dupe::Network do
|
4
|
-
|
5
|
-
describe "new" do
|
6
|
-
before do
|
7
|
-
@network = Dupe::Network.new
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should initialize @mocks to a hash of empty arrays keyed with valid REST verbs" do
|
11
|
-
Dupe::Network::VERBS.each do |verb|
|
12
|
-
@network.mocks[verb].should == []
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should initialize @log to a new Dupe::Network::Log" do
|
17
|
-
@network.log.should be_kind_of(Dupe::Network::Log)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "request" do
|
22
|
-
before do
|
23
|
-
@network = Dupe::Network.new
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should require a valid REST verb" do
|
27
|
-
proc { @network.request }.should raise_error
|
28
|
-
proc { @network.request :invalid_rest_verb, '/some_url' }.should raise_error(Dupe::Network::UnknownRestVerbError)
|
29
|
-
proc { @network.request :get, '/some_url' }.should_not raise_error(Dupe::Network::UnknownRestVerbError)
|
30
|
-
proc { @network.request :post, '/some_url', 'some body' }.should_not raise_error(Dupe::Network::UnknownRestVerbError)
|
31
|
-
proc { @network.request :put, '/some_url' }.should_not raise_error(Dupe::Network::UnknownRestVerbError)
|
32
|
-
proc { @network.request :delete, '/some_url' }.should_not raise_error(Dupe::Network::UnknownRestVerbError)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should require a URL" do
|
36
|
-
proc { @network.request :get }.should raise_error(ArgumentError)
|
37
|
-
proc { @network.request :get, 'some_url'}.should_not raise_error(ArgumentError)
|
38
|
-
proc { @network.request :post, 'some_url', 'some body'}.should_not raise_error(ArgumentError)
|
39
|
-
proc { @network.request :put, 'some_url'}.should_not raise_error(ArgumentError)
|
40
|
-
proc { @network.request :delete, 'some_url'}.should_not raise_error(ArgumentError)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should raise an exception if the network has no mocks that match the url" do
|
44
|
-
proc { @network.request(:get, '/some_url')}.should raise_error(Dupe::Network::RequestNotFoundError)
|
45
|
-
proc { @network.request(:post, '/some_url', 'some body')}.should raise_error(Dupe::Network::RequestNotFoundError)
|
46
|
-
proc { @network.request(:put, '/some_url')}.should raise_error(Dupe::Network::RequestNotFoundError)
|
47
|
-
proc { @network.request(:delete, '/some_url')}.should raise_error(Dupe::Network::RequestNotFoundError)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should return the appropriate mock response if a mock matches the url" do
|
51
|
-
@network.define_service_mock :get, %r{/greeting$}, proc { "hello" }
|
52
|
-
@network.request(:get, '/greeting').should == 'hello'
|
53
|
-
|
54
|
-
@network.define_service_mock :post, %r{/greeting$}, proc { |post_data| Dupe.create(:greeting, post_data) }
|
55
|
-
resp, url = @network.request(:post, '/greeting', {} )
|
56
|
-
resp.should == Dupe.find(:greeting).to_xml_safe(:root => 'greeting')
|
57
|
-
url.should == "/greetings/1.xml"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "define_service_mock" do
|
62
|
-
before do
|
63
|
-
@network = Dupe::Network.new
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should require a valid REST verb" do
|
67
|
-
proc { @network.define_service_mock }.should raise_error
|
68
|
-
proc { @network.define_service_mock :invalid_rest_verb, // }.should raise_error(Dupe::Network::UnknownRestVerbError)
|
69
|
-
proc { @network.define_service_mock :get, // }.should_not raise_error(Dupe::Network::UnknownRestVerbError)
|
70
|
-
proc { @network.define_service_mock :post, // }.should_not raise_error(Dupe::Network::UnknownRestVerbError)
|
71
|
-
proc { @network.define_service_mock :put, // }.should_not raise_error(Dupe::Network::UnknownRestVerbError)
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should require a valid Regexp url pattern" do
|
75
|
-
proc { @network.define_service_mock :get, 'not a regular expression' }.should raise_error(ArgumentError)
|
76
|
-
proc { @network.define_service_mock :post, 'not a regular expression' }.should raise_error(ArgumentError)
|
77
|
-
proc { @network.define_service_mock :get, // }.should_not raise_error
|
78
|
-
proc { @network.define_service_mock :post, // }.should_not raise_error
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should create and return a new get service mock when given valid parameters" do
|
82
|
-
verb = :get
|
83
|
-
pattern = //
|
84
|
-
response = proc { 'test' }
|
85
|
-
@network.mocks[:get].should be_empty
|
86
|
-
mock = @network.define_service_mock verb, pattern, response
|
87
|
-
@network.mocks[:get].should_not be_empty
|
88
|
-
@network.mocks[:get].first.class.should == Dupe::Network::GetMock
|
89
|
-
@network.mocks[:get].length.should == 1
|
90
|
-
@network.mocks[:get].first.should == mock
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should create and return a new post service mock when given valid parameters" do
|
94
|
-
verb = :post
|
95
|
-
pattern = //
|
96
|
-
response = proc { 'test' }
|
97
|
-
@network.mocks[:post].should be_empty
|
98
|
-
mock = @network.define_service_mock verb, pattern, response
|
99
|
-
@network.mocks[:post].should_not be_empty
|
100
|
-
@network.mocks[:post].first.class.should == Dupe::Network::PostMock
|
101
|
-
@network.mocks[:post].length.should == 1
|
102
|
-
@network.mocks[:post].first.should == mock
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should create and return a new put service mock when given valid parameters" do
|
106
|
-
verb = :put
|
107
|
-
pattern = //
|
108
|
-
response = proc { 'test' }
|
109
|
-
@network.mocks[:put].should be_empty
|
110
|
-
mock = @network.define_service_mock verb, pattern, response
|
111
|
-
@network.mocks[:put].should_not be_empty
|
112
|
-
@network.mocks[:put].first.class.should == Dupe::Network::PutMock
|
113
|
-
@network.mocks[:put].length.should == 1
|
114
|
-
@network.mocks[:put].first.should == mock
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should create and return a new delete service mock when given valid parameters" do
|
118
|
-
verb = :delete
|
119
|
-
pattern = //
|
120
|
-
response = proc { 'test' }
|
121
|
-
@network.mocks[:delete].should be_empty
|
122
|
-
mock = @network.define_service_mock verb, pattern, response
|
123
|
-
@network.mocks[:delete].should_not be_empty
|
124
|
-
@network.mocks[:delete].first.class.should == Dupe::Network::DeleteMock
|
125
|
-
@network.mocks[:delete].length.should == 1
|
126
|
-
@network.mocks[:delete].first.should == mock
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|