active_type 0.2.0 → 0.2.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: bf3e434ef181d6b90bc9254d3d00824e02abc575
4
- data.tar.gz: 83883dad267701774625763bde13c919fb89f4f7
3
+ metadata.gz: 7180486f774d7be6e2e72c7a143ce953fa4dfb53
4
+ data.tar.gz: a3e11be0ca7a917b94ee3d9dfe5de50cab2d2ef9
5
5
  SHA512:
6
- metadata.gz: 749cf455d62f3463b339b3964fb2acad5375cc9357939f2c93fa780045bc233c8e6db7457fb83ba5061f0f9ea78d975ae49b5eeef99135a2571ffa293ebfa9d8
7
- data.tar.gz: f4f5718c15b260464619ed1e0cb9c33b6fed16aed6f1503bc7ef8282219cafb852f8d5d6d5d08b17f4c8ae67f057963b482ef0c9409c12600408411fcdd4e608
6
+ metadata.gz: 7f3a7e25ee5308b7391998653c11742ace74366ad096381306fb13692c2e58093a598c7a2e82963009e3f2daac59b161365082e1e032056cc475f8fe18340079
7
+ data.tar.gz: 626eda35b1cf0536d46956cda85843d88e92a056b2a62ad1194310347f7c91d4614c02ffe473d9df71294246e86287bd35ffb8b913051413bac12879a89520f0
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.1.2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_type (0.2.0)
4
+ active_type (0.2.1)
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.2.0)
4
+ active_type (0.2.1)
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.2.0)
4
+ active_type (0.2.1)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,3 +1,3 @@
1
1
  module ActiveType
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -101,6 +101,14 @@ module ActiveType
101
101
 
102
102
  end
103
103
 
104
+ def self.deep_dup(hash)
105
+ result = hash.dup
106
+ result.each do |key, value|
107
+ result[key] = value.dup if value.duplicable?
108
+ end
109
+ result
110
+ end
111
+
104
112
 
105
113
  extend ActiveSupport::Concern
106
114
 
@@ -109,6 +117,13 @@ module ActiveType
109
117
  self.virtual_columns_hash = {}
110
118
  end
111
119
 
120
+ def initialize_dup(other)
121
+ @virtual_attributes_cache = {}
122
+ @virtual_attributes = VirtualAttributes.deep_dup(@virtual_attributes)
123
+
124
+ super
125
+ end
126
+
112
127
  def virtual_attributes
113
128
  @virtual_attributes ||= {}
114
129
  end
@@ -288,6 +288,10 @@ describe ActiveType::Object do
288
288
  it_should_behave_like "a class accepting attribute defaults", ActiveType::Object
289
289
  end
290
290
 
291
+ describe 'duping' do
292
+ it_should_behave_like "a class supporting dup for attributes", ActiveType::Object
293
+ end
294
+
291
295
  describe '#belongs_to' do
292
296
  subject { ObjectSpec::ObjectWithBelongsTo.new }
293
297
 
@@ -195,6 +195,10 @@ describe ActiveType::Record do
195
195
  it_should_behave_like "a class accepting attribute defaults", RecordSpec::Record
196
196
  end
197
197
 
198
+ describe 'duping' do
199
+ it_should_behave_like "a class supporting dup for attributes", RecordSpec::Record
200
+ end
201
+
198
202
  describe 'persistence' do
199
203
 
200
204
  it 'persists to the database' do
@@ -0,0 +1,31 @@
1
+ shared_examples_for "a class supporting dup for attributes" do |klass|
2
+
3
+ subject do
4
+ Class.new(klass) do
5
+ attribute :attribute
6
+ end.new
7
+ end
8
+
9
+ describe '#dup' do
10
+
11
+ it 'returns an object with independent attributes' do
12
+ subject.attribute = "foo"
13
+ duped = subject.dup
14
+ duped.attribute = "bar"
15
+
16
+ subject.attribute.should == "foo"
17
+ duped.attribute.should == "bar"
18
+ end
19
+
20
+ it 'does a deep copy' do
21
+ subject.attribute = { :foo => "bar" }
22
+ duped = subject.dup
23
+ duped.attribute.merge!(:foo => "baz")
24
+
25
+ subject.attribute.should == { :foo => "bar" }
26
+ duped.attribute.should == { :foo => "baz" }
27
+ end
28
+
29
+ end
30
+
31
+ end
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Kraze
@@ -9,48 +9,48 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-05 00:00:00.000000000 Z
12
+ date: 2014-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '1.5'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.5'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: activerecord
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '3.2'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '>='
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '3.2'
56
56
  description: Make any Ruby object quack like ActiveRecord
@@ -59,9 +59,9 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
63
- - .ruby-version
64
- - .travis.yml
62
+ - ".gitignore"
63
+ - ".ruby-version"
64
+ - ".travis.yml"
65
65
  - LICENSE
66
66
  - README.md
67
67
  - Rakefile
@@ -99,6 +99,7 @@ files:
99
99
  - spec/shared_examples/coercible_columns.rb
100
100
  - spec/shared_examples/constructor.rb
101
101
  - spec/shared_examples/defaults.rb
102
+ - spec/shared_examples/dupable.rb
102
103
  - spec/shared_examples/mass_assignment.rb
103
104
  - spec/spec_helper.rb
104
105
  - spec/support/database.rb
@@ -116,12 +117,12 @@ require_paths:
116
117
  - lib
117
118
  required_ruby_version: !ruby/object:Gem::Requirement
118
119
  requirements:
119
- - - '>='
120
+ - - ">="
120
121
  - !ruby/object:Gem::Version
121
122
  version: '0'
122
123
  required_rubygems_version: !ruby/object:Gem::Requirement
123
124
  requirements:
124
- - - '>='
125
+ - - ">="
125
126
  - !ruby/object:Gem::Version
126
127
  version: '0'
127
128
  requirements: []
@@ -145,6 +146,7 @@ test_files:
145
146
  - spec/shared_examples/coercible_columns.rb
146
147
  - spec/shared_examples/constructor.rb
147
148
  - spec/shared_examples/defaults.rb
149
+ - spec/shared_examples/dupable.rb
148
150
  - spec/shared_examples/mass_assignment.rb
149
151
  - spec/spec_helper.rb
150
152
  - spec/support/database.rb