active_type 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -0
  3. data/active_type.gemspec +1 -1
  4. data/gemfiles/Gemfile.3.2.mysql2.lock +1 -1
  5. data/gemfiles/Gemfile.3.2.sqlite3.lock +1 -1
  6. data/gemfiles/Gemfile.4.0.sqlite3.lock +1 -1
  7. data/gemfiles/Gemfile.4.1.sqlite3.lock +1 -1
  8. data/gemfiles/Gemfile.4.2.1.mysql2.lock +1 -1
  9. data/gemfiles/Gemfile.4.2.1.pg.lock +1 -1
  10. data/gemfiles/Gemfile.4.2.1.sqlite3.lock +1 -1
  11. data/gemfiles/Gemfile.5.0.0.mysql2.lock +1 -1
  12. data/gemfiles/Gemfile.5.0.0.pg.lock +1 -1
  13. data/gemfiles/Gemfile.5.0.0.sqlite3.lock +1 -1
  14. data/lib/active_type/version.rb +1 -1
  15. metadata +3 -53
  16. data/spec/active_type/extended_record/single_table_inheritance_spec.rb +0 -62
  17. data/spec/active_type/extended_record_spec.rb +0 -233
  18. data/spec/active_type/nested_attributes_spec.rb +0 -704
  19. data/spec/active_type/object_spec.rb +0 -463
  20. data/spec/active_type/record_spec.rb +0 -274
  21. data/spec/active_type/util_spec.rb +0 -142
  22. data/spec/integration/holidays_spec.rb +0 -102
  23. data/spec/integration/shape_spec.rb +0 -110
  24. data/spec/integration/sign_in_spec.rb +0 -101
  25. data/spec/integration/sign_up_spec.rb +0 -102
  26. data/spec/shared_examples/accessors.rb +0 -24
  27. data/spec/shared_examples/belongs_to.rb +0 -17
  28. data/spec/shared_examples/coercible_columns.rb +0 -248
  29. data/spec/shared_examples/constructor.rb +0 -30
  30. data/spec/shared_examples/defaults.rb +0 -60
  31. data/spec/shared_examples/dirty_tracking.rb +0 -40
  32. data/spec/shared_examples/dupable.rb +0 -31
  33. data/spec/shared_examples/mass_assignment.rb +0 -26
  34. data/spec/spec_helper.rb +0 -28
  35. data/spec/support/database.rb +0 -53
  36. data/spec/support/database.sample.yml +0 -3
  37. data/spec/support/error_on.rb +0 -12
  38. data/spec/support/i18n.rb +0 -1
  39. data/spec/support/protected_params.rb +0 -20
  40. data/spec/support/time_zone.rb +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b973cce18664ad143d834c1ab76a67560a7d7625
4
- data.tar.gz: 8de998fb74cc5a6bc9217b072461ac293cf83951
3
+ metadata.gz: 92c728f619a6d8e84a202bb91649085ebf7af041
4
+ data.tar.gz: ebdfd555c423a97ac64092948b5b1fae8523f1ea
5
5
  SHA512:
6
- metadata.gz: 28e1d976f66a72868ce6321a589235bb1536accd6b01fb5312f337d76ad191e3542b324e98e1b640e2718a45b8e423bdae5b1512e75fe50bc3896381bcae4f55
7
- data.tar.gz: 1582cff084f91960662efda6b38ce5fa8d5ff4379e11a5b3181b64f70f1021b5b3074ea33c867a362942ae912ca4bcbba942daf53db1874f6548b3daf6b439e3
6
+ metadata.gz: f1cbed5159da5c1b41e18da5c3656c5a2d2ccef766e317e25272fa7212cd17671754614c1b7ecf2648547808bc23001aa69a4112227348490deacfcc15ea8438
7
+ data.tar.gz: ba963a430fc2d990c7bfc566d63adbdccbcf60f95dc65d504428c05b4313dad3c8af98c408654a34660030a571a8a50bf989d5a9ae1bcbb79c7a78fe6619f840
data/README.md CHANGED
@@ -164,6 +164,27 @@ SignIn.new(email: "tobias@example.org").nickname # "tobias"
164
164
  SignIn.new(email: "tobias@example.org", :nickname => "kratob").nickname # "kratob"
165
165
  ```
166
166
 
167
+ ### Overriding accessors
168
+
169
+ You can override attribute getters and setters using `super`:
170
+
171
+ ```
172
+ class SignIn < ActiveType::Object
173
+
174
+ attribute :email, :string
175
+ attribute :nickname, :string
176
+
177
+ def email
178
+ super.downcase
179
+ end
180
+
181
+ def nickname=(value)
182
+ super(value.titeleize)
183
+ end
184
+
185
+ end
186
+ ```
187
+
167
188
  ### Nested attributes
168
189
 
169
190
  ActiveType supports its own variant of nested attributes via the `nests_one` /
data/active_type.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.description = s.summary
12
12
  s.license = 'MIT'
13
13
 
14
- s.files = `git ls-files -z`.split("\x0")
14
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
15
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
16
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
17
17
  s.require_paths = ["lib"]
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- active_type (0.6.0)
4
+ active_type (0.6.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.6.0)
4
+ active_type (0.6.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.6.0)
4
+ active_type (0.6.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.6.0)
4
+ active_type (0.6.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.6.0)
4
+ active_type (0.6.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.6.0)
4
+ active_type (0.6.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.6.0)
4
+ active_type (0.6.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.6.0)
4
+ active_type (0.6.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.6.0)
4
+ active_type (0.6.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.6.0)
4
+ active_type (0.6.1)
5
5
  activerecord (>= 3.2)
6
6
 
7
7
  GEM
@@ -1,3 +1,3 @@
1
1
  module ActiveType
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.1'
3
3
  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.6.0
4
+ version: 0.6.1
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-07-05 00:00:00.000000000 Z
12
+ date: 2016-12-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -103,31 +103,6 @@ files:
103
103
  - lib/active_type/util.rb
104
104
  - lib/active_type/version.rb
105
105
  - lib/active_type/virtual_attributes.rb
106
- - spec/active_type/extended_record/single_table_inheritance_spec.rb
107
- - spec/active_type/extended_record_spec.rb
108
- - spec/active_type/nested_attributes_spec.rb
109
- - spec/active_type/object_spec.rb
110
- - spec/active_type/record_spec.rb
111
- - spec/active_type/util_spec.rb
112
- - spec/integration/holidays_spec.rb
113
- - spec/integration/shape_spec.rb
114
- - spec/integration/sign_in_spec.rb
115
- - spec/integration/sign_up_spec.rb
116
- - spec/shared_examples/accessors.rb
117
- - spec/shared_examples/belongs_to.rb
118
- - spec/shared_examples/coercible_columns.rb
119
- - spec/shared_examples/constructor.rb
120
- - spec/shared_examples/defaults.rb
121
- - spec/shared_examples/dirty_tracking.rb
122
- - spec/shared_examples/dupable.rb
123
- - spec/shared_examples/mass_assignment.rb
124
- - spec/spec_helper.rb
125
- - spec/support/database.rb
126
- - spec/support/database.sample.yml
127
- - spec/support/error_on.rb
128
- - spec/support/i18n.rb
129
- - spec/support/protected_params.rb
130
- - spec/support/time_zone.rb
131
106
  homepage: https://github.com/makandra/active_type
132
107
  licenses:
133
108
  - MIT
@@ -152,29 +127,4 @@ rubygems_version: 2.4.5.1
152
127
  signing_key:
153
128
  specification_version: 4
154
129
  summary: Make any Ruby object quack like ActiveRecord
155
- test_files:
156
- - spec/active_type/extended_record/single_table_inheritance_spec.rb
157
- - spec/active_type/extended_record_spec.rb
158
- - spec/active_type/nested_attributes_spec.rb
159
- - spec/active_type/object_spec.rb
160
- - spec/active_type/record_spec.rb
161
- - spec/active_type/util_spec.rb
162
- - spec/integration/holidays_spec.rb
163
- - spec/integration/shape_spec.rb
164
- - spec/integration/sign_in_spec.rb
165
- - spec/integration/sign_up_spec.rb
166
- - spec/shared_examples/accessors.rb
167
- - spec/shared_examples/belongs_to.rb
168
- - spec/shared_examples/coercible_columns.rb
169
- - spec/shared_examples/constructor.rb
170
- - spec/shared_examples/defaults.rb
171
- - spec/shared_examples/dirty_tracking.rb
172
- - spec/shared_examples/dupable.rb
173
- - spec/shared_examples/mass_assignment.rb
174
- - spec/spec_helper.rb
175
- - spec/support/database.rb
176
- - spec/support/database.sample.yml
177
- - spec/support/error_on.rb
178
- - spec/support/i18n.rb
179
- - spec/support/protected_params.rb
180
- - spec/support/time_zone.rb
130
+ test_files: []
@@ -1,62 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module STISpec
4
-
5
- class Parent < ActiveRecord::Base
6
- self.table_name = 'sti_records'
7
- end
8
-
9
- class Child < Parent
10
- end
11
-
12
- class ExtendedChild < ActiveType::Record[Child]
13
- end
14
-
15
- class ExtendedExtendedChild < ActiveType::Record[ExtendedChild]
16
- end
17
-
18
- end
19
-
20
-
21
- describe 'ActiveType::Record[STIModel]' do
22
-
23
- describe 'persistence' do
24
-
25
- def should_save_and_load(save_as, load_as)
26
- record = save_as.new(:persisted_string => "string")
27
- expect(record.save).to eq(true)
28
-
29
- reloaded_child = load_as.find(record.id)
30
- expect(reloaded_child.persisted_string).to eq("string")
31
- expect(reloaded_child).to be_a(load_as)
32
- end
33
-
34
- it 'can save and load the active type record' do
35
-
36
- should_save_and_load(STISpec::ExtendedChild, STISpec::ExtendedChild)
37
- end
38
-
39
- it 'can save as base and load as active type record' do
40
- should_save_and_load(STISpec::Child, STISpec::ExtendedChild)
41
- end
42
-
43
- it 'can save as active type and load as base record' do
44
- should_save_and_load(STISpec::ExtendedChild, STISpec::Child)
45
- end
46
-
47
- it 'can load via the base class and convert to active type record' do
48
- record = STISpec::ExtendedChild.new(:persisted_string => "string")
49
- expect(record.save).to eq(true)
50
-
51
- reloaded_child = STISpec::Child.find(record.id).becomes(STISpec::ExtendedChild)
52
- expect(reloaded_child.persisted_string).to eq("string")
53
- expect(reloaded_child).to be_a(STISpec::ExtendedChild)
54
- end
55
-
56
- it 'can save classes further down the inheritance tree' do
57
- should_save_and_load(STISpec::ExtendedExtendedChild, STISpec::ExtendedExtendedChild)
58
- end
59
-
60
- end
61
-
62
- end
@@ -1,233 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module ExtendedRecordSpec
4
-
5
- class BaseRecord < ActiveRecord::Base
6
- self.table_name = 'records'
7
- end
8
-
9
- class BaseActiveTypeRecord < ActiveType::Record
10
- self.table_name = 'records'
11
-
12
- attribute :virtual_string, :string
13
- end
14
-
15
- class ExtendedRecord < ActiveType::Record[BaseRecord]
16
- attribute :another_virtual_string, :string
17
- end
18
-
19
- class ExtendedActiveTypeRecord < ActiveType::Record[BaseActiveTypeRecord]
20
- attribute :another_virtual_string, :string
21
- end
22
-
23
- class InheritingFromExtendedRecord < ExtendedRecord
24
- attribute :yet_another_virtual_string, :string
25
- end
26
-
27
- class ExtendedRecordWithValidations < ExtendedActiveTypeRecord
28
- validates :persisted_string, :presence => true
29
- validates :virtual_string, :presence => true
30
- validates :another_virtual_string, :presence => true
31
- end
32
-
33
- end
34
-
35
-
36
- describe "ActiveType::Record[ActiveRecord::Base]" do
37
-
38
- subject { ExtendedRecordSpec::ExtendedRecord.new }
39
-
40
- it 'is inherits from the base type' do
41
- expect(subject).to be_a(ExtendedRecordSpec::BaseRecord)
42
- end
43
-
44
- it 'has the same model name as the base class' do
45
- expect(subject.class.model_name.singular).to eq(ExtendedRecordSpec::BaseRecord.model_name.singular)
46
- end
47
-
48
- describe 'constructors' do
49
- subject { ExtendedRecordSpec::ExtendedRecord }
50
-
51
- it_should_behave_like 'ActiveRecord-like constructors', { :persisted_string => "persisted string", :another_virtual_string => "another virtual string" }
52
- end
53
-
54
- describe '#attributes' do
55
-
56
- it 'returns a hash of virtual and persisted attributes' do
57
- subject.persisted_string = "string"
58
- subject.another_virtual_string = "string"
59
-
60
- expect(subject.attributes).to eq({
61
- "another_virtual_string" => "string",
62
- "id" => nil,
63
- "persisted_string" => "string",
64
- "persisted_integer" => nil,
65
- "persisted_time" => nil,
66
- "persisted_date" => nil,
67
- "persisted_boolean" => nil
68
- })
69
- end
70
-
71
- end
72
-
73
- describe 'accessors' do
74
- it_should_behave_like 'ActiveRecord-like accessors', { :persisted_string => "persisted string", :another_virtual_string => "another virtual string" }
75
- end
76
-
77
- describe 'persistence' do
78
- it 'persists to the database' do
79
- subject.persisted_string = "persisted string"
80
- expect(subject.save).to eq(true)
81
-
82
- expect(subject.class.find(subject.id).persisted_string).to eq("persisted string")
83
- end
84
- end
85
-
86
- describe '.find' do
87
- it 'returns an instance of the extended model' do
88
- subject.save
89
-
90
- expect(subject.class.find(subject.id)).to be_a(subject.class)
91
- end
92
- end
93
-
94
- describe '.base_class' do
95
- it 'is the base class inherited from' do
96
- expect(subject.class.base_class).to eq(ExtendedRecordSpec::BaseRecord)
97
- end
98
- end
99
-
100
- end
101
-
102
- describe "class ... < ActiveType::Record[ActiveRecord::Base]" do
103
-
104
- subject { ExtendedRecordSpec::InheritingFromExtendedRecord.new }
105
-
106
- it 'is inherits from the base type' do
107
- expect(subject).to be_a(ExtendedRecordSpec::ExtendedRecord)
108
- end
109
-
110
- it 'has the same model name as the base class' do
111
- expect(subject.class.model_name.singular).to eq(ExtendedRecordSpec::BaseRecord.model_name.singular)
112
- end
113
-
114
- describe '#attributes' do
115
-
116
- it 'returns a hash of virtual and persisted attributes' do
117
- subject.persisted_string = "string"
118
- subject.another_virtual_string = "string"
119
- subject.yet_another_virtual_string = "string"
120
-
121
- expect(subject.attributes).to eq({
122
- "another_virtual_string" => "string",
123
- "yet_another_virtual_string" => "string",
124
- "id" => nil,
125
- "persisted_string" => "string",
126
- "persisted_integer" => nil,
127
- "persisted_time" => nil,
128
- "persisted_date" => nil,
129
- "persisted_boolean" => nil
130
- })
131
- end
132
-
133
- end
134
-
135
- describe 'persistence' do
136
- it 'persists to the database' do
137
- subject.persisted_string = "persisted string"
138
- expect(subject.save).to eq(true)
139
-
140
- expect(subject.class.find(subject.id).persisted_string).to eq("persisted string")
141
- end
142
- end
143
-
144
- describe '.find' do
145
- it 'returns an instance of the inheriting model' do
146
- subject.save
147
-
148
- expect(subject.class.find(subject.id)).to be_a(subject.class)
149
- end
150
- end
151
-
152
- end
153
-
154
- describe "ActiveType::Record[ActiveType::Record]" do
155
-
156
- subject { ExtendedRecordSpec::ExtendedActiveTypeRecord.new }
157
-
158
- it 'is inherits from the base type' do
159
- expect(subject).to be_a(ExtendedRecordSpec::BaseActiveTypeRecord)
160
- end
161
-
162
- it 'has the same model name as the base class' do
163
- expect(subject.class.model_name.singular).to eq(ExtendedRecordSpec::BaseActiveTypeRecord.model_name.singular)
164
- end
165
-
166
- describe 'constructors' do
167
- subject { ExtendedRecordSpec::ExtendedActiveTypeRecord }
168
-
169
- it_should_behave_like 'ActiveRecord-like constructors', { :persisted_string => "persisted string", :virtual_string => "virtual string", :another_virtual_string => "another virtual string" }
170
- end
171
-
172
- describe '#attributes' do
173
-
174
- it 'returns a hash of virtual and persisted attributes' do
175
- subject.persisted_string = "string"
176
- subject.virtual_string = "string"
177
-
178
- expect(subject.attributes).to eq({
179
- "virtual_string" => "string",
180
- "another_virtual_string" => nil,
181
- "id" => nil,
182
- "persisted_string" => "string",
183
- "persisted_integer" => nil,
184
- "persisted_time" => nil,
185
- "persisted_date" => nil,
186
- "persisted_boolean" => nil
187
- })
188
- end
189
-
190
- end
191
-
192
- describe 'accessors' do
193
- it_should_behave_like 'ActiveRecord-like accessors', { :persisted_string => "persisted string", :virtual_string => "virtual string", :another_virtual_string => "another virtual string" }
194
- end
195
-
196
- describe 'validations' do
197
- subject { ExtendedRecordSpec::ExtendedRecordWithValidations.new }
198
-
199
- it 'has 1 error_on' do
200
- expect(subject.error_on(:persisted_string).size).to eq(1)
201
- end
202
- it 'has 1 error_on' do
203
- expect(subject.error_on(:virtual_string).size).to eq(1)
204
- end
205
- it 'has 1 error_on' do
206
- expect(subject.error_on(:another_virtual_string).size).to eq(1)
207
- end
208
- end
209
-
210
- describe 'persistence' do
211
- it 'persists to the database' do
212
- subject.persisted_string = "persisted string"
213
- expect(subject.save).to eq(true)
214
-
215
- expect(subject.class.find(subject.id).persisted_string).to eq("persisted string")
216
- end
217
- end
218
-
219
- describe '.find' do
220
- it 'returns an instance of the extended model' do
221
- subject.save
222
-
223
- expect(subject.class.find(subject.id)).to be_a(subject.class)
224
- end
225
- end
226
-
227
- describe '.base_class' do
228
- it 'is the base class inherited from' do
229
- expect(subject.class.base_class).to eq(ExtendedRecordSpec::BaseActiveTypeRecord)
230
- end
231
- end
232
-
233
- end