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/design_test.rb
CHANGED
|
@@ -21,7 +21,7 @@ class DesignTestDatabase
|
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
describe Exegesis::Design do
|
|
25
25
|
|
|
26
26
|
def setup_db(with_doc=true)
|
|
27
27
|
reset_db
|
|
@@ -38,19 +38,19 @@ class ExegesisDesignTest < Test::Unit::TestCase
|
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
describe "design instances" do
|
|
42
42
|
before { setup_db }
|
|
43
|
-
expect { @db.things.database.
|
|
43
|
+
expect { @db.things.database.must_equal @db }
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
describe "design declarations" do
|
|
47
47
|
before { setup_db }
|
|
48
|
-
expect { @db.things.class.
|
|
49
|
-
expect { @db.things.
|
|
50
|
-
expect { @db.things.design_name.
|
|
48
|
+
expect { @db.things.class.must_equal DesignTestDatabase::ThingsDesign }
|
|
49
|
+
expect { @db.things.must_be_kind_of Exegesis::Design }
|
|
50
|
+
expect { @db.things.design_name.must_equal 'things' }
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
describe "view declarations" do
|
|
54
54
|
before do
|
|
55
55
|
setup_db
|
|
56
56
|
@docs = [
|
|
@@ -61,26 +61,26 @@ class ExegesisDesignTest < Test::Unit::TestCase
|
|
|
61
61
|
@db.save(@docs)
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
describe "declared docs" do
|
|
65
65
|
describe "with default key" do
|
|
66
66
|
before { @response = @db.things.by_tag('foo') }
|
|
67
|
-
expect { @response.
|
|
68
|
-
expect { @response.size.
|
|
69
|
-
expect { @response.documents.
|
|
70
|
-
expect { @response.documents.
|
|
67
|
+
expect { @response.must_be_kind_of Exegesis::DocumentCollection }
|
|
68
|
+
expect { @response.size.must_equal @docs.select{|d| d['tags'].include?('foo')}.size }
|
|
69
|
+
expect { @response.documents.each {|id,d| d.must_be_kind_of DesignTestDoc } }
|
|
70
|
+
expect { @response.documents.each {|id,d| d['tags'].must_include 'foo' } }
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
describe "with multiple keys" do
|
|
74
74
|
before { @response = @db.things.by_tag :keys => %w(bar bee) }
|
|
75
|
-
expect { @response.
|
|
76
|
-
expect { @response.size.
|
|
77
|
-
expect { @response.documents.size.
|
|
78
|
-
expect { @response.documents.
|
|
75
|
+
expect { @response.must_be_kind_of Exegesis::DocumentCollection }
|
|
76
|
+
expect { @response.size.must_equal @docs.inject(0){|sum,d| sum+=(d['tags'] & %w(bar bee)).size } }
|
|
77
|
+
expect { @response.documents.size.must_equal @docs.select{|d| (d['tags'] & %w(bar bee)).size > 0}.size }
|
|
78
|
+
expect { @response.documents.each {|id,d| d.must_be_kind_of DesignTestDoc } }
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
end
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
describe "declared hashes" do
|
|
84
84
|
before do
|
|
85
85
|
@counts = Hash.new(0)
|
|
86
86
|
@docs.each do |doc|
|
|
@@ -94,111 +94,53 @@ class ExegesisDesignTest < Test::Unit::TestCase
|
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
96
|
end
|
|
97
|
-
expect { @db.things.count.
|
|
98
|
-
expect { @db.things.count('foo').
|
|
97
|
+
expect { @db.things.count.must_equal @counts }
|
|
98
|
+
expect { @db.things.count('foo').must_equal @counts['foo'] }
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
expect { lambda{@db.things.count(:group=>false)}.
|
|
102
|
-
expect { lambda{@db.things.count(:include_docs=>true)}.
|
|
100
|
+
describe "invalid options" do
|
|
101
|
+
expect { lambda{@db.things.count(:group=>false)}.must_raise ArgumentError }
|
|
102
|
+
expect { lambda{@db.things.count(:include_docs=>true)}.must_raise ArgumentError }
|
|
103
103
|
end
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
describe "for views without reduce" do
|
|
106
106
|
before { @klass = DesignTestDatabase::StuffDesign }
|
|
107
|
-
expect { lambda{@klass.class_eval{hash(:name_count, :view=>:by_name)}}.
|
|
107
|
+
expect { lambda{@klass.class_eval{hash(:name_count, :view=>:by_name)}}.must_raise(ArgumentError) }
|
|
108
108
|
end
|
|
109
109
|
end
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
context "with a key as an initial arguemnt" do
|
|
116
|
-
expect { @db.things.parse_opts('foo').will == {:key => 'foo'} }
|
|
117
|
-
expect { @db.things.parse_opts('foo', :include_docs => true).will == {:key => 'foo', :include_docs => true} }
|
|
118
|
-
expect { @db.things.parse_opts('foo', {:stale => 'ok'}, {:include_docs => true}).will == {:key => 'foo', :stale => 'ok', :include_docs => true }}
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
context "without an implied key" do
|
|
122
|
-
expect { @db.things.parse_opts(:key => 'foo').will == {:key => 'foo'} }
|
|
123
|
-
expect { @db.things.parse_opts({:key => 'foo'}, nil, {:stale => 'ok'}).will == {:key => 'foo', :stale => 'ok'} }
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
context "when a keys option is empty" do
|
|
127
|
-
expect { @db.things.parse_opts(:keys => []).will == {} }
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
context "for ranges" do
|
|
131
|
-
context "when the key _is_ a range" do
|
|
132
|
-
before { @opts = @db.things.parse_opts(:key => 'bar'..'baz') }
|
|
133
|
-
expect { @opts.has_key?(:key).will == false }
|
|
134
|
-
expect { @opts[:startkey].will == 'bar' }
|
|
135
|
-
expect { @opts[:endkey].will == 'baz'}
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
context "when the key is an array that includes a range" do
|
|
139
|
-
before { @opts = @db.things.parse_opts(:key => ['published', '2009'..'2009/04']) }
|
|
140
|
-
expect { @opts.has_key?(:key).will == false }
|
|
141
|
-
expect { @opts[:startkey].will == ['published', '2009'] }
|
|
142
|
-
expect { @opts[:endkey].will == ['published', '2009/04'] }
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
context "for non inclusive ranges" do
|
|
146
|
-
end
|
|
147
|
-
context "when descending:true is an option" do
|
|
148
|
-
context "and first value is greater than the end value" do
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
context "when the first value is greater than the end value" do
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
context "invalid option configurations" do
|
|
155
|
-
expect { lambda {@db.things.parse_opts(:startkey => 'foo')}.will raise_error(ArgumentError) }
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
context "reducing" do
|
|
160
|
-
before { @parsing = lambda{|opts| @db.things.parse_opts(opts) } }
|
|
161
|
-
expect { @parsing.call(:group => 3).will == {:group_level => 3}}
|
|
162
|
-
expect { lambda{@parsing.call(:group => true, :reduce => false)}.will raise_error(ArgumentError) }
|
|
163
|
-
expect { lambda{@parsing.call(:group => true, :include_docs => true)}.will raise_error(ArgumentError) }
|
|
164
|
-
expect { lambda{@parsing.call(:group => 1, :reduce => false)}.will raise_error(ArgumentError) }
|
|
165
|
-
expect { lambda{@parsing.call(:group => 1, :include_docs => true)}.will raise_error(ArgumentError) }
|
|
166
|
-
end
|
|
112
|
+
describe "design doc meta declarations" do
|
|
113
|
+
expect { DesignTestDatabase::StuffDesign.design_name.must_equal "things" }
|
|
114
|
+
expect { DesignTestDatabase::StuffDesign.design_directory.must_equal Pathname.new("app/designs/stuff") }
|
|
167
115
|
end
|
|
168
116
|
|
|
169
|
-
|
|
170
|
-
expect { DesignTestDatabase::StuffDesign.design_name.will == "things" }
|
|
171
|
-
expect { DesignTestDatabase::StuffDesign.design_directory.will == Pathname.new("app/designs/stuff") }
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
context "the design document" do
|
|
117
|
+
describe "the design document" do
|
|
175
118
|
before do
|
|
176
119
|
@canonical = DesignTestDatabase::ThingsDesign.canonical_design
|
|
177
120
|
end
|
|
178
121
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
expect { @canonical['views']['by_tag']['map'].
|
|
182
|
-
expect { @canonical['views']['by_tag']['reduce'].
|
|
122
|
+
describe "composing the canonical version" do
|
|
123
|
+
describe "from files" do
|
|
124
|
+
expect { @canonical['views']['by_tag']['map'].must_equal File.read(fixtures_path('designs/things/views/by_tag/map.js')) }
|
|
125
|
+
expect { @canonical['views']['by_tag']['reduce'].must_equal File.read(fixtures_path('designs/things/views/by_tag/reduce.js')) }
|
|
183
126
|
end
|
|
184
127
|
|
|
185
|
-
|
|
128
|
+
describe "from class declarations" do
|
|
186
129
|
# tk
|
|
187
130
|
end
|
|
188
131
|
end
|
|
189
132
|
|
|
190
|
-
|
|
191
|
-
|
|
133
|
+
describe "syncronizing" do
|
|
134
|
+
describe "when the design_doc doesn't exist in the db yet" do
|
|
192
135
|
before do
|
|
193
136
|
setup_db(false)
|
|
194
|
-
@db.things
|
|
195
137
|
end
|
|
196
|
-
expect { lambda{@db.get('_design/things')}.
|
|
197
|
-
expect { @db.things['views'].
|
|
198
|
-
expect { @db.things.rev.
|
|
138
|
+
expect { lambda{@db.get('_design/things')}.must_raise RestClient::ResourceNotFound }
|
|
139
|
+
expect { @db.things['views'].must_equal @canonical['views'] }
|
|
140
|
+
expect { @db.things.rev.must_match /\d-\d{6,12}/ }
|
|
199
141
|
end
|
|
200
142
|
|
|
201
|
-
|
|
143
|
+
describe "when the design_doc exists but is not canonical" do
|
|
202
144
|
before do
|
|
203
145
|
# there are no line breaks in the version that setup_db posts
|
|
204
146
|
setup_db
|
|
@@ -206,10 +148,10 @@ class ExegesisDesignTest < Test::Unit::TestCase
|
|
|
206
148
|
@db.things
|
|
207
149
|
end
|
|
208
150
|
|
|
209
|
-
expect { @db.things.rev.
|
|
151
|
+
expect { @db.things.rev.wont_equal @old['_rev'] }
|
|
210
152
|
end
|
|
211
153
|
|
|
212
|
-
|
|
154
|
+
describe "when the design_doc exists and is canonical" do
|
|
213
155
|
before do
|
|
214
156
|
setup_db(false)
|
|
215
157
|
@db.put('_design/things', DesignTestDatabase::ThingsDesign.canonical_design)
|
|
@@ -217,18 +159,18 @@ class ExegesisDesignTest < Test::Unit::TestCase
|
|
|
217
159
|
@db.things
|
|
218
160
|
end
|
|
219
161
|
|
|
220
|
-
expect { @db.things.rev.
|
|
162
|
+
expect { @db.things.rev.must_equal @old['_rev'] }
|
|
221
163
|
end
|
|
222
164
|
end
|
|
223
165
|
|
|
224
|
-
|
|
166
|
+
describe "knowing the views" do
|
|
225
167
|
before do
|
|
226
168
|
@klass = DesignTestDatabase::ThingsDesign
|
|
227
169
|
end
|
|
228
170
|
|
|
229
|
-
expect { @klass.views.
|
|
230
|
-
expect { @klass.reduceable?('by_tag')
|
|
231
|
-
expect { @klass.reduceable?('by_name')
|
|
171
|
+
expect { @klass.views.must_equal @canonical['views'].keys }
|
|
172
|
+
expect { assert @klass.reduceable?('by_tag') }
|
|
173
|
+
expect { refute @klass.reduceable?('by_name') }
|
|
232
174
|
end
|
|
233
175
|
end
|
|
234
176
|
|
|
@@ -4,9 +4,9 @@ class DocCollectionTestDoc
|
|
|
4
4
|
include Exegesis::Document
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
describe Exegesis::DocumentCollection do
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
describe "when dealing with view response rows" do
|
|
10
10
|
before do
|
|
11
11
|
reset_db
|
|
12
12
|
@docs = [{'_id' => 'foo'}, {'_id' => 'bar'}, {'_id' => 'bee'}].map {|d| d.update('class' => 'DocCollectionTestDoc') }
|
|
@@ -16,14 +16,14 @@ class ExegesisDocumentCollectionTest < Test::Unit::TestCase
|
|
|
16
16
|
@collection = Exegesis::DocumentCollection.new(@response_rows, @db)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
expect { @collection.size.
|
|
20
|
-
expect { @collection.keys.
|
|
21
|
-
expect { @collection.values.
|
|
22
|
-
expect { @collection.documents.size.
|
|
23
|
-
expect { @collection.documents.
|
|
24
|
-
expect { @collection.documents['foo'].id.
|
|
19
|
+
expect { @collection.size.must_equal @rows.size }
|
|
20
|
+
expect { @collection.keys.must_equal @rows.map{|r| r.first}.uniq }
|
|
21
|
+
expect { @collection.values.must_equal @rows.map{|r| r[1]} }
|
|
22
|
+
expect { @collection.documents.size.must_equal @rows.map{|r| r[2]}.uniq.size }
|
|
23
|
+
expect { @collection.documents.each {|id,d| d.must_be_kind_of DocCollectionTestDoc } }
|
|
24
|
+
expect { @collection.documents['foo'].id.must_equal @docs.first['_id'] }
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
describe "when documents are already in the rows" do
|
|
27
27
|
before do
|
|
28
28
|
# "thing":"foobar" is not in the docs that have been saved to the database
|
|
29
29
|
@docs.each {|d| d.update('thing' => 'foobar') }
|
|
@@ -31,22 +31,22 @@ class ExegesisDocumentCollectionTest < Test::Unit::TestCase
|
|
|
31
31
|
@collection = Exegesis::DocumentCollection.new(@response_rows, @db)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
expect { @collection.documents.
|
|
34
|
+
expect { @collection.documents.each {|id,d| d['thing'].must_equal 'foobar' } }
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
describe "filtering to a specific key" do
|
|
38
38
|
before do
|
|
39
39
|
@rows = @rows.select {|r| r[0]=="foo" }
|
|
40
40
|
@foos = @collection['foo']
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
expect { @foos.size.
|
|
44
|
-
expect { @foos.values.
|
|
45
|
-
expect { @foos.documents.size.
|
|
46
|
-
expect { @foos.documents.
|
|
47
|
-
expect { @foos.documents['foo'].object_id.
|
|
43
|
+
expect { @foos.size.must_equal @rows.size }
|
|
44
|
+
expect { @foos.values.must_equal @rows.map{|r| r[1]} }
|
|
45
|
+
expect { @foos.documents.size.must_equal @rows.map{|r| r[2]}.uniq.size }
|
|
46
|
+
expect { @foos.documents.each {|id,d| d.must_be_kind_of DocCollectionTestDoc } }
|
|
47
|
+
expect { @foos.documents['foo'].object_id.must_equal @collection.documents['foo'].object_id }
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
describe "with array keys" do
|
|
50
50
|
before do
|
|
51
51
|
@rows = [ [%w(bar baz), 5, 'bar'],
|
|
52
52
|
[%w(bar bee), 5, 'bee'],
|
|
@@ -60,17 +60,17 @@ class ExegesisDocumentCollectionTest < Test::Unit::TestCase
|
|
|
60
60
|
@collection = Exegesis::DocumentCollection.new(@response_rows, @db)
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
expect { @collection['foo'].size.
|
|
64
|
-
expect { @collection['foo'].values.
|
|
65
|
-
expect { @collection['foo']['bar'].size.
|
|
66
|
-
expect { @collection['foo']['bar'].values.
|
|
63
|
+
expect { @collection['foo'].size.must_equal @rows.select{|r| r[0][0]=='foo'}.size }
|
|
64
|
+
expect { @collection['foo'].values.must_equal @rows.select{|r| r[0][0]=='foo' }.map{|r| r[1]} }
|
|
65
|
+
expect { @collection['foo']['bar'].size.must_equal @rows.select{|r| r[0][0]=='foo' && r[0][1]=='bar'}.size }
|
|
66
|
+
expect { @collection['foo']['bar'].values.must_equal @rows.select{|r| r[0][0]=='foo'&&r[0][1]=='bar'}.map{|r| r[1]} }
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
describe "iterating" do
|
|
74
74
|
before do
|
|
75
75
|
reset_db
|
|
76
76
|
@docs = [%w(bar bee), %w(bee foo), %w(foo bar)].map {|k,t| {'_id'=>k, 'thing'=>t, 'class'=>'DocCollectionTestDoc'} }
|
|
@@ -79,7 +79,7 @@ class ExegesisDocumentCollectionTest < Test::Unit::TestCase
|
|
|
79
79
|
@collection = Exegesis::DocumentCollection.new(@rows, @db)
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
describe "each" do
|
|
83
83
|
before do
|
|
84
84
|
@counter = 0
|
|
85
85
|
@bin = []
|
|
@@ -88,10 +88,10 @@ class ExegesisDocumentCollectionTest < Test::Unit::TestCase
|
|
|
88
88
|
@valbinning = lambda{ @collection.each{|k,v,d| @bin << v }; @bin }
|
|
89
89
|
@docbinning = lambda{ @collection.each{|k,v,d| @bin << d.id }; @bin }
|
|
90
90
|
end
|
|
91
|
-
expect { @counting.call.
|
|
92
|
-
expect { @keybinning.call.
|
|
93
|
-
expect { @valbinning.call.
|
|
94
|
-
expect { @docbinning.call.
|
|
91
|
+
expect { @counting.call.must_equal 3 }
|
|
92
|
+
expect { @keybinning.call.must_equal @rows.map{|r| r['key']} }
|
|
93
|
+
expect { @valbinning.call.must_equal @rows.map{|r| r['value']} }
|
|
94
|
+
expect { @docbinning.call.must_equal @rows.map{|r| @db.get(r['id']).id} }
|
|
95
95
|
end
|
|
96
96
|
end
|
|
97
97
|
end
|
data/test/document_test.rb
CHANGED
|
@@ -23,10 +23,10 @@ class UniqueIdBlockTestDocument
|
|
|
23
23
|
unique_id {|doc, attempt| attempt.zero? ? doc['pk'] : "#{doc['pk']}-#{attempt}" }
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
describe Exegesis::Document do
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
describe "class definitions" do
|
|
29
|
+
describe "with timestamps" do
|
|
30
30
|
before do
|
|
31
31
|
reset_db
|
|
32
32
|
@obj = TimestampTestDocument.new({}, @db)
|
|
@@ -34,144 +34,143 @@ class ExegesisDocumentClassDefinitionsTest < Test::Unit::TestCase
|
|
|
34
34
|
@obj = @db.get(@obj.id)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
expect { @obj.created_at.to_f.
|
|
39
|
-
expect { @obj.updated_at.to_f.
|
|
37
|
+
describe "initial save" do
|
|
38
|
+
expect { @obj.created_at.to_f.must_be_close_to Time.now.to_f, 2 }
|
|
39
|
+
expect { @obj.updated_at.to_f.must_be_close_to Time.now.to_f, 2 }
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
describe "when created_at already exists" do
|
|
43
43
|
before do
|
|
44
44
|
@obj['created_at'] = Time.now - 3600
|
|
45
45
|
@obj.save
|
|
46
46
|
@obj = @db.get(@obj.id)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
expect { @obj.created_at.to_f.
|
|
50
|
-
expect { @obj.updated_at.to_f.
|
|
49
|
+
expect { @obj.created_at.to_f.must_be_close_to((Time.now - 3600).to_f, 2) }
|
|
50
|
+
expect { @obj.updated_at.to_f.must_be_close_to Time.now.to_f, 2 }
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
describe "with a custom unique_id setter" do
|
|
56
|
+
describe "as a method" do
|
|
57
57
|
before do
|
|
58
58
|
reset_db
|
|
59
59
|
@obj = UniqueIdTestDocument.new({}, @db)
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
describe "when the id isn't in place yet" do
|
|
63
63
|
before do
|
|
64
64
|
@obj.save
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
expect { @obj.id.
|
|
67
|
+
expect { @obj.id.must_equal "snowflake" }
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
describe "when there is an id in place already" do
|
|
71
71
|
before do
|
|
72
72
|
@obj['_id'] = 'foo'
|
|
73
73
|
@obj.save
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
expect { @obj.id.
|
|
76
|
+
expect { @obj.id.must_equal "foo" }
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
describe "when the desired id is already in use" do
|
|
80
80
|
before do
|
|
81
81
|
@db.put('snowflake', {'_id' => 'snowflake', 'foo' => 'bar'})
|
|
82
82
|
@obj.save
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
-
expect { @obj.id.
|
|
85
|
+
expect { @obj.id.must_equal 'snowflake-1' }
|
|
86
86
|
end
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
describe "as a block" do
|
|
90
90
|
before do
|
|
91
91
|
reset_db
|
|
92
92
|
@obj = UniqueIdBlockTestDocument.new({'pk'=>'bar'}, @db)
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
describe "when the id doesn't yet exist and no id in place" do
|
|
96
96
|
before { @obj.save }
|
|
97
|
-
expect { @obj.id.
|
|
97
|
+
expect { @obj.id.must_equal @obj['pk'] }
|
|
98
98
|
end
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
describe "when the document has an id in place already" do
|
|
101
101
|
before do
|
|
102
102
|
@obj['_id'] = 'foo'
|
|
103
103
|
@obj.save
|
|
104
104
|
end
|
|
105
|
-
expect { @obj.id.
|
|
105
|
+
expect { @obj.id.must_equal 'foo' }
|
|
106
106
|
end
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
describe "when the desired id is already in use" do
|
|
109
109
|
before do
|
|
110
110
|
@db.put('bar', {'_id' => 'bar', 'pk' => 'bar'})
|
|
111
111
|
@obj.save
|
|
112
112
|
end
|
|
113
|
-
expect { @obj.id.
|
|
113
|
+
expect { @obj.id.must_equal 'bar-1'}
|
|
114
114
|
end
|
|
115
115
|
end
|
|
116
116
|
end
|
|
117
117
|
end
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
describe "instance methods" do
|
|
120
120
|
before do
|
|
121
121
|
reset_db
|
|
122
122
|
end
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
describe "updating attributes" do
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
describe "an existing doc" do
|
|
127
127
|
before do
|
|
128
128
|
@doc = TestDocument.new({'foo' => 'bar'}, @db)
|
|
129
129
|
@doc.save
|
|
130
130
|
@old_rev = @doc.rev
|
|
131
131
|
end
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
expect { lambda
|
|
135
|
-
expect { lambda
|
|
133
|
+
describe "without a matching rev" do
|
|
134
|
+
expect { lambda{@doc.update_attributes({'foo' => 'bee'})}.must_raise ArgumentError }
|
|
135
|
+
expect { lambda{@doc.update_attributes({'foo' => 'bee', '_rev' => 'z'})}.must_raise ArgumentError }
|
|
136
136
|
end
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
describe "with a matching rev" do
|
|
139
139
|
before do
|
|
140
140
|
@doc.update_attributes({'_rev' => @doc.rev, 'foo' => 'bee'})
|
|
141
141
|
end
|
|
142
142
|
|
|
143
|
-
expect { @doc['foo'].
|
|
144
|
-
expect { @doc.rev.
|
|
143
|
+
expect { @doc['foo'].must_equal 'bee' }
|
|
144
|
+
expect { @doc.rev.wont_equal @old_rev }
|
|
145
145
|
end
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
describe "when given keys without writers" do
|
|
148
148
|
before do
|
|
149
149
|
@action = lambda {@doc.update_attributes({'_rev' => @doc.rev, 'bar' => 'boo'})}
|
|
150
150
|
end
|
|
151
151
|
|
|
152
|
-
expect { @action.
|
|
152
|
+
expect { @action.must_raise NoMethodError }
|
|
153
153
|
end
|
|
154
154
|
end
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
describe "a new doc" do
|
|
157
157
|
before { @doc = TestDocument.new({'foo' => 'bar'}, @db) }
|
|
158
158
|
|
|
159
|
-
|
|
159
|
+
describe "without a rev" do
|
|
160
160
|
before { @doc.update_attributes({'foo' => 'baz'}) }
|
|
161
|
-
expect { @doc['foo'].
|
|
161
|
+
expect { @doc['foo'].must_equal 'baz' }
|
|
162
162
|
end
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
describe "with a blank rev" do
|
|
165
165
|
before { @doc.update_attributes({'foo' => 'baz', '_rev' => ''}) }
|
|
166
|
-
expect { @doc['foo'].
|
|
166
|
+
expect { @doc['foo'].must_equal 'baz' }
|
|
167
167
|
end
|
|
168
|
-
|
|
168
|
+
describe "with a non blank rev" do
|
|
169
169
|
before { @action = lambda{@doc.update_attributes({'foo'=>'baz', '_rev'=>'1-3034523523'})} }
|
|
170
|
-
expect { @action.
|
|
170
|
+
expect { @action.must_raise ArgumentError }
|
|
171
171
|
end
|
|
172
172
|
end
|
|
173
173
|
|
|
174
|
-
|
|
175
174
|
end
|
|
176
175
|
end
|
|
177
176
|
|
data/test/http_test.rb
CHANGED
|
@@ -2,20 +2,20 @@ require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
|
|
2
2
|
require 'restclient'
|
|
3
3
|
require 'json'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
describe Exegesis::Http do
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
describe "url formatting" do
|
|
8
|
+
describe "with no params" do
|
|
9
9
|
before do
|
|
10
10
|
@url = "/some_url"
|
|
11
11
|
@action = lambda {|params| Exegesis::Http.format_url(@url, params) }
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
expect { @action.call(nil).
|
|
15
|
-
expect { @action.call({}).
|
|
14
|
+
expect { @action.call(nil).must_equal "/some_url" }
|
|
15
|
+
expect { @action.call({}).must_equal "/some_url" }
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
describe "with normal params" do
|
|
19
19
|
before do
|
|
20
20
|
@url = "/some_url"
|
|
21
21
|
@params = {
|
|
@@ -25,54 +25,52 @@ class HttpTest < Test::Unit::TestCase
|
|
|
25
25
|
@expected = ["/some_url?one=1&two=2", "/some_url?two=2&one=1"]
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
expect { @expected.
|
|
28
|
+
expect { @expected.must_include Exegesis::Http.format_url(@url, @params) }
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
before
|
|
32
|
+
describe "making requests" do
|
|
33
|
+
before do
|
|
34
34
|
@db = 'http://localhost:5984/exegesis-test'
|
|
35
35
|
RestClient.delete(@db) rescue nil
|
|
36
36
|
RestClient.put(@db, '')
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
after
|
|
39
|
+
after do
|
|
40
40
|
RestClient.delete(@db) rescue nil
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
describe "get requests" do
|
|
44
44
|
before do
|
|
45
45
|
@response = Exegesis::Http.get(@db)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
expect { @response['db_name'].
|
|
48
|
+
expect { @response['db_name'].must_equal 'exegesis-test' }
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
describe "post requests" do
|
|
52
52
|
before do
|
|
53
53
|
@response = Exegesis::Http.post(@db, {'test' => 'value'}.to_json)
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
expect { @response['ok'].
|
|
56
|
+
expect { @response['ok'].must_equal true }
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
describe "put requests" do
|
|
60
60
|
before do
|
|
61
61
|
@response = Exegesis::Http.put("#{@db}/test-document", {'test' => 'value'}.to_json)
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
expect { @response['ok'].
|
|
65
|
-
|
|
66
|
-
after { RestClient.delete("#{@db}/test-document?rev=#{@response['rev']}") }
|
|
64
|
+
expect { @response['ok'].must_equal true }
|
|
67
65
|
end
|
|
68
66
|
|
|
69
|
-
|
|
67
|
+
describe "delete requests" do
|
|
70
68
|
before do
|
|
71
69
|
@doc = JSON.parse RestClient.put("#{@db}/test-document", {'test' => 'value'}.to_json)
|
|
72
70
|
@response = RestClient.delete("#{@db}/test-document?rev=#{@doc['rev']}")
|
|
73
71
|
end
|
|
74
72
|
|
|
75
|
-
expect { @response['ok'].
|
|
73
|
+
expect { @response['ok'].must_equal 'ok' }
|
|
76
74
|
end
|
|
77
75
|
end
|
|
78
76
|
|