active_type 0.1.0 → 0.1.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f6709aa6a9fb26d216bd6824523b35af47d6e53
|
4
|
+
data.tar.gz: c4699de79bcfca007fd56d7f513916fccb424fbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4285b28839f7e1ba7a10c807cdc0cb497d46bdedfa5f621e4ec699787e564145d3e2819134dc8250739d18e7de6aa3eea33e9e83989446b0f031d46611754e04
|
7
|
+
data.tar.gz: 139b82919f9a75396ac3c15174d946aa5e12e9a14dea25fe8a24a6b14bb334bbec090ab5a5903c538ff34004cf7ca878cb7e6ceab6648af5390d725e0503b8cd
|
data/lib/active_type/version.rb
CHANGED
@@ -36,6 +36,8 @@ module ActiveType
|
|
36
36
|
else
|
37
37
|
super
|
38
38
|
end
|
39
|
+
when nil
|
40
|
+
value
|
39
41
|
else
|
40
42
|
super
|
41
43
|
end
|
@@ -154,7 +156,7 @@ module ActiveType
|
|
154
156
|
end
|
155
157
|
end
|
156
158
|
|
157
|
-
def attribute(name, type)
|
159
|
+
def attribute(name, type = nil)
|
158
160
|
self.virtual_columns_hash = virtual_columns_hash.merge(name.to_s => VirtualColumn.new(name, type))
|
159
161
|
AccessorGenerator.new(generated_virtual_attribute_methods).generate_accessors(name)
|
160
162
|
end
|
@@ -9,6 +9,7 @@ module ObjectSpec
|
|
9
9
|
attribute :virtual_time, :datetime
|
10
10
|
attribute :virtual_date, :date
|
11
11
|
attribute :virtual_boolean, :boolean
|
12
|
+
attribute :virtual_attribute
|
12
13
|
|
13
14
|
end
|
14
15
|
|
@@ -142,6 +143,10 @@ describe ActiveType::Object do
|
|
142
143
|
describe 'boolean columns' do
|
143
144
|
it_should_behave_like 'a coercible boolean column', :virtual_boolean
|
144
145
|
end
|
146
|
+
|
147
|
+
describe 'untyped columns' do
|
148
|
+
it_should_behave_like 'an untyped column', :virtual_attribute
|
149
|
+
end
|
145
150
|
end
|
146
151
|
|
147
152
|
describe 'inherited classes' do
|
@@ -9,6 +9,7 @@ module RecordSpec
|
|
9
9
|
attribute :virtual_time, :datetime
|
10
10
|
attribute :virtual_date, :date
|
11
11
|
attribute :virtual_boolean, :boolean
|
12
|
+
attribute :virtual_attribute
|
12
13
|
|
13
14
|
end
|
14
15
|
|
@@ -133,6 +134,10 @@ describe ActiveType::Record do
|
|
133
134
|
it_should_behave_like 'a coercible boolean column', :persisted_boolean
|
134
135
|
it_should_behave_like 'a coercible boolean column', :virtual_boolean
|
135
136
|
end
|
137
|
+
|
138
|
+
describe 'untyped columns' do
|
139
|
+
it_should_behave_like 'an untyped column', :virtual_attribute
|
140
|
+
end
|
136
141
|
end
|
137
142
|
|
138
143
|
describe 'validations' do
|
@@ -201,3 +201,28 @@ shared_examples_for 'a coercible boolean column' do |column|
|
|
201
201
|
end
|
202
202
|
|
203
203
|
end
|
204
|
+
|
205
|
+
shared_examples_for 'an untyped column' do |column|
|
206
|
+
it 'is nil by default' do
|
207
|
+
subject.send(column).should be_nil
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'leaves strings alone' do
|
211
|
+
subject.send(:"#{column}=", "string")
|
212
|
+
|
213
|
+
subject.send(column).should == "string"
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'leaves integers alone' do
|
217
|
+
subject.send(:"#{column}=", 17)
|
218
|
+
|
219
|
+
subject.send(column).should == 17
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'leaves objects alone' do
|
223
|
+
object = Object.new
|
224
|
+
subject.send(:"#{column}=", object)
|
225
|
+
|
226
|
+
subject.send(column).should == object
|
227
|
+
end
|
228
|
+
end
|