mattly-exegesis 0.2.0 → 0.2.1

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.
@@ -0,0 +1,13 @@
1
+ function(doc) {
2
+ if (doc.tags) {
3
+ // assumes doc.tags is an array of strings
4
+ var tags = doc.tags;
5
+ tags.sort();
6
+ for (var i=0; i < tags.length; i++) {
7
+ emit(tags[i], 1);
8
+ for (var j = i+1; j < tags.length; j++) {
9
+ emit(tags.slice(i, j+1), 1);
10
+ }
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,11 @@
1
+ function(doc) {
2
+ if (!doc.date) { return; }
3
+ if (doc.path) {
4
+ emit([doc.path, 'path', doc.date], null);
5
+ }
6
+ if (doc.tags) {
7
+ for (var tag in doc.tags) {
8
+ emit([doc.tags[tag], 'tag', doc.date], null);
9
+ }
10
+ }
11
+ }
data/test/http_test.rb CHANGED
@@ -50,7 +50,7 @@ class HttpTest < Test::Unit::TestCase
50
50
 
51
51
  context "post requests" do
52
52
  before do
53
- @response = Exegesis::Http.post(@db, {'test' => 'value'})
53
+ @response = Exegesis::Http.post(@db, {'test' => 'value'}.to_json)
54
54
  end
55
55
 
56
56
  expect { @response['ok'].will == true }
@@ -58,7 +58,7 @@ class HttpTest < Test::Unit::TestCase
58
58
 
59
59
  context "put requests" do
60
60
  before do
61
- @response = Exegesis::Http.put("#{@db}/test-document", {'test' => 'value'})
61
+ @response = Exegesis::Http.put("#{@db}/test-document", {'test' => 'value'}.to_json)
62
62
  end
63
63
 
64
64
  expect { @response['ok'].will == true }
data/test/model_test.rb CHANGED
@@ -14,8 +14,7 @@ class WithDefaultTestModel
14
14
  end
15
15
 
16
16
  class ModelTestDocument
17
- include Exegesis::Model
18
- attr_accessor :database
17
+ include Exegesis::Document
19
18
  end
20
19
 
21
20
  class ExposeTestModel
@@ -82,6 +81,8 @@ class ExegesisModelTest < Test::Unit::TestCase
82
81
  {'foo' => 'bar', 'class' => 'BarTestModel'}
83
82
  ]
84
83
  })
84
+ @obj.castee
85
+ @obj.castees
85
86
  end
86
87
 
87
88
  expect { @obj.castee.class.will == FooTestModel }
@@ -95,11 +96,22 @@ class ExegesisModelTest < Test::Unit::TestCase
95
96
  expect { @obj.castees[1].class.will == BarTestModel }
96
97
  expect { @obj.castees[1]['foo'].will == 'bar' }
97
98
  expect { @obj.castees[1].parent.will == @obj }
99
+
100
+ context "defining the writer" do
101
+ before do
102
+ @obj = ExposeTestModel.new
103
+ @foo = FooTestModel.new({'foo' => 'bar'})
104
+ @obj.castee = @foo
105
+ end
106
+ expect { @obj.castee.will == @foo }
107
+ end
98
108
  end
99
109
 
100
110
  context "when as time" do
101
111
  before do
102
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
+ @obj.time
114
+ @obj.times
103
115
  end
104
116
 
105
117
  expect { @obj.time.class.will == Time }
@@ -110,6 +122,29 @@ class ExegesisModelTest < Test::Unit::TestCase
110
122
  expect { @obj.times[0].will == Time.local(2009,3,1) }
111
123
  expect { @obj.times[1].class.will == Time }
112
124
  expect { @obj.times[1].will == Time.local(2009,2,1) }
125
+
126
+ context "writing times" do
127
+ before do
128
+ @obj = ExposeTestModel.new
129
+ @time = Time.local(2009,4,16,20,14,26)
130
+ end
131
+ context "from a time object" do
132
+ before do
133
+ @obj.time = @time
134
+ @obj.times = [@time, @time]
135
+ end
136
+ expect { @obj.time.will == @time }
137
+ expect { @obj.times.will == [@time, @time] }
138
+ end
139
+ context "from a string" do
140
+ before do
141
+ @obj.time = @time.xmlschema
142
+ @obj.times = [@time.rfc2822, @time.getutc.strftime("%a, %d %b %Y %H:%M:%S GMT")]
143
+ end
144
+ expect { @obj.time.will == @time }
145
+ expect { @obj.times.map{|time| time.localtime }.will == [@time, @time] }
146
+ end
147
+ end
113
148
  end
114
149
 
115
150
  context "when as non document class" do
@@ -118,6 +153,8 @@ class ExegesisModelTest < Test::Unit::TestCase
118
153
  :regex => 'foo',
119
154
  :regexen => ['foo', 'bar']
120
155
  })
156
+ @obj.regex
157
+ @obj.regexen
121
158
  end
122
159
 
123
160
  expect { @obj.regex.will == /foo/ }
@@ -125,6 +162,15 @@ class ExegesisModelTest < Test::Unit::TestCase
125
162
  expect { @obj.regexen.class.will == Array }
126
163
  expect { @obj.regexen[0].will == /foo/ }
127
164
  expect { @obj.regexen[1].will == /bar/ }
165
+
166
+ context "writing values from the class" do
167
+ before do
168
+ @obj = ExposeTestModel.new
169
+ @regex = /foo/
170
+ @obj.regex = @regex
171
+ end
172
+ expect { @obj.regex.will == @regex }
173
+ end
128
174
  end
129
175
 
130
176
  context "when as reference" do
@@ -133,8 +179,7 @@ class ExegesisModelTest < Test::Unit::TestCase
133
179
  reset_db
134
180
  @obj = ExposeTestModel.new(:other_doc => "other_doc",
135
181
  :other_docs => ["other_docs_1", "other_docs_2"])
136
- @doc = ModelTestDocument.new
137
- @doc.database = @db
182
+ @doc = ModelTestDocument.new({}, @db)
138
183
  @obj.parent = @doc
139
184
  end
140
185
 
@@ -186,6 +231,31 @@ class ExegesisModelTest < Test::Unit::TestCase
186
231
  before { @obj = ExposeTestModel.new(:other_doc => "some_doc_id") }
187
232
  expect { lambda{@obj.other_doc}.will raise_error(ArgumentError) }
188
233
  end
234
+
235
+ context "setting references" do
236
+ before do
237
+ reset_db
238
+ @parent = ModelTestDocument.new({}, @db)
239
+ @obj = ExposeTestModel.new
240
+ @obj.parent = @parent
241
+ @doc = ModelTestDocument.new({}, @db)
242
+ @doc.save
243
+ end
244
+ context "from a doc that has been saved" do
245
+ before do
246
+ @obj.other_doc = @doc
247
+ end
248
+ expect { @obj['other_doc'].will == @doc.id }
249
+ expect { @obj.other_doc.will == @doc }
250
+ end
251
+ context "from an id" do
252
+ before do
253
+ @obj.other_doc = @doc.id
254
+ end
255
+ expect { @obj['other_doc'].will == @doc.id }
256
+ expect { @obj.other_doc.will == @doc }
257
+ end
258
+ end
189
259
  end
190
260
 
191
261
  context "when the value is nil" do
@@ -196,6 +266,7 @@ class ExegesisModelTest < Test::Unit::TestCase
196
266
  expect { @obj.castees.will be(nil) }
197
267
  expect { @obj.regexen.will == [/foo/] }
198
268
  end
269
+
199
270
  end
200
271
  end
201
272
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mattly-exegesis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Lyon
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-04 00:00:00 -07:00
12
+ date: 2009-04-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -29,43 +29,43 @@ executables: []
29
29
  extensions: []
30
30
 
31
31
  extra_rdoc_files:
32
- - README.rdoc
33
32
  - LICENSE
33
+ - README.rdoc
34
34
  files:
35
+ - LICENSE
35
36
  - README.rdoc
37
+ - Rakefile
36
38
  - VERSION.yml
37
- - lib/exegesis
39
+ - lib/exegesis.rb
38
40
  - lib/exegesis/database.rb
39
41
  - lib/exegesis/design.rb
40
42
  - lib/exegesis/document.rb
43
+ - lib/exegesis/document/attachment.rb
44
+ - lib/exegesis/document/attachments.rb
45
+ - lib/exegesis/document/collection.rb
46
+ - lib/exegesis/document/generic_document.rb
41
47
  - lib/exegesis/model.rb
42
48
  - lib/exegesis/server.rb
43
- - lib/exegesis/utils
44
49
  - lib/exegesis/utils/http.rb
45
- - lib/exegesis.rb
46
- - lib/monkeypatches
47
50
  - lib/monkeypatches/time.rb
51
+ - test/attachments_test.rb
48
52
  - test/database_test.rb
49
53
  - test/design_test.rb
54
+ - test/document_collection_test.rb
50
55
  - test/document_test.rb
51
- - test/fixtures
52
- - test/fixtures/designs
53
- - test/fixtures/designs/foos.js
54
- - test/fixtures/designs/tags
55
- - test/fixtures/designs/tags/views
56
- - test/fixtures/designs/tags/views/by_tag
57
- - test/fixtures/designs/tags/views/by_tag/map.js
58
- - test/fixtures/designs/tags/views/by_tag/reduce.js
56
+ - test/fixtures/attachments/flavakitten.jpg
57
+ - test/fixtures/designs/things/views/by_name/map.js
58
+ - test/fixtures/designs/things/views/by_tag/map.js
59
+ - test/fixtures/designs/things/views/by_tag/reduce.js
60
+ - test/fixtures/designs/things/views/for_path/map.js
59
61
  - test/http_test.rb
60
62
  - test/model_test.rb
61
63
  - test/server_test.rb
62
64
  - test/test_helper.rb
63
- - LICENSE
64
65
  has_rdoc: true
65
66
  homepage: http://github.com/mattly/exegesis
66
67
  post_install_message:
67
68
  rdoc_options:
68
- - --inline-source
69
69
  - --charset=UTF-8
70
70
  require_paths:
71
71
  - lib
@@ -88,5 +88,13 @@ rubygems_version: 1.2.0
88
88
  signing_key:
89
89
  specification_version: 2
90
90
  summary: TODO
91
- test_files: []
92
-
91
+ test_files:
92
+ - test/attachments_test.rb
93
+ - test/database_test.rb
94
+ - test/design_test.rb
95
+ - test/document_collection_test.rb
96
+ - test/document_test.rb
97
+ - test/http_test.rb
98
+ - test/model_test.rb
99
+ - test/server_test.rb
100
+ - test/test_helper.rb
@@ -1,12 +0,0 @@
1
- {
2
- views: {
3
- by_bar: {
4
- map: function(doc) {
5
- emit(doc.bar, null)
6
- },
7
- reduce: function(keys, values, rereduce) {
8
- return(sum(values))
9
- }
10
- },
11
- }
12
- }
@@ -1,8 +0,0 @@
1
- function(doc) {
2
- if (doc.tags) {
3
- // assumes doc.tags is an array of strings
4
- for (var tag in doc.tags) {
5
- emit(doc.tags[tag], 1);
6
- }
7
- }
8
- }