mattly-exegesis 0.2.2 → 0.2.3
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.
- data/README.rdoc +11 -6
- data/VERSION.yml +1 -1
- data/lib/exegesis/design.rb +1 -1
- data/test/attachments_test.rb +35 -35
- data/test/database_test.rb +61 -61
- data/test/design_test.rb +47 -105
- data/test/document_collection_test.rb +27 -27
- data/test/document_test.rb +42 -43
- data/test/http_test.rb +18 -20
- data/test/model_test.rb +93 -93
- data/test/server_test.rb +6 -6
- data/test/test_helper.rb +22 -13
- metadata +1 -1
data/test/model_test.rb
CHANGED
|
@@ -28,51 +28,51 @@ class ExposeTestModel
|
|
|
28
28
|
expose :other_doc, :other_docs, :as => :reference
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
describe Exegesis::Model do
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
expect { WithDefaultTestModel.new['foo'].
|
|
36
|
-
expect { WithDefaultTestModel.new({'foo' => 'baz'})['foo'].
|
|
33
|
+
describe "class definitions" do
|
|
34
|
+
describe "default objects" do
|
|
35
|
+
expect { WithDefaultTestModel.new['foo'].must_equal 'bar' }
|
|
36
|
+
expect { WithDefaultTestModel.new({'foo' => 'baz'})['foo'].must_equal 'baz' }
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
describe "exposing keys" do
|
|
40
|
+
describe "regular declarations" do
|
|
41
41
|
before do
|
|
42
42
|
@obj = ExposeTestModel.new(:foo => 'bar', :bar => 'foo')
|
|
43
43
|
end
|
|
44
|
-
|
|
45
|
-
expect { @obj.foo.
|
|
46
|
-
expect { @obj.bar.
|
|
44
|
+
describe "reading" do
|
|
45
|
+
expect { @obj.foo.must_equal 'bar' }
|
|
46
|
+
expect { @obj.bar.must_equal 'foo' }
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
describe "writing" do
|
|
50
50
|
before do
|
|
51
51
|
@obj.bar = "bee"
|
|
52
52
|
end
|
|
53
|
-
expect { @obj.bar.
|
|
53
|
+
expect { @obj.bar.must_equal "bee" }
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
describe "with a custom writer" do
|
|
58
|
+
describe "when false" do
|
|
59
59
|
before { @obj = ExposeTestModel.new(:read_only => 'value') }
|
|
60
|
-
expect { @obj.read_only.
|
|
61
|
-
expect { lambda{@obj.read_only = "other value"}.
|
|
60
|
+
expect { @obj.read_only.must_equal 'value' }
|
|
61
|
+
expect { lambda{@obj.read_only = "other value"}.must_raise NoMethodError }
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
describe "when lambda" do
|
|
65
65
|
before do
|
|
66
66
|
@obj = ExposeTestModel.new(:custom_writer => 'value')
|
|
67
67
|
@obj.custom_writer = 'other value'
|
|
68
68
|
@expected = {'value' => 'other value'}
|
|
69
69
|
end
|
|
70
|
-
expect { @obj.custom_writer.
|
|
70
|
+
expect { @obj.custom_writer.must_equal @expected }
|
|
71
71
|
end
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
describe "when casting a value" do
|
|
75
|
+
describe "when as given" do
|
|
76
76
|
before do
|
|
77
77
|
@obj = ExposeTestModel.new({
|
|
78
78
|
:castee => {'foo' => 'foo', 'class' => 'FooTestModel'},
|
|
@@ -85,69 +85,69 @@ class ExegesisModelTest < Test::Unit::TestCase
|
|
|
85
85
|
@obj.castees
|
|
86
86
|
end
|
|
87
87
|
|
|
88
|
-
expect { @obj.castee.
|
|
89
|
-
expect { @obj.castee['foo'].
|
|
90
|
-
expect { @obj.castee.parent.
|
|
88
|
+
expect { @obj.castee.must_be_kind_of FooTestModel }
|
|
89
|
+
expect { @obj.castee['foo'].must_equal 'foo' }
|
|
90
|
+
expect { @obj.castee.parent.must_equal @obj }
|
|
91
91
|
|
|
92
|
-
expect { @obj.castees.
|
|
93
|
-
expect { @obj.castees[0].
|
|
94
|
-
expect { @obj.castees[0]['foo'].
|
|
95
|
-
expect { @obj.castees[0].parent.
|
|
96
|
-
expect { @obj.castees[1].
|
|
97
|
-
expect { @obj.castees[1]['foo'].
|
|
98
|
-
expect { @obj.castees[1].parent.
|
|
92
|
+
expect { @obj.castees.must_be_kind_of Array }
|
|
93
|
+
expect { @obj.castees[0].must_be_kind_of FooTestModel }
|
|
94
|
+
expect { @obj.castees[0]['foo'].must_equal 'foo' }
|
|
95
|
+
expect { @obj.castees[0].parent.must_equal @obj }
|
|
96
|
+
expect { @obj.castees[1].must_be_kind_of BarTestModel }
|
|
97
|
+
expect { @obj.castees[1]['foo'].must_equal 'bar' }
|
|
98
|
+
expect { @obj.castees[1].parent.must_equal @obj }
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
describe "defining the writer" do
|
|
101
101
|
before do
|
|
102
102
|
@obj = ExposeTestModel.new
|
|
103
103
|
@foo = FooTestModel.new({'foo' => 'bar'})
|
|
104
104
|
@obj.castee = @foo
|
|
105
105
|
end
|
|
106
|
-
expect { @obj.castee.
|
|
106
|
+
expect { @obj.castee.must_equal @foo }
|
|
107
107
|
end
|
|
108
108
|
end
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
describe "when as time" do
|
|
111
111
|
before do
|
|
112
112
|
@obj = ExposeTestModel.new({:time => Time.now.to_json, :times => [Time.local(2009,3,1).to_json, Time.local(2009,2,1).to_json]})
|
|
113
113
|
@obj.time
|
|
114
114
|
@obj.times
|
|
115
115
|
end
|
|
116
116
|
|
|
117
|
-
expect { @obj.time.
|
|
118
|
-
expect { @obj.time.to_f.
|
|
117
|
+
expect { @obj.time.must_be_kind_of Time }
|
|
118
|
+
expect { @obj.time.to_f.must_be_close_to Time.now.to_f, 1 }
|
|
119
119
|
|
|
120
|
-
expect { @obj.times.
|
|
121
|
-
expect { @obj.times[0].
|
|
122
|
-
expect { @obj.times[0].
|
|
123
|
-
expect { @obj.times[1].
|
|
124
|
-
expect { @obj.times[1].
|
|
120
|
+
expect { @obj.times.must_be_kind_of Array }
|
|
121
|
+
expect { @obj.times[0].must_be_kind_of Time }
|
|
122
|
+
expect { @obj.times[0].must_equal Time.local(2009,3,1) }
|
|
123
|
+
expect { @obj.times[1].must_be_kind_of Time }
|
|
124
|
+
expect { @obj.times[1].must_equal Time.local(2009,2,1) }
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
describe "writing times" do
|
|
127
127
|
before do
|
|
128
128
|
@obj = ExposeTestModel.new
|
|
129
129
|
@time = Time.local(2009,4,16,20,14,26)
|
|
130
130
|
end
|
|
131
|
-
|
|
131
|
+
describe "from a time object" do
|
|
132
132
|
before do
|
|
133
133
|
@obj.time = @time
|
|
134
134
|
@obj.times = [@time, @time]
|
|
135
135
|
end
|
|
136
|
-
expect { @obj.time.
|
|
137
|
-
expect { @obj.times.
|
|
136
|
+
expect { @obj.time.must_equal @time }
|
|
137
|
+
expect { @obj.times.must_equal [@time, @time] }
|
|
138
138
|
end
|
|
139
|
-
|
|
139
|
+
describe "from a string" do
|
|
140
140
|
before do
|
|
141
141
|
@obj.time = @time.xmlschema
|
|
142
142
|
@obj.times = [@time.rfc2822, @time.getutc.strftime("%a, %d %b %Y %H:%M:%S GMT")]
|
|
143
143
|
end
|
|
144
|
-
expect { @obj.time.
|
|
145
|
-
expect { @obj.times.map{|time| time.localtime }.
|
|
144
|
+
expect { @obj.time.must_equal @time }
|
|
145
|
+
expect { @obj.times.map{|time| time.localtime }.must_equal [@time, @time] }
|
|
146
146
|
end
|
|
147
147
|
end
|
|
148
148
|
end
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
describe "when as non document class" do
|
|
151
151
|
before do
|
|
152
152
|
@obj = ExposeTestModel.new({
|
|
153
153
|
:regex => 'foo',
|
|
@@ -157,24 +157,24 @@ class ExegesisModelTest < Test::Unit::TestCase
|
|
|
157
157
|
@obj.regexen
|
|
158
158
|
end
|
|
159
159
|
|
|
160
|
-
expect { @obj.regex.
|
|
160
|
+
expect { @obj.regex.must_equal /foo/ }
|
|
161
161
|
|
|
162
|
-
expect { @obj.regexen.
|
|
163
|
-
expect { @obj.regexen[0].
|
|
164
|
-
expect { @obj.regexen[1].
|
|
162
|
+
expect { @obj.regexen.must_be_kind_of Array }
|
|
163
|
+
expect { @obj.regexen[0].must_equal /foo/ }
|
|
164
|
+
expect { @obj.regexen[1].must_equal /bar/ }
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
describe "writing values from the class" do
|
|
167
167
|
before do
|
|
168
168
|
@obj = ExposeTestModel.new
|
|
169
169
|
@regex = /foo/
|
|
170
170
|
@obj.regex = @regex
|
|
171
171
|
end
|
|
172
|
-
expect { @obj.regex.
|
|
172
|
+
expect { @obj.regex.must_equal @regex }
|
|
173
173
|
end
|
|
174
174
|
end
|
|
175
175
|
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
describe "when as reference" do
|
|
177
|
+
describe "with a database present" do
|
|
178
178
|
before do
|
|
179
179
|
reset_db
|
|
180
180
|
@obj = ExposeTestModel.new(:other_doc => "other_doc",
|
|
@@ -183,7 +183,7 @@ class ExegesisModelTest < Test::Unit::TestCase
|
|
|
183
183
|
@obj.parent = @doc
|
|
184
184
|
end
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
describe "when the referenced document exists" do
|
|
187
187
|
before do
|
|
188
188
|
[ {'class' => 'ModelTestDocument', '_id' => 'other_doc'},
|
|
189
189
|
{'class' => 'ModelTestDocument', '_id' => 'other_docs_1'},
|
|
@@ -191,15 +191,15 @@ class ExegesisModelTest < Test::Unit::TestCase
|
|
|
191
191
|
].each {|doc| @db.put(doc.delete('_id'), doc) }
|
|
192
192
|
end
|
|
193
193
|
|
|
194
|
-
expect { @obj.other_doc['_rev'].
|
|
195
|
-
expect { @obj.other_doc.
|
|
196
|
-
expect { @obj.other_docs.
|
|
197
|
-
expect { @obj.other_docs[0]['_rev'].
|
|
198
|
-
expect { @obj.other_docs[0].
|
|
199
|
-
expect { @obj.other_docs[1]['_rev'].
|
|
200
|
-
expect { @obj.other_docs[1].
|
|
194
|
+
expect { @obj.other_doc['_rev'].must_equal @db.get('other_doc')['_rev'] }
|
|
195
|
+
expect { @obj.other_doc.must_be_kind_of ModelTestDocument }
|
|
196
|
+
expect { @obj.other_docs.must_be_kind_of Array }
|
|
197
|
+
expect { @obj.other_docs[0]['_rev'].must_equal @db.get('other_docs_1')['_rev'] }
|
|
198
|
+
expect { @obj.other_docs[0].must_be_kind_of ModelTestDocument }
|
|
199
|
+
expect { @obj.other_docs[1]['_rev'].must_equal @db.get('other_docs_2')['_rev'] }
|
|
200
|
+
expect { @obj.other_docs[1].must_be_kind_of ModelTestDocument }
|
|
201
201
|
|
|
202
|
-
|
|
202
|
+
describe "caching" do
|
|
203
203
|
before do
|
|
204
204
|
@obj.other_doc # load it
|
|
205
205
|
doc = @db.get('other_doc')
|
|
@@ -207,32 +207,32 @@ class ExegesisModelTest < Test::Unit::TestCase
|
|
|
207
207
|
@db.put(doc['_id'], doc.attributes)
|
|
208
208
|
end
|
|
209
209
|
|
|
210
|
-
expect { @obj.other_doc['foo'].
|
|
211
|
-
expect { @obj.other_doc(true)['foo'].
|
|
210
|
+
expect { @obj.other_doc['foo'].must_be_nil }
|
|
211
|
+
expect { @obj.other_doc(true)['foo'].must_equal 'updated' }
|
|
212
212
|
end
|
|
213
213
|
end
|
|
214
214
|
|
|
215
|
-
|
|
216
|
-
expect { lambda{@obj.other_doc}.
|
|
217
|
-
expect { lambda{@obj.other_docs}.
|
|
215
|
+
describe "when the document is missing" do
|
|
216
|
+
expect { lambda{@obj.other_doc}.must_raise RestClient::ResourceNotFound }
|
|
217
|
+
expect { lambda{@obj.other_docs}.must_raise RestClient::ResourceNotFound }
|
|
218
218
|
end
|
|
219
219
|
|
|
220
|
-
|
|
220
|
+
describe "when the model has a parent" do
|
|
221
221
|
before do
|
|
222
222
|
@obj.castee = {'class' => 'FooTestModel', 'ref' => 'other_doc'}
|
|
223
223
|
@db.put('other_doc', {'class' => 'ModelTestDocument', '_id' => 'other_doc'})
|
|
224
224
|
end
|
|
225
225
|
|
|
226
|
-
expect { @obj.castee.ref['_rev'].
|
|
226
|
+
expect { @obj.castee.ref['_rev'].must_equal @db.get('other_doc')['_rev'] }
|
|
227
227
|
end
|
|
228
228
|
end
|
|
229
229
|
|
|
230
|
-
|
|
230
|
+
describe "without any database present" do
|
|
231
231
|
before { @obj = ExposeTestModel.new(:other_doc => "some_doc_id") }
|
|
232
|
-
expect { lambda{@obj.other_doc}.
|
|
232
|
+
expect { lambda{@obj.other_doc}.must_raise ArgumentError }
|
|
233
233
|
end
|
|
234
234
|
|
|
235
|
-
|
|
235
|
+
describe "setting references" do
|
|
236
236
|
before do
|
|
237
237
|
reset_db
|
|
238
238
|
@parent = ModelTestDocument.new({}, @db)
|
|
@@ -241,59 +241,59 @@ class ExegesisModelTest < Test::Unit::TestCase
|
|
|
241
241
|
@doc = ModelTestDocument.new({}, @db)
|
|
242
242
|
@doc.save
|
|
243
243
|
end
|
|
244
|
-
|
|
244
|
+
describe "from a doc that has been saved" do
|
|
245
245
|
before do
|
|
246
246
|
@obj.other_doc = @doc
|
|
247
247
|
end
|
|
248
|
-
expect { @obj['other_doc'].
|
|
249
|
-
expect { @obj.other_doc.
|
|
248
|
+
expect { @obj['other_doc'].must_equal @doc.id }
|
|
249
|
+
expect { @obj.other_doc.must_equal @doc }
|
|
250
250
|
end
|
|
251
|
-
|
|
251
|
+
describe "from an id" do
|
|
252
252
|
before do
|
|
253
253
|
@obj.other_doc = @doc.id
|
|
254
254
|
end
|
|
255
|
-
expect { @obj['other_doc'].
|
|
256
|
-
expect { @obj.other_doc.
|
|
255
|
+
expect { @obj['other_doc'].must_equal @doc.id }
|
|
256
|
+
expect { @obj.other_doc.must_equal @doc }
|
|
257
257
|
end
|
|
258
258
|
end
|
|
259
259
|
end
|
|
260
260
|
|
|
261
|
-
|
|
261
|
+
describe "when the value is nil" do
|
|
262
262
|
before do
|
|
263
263
|
@obj = ExposeTestModel.new({:castee => nil, :castees => nil, :regexen => ['foo', nil]})
|
|
264
264
|
end
|
|
265
|
-
expect { @obj.castee.
|
|
266
|
-
expect { @obj.castees.
|
|
267
|
-
expect { @obj.regexen.
|
|
265
|
+
expect { @obj.castee.must_be_nil }
|
|
266
|
+
expect { @obj.castees.must_be_nil }
|
|
267
|
+
expect { @obj.regexen.must_equal [/foo/] }
|
|
268
268
|
end
|
|
269
269
|
|
|
270
270
|
end
|
|
271
271
|
end
|
|
272
272
|
end
|
|
273
273
|
|
|
274
|
-
|
|
274
|
+
describe "instance methods" do
|
|
275
275
|
before do
|
|
276
276
|
@obj = ExposeTestModel.new({:read_only => 'bar'})
|
|
277
277
|
end
|
|
278
|
-
|
|
278
|
+
describe "update" do
|
|
279
279
|
before do
|
|
280
280
|
@obj.update({:read_only => 'bee'})
|
|
281
281
|
end
|
|
282
282
|
|
|
283
|
-
expect { @obj.read_only.
|
|
283
|
+
expect { @obj.read_only.must_equal 'bee' }
|
|
284
284
|
end
|
|
285
285
|
|
|
286
|
-
|
|
287
|
-
|
|
286
|
+
describe "update" do
|
|
287
|
+
describe "with a writer" do
|
|
288
288
|
before do
|
|
289
289
|
@obj.update_attributes(:foo => 'foo')
|
|
290
290
|
end
|
|
291
291
|
|
|
292
|
-
expect { @obj.foo.
|
|
292
|
+
expect { @obj.foo.must_equal "foo" }
|
|
293
293
|
end
|
|
294
294
|
|
|
295
|
-
|
|
296
|
-
expect { lambda{@obj.update_attributes({:read_only => 'bee'})}.
|
|
295
|
+
describe "without a writer" do
|
|
296
|
+
expect { lambda{@obj.update_attributes({:read_only => 'bee'})}.must_raise NoMethodError }
|
|
297
297
|
end
|
|
298
298
|
end
|
|
299
299
|
end
|
data/test/server_test.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
describe Exegesis::Server do
|
|
4
4
|
|
|
5
|
-
before
|
|
5
|
+
before do
|
|
6
6
|
@db = 'http://localhost:5984/exegesis-test'
|
|
7
7
|
RestClient.delete @db rescue nil
|
|
8
8
|
RestClient.delete "#{@db}-2" rescue nil
|
|
@@ -11,16 +11,16 @@ class ExegesisServerTest < Test::Unit::TestCase
|
|
|
11
11
|
@server = Exegesis::Server.new('http://localhost:5984')
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
expect { @server.databases.
|
|
14
|
+
describe "listing databases" do
|
|
15
|
+
expect { @server.databases.must_include('exegesis-test') }
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
describe "creating a database" do
|
|
19
19
|
before do
|
|
20
20
|
@response = @server.create_database('exegesis-test-2')
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
expect { @response['ok']
|
|
23
|
+
expect { assert @response['ok'] }
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
end
|
data/test/test_helper.rb
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
|
-
require '
|
|
2
|
+
require 'minitest/spec'
|
|
3
|
+
MiniTest::Unit.autorun
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
require '
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
rescue
|
|
12
|
-
puts "no ruby-debug installed? REAlLY? ok, if that's how you roll..."
|
|
5
|
+
unless RUBY_VERSION =~ /^1\.9/
|
|
6
|
+
begin
|
|
7
|
+
require 'ruby-debug'
|
|
8
|
+
Debugger.start
|
|
9
|
+
rescue
|
|
10
|
+
puts "protip: `(sudo) gem install ruby-debug` for superhuman debugging powers"
|
|
11
|
+
end
|
|
13
12
|
end
|
|
14
13
|
|
|
15
14
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
@@ -19,7 +18,17 @@ class TestingDatabase
|
|
|
19
18
|
include Exegesis::Database
|
|
20
19
|
end
|
|
21
20
|
|
|
22
|
-
class
|
|
21
|
+
class MiniTest::Spec
|
|
22
|
+
# beacuse test names are really just comments, and therefore a code smell
|
|
23
|
+
def self.expect(desc=nil, &block)
|
|
24
|
+
@counter ||= 0; @counter += 1
|
|
25
|
+
desc ||= "[#{@counter}]"
|
|
26
|
+
name = ["test_", description_stack.join(' '), desc].join(' ')
|
|
27
|
+
define_method name, &block
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class MiniTest::Unit::TestCase
|
|
23
32
|
|
|
24
33
|
def fixtures_path fixtures
|
|
25
34
|
File.join(File.dirname(__FILE__), 'fixtures', fixtures)
|
|
@@ -30,10 +39,10 @@ class Test::Unit::TestCase
|
|
|
30
39
|
end
|
|
31
40
|
|
|
32
41
|
# todo: extract to some helper methods to include ala RR, etc
|
|
33
|
-
def reset_db(name=nil)
|
|
42
|
+
def reset_db(name=nil, klass=TestingDatabase)
|
|
34
43
|
RestClient.delete "http://localhost:5984/#{db(name)}" rescue nil
|
|
35
44
|
db_server.create_database(db(name))
|
|
36
|
-
@db =
|
|
45
|
+
@db = klass.new(db_server, db(name))
|
|
37
46
|
end
|
|
38
47
|
|
|
39
48
|
def db(name)
|