rufus-doric 0.1.0 → 0.1.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.
data/CHANGELOG.txt CHANGED
@@ -2,6 +2,15 @@
2
2
  = rufus-doric CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-doric - 0.1.1 not yet released
6
+
7
+ - associations are in (_id[s]) for Model
8
+ - equality and hash for Model
9
+ - now raises if putting a design doc fails
10
+ - Rufus::Doric.db(dbname) returns the couchdb 'connection'
11
+ - Rufus::Doric::Value : one document containing a single [big] value
12
+
13
+
5
14
  == rufus-doric - 0.1.0 released 2010/03/17
6
15
 
7
16
  - initial release
data/Rakefile CHANGED
@@ -36,7 +36,7 @@ something at the intersection of Rails3, CouchDB and rufus-jig
36
36
  gem.test_file = 'test/test.rb'
37
37
 
38
38
  gem.add_dependency 'activerecord', '~> 3.0.0.beta'
39
- gem.add_dependency 'rufus-jig', '>= 0.1.16'
39
+ gem.add_dependency 'rufus-jig', '>= 0.1.17'
40
40
  gem.add_dependency 'mime-types', '>= 1.16'
41
41
  gem.add_development_dependency 'rake'
42
42
  gem.add_development_dependency 'yard'
@@ -29,56 +29,55 @@
29
29
  module Rufus
30
30
  module Doric
31
31
 
32
- module Couch
32
+ def self.couch_url
33
33
 
34
- def self.url
34
+ if defined?(Rails)
35
+ return File.read(Rails.root.join('config', 'couch_url.txt')).strip
36
+ end
37
+ if File.exist?('couch_url.txt')
38
+ return File.read('couch_url.txt').strip
39
+ end
35
40
 
36
- if defined?(Rails)
37
- return File.read(Rails.root.join('config', 'couch_url.txt')).strip
38
- end
39
- if File.exist?('couch_url.txt')
40
- return File.read('couch_url.txt').strip
41
- end
41
+ 'http://127.0.0.1:5984'
42
+ end
42
43
 
43
- 'http://127.0.0.1:5984'
44
- end
44
+ def self.couch
45
45
 
46
- def self.couch
46
+ Rufus::Jig::Couch.new(couch_url)
47
+ end
47
48
 
48
- Rufus::Jig::Couch.new(url)
49
- end
49
+ def self.db (name, opts={})
50
50
 
51
- def self.db (name, opts={})
51
+ env = opts[:env]
52
+ env ||= Rails.env if defined?(Rails)
53
+ env ||= 'test'
52
54
 
53
- env = opts[:env]
54
- env ||= Rails.env if defined?(Rails)
55
- env ||= 'test'
55
+ u = opts[:absolute] ? "#{couch_url}/#{name}" : "#{couch_url}/#{name}_#{env}"
56
56
 
57
- u = opts[:absolute] ? "#{url}/#{name}" : "#{url}/#{name}_#{env}"
57
+ return u if opts[:url_only] || opts[:uo]
58
58
 
59
- return u if opts[:url_only] || opts[:uo]
59
+ @connections ||= {}
60
60
 
61
- Rufus::Jig::Couch.new(u)
62
- end
61
+ @connections[u] ||= Rufus::Jig::Couch.new(u)
62
+ end
63
63
 
64
- # def self.purge! TODO (name, env)
64
+ # def self.purge! TODO (name, env)
65
65
  #
66
- # result = Doric::Couch.get('_all_docs')
66
+ # result = Doric::Couch.get('_all_docs')
67
67
  #
68
- # return unless result
68
+ # return unless result
69
69
  #
70
- # result['rows'].each do |r|
70
+ # result['rows'].each do |r|
71
71
  #
72
- # _id = r['id']
72
+ # _id = r['id']
73
73
  #
74
- # next if _id.match(/^\_design\//)
74
+ # next if _id.match(/^\_design\//)
75
75
  #
76
- # _rev = r['value']['rev']
76
+ # _rev = r['value']['rev']
77
77
  #
78
- # Doric::Couch.delete('_id' => _id, '_rev' => _rev)
79
- # end
78
+ # Doric::Couch.delete('_id' => _id, '_rev' => _rev)
80
79
  # end
81
- end
80
+ # end
82
81
  end
83
82
  end
84
83
 
@@ -179,6 +179,51 @@ module Doric
179
179
  delete
180
180
  end
181
181
 
182
+ def method_missing (m, *args)
183
+
184
+ mm = m.to_s
185
+ sm = mm.singularize
186
+ multiple = (mm != sm)
187
+
188
+ klass = sm.camelize
189
+ klass = (self.class.const_get(klass) rescue nil)
190
+
191
+ return super unless klass
192
+
193
+ id_method = multiple ? "#{sm}_ids" : "#{mm}_id"
194
+
195
+ if multiple
196
+
197
+ if self.respond_to?(id_method)
198
+
199
+ ids = self.send(id_method)
200
+ return [] unless ids
201
+
202
+ ids.collect { |i| klass.find(i) }
203
+
204
+ else
205
+
206
+ by_method = "by_#{self.class.doric_type.singularize}_id"
207
+ klass.send(by_method, self._id)
208
+ end
209
+
210
+ else
211
+
212
+ return super unless self.respond_to?(id_method)
213
+ klass.find(self.send(id_method))
214
+ end
215
+ end
216
+
217
+ def hash
218
+ h.hash
219
+ end
220
+
221
+ def == (other)
222
+ return false unless other.class == self.class
223
+ (h == other.h)
224
+ end
225
+ alias eql? ==
226
+
182
227
  #--
183
228
  # class methods
184
229
  #++
@@ -216,10 +261,7 @@ module Doric
216
261
 
217
262
  # the 'all' view
218
263
 
219
- unless key
220
- db.put(DORIC_DESIGN_DOC)
221
- return
222
- end
264
+ return db.put(DORIC_DESIGN_DOC) unless key
223
265
 
224
266
  # by_{key} views
225
267
 
@@ -268,7 +310,10 @@ module Doric
268
310
 
269
311
  # insert design doc
270
312
 
271
- put_design_doc
313
+ r = put_design_doc
314
+ raise(
315
+ "failed to insert design_doc in db '#{db.name}'"
316
+ ) if r == true
272
317
  return get_all(opts)
273
318
  end
274
319
 
@@ -292,7 +337,7 @@ module Doric
292
337
  return by(key, val, opts)
293
338
  end
294
339
 
295
- result['rows'].collect { |r| r['doc'] }
340
+ result['rows'].collect { |r| self.new(r['doc']) }
296
341
  end
297
342
  end
298
343
  end
@@ -82,7 +82,7 @@ module Doric
82
82
  return @db
83
83
  end
84
84
 
85
- Rufus::Doric::Couch.db(@db, @db_opts)
85
+ Rufus::Doric.db(@db, @db_opts)
86
86
  end
87
87
  end
88
88
 
@@ -120,3 +120,5 @@ end
120
120
  require 'rufus/doric/model'
121
121
  require 'rufus/doric/one_doc_model'
122
122
 
123
+ require 'rufus/doric/value'
124
+
@@ -0,0 +1,88 @@
1
+ #--
2
+ # Copyright (c) 2010, John Mettraux, jmettraux@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+ # Made in Japan.
23
+ #++
24
+
25
+
26
+ module Rufus
27
+ module Doric
28
+
29
+ #
30
+ # One document containing a single value
31
+ #
32
+ class Value
33
+
34
+ #
35
+ # class 'helpers'
36
+
37
+ def self.doc_id (_id=nil)
38
+
39
+ @doc_id = _id.to_s if _id
40
+ @doc_id
41
+ end
42
+
43
+ include WithDb
44
+
45
+ #
46
+ # constructor and instance methods
47
+
48
+ attr_reader :h
49
+
50
+ def initialize (h)
51
+
52
+ @h = h.inject({}) { |hh, (k, v)| hh[k.to_s] = v; hh }
53
+ end
54
+
55
+ def value
56
+
57
+ @h['value']
58
+ end
59
+
60
+ def save!
61
+
62
+ doc = self.class.do_get(self.class.doc_id)
63
+ doc ||= { '_id' => self.class.doc_id }
64
+
65
+ doc['value'] = value
66
+
67
+ db.put(doc)
68
+ end
69
+
70
+ #--
71
+ # class methods
72
+ #++
73
+
74
+ def self.load
75
+
76
+ self.new(do_get(doc_id))
77
+ end
78
+
79
+ protected
80
+
81
+ def self.do_get (doc_id)
82
+
83
+ db.get(doc_id) || { '_id' => doc_id, 'value' => nil }
84
+ end
85
+ end
86
+ end
87
+ end
88
+
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Rufus
3
3
  module Doric
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
6
6
  end
7
7
 
data/rufus-doric.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rufus-doric}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Mettraux"]
12
- s.date = %q{2010-03-17}
12
+ s.date = %q{2010-03-22}
13
13
  s.description = %q{
14
14
  something at the intersection of Rails3, CouchDB and rufus-jig
15
15
  }
@@ -31,6 +31,7 @@ something at the intersection of Rails3, CouchDB and rufus-jig
31
31
  "lib/rufus/doric/model.rb",
32
32
  "lib/rufus/doric/models.rb",
33
33
  "lib/rufus/doric/one_doc_model.rb",
34
+ "lib/rufus/doric/value.rb",
34
35
  "lib/rufus/doric/version.rb",
35
36
  "rufus-doric.gemspec",
36
37
  "test/base.rb",
@@ -38,6 +39,7 @@ something at the intersection of Rails3, CouchDB and rufus-jig
38
39
  "test/fixtures/test/doric/69249__picture.jpg",
39
40
  "test/fixtures/test/doric/product0.json",
40
41
  "test/fixtures/test/doric/product1.json",
42
+ "test/fixtures/test/doric/tuples.json",
41
43
  "test/fixtures/test/doric/users.json",
42
44
  "test/fixtures/test/doric/users__jami.png",
43
45
  "test/fixtures/test/doric/users__john.jpg",
@@ -47,7 +49,9 @@ something at the intersection of Rails3, CouchDB and rufus-jig
47
49
  "test/ut_1_model.rb",
48
50
  "test/ut_2_model_view.rb",
49
51
  "test/ut_3_model_lint.rb",
50
- "test/ut_4_one_doc_model.rb"
52
+ "test/ut_4_one_doc_model.rb",
53
+ "test/ut_5_value.rb",
54
+ "test/ut_6_model_associations.rb"
51
55
  ]
52
56
  s.homepage = %q{http://github.com/jmettraux/rufus-doric/}
53
57
  s.rdoc_options = ["--charset=UTF-8"]
@@ -65,14 +69,14 @@ something at the intersection of Rails3, CouchDB and rufus-jig
65
69
 
66
70
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
67
71
  s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.0.beta"])
68
- s.add_runtime_dependency(%q<rufus-jig>, [">= 0.1.16"])
72
+ s.add_runtime_dependency(%q<rufus-jig>, [">= 0.1.17"])
69
73
  s.add_runtime_dependency(%q<mime-types>, [">= 1.16"])
70
74
  s.add_development_dependency(%q<rake>, [">= 0"])
71
75
  s.add_development_dependency(%q<yard>, [">= 0"])
72
76
  s.add_development_dependency(%q<jeweler>, [">= 0"])
73
77
  else
74
78
  s.add_dependency(%q<activerecord>, ["~> 3.0.0.beta"])
75
- s.add_dependency(%q<rufus-jig>, [">= 0.1.16"])
79
+ s.add_dependency(%q<rufus-jig>, [">= 0.1.17"])
76
80
  s.add_dependency(%q<mime-types>, [">= 1.16"])
77
81
  s.add_dependency(%q<rake>, [">= 0"])
78
82
  s.add_dependency(%q<yard>, [">= 0"])
@@ -80,7 +84,7 @@ something at the intersection of Rails3, CouchDB and rufus-jig
80
84
  end
81
85
  else
82
86
  s.add_dependency(%q<activerecord>, ["~> 3.0.0.beta"])
83
- s.add_dependency(%q<rufus-jig>, [">= 0.1.16"])
87
+ s.add_dependency(%q<rufus-jig>, [">= 0.1.17"])
84
88
  s.add_dependency(%q<mime-types>, [">= 1.16"])
85
89
  s.add_dependency(%q<rake>, [">= 0"])
86
90
  s.add_dependency(%q<yard>, [">= 0"])
@@ -0,0 +1,4 @@
1
+ {
2
+ "_id": "tuples",
3
+ "value": [ "alpha", "bravo", "charly" ]
4
+ }
@@ -15,7 +15,7 @@ class UtFixturesTest < Test::Unit::TestCase
15
15
  #def setup
16
16
  #end
17
17
  def teardown
18
- couch = Rufus::Jig::Couch.new(Rufus::Doric::Couch.url)
18
+ couch = Rufus::Jig::Couch.new(Rufus::Doric.couch_url)
19
19
  couch.delete('doric_test')
20
20
  couch.delete('doric_nada')
21
21
  couch.delete('doric')
@@ -25,11 +25,11 @@ class UtFixturesTest < Test::Unit::TestCase
25
25
  def test_load
26
26
 
27
27
  Rufus::Doric::Fixtures.load(
28
- Rufus::Doric::Couch.url, 'test/fixtures/test',
28
+ Rufus::Doric.couch_url, 'test/fixtures/test',
29
29
  :purge => true,
30
30
  :verbose => false)
31
31
 
32
- img = Rufus::Doric::Couch.db('doric').get('users/john.jpg')
32
+ img = Rufus::Doric.db('doric').get('users/john.jpg')
33
33
 
34
34
  assert_not_nil img
35
35
  end
@@ -37,12 +37,12 @@ class UtFixturesTest < Test::Unit::TestCase
37
37
  def test_env_option
38
38
 
39
39
  Rufus::Doric::Fixtures.load(
40
- Rufus::Doric::Couch.url, 'test/fixtures/test',
40
+ Rufus::Doric.couch_url, 'test/fixtures/test',
41
41
  :env => 'nada',
42
42
  :purge => true,
43
43
  :verbose => false)
44
44
 
45
- img = Rufus::Doric::Couch.db('doric', :env => 'nada').get('users/john.jpg')
45
+ img = Rufus::Doric.db('doric', :env => 'nada').get('users/john.jpg')
46
46
 
47
47
  assert_not_nil img
48
48
  end
@@ -50,12 +50,12 @@ class UtFixturesTest < Test::Unit::TestCase
50
50
  def test_absolute_option
51
51
 
52
52
  Rufus::Doric::Fixtures.load(
53
- Rufus::Doric::Couch.url, 'test/fixtures/test',
53
+ Rufus::Doric.couch_url, 'test/fixtures/test',
54
54
  :db => 'doric',
55
55
  :purge => true,
56
56
  :verbose => false)
57
57
 
58
- img = Rufus::Doric::Couch.db('doric', :absolute => true).get('users/john.jpg')
58
+ img = Rufus::Doric.db('doric', :absolute => true).get('users/john.jpg')
59
59
 
60
60
  assert_not_nil img
61
61
  end
data/test/ut_1_model.rb CHANGED
@@ -36,9 +36,15 @@ end
36
36
  class UtModelTest < Test::Unit::TestCase
37
37
 
38
38
  def setup
39
- Rufus::Doric::Couch.db('doric').delete('.')
40
- Rufus::Doric::Couch.db('doric').put('.')
39
+
40
+ Rufus::Doric.db('doric').delete('.')
41
+ Rufus::Doric.db('doric').put('.')
42
+
43
+ Rufus::Doric.db('doric').http.cache.clear
44
+ # CouchDB feeds the same etags for views, even after a db has
45
+ # been deleted and put back, so have to do that 'forgetting'
41
46
  end
47
+
42
48
  #def teardown
43
49
  #end
44
50
 
@@ -106,13 +112,13 @@ class UtModelTest < Test::Unit::TestCase
106
112
  def test_not_found
107
113
 
108
114
  assert_raise Rufus::Doric::NotFound do
109
- Thing.find('nada')
115
+ Thing.find('gozaimasen')
110
116
  end
111
117
  end
112
118
 
113
119
  def test_destroy_all
114
120
 
115
- Thing.new('name' => 'flamenco').save!
121
+ Thing.new('name' => 'dokodemo').save!
116
122
 
117
123
  assert_equal 1, Thing.all.size
118
124
 
@@ -123,11 +129,27 @@ class UtModelTest < Test::Unit::TestCase
123
129
 
124
130
  def test_putting_in_missing_db
125
131
 
126
- Rufus::Doric::Couch.db('doric').delete('.')
132
+ Rufus::Doric.db('doric').delete('.')
127
133
 
128
134
  assert_raise Rufus::Doric::SaveFailed do
129
- Thing.new('name' => 'flamenco').save!
135
+ Thing.new('name' => 'doraemon').save!
130
136
  end
131
137
  end
138
+
139
+ def test_equality
140
+
141
+ Thing.new('name' => 'onaji').save!
142
+ Thing.new('name' => 'chigau').save!
143
+
144
+ a = Thing.find('onaji')
145
+ b = Thing.find('onaji')
146
+ c = Thing.find('chigau')
147
+
148
+ assert_equal a, b
149
+ assert_equal a.hash, b.hash
150
+
151
+ assert_not_equal a, c
152
+ assert_not_equal a.hash, c.hash
153
+ end
132
154
  end
133
155
 
@@ -28,9 +28,15 @@ end
28
28
  class UtModelTest < Test::Unit::TestCase
29
29
 
30
30
  def setup
31
- Rufus::Doric::Couch.db('doric').delete('.')
32
- Rufus::Doric::Couch.db('doric').put('.')
31
+
32
+ Rufus::Doric.db('doric').delete('.')
33
+ Rufus::Doric.db('doric').put('.')
34
+
35
+ Rufus::Doric.db('doric').http.cache.clear
36
+ # CouchDB feeds the same etags for views, even after a db has
37
+ # been deleted and put back, so have to do that 'forgetting'
33
38
  end
39
+
34
40
  #def teardown
35
41
  #end
36
42
 
@@ -53,6 +59,9 @@ class UtModelTest < Test::Unit::TestCase
53
59
  assert_equal 1, Nada::Thing.by_colour('blue').size
54
60
  assert_equal 2, Nada::Thing.by_colour('red').size
55
61
 
62
+ assert_equal Nada::Thing, Nada::Thing.all.first.class
63
+ assert_equal Nada::Thing, Nada::Thing.by_colour('blue').first.class
64
+
56
65
  assert_not_nil Nada::Thing.db.get('_design/doric_nada__thing')
57
66
  end
58
67
  end
@@ -27,13 +27,13 @@ class UtOneDocModelTest < Test::Unit::TestCase
27
27
 
28
28
  def setup
29
29
 
30
- Rufus::Doric::Couch.db('doric').delete('.')
31
- Rufus::Doric::Couch.db('doric').put('.')
30
+ Rufus::Doric.db('doric').delete('.')
31
+ Rufus::Doric.db('doric').put('.')
32
32
 
33
33
  users = Rufus::Json.decode(File.read(File.join(
34
34
  File.dirname(__FILE__), 'fixtures', 'test', 'doric', 'users.json')))
35
35
 
36
- Rufus::Doric::Couch.db('doric').put(users)
36
+ Rufus::Doric.db('doric').put(users)
37
37
  end
38
38
 
39
39
  #def teardown
@@ -0,0 +1,69 @@
1
+
2
+ #
3
+ # testing rufus-doric
4
+ #
5
+ # Thu Mar 18 22:30:00 JST 2010
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'base')
9
+
10
+ require 'rufus/doric'
11
+
12
+
13
+ class Tuples < Rufus::Doric::Value
14
+
15
+ doc_id :tuples
16
+ db :doric
17
+
18
+ def to_s
19
+
20
+ value.sort.join(' ')
21
+ end
22
+ end
23
+
24
+
25
+ class UtValueTest < Test::Unit::TestCase
26
+
27
+ def setup
28
+
29
+ @db = Rufus::Doric.db('doric')
30
+ @db.delete('.')
31
+ @db.put('.')
32
+
33
+ tuples = Rufus::Json.decode(File.read(File.join(
34
+ File.dirname(__FILE__), 'fixtures', 'test', 'doric', 'tuples.json')))
35
+
36
+ @db.put(tuples)
37
+ end
38
+
39
+ #def teardown
40
+ #end
41
+
42
+ def test_load
43
+
44
+ assert_equal 'alpha bravo charly', Tuples.load.to_s
45
+ end
46
+
47
+ def test_save
48
+
49
+ tuples = Tuples.load
50
+ tuples.value << 'borneo'
51
+ tuples.save!
52
+
53
+ assert_equal 'alpha borneo bravo charly', tuples.to_s
54
+ assert_equal 'alpha borneo bravo charly', Tuples.load.to_s
55
+ end
56
+
57
+ def test_save_new
58
+
59
+ @db.delete(Tuples.load.h)
60
+
61
+ assert_nil @db.get('tuples')
62
+
63
+ tuples = Tuples.new(
64
+ '_id' => 'tuples', 'value' => %w[ alpha beta delta gamma ]).save!
65
+
66
+ assert_equal 'alpha beta delta gamma', Tuples.load.to_s
67
+ end
68
+ end
69
+
@@ -0,0 +1,125 @@
1
+
2
+ #
3
+ # testing rufus-doric
4
+ #
5
+ # Sun Mar 21 12:07:00 JST 2010
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'base')
9
+
10
+ require 'rufus/doric'
11
+
12
+
13
+ class Customer < Rufus::Doric::Model
14
+
15
+ db :doric
16
+ doric_type :customers
17
+
18
+ _id_field :name
19
+
20
+ h_accessor :name
21
+ h_accessor :region_id
22
+ h_accessor :interest_ids
23
+ end
24
+
25
+ class Interest < Rufus::Doric::Model
26
+
27
+ db :doric
28
+ doric_type :interests
29
+
30
+ _id_field :name
31
+
32
+ h_accessor :name
33
+ end
34
+
35
+ class Region < Rufus::Doric::Model
36
+
37
+ db :doric
38
+ doric_type :regions
39
+
40
+ _id_field :name
41
+
42
+ h_accessor :name
43
+ end
44
+
45
+ class Order < Rufus::Doric::Model
46
+
47
+ db :doric
48
+ doric_type :orders
49
+
50
+ _id_field :order_id
51
+
52
+ h_accessor :order_id
53
+ h_accessor :customer_id
54
+
55
+ view_by :customer_id
56
+ end
57
+
58
+
59
+ class UtModelTest < Test::Unit::TestCase
60
+
61
+ def setup
62
+
63
+ Rufus::Doric.db('doric').delete('.')
64
+ Rufus::Doric.db('doric').put('.')
65
+
66
+ Rufus::Doric.db('doric').http.cache.clear
67
+ # CouchDB feeds the same etags for views, even after a db has
68
+ # been deleted and put back, so have to do that 'forgetting'
69
+
70
+ Customer.new(
71
+ :name => 'fred', :region_id => 'eu'
72
+ ).save!
73
+ Customer.new(
74
+ :name => 'famke', :region_id => 'eu', :interest_ids => %w[ music dance ]
75
+ ).save!
76
+
77
+ Region.new(:name => 'eu').save!
78
+
79
+ Order.new(:order_id => 'a', :customer_id => 'fred').save!
80
+ Order.new(:order_id => 'b', :customer_id => 'fred').save!
81
+ Order.new(:order_id => 'c', :customer_id => 'nemo').save!
82
+
83
+ Interest.new(:name => 'litterature').save!
84
+ Interest.new(:name => 'music').save!
85
+ Interest.new(:name => 'dance').save!
86
+ end
87
+
88
+ #def teardown
89
+ #end
90
+
91
+ def test_customer
92
+
93
+ o = Order.find('a')
94
+ c = Customer.find('fred')
95
+
96
+ assert_equal c, o.customer
97
+ end
98
+
99
+ def test_missing_customer
100
+
101
+ assert_raise Rufus::Doric::NotFound do
102
+ Order.find('c').customer
103
+ end
104
+ end
105
+
106
+ def test_orders
107
+
108
+ c = Customer.find('fred')
109
+
110
+ os = c.orders
111
+
112
+ assert_equal 2, os.size
113
+ assert_equal [ Order ], os.collect { |o| o.class }.sort.uniq
114
+ end
115
+
116
+ def test_interests
117
+
118
+ fred = Customer.find('fred')
119
+ famke = Customer.find('famke')
120
+
121
+ assert_equal [], fred.interests
122
+ assert_equal %w[ dance music ], famke.interests.collect { |i| i.name }.sort
123
+ end
124
+ end
125
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Mettraux
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-17 00:00:00 +09:00
17
+ date: 2010-03-22 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -42,8 +42,8 @@ dependencies:
42
42
  segments:
43
43
  - 0
44
44
  - 1
45
- - 16
46
- version: 0.1.16
45
+ - 17
46
+ version: 0.1.17
47
47
  type: :runtime
48
48
  version_requirements: *id002
49
49
  - !ruby/object:Gem::Dependency
@@ -118,6 +118,7 @@ files:
118
118
  - lib/rufus/doric/model.rb
119
119
  - lib/rufus/doric/models.rb
120
120
  - lib/rufus/doric/one_doc_model.rb
121
+ - lib/rufus/doric/value.rb
121
122
  - lib/rufus/doric/version.rb
122
123
  - rufus-doric.gemspec
123
124
  - test/base.rb
@@ -125,6 +126,7 @@ files:
125
126
  - test/fixtures/test/doric/69249__picture.jpg
126
127
  - test/fixtures/test/doric/product0.json
127
128
  - test/fixtures/test/doric/product1.json
129
+ - test/fixtures/test/doric/tuples.json
128
130
  - test/fixtures/test/doric/users.json
129
131
  - test/fixtures/test/doric/users__jami.png
130
132
  - test/fixtures/test/doric/users__john.jpg
@@ -135,6 +137,8 @@ files:
135
137
  - test/ut_2_model_view.rb
136
138
  - test/ut_3_model_lint.rb
137
139
  - test/ut_4_one_doc_model.rb
140
+ - test/ut_5_value.rb
141
+ - test/ut_6_model_associations.rb
138
142
  has_rdoc: true
139
143
  homepage: http://github.com/jmettraux/rufus-doric/
140
144
  licenses: []