active_type 0.4.5 → 0.5.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +14 -6
- data/gemfiles/Gemfile.3.2.mysql2.lock +1 -1
- data/gemfiles/Gemfile.3.2.sqlite3.lock +1 -1
- data/gemfiles/Gemfile.4.0.sqlite3.lock +1 -1
- data/gemfiles/Gemfile.4.1.sqlite3.lock +1 -1
- data/gemfiles/Gemfile.4.2.1.mysql2.lock +1 -1
- data/gemfiles/Gemfile.4.2.1.pg.lock +1 -1
- data/gemfiles/Gemfile.4.2.1.sqlite3.lock +1 -1
- data/lib/active_type/type_caster.rb +1 -1
- data/lib/active_type/version.rb +1 -1
- data/lib/active_type/virtual_attributes.rb +22 -0
- data/spec/active_type/object_spec.rb +35 -0
- data/spec/active_type/record_spec.rb +19 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/database.rb +1 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87578ffca30cf6e55491dbdf6d2979e5f1417983
|
4
|
+
data.tar.gz: 85c59e32dfd6f173cee644da43706f74e1591d6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63c1a195fb0f6cb52ec7cdcfcdf7f32bb78dc8d584edde830eb9de59690b02bc67b2500b1365d4e3f534f2900da9bde01d006d9a74b68a205159f96c433c01dd
|
7
|
+
data.tar.gz: 87f1849abb23e4c2181d3509d6d40d6757f296f011aa8e21d7afb74d6e686b120aa2a76e905ac04a5b126d560200f8e8309188538f160f5053c1f99cdfa6e6fe
|
data/.travis.yml
CHANGED
@@ -37,19 +37,27 @@ matrix:
|
|
37
37
|
gemfile: gemfiles/Gemfile.4.2.1.mysql2
|
38
38
|
- rvm: "1.8.7"
|
39
39
|
gemfile: gemfiles/Gemfile.4.2.1.pg
|
40
|
+
- rvm: "1.9.3"
|
41
|
+
gemfile: gemfiles/Gemfile.4.0.sqlite3
|
40
42
|
- rvm: "1.9.3"
|
41
43
|
gemfile: gemfiles/Gemfile.4.2.1.mysql2
|
42
44
|
- rvm: "1.9.3"
|
43
45
|
gemfile: gemfiles/Gemfile.4.2.1.pg
|
46
|
+
- rvm: "1.9.3"
|
47
|
+
gemfile: gemfiles/Gemfile.3.2.mysql2
|
48
|
+
- rvm: "2.0.0"
|
49
|
+
gemfile: gemfiles/Gemfile.4.0.sqlite3
|
44
50
|
- rvm: "2.0.0"
|
45
51
|
gemfile: gemfiles/Gemfile.4.2.1.mysql2
|
46
52
|
- rvm: "2.0.0"
|
47
53
|
gemfile: gemfiles/Gemfile.4.2.1.pg
|
48
|
-
- rvm: "2.
|
49
|
-
gemfile: gemfiles/Gemfile.4.0.sqlite3
|
50
|
-
- rvm: "2.2.0"
|
51
|
-
gemfile: gemfiles/Gemfile.3.2.sqlite3
|
52
|
-
- rvm: "2.2.0"
|
54
|
+
- rvm: "2.0.0"
|
53
55
|
gemfile: gemfiles/Gemfile.3.2.mysql2
|
54
|
-
- rvm: "2.
|
56
|
+
- rvm: "2.1.7"
|
55
57
|
gemfile: gemfiles/Gemfile.4.0.sqlite3
|
58
|
+
- rvm: "2.1.7"
|
59
|
+
gemfile: gemfiles/Gemfile.4.2.1.mysql2
|
60
|
+
- rvm: "2.1.7"
|
61
|
+
gemfile: gemfiles/Gemfile.4.2.1.pg
|
62
|
+
- rvm: "2.1.7"
|
63
|
+
gemfile: gemfiles/Gemfile.3.2.mysql2
|
@@ -43,7 +43,7 @@ module ActiveType
|
|
43
43
|
module NativeCasters
|
44
44
|
|
45
45
|
# Adapter for Rails 3.0 - 4.1.
|
46
|
-
# In these versions, casting logic lives in ActiveRecord::ConnectionAdapters::
|
46
|
+
# In these versions, casting logic lives in ActiveRecord::ConnectionAdapters::Column
|
47
47
|
class DelegateToColumn
|
48
48
|
|
49
49
|
def initialize(type)
|
data/lib/active_type/version.rb
CHANGED
@@ -181,6 +181,28 @@ module ActiveType
|
|
181
181
|
virtual_attributes[name] = value
|
182
182
|
end
|
183
183
|
|
184
|
+
# Returns the contents of the record as a nicely formatted string.
|
185
|
+
def inspect
|
186
|
+
inspection = attributes.collect do |name, value|
|
187
|
+
"#{name}: #{VirtualAttributes.attribute_for_inspect(value)}"
|
188
|
+
end.sort.compact.join(", ")
|
189
|
+
"#<#{self.class} #{inspection}>"
|
190
|
+
end
|
191
|
+
|
192
|
+
def self.attribute_for_inspect(value)
|
193
|
+
if value.is_a?(String) && value.length > 50
|
194
|
+
"#{value[0, 50]}...".inspect
|
195
|
+
elsif value.is_a?(Date) || value.is_a?(Time)
|
196
|
+
%("#{value.to_s(:db)}")
|
197
|
+
elsif value.is_a?(Array) && value.size > 10
|
198
|
+
inspected = value.first(10).inspect
|
199
|
+
%(#{inspected[0...-1]}, ...])
|
200
|
+
else
|
201
|
+
value.inspect
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
|
184
206
|
module ClassMethods
|
185
207
|
|
186
208
|
def _virtual_column(name)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'ostruct'
|
2
3
|
|
3
4
|
module ObjectSpec
|
4
5
|
|
@@ -61,6 +62,7 @@ module ObjectSpec
|
|
61
62
|
before_validation :before_validation_callback
|
62
63
|
after_save :after_save_callback
|
63
64
|
after_commit :after_commit_callback
|
65
|
+
after_rollback :after_rollback_callback
|
64
66
|
|
65
67
|
def before_save_callback
|
66
68
|
end
|
@@ -74,6 +76,9 @@ module ObjectSpec
|
|
74
76
|
def after_commit_callback
|
75
77
|
end
|
76
78
|
|
79
|
+
def after_rollback_callback
|
80
|
+
end
|
81
|
+
|
77
82
|
end
|
78
83
|
|
79
84
|
class Child < ActiveRecord::Base
|
@@ -202,6 +207,22 @@ describe ActiveType::Object do
|
|
202
207
|
|
203
208
|
end
|
204
209
|
|
210
|
+
describe '#inspect' do
|
211
|
+
|
212
|
+
it 'returns the contents of the object as a nicely formatted string' do
|
213
|
+
t = Time.now
|
214
|
+
subject.virtual_string = "string"
|
215
|
+
subject.virtual_integer = 17
|
216
|
+
subject.virtual_time = t
|
217
|
+
subject.virtual_date = Date.today
|
218
|
+
subject.virtual_boolean = true
|
219
|
+
subject.virtual_attribute = OpenStruct.new({:test => "openstruct"})
|
220
|
+
|
221
|
+
expect(subject.inspect).to eq("#<ObjectSpec::Object virtual_attribute: #<OpenStruct test=\"openstruct\">, virtual_boolean: true, virtual_date: \"#{Date.today}\", virtual_integer: 17, virtual_string: \"string\", virtual_time: \"#{t.to_s(:db)}\">")
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
225
|
+
|
205
226
|
describe '#attributes' do
|
206
227
|
|
207
228
|
it 'returns a hash of virtual attributes' do
|
@@ -367,6 +388,20 @@ describe ActiveType::Object do
|
|
367
388
|
|
368
389
|
end
|
369
390
|
|
391
|
+
it 'runs after_rollback callbacks if an after_save callback raises an error', :rollback => false do
|
392
|
+
expect(subject).to receive(:after_save_callback).ordered.and_raise(ActiveRecord::Rollback)
|
393
|
+
expect(subject).to receive(:after_rollback_callback).ordered
|
394
|
+
|
395
|
+
expect(subject.save).to be_falsey
|
396
|
+
end
|
397
|
+
|
398
|
+
it 'does not run after_rollback callbacks if after_save does not raise an error', :rollback => false do
|
399
|
+
expect(subject).to_not receive(:after_rollback_callback)
|
400
|
+
|
401
|
+
expect(subject.save).to be_truthy
|
402
|
+
|
403
|
+
end
|
404
|
+
|
370
405
|
end
|
371
406
|
|
372
407
|
describe '.find' do
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'ostruct'
|
2
3
|
|
3
4
|
module RecordSpec
|
4
5
|
|
@@ -151,6 +152,24 @@ describe ActiveType::Record do
|
|
151
152
|
end
|
152
153
|
end
|
153
154
|
|
155
|
+
describe '#inspect' do
|
156
|
+
|
157
|
+
it 'returns the contents of the object as a nicely formatted string' do
|
158
|
+
t = Time.now
|
159
|
+
subject.persisted_string = "persisted string"
|
160
|
+
subject.virtual_string = "string"
|
161
|
+
subject.persisted_integer = 20
|
162
|
+
subject.virtual_integer = 17
|
163
|
+
subject.virtual_time = t
|
164
|
+
subject.virtual_date = Date.today
|
165
|
+
subject.virtual_boolean = true
|
166
|
+
subject.virtual_attribute = OpenStruct.new({:test => "openstruct"})
|
167
|
+
|
168
|
+
expect(subject.inspect).to eq("#<RecordSpec::Record id: nil, persisted_boolean: nil, persisted_date: nil, persisted_integer: 20, persisted_string: \"persisted string\", persisted_time: nil, virtual_attribute: #<OpenStruct test=\"openstruct\">, virtual_boolean: true, virtual_date: \"#{Date.today}\", virtual_integer: 17, virtual_string: \"string\", virtual_time: \"#{t.to_s(:db)}\">")
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
154
173
|
describe '#attributes' do
|
155
174
|
|
156
175
|
it 'returns a hash of virtual and persisted attributes' do
|
data/spec/spec_helper.rb
CHANGED
@@ -5,6 +5,7 @@ $: << File.join(File.dirname(__FILE__), "/../../lib" )
|
|
5
5
|
require 'active_type'
|
6
6
|
|
7
7
|
ActiveRecord::Base.default_timezone = :local
|
8
|
+
ActiveRecord::Base.raise_in_transactional_callbacks = true if ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks)
|
8
9
|
|
9
10
|
Dir["#{File.dirname(__FILE__)}/support/*.rb"].each {|f| require f}
|
10
11
|
Dir["#{File.dirname(__FILE__)}/shared_examples/*.rb"].each {|f| require f}
|
data/spec/support/database.rb
CHANGED
@@ -17,10 +17,8 @@ when /mysql2/
|
|
17
17
|
config.merge!(custom_config)
|
18
18
|
end
|
19
19
|
ActiveRecord::Base.establish_connection(config)
|
20
|
-
when /sqlite3/
|
21
|
-
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
22
20
|
else
|
23
|
-
|
21
|
+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
24
22
|
end
|
25
23
|
|
26
24
|
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Kraze
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-04-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|