couch_potato 1.6.3 → 1.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8581d86c34cc798e082cfd4e02bb53f042fa7751
4
- data.tar.gz: b2f1a4996b05581a519706cb0efb10db43aa942f
3
+ metadata.gz: 838a4fbf0f5af5fd3306a1cc2284d9c077397de1
4
+ data.tar.gz: 76306355648a9447a58c24b0e802f2f79bcc86e7
5
5
  SHA512:
6
- metadata.gz: aead6991131097d92510834befd4feb441c477a761472d43b72c3422cf0371eef35c7acfd52e2711483812c48f508ed706a72c8194875d00ebdd233fad774c38
7
- data.tar.gz: f15626c508f062dbfd99d6672e0ed94b8364ec85d5030b77935656a42e3d27923b9bbc2e2bb8028f8f985de8c3967e55ff7754a410d97844f6836b410b8d05ba
6
+ metadata.gz: a914b059c4f92b4141eea0b8278d308a8101ba555f76db3fd83d11020f03605bc71553a99889cc0260da27b7421c347c7ebbca76bafe30843b18e2cd852ef9df
7
+ data.tar.gz: 13eae7928a7a82b7102cf2d9b47da78352d225e01b28192015a18b63232afe410c29b220ed8012aabe8b1f09ab2dc33a90d5bbf120a129dd3516eb3944de9a5c
@@ -25,7 +25,7 @@ module CouchPotato
25
25
  end
26
26
 
27
27
  def find_property(name)
28
- @hash[name]
28
+ @hash[name] || @clazz.superclass.properties.find_property(name)
29
29
  end
30
30
 
31
31
  # XXX
@@ -1,4 +1,4 @@
1
1
  module CouchPotato
2
- VERSION = '1.6.3'
2
+ VERSION = '1.6.4'
3
3
  RSPEC_VERSION = '3.0.0'
4
4
  end
@@ -6,54 +6,61 @@ class Branch
6
6
  property :leafs
7
7
  end
8
8
 
9
-
10
9
  class Plant
11
10
  include CouchPotato::Persistence
12
11
  property :leaf_count
13
- property :typed_leaf_count, :type => Fixnum
14
- property :typed_leaf_size, :type => Float
15
- property :branch, :type => Branch
12
+ property :typed_leaf_count, type: Fixnum
13
+ property :typed_leaf_size, type: Float
14
+ property :branch, type: Branch
15
+ end
16
+
17
+ class SpecialPlant < Plant
16
18
  end
17
19
 
18
20
 
19
- describe "attributes" do
21
+ describe 'attributes' do
20
22
  context 'attributes=' do
21
- it "should assign the attributes" do
23
+ it 'assigns the attributes' do
22
24
  plant = Plant.new
23
- plant.attributes = {:leaf_count => 1}
25
+ plant.attributes = {leaf_count: 1}
26
+
24
27
  expect(plant.leaf_count).to eq(1)
25
28
  end
26
29
 
27
- it "should assign the attributes via []=" do
30
+ it 'assigns the attributes via []=' do
28
31
  plant = Plant.new
29
32
  plant[:leaf_count] = 1
33
+
30
34
  expect(plant.leaf_count).to eq(1)
31
35
  end
32
36
  end
33
37
 
34
- context "attributes" do
35
- it "should return the attributes" do
36
- plant = Plant.new(:leaf_count => 1)
37
- expect(plant.attributes).to eq({'leaf_count' => 1, 'created_at' => nil, 'updated_at' => nil,
38
- 'typed_leaf_count' => nil, 'typed_leaf_size' => nil, 'branch' => nil})
38
+ context 'attributes' do
39
+ it 'returns the attributes' do
40
+ plant = Plant.new(leaf_count: 1)
41
+
42
+ expect(plant.attributes).to eq('leaf_count' => 1, 'created_at' => nil,
43
+ 'updated_at' => nil, 'typed_leaf_count' => nil,
44
+ 'typed_leaf_size' => nil, 'branch' => nil)
39
45
  end
40
46
 
41
- it "should return the attributes via [symbol]" do
42
- plant = Plant.new(:leaf_count => 1)
47
+ it 'returns the attributes via [symbol]' do
48
+ plant = Plant.new(leaf_count: 1)
49
+
43
50
  expect(plant.attributes[:leaf_count]).to eql(plant[:leaf_count])
44
51
  expect(plant.attributes[:leaf_count]).to eql(1)
45
52
  end
46
53
 
47
- it "should return the attributes via [string]" do
54
+ it 'returns the attributes via [string]' do
48
55
  plant = Plant.new(leaf_count: 1)
49
56
 
50
- expect(plant.attributes["leaf_count"]).to eql(plant[:leaf_count])
51
- expect(plant.attributes["leaf_count"]).to eql(1)
57
+ expect(plant.attributes['leaf_count']).to eql(plant[:leaf_count])
58
+ expect(plant.attributes['leaf_count']).to eql(1)
52
59
  end
53
60
  end
54
61
 
55
- context "has_key?" do
56
- it 'should respond to has_key?' do
62
+ context 'has_key?' do
63
+ it 'responds to has_key?' do
57
64
  plant = Plant.new(leaf_count: 1)
58
65
 
59
66
  expect(plant.has_key?(:leaf_count)).to be_truthy
@@ -61,20 +68,21 @@ describe "attributes" do
61
68
  end
62
69
 
63
70
  # useful when loading models from custom views
64
- context "accessing ghost attributes" do
65
- it "should allow me to access attributes that are in the couchdb document but not defined as a property" do
66
- plant = Plant.json_create({JSON.create_id => "Plant", "color" => "red", "leaf_count" => 1})
71
+ context 'accessing ghost attributes' do
72
+ it 'allows me to access attributes that are in the couchdb document but not defined as a property' do
73
+ plant = Plant.json_create(JSON.create_id => 'Plant', 'color' => 'red', 'leaf_count' => 1)
74
+
67
75
  expect(plant.color).to eq('red')
68
76
  end
69
77
 
70
- it "should raise a no method error when trying to read attributes that are not in the document" do
71
- plant = Plant.json_create({JSON.create_id => "Plant", "leaf_count" => 1})
78
+ it 'raises a no method error when trying to read attributes that are not in the document' do
79
+ plant = Plant.json_create(JSON.create_id => 'Plant', 'leaf_count' => 1)
72
80
  expect do
73
81
  plant.length
74
82
  end.to raise_error(NoMethodError)
75
83
  end
76
84
 
77
- it "should raise a no method error if the document hasn't been loaded from the database" do
85
+ it "raises a no method error if the document hasn't been loaded from the database" do
78
86
  plant = Plant.new
79
87
  expect do
80
88
  plant.length
@@ -82,6 +90,14 @@ describe "attributes" do
82
90
  end
83
91
  end
84
92
 
93
+ context 'inherited attributes' do
94
+ it 'returns inherited attributes' do
95
+ plant = SpecialPlant.new _document: {leaf_count: 1}
96
+
97
+ expect(plant.leaf_count).to eq(1)
98
+ end
99
+ end
100
+
85
101
  context 'typed attributes' do
86
102
  before(:each) do
87
103
  @plant = Plant.new
@@ -89,90 +105,106 @@ describe "attributes" do
89
105
 
90
106
  context 'nested objects' do
91
107
  it 'assigns the attributes of nested objects' do
92
- expect(Plant.new(:branch => {:leafs => 3}).branch.leafs).to eq(3)
108
+ expect(Plant.new(branch: {leafs: 3}).branch.leafs).to eq(3)
93
109
  end
94
110
  end
95
111
 
96
- describe "fixnum" do
112
+ describe 'fixnum' do
97
113
  it 'rounds a float to a fixnum' do
98
114
  @plant.typed_leaf_count = 4.5
115
+
99
116
  expect(@plant.typed_leaf_count).to eq(5)
100
117
  end
101
118
 
102
- it "converts a string into a fixnum" do
119
+ it 'converts a string into a fixnum' do
103
120
  @plant.typed_leaf_count = '4'
121
+
104
122
  expect(@plant.typed_leaf_count).to eq(4)
105
123
  end
106
124
 
107
- it "converts a string into a negative fixnum" do
125
+ it 'converts a string into a negative fixnum' do
108
126
  @plant.typed_leaf_count = '-4'
127
+
109
128
  expect(@plant.typed_leaf_count).to eq(-4)
110
129
  end
111
130
 
112
- it "leaves a fixnum as is" do
131
+ it 'leaves a fixnum as is' do
113
132
  @plant.typed_leaf_count = 4
133
+
114
134
  expect(@plant.typed_leaf_count).to eq(4)
115
135
  end
116
136
 
117
- it "leaves nil as is" do
137
+ it 'leaves nil as is' do
118
138
  @plant.typed_leaf_count = nil
139
+
119
140
  expect(@plant.typed_leaf_count).to be_nil
120
141
  end
121
142
 
122
- it "sets the attributes to zero if a string given" do
143
+ it 'sets the attributes to zero if a string given' do
123
144
  @plant.typed_leaf_count = 'x'
145
+
124
146
  expect(@plant.typed_leaf_count).to eq(0)
125
147
  end
126
148
 
127
- it "parses numbers out of a string" do
149
+ it 'parses numbers out of a string' do
128
150
  @plant.typed_leaf_count = 'x123'
151
+
129
152
  expect(@plant.typed_leaf_count).to eq(123)
130
153
  end
131
154
 
132
- it "set the attributes to nil if given a blank string" do
155
+ it 'sets the attributes to nil if given a blank string' do
133
156
  @plant.typed_leaf_count = ''
157
+
134
158
  expect(@plant.typed_leaf_count).to be_nil
135
159
  end
136
160
  end
137
161
 
138
- context "float" do
139
- it "should convert a number in a string with a decimal place" do
162
+ context 'float' do
163
+ it 'converts a number in a string with a decimal place' do
140
164
  @plant.typed_leaf_size = '0.5001'
165
+
141
166
  expect(@plant.typed_leaf_size).to eq(0.5001)
142
167
  end
143
168
 
144
- it "should convert a number in a string without a decimal place" do
169
+ it 'converts a number in a string without a decimal place' do
145
170
  @plant.typed_leaf_size = '5'
171
+
146
172
  expect(@plant.typed_leaf_size).to eq(5.0)
147
173
  end
148
174
 
149
- it "should convert a negative number in a string" do
175
+ it 'converts a negative number in a string' do
150
176
  @plant.typed_leaf_size = '-5.0'
177
+
151
178
  expect(@plant.typed_leaf_size).to eq(-5.0)
152
179
  end
153
180
 
154
- it "should leave a float as it is" do
181
+ it 'leaves a float as it is' do
155
182
  @plant.typed_leaf_size = 0.5
183
+
156
184
  expect(@plant.typed_leaf_size).to eq(0.5)
157
185
  end
158
186
 
159
- it "should leave nil as is" do
187
+ it 'leaves nil as is' do
160
188
  @plant.typed_leaf_size = nil
189
+
161
190
  expect(@plant.typed_leaf_size).to be_nil
162
191
  end
163
192
 
164
- it "should set the attributes to zero if a string given" do
193
+ it 'sets the attributes to zero if a string given' do
165
194
  @plant.typed_leaf_size = 'x'
195
+
166
196
  expect(@plant.typed_leaf_size).to eq(0)
167
197
  end
168
198
 
169
- it "should parse numbers out of a string" do
199
+ it 'parses numbers out of a string' do
170
200
  @plant.typed_leaf_size = 'x00.123'
201
+
171
202
  expect(@plant.typed_leaf_size).to eq(0.123)
172
203
  end
173
204
 
174
- it "should set the attributes to nil if given a blank string" do
205
+ it 'sets the attributes to nil if given a blank string' do
175
206
  @plant.typed_leaf_size = ''
207
+
176
208
  expect(@plant.typed_leaf_size).to be_nil
177
209
  end
178
210
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couch_potato
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.3
4
+ version: 1.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Lang