rufus-doric 0.1.17 → 0.1.18
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 +7 -0
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/lib/rufus/doric/model.rb +10 -5
- data/lib/rufus/doric/one_doc_model.rb +3 -1
- data/lib/rufus/doric/version.rb +1 -1
- data/rufus-doric.gemspec +5 -5
- data/test/ut_12_model_default.rb +19 -1
- data/test/ut_13_one_doc_model_default.rb +14 -1
- data/test/ut_15_model_view_by_and.rb +18 -6
- metadata +5 -5
data/CHANGELOG.txt
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
= rufus-doric CHANGELOG.txt
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
== rufus-doric - 0.1.18 released 2010/11/09
|
|
6
|
+
|
|
7
|
+
- made sure to do a deep clone of model default values. Thanks Claudio.
|
|
8
|
+
- views : :raw => true option
|
|
9
|
+
- pointing to rufus-jig 0.1.23
|
|
10
|
+
|
|
11
|
+
|
|
5
12
|
== rufus-doric - 0.1.17 released 2010/09/30
|
|
6
13
|
|
|
7
14
|
- basic auth thanks to rufus-jig 0.1.22
|
data/README.rdoc
CHANGED
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'
|
|
39
|
-
gem.add_dependency 'rufus-jig', '>= 0.1.
|
|
39
|
+
gem.add_dependency 'rufus-jig', '>= 0.1.23'
|
|
40
40
|
gem.add_dependency 'mime-types', '>= 1.16'
|
|
41
41
|
gem.add_development_dependency 'rake'
|
|
42
42
|
gem.add_development_dependency 'jeweler'
|
data/lib/rufus/doric/model.rb
CHANGED
|
@@ -225,7 +225,9 @@ module Doric
|
|
|
225
225
|
|
|
226
226
|
def initialize (doc={})
|
|
227
227
|
|
|
228
|
-
@h = doc.inject(self.class.defaults
|
|
228
|
+
@h = doc.inject(Rufus::Json.dup(self.class.defaults)) { |h, (k, v)|
|
|
229
|
+
h[k.to_s] = v; h
|
|
230
|
+
}
|
|
229
231
|
@h['doric_type'] = self.class.doric_type
|
|
230
232
|
end
|
|
231
233
|
|
|
@@ -760,6 +762,8 @@ module Doric
|
|
|
760
762
|
|
|
761
763
|
#p [ key, val, opts ]
|
|
762
764
|
|
|
765
|
+
raw = opts.delete(:raw)
|
|
766
|
+
|
|
763
767
|
reduce = key.is_a?(Hash) && key[:reduce]
|
|
764
768
|
|
|
765
769
|
qs = reduce ? [] : [ 'include_docs=true' ]
|
|
@@ -789,13 +793,14 @@ module Doric
|
|
|
789
793
|
|
|
790
794
|
result = get_result(path, key, opts)
|
|
791
795
|
|
|
792
|
-
|
|
796
|
+
rows = result['rows']
|
|
797
|
+
|
|
798
|
+
return rows if raw
|
|
793
799
|
|
|
794
800
|
if reduce
|
|
795
|
-
|
|
796
|
-
r ? r['value'] : []
|
|
801
|
+
rows.first ? rows.first['value'] : []
|
|
797
802
|
else
|
|
798
|
-
|
|
803
|
+
rows.collect { |r| self.new(r['doc']) }.uniq
|
|
799
804
|
end
|
|
800
805
|
end
|
|
801
806
|
|
|
@@ -54,7 +54,9 @@ module Doric
|
|
|
54
54
|
|
|
55
55
|
def initialize (h, doc=nil)
|
|
56
56
|
|
|
57
|
-
@h = h.inject(self.class.defaults
|
|
57
|
+
@h = h.inject(Rufus::Json.dup(self.class.defaults)) { |hh, (k, v)|
|
|
58
|
+
hh[k.to_s] = v; hh
|
|
59
|
+
}
|
|
58
60
|
|
|
59
61
|
if doc && atts = doc['_attachments']
|
|
60
62
|
|
data/lib/rufus/doric/version.rb
CHANGED
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.
|
|
8
|
+
s.version = "0.1.18"
|
|
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-09
|
|
12
|
+
s.date = %q{2010-11-09}
|
|
13
13
|
s.description = %q{
|
|
14
14
|
something at the intersection of Rails3, CouchDB and rufus-jig
|
|
15
15
|
}
|
|
@@ -85,20 +85,20 @@ something at the intersection of Rails3, CouchDB and rufus-jig
|
|
|
85
85
|
|
|
86
86
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
87
87
|
s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.0"])
|
|
88
|
-
s.add_runtime_dependency(%q<rufus-jig>, [">= 0.1.
|
|
88
|
+
s.add_runtime_dependency(%q<rufus-jig>, [">= 0.1.23"])
|
|
89
89
|
s.add_runtime_dependency(%q<mime-types>, [">= 1.16"])
|
|
90
90
|
s.add_development_dependency(%q<rake>, [">= 0"])
|
|
91
91
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
|
92
92
|
else
|
|
93
93
|
s.add_dependency(%q<activerecord>, ["~> 3.0.0"])
|
|
94
|
-
s.add_dependency(%q<rufus-jig>, [">= 0.1.
|
|
94
|
+
s.add_dependency(%q<rufus-jig>, [">= 0.1.23"])
|
|
95
95
|
s.add_dependency(%q<mime-types>, [">= 1.16"])
|
|
96
96
|
s.add_dependency(%q<rake>, [">= 0"])
|
|
97
97
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
|
98
98
|
end
|
|
99
99
|
else
|
|
100
100
|
s.add_dependency(%q<activerecord>, ["~> 3.0.0"])
|
|
101
|
-
s.add_dependency(%q<rufus-jig>, [">= 0.1.
|
|
101
|
+
s.add_dependency(%q<rufus-jig>, [">= 0.1.23"])
|
|
102
102
|
s.add_dependency(%q<mime-types>, [">= 1.16"])
|
|
103
103
|
s.add_dependency(%q<rake>, [">= 0"])
|
|
104
104
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
data/test/ut_12_model_default.rb
CHANGED
|
@@ -20,6 +20,7 @@ class Can < Rufus::Doric::Model
|
|
|
20
20
|
h_accessor :content, :default => 'tuna'
|
|
21
21
|
h_accessor :colour
|
|
22
22
|
property :sold, :default => false
|
|
23
|
+
property :customers, :default => []
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
|
|
@@ -43,12 +44,29 @@ class UtModelDefaultTest < Test::Unit::TestCase
|
|
|
43
44
|
Can.new(:serial => 'abcd', :content => 'anchovy').save!
|
|
44
45
|
Can.new(:serial => 'efgh').save!
|
|
45
46
|
|
|
46
|
-
assert_equal(
|
|
47
|
+
assert_equal(
|
|
48
|
+
{ 'content' => 'tuna', 'sold' => false, 'customers' => [] },
|
|
49
|
+
Can.defaults)
|
|
47
50
|
|
|
48
51
|
assert_equal 'anchovy', Can.find('abcd').content
|
|
49
52
|
assert_equal 'tuna', Can.find('efgh').content
|
|
50
53
|
assert_equal nil, Can.find('abcd').colour
|
|
51
54
|
assert_equal false, Can.find('abcd').sold
|
|
52
55
|
end
|
|
56
|
+
|
|
57
|
+
def test_default_is_not_shared_among_all_instances
|
|
58
|
+
|
|
59
|
+
anchovy = Can.new(:serial => 'anchovy', :content => 'anchovy')
|
|
60
|
+
tuna = Can.new(:serial => 'tuna', :content => 'tuna')
|
|
61
|
+
|
|
62
|
+
anchovy.customers << 'alice'
|
|
63
|
+
anchovy.customers << 'bob'
|
|
64
|
+
|
|
65
|
+
anchovy.save!
|
|
66
|
+
tuna.save!
|
|
67
|
+
|
|
68
|
+
assert_equal %w[ alice bob ], Can.find('anchovy').customers
|
|
69
|
+
assert_equal [], Can.find('tuna').customers
|
|
70
|
+
end
|
|
53
71
|
end
|
|
54
72
|
|
|
@@ -18,6 +18,7 @@ class Place < Rufus::Doric::OneDocModel
|
|
|
18
18
|
h_accessor :name
|
|
19
19
|
h_accessor :zip
|
|
20
20
|
h_accessor :country, :default => 'UK'
|
|
21
|
+
h_accessor :neighbours, :default => []
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
|
|
@@ -32,7 +33,9 @@ class UtOneDocModelDefaultTest < Test::Unit::TestCase
|
|
|
32
33
|
|
|
33
34
|
def test_defaults
|
|
34
35
|
|
|
35
|
-
assert_equal(
|
|
36
|
+
assert_equal(
|
|
37
|
+
{ 'country' => 'UK', 'neighbours' => [] },
|
|
38
|
+
Place.defaults)
|
|
36
39
|
end
|
|
37
40
|
|
|
38
41
|
def test_default
|
|
@@ -43,5 +46,15 @@ class UtOneDocModelDefaultTest < Test::Unit::TestCase
|
|
|
43
46
|
assert_equal 'UK', london.country
|
|
44
47
|
assert_equal 'Germany', berlin.country
|
|
45
48
|
end
|
|
49
|
+
|
|
50
|
+
def test_default_is_not_shared_among_all_instances
|
|
51
|
+
|
|
52
|
+
tokyo = Place.new(:name => 'Tokyo')
|
|
53
|
+
hiroshima = Place.new(:name => 'Hiroshima')
|
|
54
|
+
|
|
55
|
+
tokyo.neighbours << 'Yokohama'
|
|
56
|
+
|
|
57
|
+
assert_equal [], hiroshima.neighbours
|
|
58
|
+
end
|
|
46
59
|
end
|
|
47
60
|
|
|
@@ -33,12 +33,6 @@ class UtModelViewByAndTest < Test::Unit::TestCase
|
|
|
33
33
|
Rufus::Doric.db('doric').http.cache.clear
|
|
34
34
|
# CouchDB feeds the same etags for views, even after a db has
|
|
35
35
|
# been deleted and put back, so have to do that 'forgetting'
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
#def teardown
|
|
39
|
-
#end
|
|
40
|
-
|
|
41
|
-
def test_view_by_and
|
|
42
36
|
|
|
43
37
|
Squad.new(
|
|
44
38
|
'type' => 'rifle',
|
|
@@ -56,9 +50,27 @@ class UtModelViewByAndTest < Test::Unit::TestCase
|
|
|
56
50
|
'type' => 'artillery',
|
|
57
51
|
'ranking' => 'first'
|
|
58
52
|
).save!
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
#def teardown
|
|
56
|
+
#end
|
|
57
|
+
|
|
58
|
+
def test_view_by_and
|
|
59
59
|
|
|
60
60
|
assert_equal 2, Squad.by_type_and_ranking([ 'rifle', 'first' ]).size
|
|
61
61
|
assert_equal 3, Squad.by_ranking('first').size
|
|
62
62
|
end
|
|
63
|
+
|
|
64
|
+
def test_view_raw
|
|
65
|
+
|
|
66
|
+
br = Squad.by_ranking('first', :raw => true)
|
|
67
|
+
btar = Squad.by_type_and_ranking([ 'rifle', 'first' ], :raw => true)
|
|
68
|
+
|
|
69
|
+
assert_equal 3, br.size
|
|
70
|
+
assert_equal Hash, br.first.class
|
|
71
|
+
assert_equal %w[ doc id key value ], br.first.keys.sort
|
|
72
|
+
|
|
73
|
+
assert_equal 2, btar.size
|
|
74
|
+
end
|
|
63
75
|
end
|
|
64
76
|
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 1
|
|
8
|
-
-
|
|
9
|
-
version: 0.1.
|
|
8
|
+
- 18
|
|
9
|
+
version: 0.1.18
|
|
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-09
|
|
17
|
+
date: 2010-11-09 00:00:00 +09:00
|
|
18
18
|
default_executable:
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
@@ -41,8 +41,8 @@ dependencies:
|
|
|
41
41
|
segments:
|
|
42
42
|
- 0
|
|
43
43
|
- 1
|
|
44
|
-
-
|
|
45
|
-
version: 0.1.
|
|
44
|
+
- 23
|
|
45
|
+
version: 0.1.23
|
|
46
46
|
type: :runtime
|
|
47
47
|
version_requirements: *id002
|
|
48
48
|
- !ruby/object:Gem::Dependency
|