active_type 0.1.1 → 0.1.2

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: 2f6709aa6a9fb26d216bd6824523b35af47d6e53
4
- data.tar.gz: c4699de79bcfca007fd56d7f513916fccb424fbb
3
+ metadata.gz: 246d6b642fc001e5a1df57b9c4cd42e20a6fe68c
4
+ data.tar.gz: dbce1038dc7d9d74d6258927e0e3a1bfb995af70
5
5
  SHA512:
6
- metadata.gz: 4285b28839f7e1ba7a10c807cdc0cb497d46bdedfa5f621e4ec699787e564145d3e2819134dc8250739d18e7de6aa3eea33e9e83989446b0f031d46611754e04
7
- data.tar.gz: 139b82919f9a75396ac3c15174d946aa5e12e9a14dea25fe8a24a6b14bb334bbec090ab5a5903c538ff34004cf7ca878cb7e6ceab6648af5390d725e0503b8cd
6
+ metadata.gz: 68925ab89dbead458c046fcdea66fc7493e16e616af15aec2647c5800851f7bc6db00fc1f61077aadabebf310b1a52dec2c84e8f64c37aa012c0886173c5e5d4
7
+ data.tar.gz: e7dd74a94787288cc37b6dadfbae1f4e3451cb6707c4733cd6e1dd357bc906b8bc323fe08102b7824d9661fee7d0fb57b6dc6a9e642618233f1f5514920233ac
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_type (0.1.0)
4
+ active_type (0.1.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_type (0.1.0)
4
+ active_type (0.1.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_type (0.1.0)
4
+ active_type (0.1.2)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -11,7 +11,6 @@ module ActiveType
11
11
 
12
12
  def [](base)
13
13
  Class.new(base) do
14
- @abstract_class = true
15
14
 
16
15
  include VirtualAttributes
17
16
  include Inheritance
@@ -30,6 +30,10 @@ module ActiveType
30
30
  nil
31
31
  end
32
32
 
33
+ def attribute_names
34
+ []
35
+ end
36
+
33
37
  def transaction(&block)
34
38
  @_current_transaction_records ||= []
35
39
  yield
@@ -1,3 +1,3 @@
1
1
  module ActiveType
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -64,6 +64,10 @@ module ActiveType
64
64
  def #{name}
65
65
  read_virtual_attribute('#{name}')
66
66
  end
67
+
68
+ def #{name}?
69
+ read_virtual_attribute('#{name}').present?
70
+ end
67
71
  BODY
68
72
  end
69
73
 
@@ -113,6 +117,12 @@ module ActiveType
113
117
  end
114
118
  end
115
119
 
120
+ def attributes
121
+ self.class._virtual_column_names.each_with_object(super) do |name, attrs|
122
+ attrs[name] = read_virtual_attribute(name)
123
+ end
124
+ end
125
+
116
126
  def read_virtual_attribute(name)
117
127
  name = name.to_s
118
128
  @virtual_attributes_cache[name] ||= begin
@@ -138,6 +148,16 @@ module ActiveType
138
148
  end
139
149
  end
140
150
 
151
+ def _virtual_column_names
152
+ @virtual_column_names ||= begin
153
+ names = virtual_columns_hash.keys
154
+ if defined?(super)
155
+ names += super
156
+ end
157
+ names
158
+ end
159
+ end
160
+
141
161
  def _has_virtual_column?(name)
142
162
  virtual_columns_hash.has_key?(name.to_s) || begin
143
163
  if defined?(super)
@@ -44,6 +44,25 @@ describe "ActiveType::Record[ActiveRecord::Base]" do
44
44
  it_should_behave_like 'ActiveRecord-like constructors', { :persisted_string => "persisted string", :another_virtual_string => "another virtual string" }
45
45
  end
46
46
 
47
+ describe '#attributes' do
48
+
49
+ it 'returns a hash of virtual and persisted attributes' do
50
+ subject.persisted_string = "string"
51
+ subject.another_virtual_string = "string"
52
+
53
+ subject.attributes.should == {
54
+ "another_virtual_string" => "string",
55
+ "id" => nil,
56
+ "persisted_string" => "string",
57
+ "persisted_integer" => nil,
58
+ "persisted_time" => nil,
59
+ "persisted_date" => nil,
60
+ "persisted_boolean" => nil
61
+ }
62
+ end
63
+
64
+ end
65
+
47
66
  describe 'accessors' do
48
67
  it_should_behave_like 'ActiveRecord-like accessors', { :persisted_string => "persisted string", :another_virtual_string => "another virtual string" }
49
68
  end
@@ -65,6 +84,12 @@ describe "ActiveType::Record[ActiveRecord::Base]" do
65
84
  end
66
85
  end
67
86
 
87
+ describe '.base_class' do
88
+ it 'is the base class inherited from' do
89
+ subject.class.base_class.should == ExtendedRecordSpec::BaseRecord
90
+ end
91
+ end
92
+
68
93
  end
69
94
 
70
95
 
@@ -86,6 +111,26 @@ describe "ActiveType::Record[ActiveType::Record]" do
86
111
  it_should_behave_like 'ActiveRecord-like constructors', { :persisted_string => "persisted string", :virtual_string => "virtual string", :another_virtual_string => "another virtual string" }
87
112
  end
88
113
 
114
+ describe '#attributes' do
115
+
116
+ it 'returns a hash of virtual and persisted attributes' do
117
+ subject.persisted_string = "string"
118
+ subject.virtual_string = "string"
119
+
120
+ subject.attributes.should == {
121
+ "virtual_string" => "string",
122
+ "another_virtual_string" => nil,
123
+ "id" => nil,
124
+ "persisted_string" => "string",
125
+ "persisted_integer" => nil,
126
+ "persisted_time" => nil,
127
+ "persisted_date" => nil,
128
+ "persisted_boolean" => nil
129
+ }
130
+ end
131
+
132
+ end
133
+
89
134
  describe 'accessors' do
90
135
  it_should_behave_like 'ActiveRecord-like accessors', { :persisted_string => "persisted string", :virtual_string => "virtual string", :another_virtual_string => "another virtual string" }
91
136
  end
@@ -115,4 +160,10 @@ describe "ActiveType::Record[ActiveType::Record]" do
115
160
  end
116
161
  end
117
162
 
163
+ describe '.base_class' do
164
+ it 'is the base class inherited from' do
165
+ subject.class.base_class.should == ExtendedRecordSpec::BaseActiveTypeRecord
166
+ end
167
+ end
168
+
118
169
  end
@@ -149,6 +149,90 @@ describe ActiveType::Object do
149
149
  end
150
150
  end
151
151
 
152
+ describe 'query methods' do
153
+
154
+ it 'returns true for true' do
155
+ subject.virtual_attribute = true
156
+
157
+ subject.virtual_attribute?.should == true
158
+ end
159
+
160
+ it 'returns false for false' do
161
+ subject.virtual_attribute = false
162
+
163
+ subject.virtual_attribute?.should == false
164
+ end
165
+
166
+ it 'returns false for nil' do
167
+ subject.virtual_attribute = nil
168
+
169
+ subject.virtual_attribute?.should == false
170
+ end
171
+
172
+ it 'returns true for 1' do
173
+ subject.virtual_attribute = 1
174
+
175
+ subject.virtual_attribute?.should == true
176
+ end
177
+
178
+ it 'returns true for an object' do
179
+ subject.virtual_attribute = Object.new
180
+
181
+ subject.virtual_attribute?.should == true
182
+ end
183
+
184
+ end
185
+
186
+ describe '#attributes' do
187
+
188
+ it 'returns a hash of virtual attributes' do
189
+ subject.virtual_string = "string"
190
+ subject.virtual_integer = "17"
191
+
192
+ subject.attributes.should == {
193
+ "virtual_string" => "string",
194
+ "virtual_integer" => 17,
195
+ "virtual_time" => nil,
196
+ "virtual_date" => nil,
197
+ "virtual_boolean" => nil,
198
+ "virtual_attribute" => nil,
199
+ }
200
+ end
201
+
202
+ it 'also includes inherited attributes' do
203
+ object = ObjectSpec::InheritingObject.new
204
+ object.virtual_string = "string"
205
+ object.virtual_integer = "17"
206
+
207
+ object.attributes.should == {
208
+ "virtual_string" => "string",
209
+ "virtual_integer" => 17,
210
+ "virtual_time" => nil,
211
+ "virtual_date" => nil,
212
+ "virtual_boolean" => nil,
213
+ "virtual_attribute" => nil,
214
+ "another_virtual_string" => nil,
215
+ }
216
+ end
217
+
218
+ it 'also includes included attributes' do
219
+ object = ObjectSpec::IncludingObject.new
220
+ object.virtual_string = "string"
221
+ object.virtual_integer = "17"
222
+
223
+ object.attributes.should == {
224
+ "virtual_string" => "string",
225
+ "virtual_integer" => 17,
226
+ "virtual_time" => nil,
227
+ "virtual_date" => nil,
228
+ "virtual_boolean" => nil,
229
+ "virtual_attribute" => nil,
230
+ "another_virtual_string" => nil,
231
+ }
232
+ end
233
+
234
+ end
235
+
152
236
  describe 'inherited classes' do
153
237
 
154
238
  it 'sees attributes of both classes' do
@@ -140,6 +140,31 @@ describe ActiveType::Record do
140
140
  end
141
141
  end
142
142
 
143
+ describe '#attributes' do
144
+
145
+ it 'returns a hash of virtual and persisted attributes' do
146
+ subject.persisted_string = "string"
147
+ subject.virtual_string = "string"
148
+ subject.virtual_integer = "17"
149
+
150
+ subject.attributes.should == {
151
+ "virtual_string" => "string",
152
+ "virtual_integer" => 17,
153
+ "virtual_time" => nil,
154
+ "virtual_date" => nil,
155
+ "virtual_boolean" => nil,
156
+ "virtual_attribute" => nil,
157
+ "id" => nil,
158
+ "persisted_string" => "string",
159
+ "persisted_integer" => nil,
160
+ "persisted_time" => nil,
161
+ "persisted_date" => nil,
162
+ "persisted_boolean" => nil
163
+ }
164
+ end
165
+
166
+ end
167
+
143
168
  describe 'validations' do
144
169
  subject { RecordSpec::RecordWithValidations.new }
145
170
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_type
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Kraze