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/README.rdoc
CHANGED
|
@@ -51,13 +51,18 @@ CouchDB is table-less, and Exegesis's design reflects this. In CouchDB, Document
|
|
|
51
51
|
|
|
52
52
|
== Requirements:
|
|
53
53
|
|
|
54
|
-
* RestClient
|
|
54
|
+
* RestClient 0.9 or later.
|
|
55
55
|
|
|
56
56
|
For running the tests:
|
|
57
57
|
|
|
58
|
-
*
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
* MiniTest
|
|
59
|
+
MiniTest is the default testing framework for Ruby 1.9
|
|
60
|
+
However, these tests require the trunk version, and my patches against the trunk version.
|
|
61
|
+
The trunk version is here: http://github.com/seattlerb/minitest
|
|
62
|
+
My patches are in my fork: http://github.com/mattly/minitest
|
|
63
|
+
You will need to clone my repo and from its directory, do the following:
|
|
64
|
+
`rake gem`
|
|
65
|
+
`sudo gem install pkg/minitest-1.3.1`
|
|
66
|
+
Once MiniTest 1.3.2 is released you should be able to use the standard gem.
|
|
62
67
|
|
|
63
|
-
The test suite creates and destroys a database for each test that requires access to the database. This is slow, and the test suite may take some time to run. However, I would rather the test suite be slow and accurate than quick and full of mocking.
|
|
68
|
+
The test suite creates and destroys a database for each test that requires access to the database. This is slow, and the test suite may take some time to run. However, I would rather the test suite be slow and accurate than quick and full of mocking or possibly error-prone deleting.
|
data/VERSION.yml
CHANGED
data/lib/exegesis/design.rb
CHANGED
|
@@ -21,7 +21,7 @@ module Exegesis
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def self.compose_canonical
|
|
24
|
-
Dir[design_directory + 'views' + '**/*.js'].each do |view_func|
|
|
24
|
+
Dir[(design_directory + 'views' + '**/*.js').to_s].each do |view_func|
|
|
25
25
|
path = view_func.split('/')
|
|
26
26
|
func = path.pop.sub(/\.js$/,'')
|
|
27
27
|
name = path.pop
|
data/test/attachments_test.rb
CHANGED
|
@@ -4,18 +4,18 @@ class AttachmentsDocumentTest
|
|
|
4
4
|
include Exegesis::Document
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
describe Exegesis::Document::Attachments do
|
|
8
8
|
before do
|
|
9
9
|
reset_db
|
|
10
10
|
@doc = AttachmentsDocumentTest.new({}, @db)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
expect { @doc.attachments.
|
|
15
|
-
expect { @doc.attachments.size.
|
|
13
|
+
describe "document methods" do
|
|
14
|
+
expect { @doc.attachments.must_be_kind_of Exegesis::Document::Attachments }
|
|
15
|
+
expect { @doc.attachments.size.must_equal 0 }
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
describe "reading existing attachments" do
|
|
19
19
|
before do
|
|
20
20
|
@doc.save
|
|
21
21
|
@text = "this is a file"
|
|
@@ -23,20 +23,20 @@ class ExegesisAttachmentsTest < Test::Unit::TestCase
|
|
|
23
23
|
@doc = @db.get(@doc['_id'])
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
expect { @doc.attachments.size.
|
|
27
|
-
expect { @doc.attachments.keys.
|
|
28
|
-
expect { @doc.attachments['file.txt'].content_type.
|
|
29
|
-
expect { @doc.attachments['file.txt'].length.
|
|
30
|
-
expect { @doc.attachments['file.txt'].stub
|
|
31
|
-
expect { @doc.attachments['file.txt'].file.
|
|
26
|
+
expect { @doc.attachments.size.must_equal 1 }
|
|
27
|
+
expect { @doc.attachments.keys.must_equal %w(file.txt) }
|
|
28
|
+
expect { @doc.attachments['file.txt'].content_type.must_equal 'text/plain' }
|
|
29
|
+
expect { @doc.attachments['file.txt'].length.must_equal @text.length }
|
|
30
|
+
expect { assert @doc.attachments['file.txt'].stub? }
|
|
31
|
+
expect { @doc.attachments['file.txt'].file.must_equal @text }
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
describe "writing attachments" do
|
|
35
35
|
before do
|
|
36
36
|
@doc.save
|
|
37
37
|
end
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
describe "directly using attachments put" do
|
|
39
|
+
describe "with the file's contents as a string" do
|
|
40
40
|
before do
|
|
41
41
|
@contents = "this is the contents of a text file"
|
|
42
42
|
@type = 'text/plain'
|
|
@@ -44,62 +44,62 @@ class ExegesisAttachmentsTest < Test::Unit::TestCase
|
|
|
44
44
|
@putting.call 'f.txt', @contents, @type
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
expect { RestClient.get("#{@doc.uri}/f.txt").
|
|
49
|
-
expect { @doc.attachments['f.txt'].file.
|
|
50
|
-
expect { @doc.rev.
|
|
47
|
+
describe "when they don't exist yet" do
|
|
48
|
+
expect { RestClient.get("#{@doc.uri}/f.txt").must_equal @contents }
|
|
49
|
+
expect { @doc.attachments['f.txt'].file.must_equal @contents }
|
|
50
|
+
expect { @doc.rev.must_equal @db.raw_get(@doc.id)['_rev'] }
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
describe "when they do exist" do
|
|
54
54
|
before do
|
|
55
55
|
@putting.call 'f.txt', "foo", @type
|
|
56
56
|
end
|
|
57
|
-
expect { @doc.attachments['f.txt'].file.
|
|
57
|
+
expect { @doc.attachments['f.txt'].file.must_equal "foo" }
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
# it turns out rest-client doesn't actually support streaming uploads/downloads yet
|
|
62
|
-
#
|
|
62
|
+
# describe "streaming the file as a block given" do
|
|
63
63
|
# before do
|
|
64
64
|
# @file = File.open(fixtures_path('attachments/flavakitten.jpg'))
|
|
65
65
|
# @type = 'image/jpeg'
|
|
66
66
|
# @doc.attachments.put('kitten.jpg', @type) { @file.read }
|
|
67
67
|
# end
|
|
68
68
|
#
|
|
69
|
-
# expect {
|
|
69
|
+
# expect { lambda{|e| e.attachments['kitten.jpg'].file == @file.read }.must_be true }
|
|
70
70
|
# end
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
describe "indirectly, saved with the document" do
|
|
74
74
|
before do
|
|
75
75
|
@content = "this is an example file"
|
|
76
76
|
@doc.attachments['file.txt'] = @content, 'text/plain'
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
-
expect { @doc.attachments['file.txt'].content_type.
|
|
80
|
-
expect { @doc.attachments['file.txt'].metadata['data'].
|
|
81
|
-
expect { @doc.attachments['file.txt'].length.
|
|
82
|
-
expect { @doc.attachments.dirty
|
|
79
|
+
expect { @doc.attachments['file.txt'].content_type.must_equal 'text/plain' }
|
|
80
|
+
expect { @doc.attachments['file.txt'].metadata['data'].must_equal Base64.encode64(@content).strip }
|
|
81
|
+
expect { @doc.attachments['file.txt'].length.must_equal @content.length }
|
|
82
|
+
expect { assert @doc.attachments.dirty? }
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
describe "when saving" do
|
|
85
85
|
before do
|
|
86
86
|
@doc.save
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
-
expect { @doc.attachments['file.txt'].file.
|
|
90
|
-
expect { @doc.attachments['file.txt'].stub
|
|
91
|
-
expect { @doc.attachments['file.txt'].metadata.has_key?('data')
|
|
92
|
-
expect { @doc.attachments.dirty
|
|
89
|
+
expect { @doc.attachments['file.txt'].file.must_equal @content }
|
|
90
|
+
expect { assert @doc.attachments['file.txt'].stub? }
|
|
91
|
+
expect { refute @doc.attachments['file.txt'].metadata.has_key?('data') }
|
|
92
|
+
expect { refute @doc.attachments.dirty? }
|
|
93
93
|
end
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
describe "removing attachments" do
|
|
98
|
+
describe "from the document" do
|
|
99
99
|
|
|
100
100
|
end
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
describe "directly from the database" do
|
|
103
103
|
|
|
104
104
|
end
|
|
105
105
|
end
|
data/test/database_test.rb
CHANGED
|
@@ -21,52 +21,52 @@ class DatabaseTestDocument
|
|
|
21
21
|
include Exegesis::Document
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
before
|
|
24
|
+
describe Exegesis::Database do
|
|
25
|
+
before do
|
|
26
26
|
@server = Exegesis::Server.new('http://localhost:5984')
|
|
27
27
|
RestClient.delete("#{@server.uri}/exegesis-test") rescue nil
|
|
28
28
|
RestClient.delete("#{@server.uri}/exegesis-test-nonexistent") rescue nil
|
|
29
29
|
RestClient.put("#{@server.uri}/exegesis-test", '')
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
describe "initializing" do
|
|
33
|
+
describe "with server and name arguments" do
|
|
34
34
|
before do
|
|
35
|
-
@db =DatabaseTest.new(@server, 'exegesis-test')
|
|
35
|
+
@db = DatabaseTest.new(@server, 'exegesis-test')
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
expect { @db.
|
|
39
|
-
expect { @db.uri.
|
|
38
|
+
expect { @db.must_be_kind_of DatabaseTest }
|
|
39
|
+
expect { @db.uri.must_equal "#{@server.uri}/exegesis-test"}
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
describe "when the database does not exist" do
|
|
42
42
|
before do
|
|
43
43
|
@action = lambda { DatabaseTest.new(@server, 'exegesis-test-nonexistent') }
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
expect { @action.
|
|
46
|
+
expect { @action.must_raise(RestClient::ResourceNotFound) }
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
describe "with a url argument" do
|
|
51
51
|
before do
|
|
52
52
|
@db = DatabaseTest.new('http://localhost:5984/exegesis-test')
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
expect { @db.
|
|
56
|
-
expect { @db.uri.
|
|
55
|
+
expect { @db.must_be_kind_of DatabaseTest }
|
|
56
|
+
expect { @db.uri.must_equal 'http://localhost:5984/exegesis-test' }
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
describe "with a name argument" do
|
|
60
60
|
before do
|
|
61
61
|
@db = DatabaseTest.new('exegesis-test')
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
expect { @db.
|
|
65
|
-
expect { @db.uri.
|
|
64
|
+
expect { @db.must_be_kind_of DatabaseTest }
|
|
65
|
+
expect { @db.uri.must_equal "http://localhost:5984/exegesis-test" }
|
|
66
66
|
end
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
describe "retrieving documents by id" do
|
|
70
70
|
before do
|
|
71
71
|
@db = DatabaseTest.new @server, 'exegesis-test'
|
|
72
72
|
RestClient.put "#{@db.uri}/test-document", {'key'=>'value', 'class'=>'DatabaseTestDocument'}.to_json rescue nil
|
|
@@ -77,63 +77,63 @@ class ExegesisDatabaseTest < Test::Unit::TestCase
|
|
|
77
77
|
RestClient.delete("#{@db.uri}/test-document?rev=#{@doc['_rev']}") rescue nil
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
expect { @doc.
|
|
81
|
-
expect { @doc.id.
|
|
82
|
-
expect { @doc['key'].
|
|
80
|
+
expect { @doc.must_be_kind_of DatabaseTestDocument }
|
|
81
|
+
expect { @doc.id.must_equal 'test-document' }
|
|
82
|
+
expect { @doc['key'].must_equal 'value' }
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
describe "retrieving the raw document" do
|
|
85
85
|
before do
|
|
86
86
|
@doc = @db.raw_get('test-document')
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
-
expect { @doc.
|
|
90
|
-
expect { @doc['_id'].
|
|
91
|
-
expect { @doc['key'].
|
|
92
|
-
expect { @doc['class'].
|
|
89
|
+
expect { @doc.must_be_kind_of Hash }
|
|
90
|
+
expect { @doc['_id'].must_equal 'test-document' }
|
|
91
|
+
expect { @doc['key'].must_equal 'value' }
|
|
92
|
+
expect { @doc['class'].must_equal 'DatabaseTestDocument' }
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
describe "retrieving multiple documents" do
|
|
96
96
|
before do
|
|
97
97
|
docs = [{"_id"=>"a"},{"_id"=>"b"},{"_id"=>"c"}].map{|d| d.update('class' => 'DatabaseTestDocument')}
|
|
98
98
|
RestClient.post("#{@db.uri}/_bulk_docs", {"docs"=>docs}.to_json)
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
-
expect { @db.get(%w(a b c)).size.
|
|
102
|
-
expect { @db.get(%w(a b c)).
|
|
101
|
+
expect { @db.get(%w(a b c)).size.must_equal 3 }
|
|
102
|
+
expect { @db.get(%w(a b c)).each{|doc| doc.must_be_kind_of DatabaseTestDocument} }
|
|
103
103
|
end
|
|
104
104
|
end
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
describe "saving docs" do
|
|
107
107
|
before do
|
|
108
108
|
reset_db
|
|
109
109
|
@db = DatabaseTest.new('exegesis-test')
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
describe "a single doc" do
|
|
113
113
|
before { @doc = {'foo' => 'bar'} }
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
describe "without an id" do
|
|
116
116
|
before do
|
|
117
117
|
@db.save(@doc)
|
|
118
118
|
@rdoc = @db.get(@doc['_id'])
|
|
119
119
|
end
|
|
120
|
-
expect { @doc['_rev'].
|
|
121
|
-
expect { @rdoc['foo'].
|
|
120
|
+
expect { @doc['_rev'].must_equal @rdoc['_rev'] }
|
|
121
|
+
expect { @rdoc['foo'].must_equal @doc['foo'] }
|
|
122
122
|
end
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
describe "with an id" do
|
|
125
125
|
before { @doc['_id'] = 'test-document' }
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
describe "when the document doesn't exist yet" do
|
|
128
128
|
before do
|
|
129
129
|
@db.save(@doc)
|
|
130
130
|
@rdoc = @db.get('test-document')
|
|
131
131
|
end
|
|
132
|
-
expect { @doc['_rev'].
|
|
133
|
-
expect { @rdoc['foo'].
|
|
132
|
+
expect { @doc['_rev'].must_equal @rdoc['_rev'] }
|
|
133
|
+
expect { @rdoc['foo'].must_equal @doc['foo'] }
|
|
134
134
|
end
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
describe "when the document exists already" do
|
|
137
137
|
before do
|
|
138
138
|
response = @db.post(@doc)
|
|
139
139
|
@doc['_id'] = response['id']
|
|
@@ -141,18 +141,18 @@ class ExegesisDatabaseTest < Test::Unit::TestCase
|
|
|
141
141
|
@doc['foo'] = 'bee'
|
|
142
142
|
end
|
|
143
143
|
|
|
144
|
-
expect {
|
|
144
|
+
expect { @db.save(@doc)['_rev'].must_match /2-\d+/ }
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
describe "without a valid rev" do
|
|
147
147
|
before { @doc.delete('_rev') }
|
|
148
|
-
expect { lambda
|
|
148
|
+
expect { lambda{ @db.save(@doc) }.must_raise RestClient::RequestFailed }
|
|
149
149
|
end
|
|
150
150
|
end
|
|
151
151
|
|
|
152
152
|
end
|
|
153
153
|
end
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
describe "multiple docs" do
|
|
156
156
|
before do
|
|
157
157
|
@updated = @db.post({'_id' => 'updated', 'key' => 'original'})
|
|
158
158
|
@deleted = @db.post({'_id' => 'deleted', 'key' => 'original'})
|
|
@@ -165,53 +165,53 @@ class ExegesisDatabaseTest < Test::Unit::TestCase
|
|
|
165
165
|
}
|
|
166
166
|
end
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
describe "without conflicts" do
|
|
169
169
|
before { @saving.call }
|
|
170
|
-
expect { @db.get('new')['key'].
|
|
171
|
-
expect { @db.get('updated')['key'].
|
|
172
|
-
expect { lambda {@db.get('deleted')}.
|
|
170
|
+
expect { @db.get('new')['key'].must_equal 'new' }
|
|
171
|
+
expect { @db.get('updated')['key'].must_equal 'new' }
|
|
172
|
+
expect { lambda {@db.get('deleted')}.must_raise RestClient::ResourceNotFound }
|
|
173
173
|
end
|
|
174
174
|
end
|
|
175
175
|
end
|
|
176
176
|
|
|
177
|
-
|
|
178
|
-
expect { DatabaseTest.designs_directory.
|
|
179
|
-
expect { CustomDesignDirDatabaseTest.designs_directory.
|
|
177
|
+
describe "setting the designs directory" do
|
|
178
|
+
expect { DatabaseTest.designs_directory.must_equal Pathname.new('designs') }
|
|
179
|
+
expect { CustomDesignDirDatabaseTest.designs_directory.must_equal Pathname.new('app/designs') }
|
|
180
180
|
end
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
describe "with a named document" do
|
|
183
|
+
describe "that doesn't exist yet" do
|
|
184
184
|
before do
|
|
185
185
|
reset_db
|
|
186
186
|
@db = NamedDocumentDatabaseTest.new('exegesis-test')
|
|
187
|
+
@db.settings
|
|
187
188
|
end
|
|
188
189
|
|
|
189
|
-
expect { @db.settings.
|
|
190
|
-
expect { @db.settings.rev.
|
|
191
|
-
expect { @db.settings.
|
|
192
|
-
expect { @db.
|
|
190
|
+
expect { @db.settings.must_be_kind_of NamedDocumentDatabaseTest::Settings }
|
|
191
|
+
expect { @db.settings.rev.must_match /1-\d{7,12}/ }
|
|
192
|
+
expect { @db.settings.must_respond_to :things }
|
|
193
|
+
expect { @db.get('settings').must_be_kind_of NamedDocumentDatabaseTest::Settings }
|
|
193
194
|
end
|
|
194
195
|
|
|
195
|
-
|
|
196
|
+
describe "that does exist" do
|
|
196
197
|
before do
|
|
197
198
|
reset_db
|
|
198
199
|
@db = NamedDocumentDatabaseTest.new('exegesis-test')
|
|
199
200
|
@doc = @db.save({'_id' => 'settings', 'things' => %w(foo bar baz), 'class' => 'NamedDocumentDatabaseTest::Settings'})
|
|
200
201
|
end
|
|
201
202
|
|
|
202
|
-
expect {
|
|
203
|
-
expect { @db.settings.rev.
|
|
204
|
-
expect { @db.settings.
|
|
205
|
-
expect { @db.settings.things.will == %w(foo bar baz) }
|
|
203
|
+
expect { @db.settings.rev.must_equal @doc['_rev'] }
|
|
204
|
+
expect { @db.settings.rev.must_match /1-\d{7,12}/ }
|
|
205
|
+
expect { @db.settings.things.must_equal %w(foo bar baz) }
|
|
206
206
|
end
|
|
207
207
|
|
|
208
|
-
|
|
208
|
+
describe "when the declaration does not have a block" do
|
|
209
209
|
before do
|
|
210
210
|
reset_db
|
|
211
211
|
@db = NamedDocumentWithoutBlockDatabaseTest.new('exegesis-test')
|
|
212
212
|
end
|
|
213
213
|
|
|
214
|
-
expect { @db.blah.
|
|
214
|
+
expect { @db.blah.must_be_kind_of NamedDocumentWithoutBlockDatabaseTest::Blah }
|
|
215
215
|
end
|
|
216
216
|
end
|
|
217
217
|
|