active_type 0.4.5 → 0.7.5
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/.gitignore +1 -0
- data/.rspec +1 -0
- data/.travis.yml +30 -24
- data/CHANGELOG.md +73 -2
- data/README.md +56 -11
- data/Rakefile +22 -1
- data/active_type.gemspec +2 -1
- data/gemfiles/Gemfile.3.2.mysql2 +1 -0
- data/gemfiles/Gemfile.3.2.mysql2.lock +4 -2
- data/gemfiles/Gemfile.3.2.sqlite3 +1 -0
- data/gemfiles/Gemfile.3.2.sqlite3.lock +4 -2
- data/gemfiles/Gemfile.4.0.sqlite3 +1 -0
- data/gemfiles/Gemfile.4.0.sqlite3.lock +4 -2
- data/gemfiles/Gemfile.4.1.sqlite3 +1 -0
- data/gemfiles/Gemfile.4.1.sqlite3.lock +4 -2
- data/gemfiles/Gemfile.4.2.1.mysql2 +1 -0
- data/gemfiles/Gemfile.4.2.1.mysql2.lock +4 -2
- data/gemfiles/Gemfile.4.2.1.pg +1 -0
- data/gemfiles/Gemfile.4.2.1.pg.lock +4 -2
- data/gemfiles/Gemfile.4.2.1.sqlite3 +1 -0
- data/gemfiles/Gemfile.4.2.1.sqlite3.lock +4 -2
- data/gemfiles/Gemfile.5.0.0.mysql2.lock +56 -0
- data/gemfiles/Gemfile.5.0.0.pg.lock +56 -0
- data/gemfiles/Gemfile.5.0.0.sqlite3 +8 -0
- data/gemfiles/Gemfile.5.0.0.sqlite3.lock +56 -0
- data/gemfiles/Gemfile.5.1.0.mysql2 +8 -0
- data/gemfiles/Gemfile.5.1.0.mysql2.lock +56 -0
- data/gemfiles/Gemfile.5.1.0.pg +8 -0
- data/gemfiles/Gemfile.5.1.0.pg.lock +56 -0
- data/gemfiles/Gemfile.5.1.0.sqlite3 +8 -0
- data/gemfiles/Gemfile.5.1.0.sqlite3.lock +56 -0
- data/lib/active_type/extended_record/inheritance.rb +41 -6
- data/lib/active_type/nested_attributes/association.rb +13 -4
- data/lib/active_type/nested_attributes/builder.rb +3 -3
- data/lib/active_type/nested_attributes/nests_many_association.rb +5 -1
- data/lib/active_type/nested_attributes/nests_one_association.rb +3 -2
- data/lib/active_type/no_table.rb +129 -42
- data/lib/active_type/type_caster.rb +66 -25
- data/lib/active_type/util.rb +21 -6
- data/lib/active_type/version.rb +1 -1
- data/lib/active_type/virtual_attributes.rb +23 -1
- data/lib/active_type.rb +13 -3
- metadata +16 -55
- data/spec/active_type/extended_record/single_table_inheritance_spec.rb +0 -62
- data/spec/active_type/extended_record_spec.rb +0 -233
- data/spec/active_type/nested_attributes_spec.rb +0 -700
- data/spec/active_type/object_spec.rb +0 -400
- data/spec/active_type/record_spec.rb +0 -236
- data/spec/active_type/util_spec.rb +0 -128
- data/spec/integration/holidays_spec.rb +0 -102
- data/spec/integration/shape_spec.rb +0 -110
- data/spec/integration/sign_in_spec.rb +0 -101
- data/spec/integration/sign_up_spec.rb +0 -102
- data/spec/shared_examples/accessors.rb +0 -41
- data/spec/shared_examples/belongs_to.rb +0 -17
- data/spec/shared_examples/coercible_columns.rb +0 -228
- data/spec/shared_examples/constructor.rb +0 -30
- data/spec/shared_examples/defaults.rb +0 -60
- data/spec/shared_examples/dirty_tracking.rb +0 -40
- data/spec/shared_examples/dupable.rb +0 -31
- data/spec/shared_examples/mass_assignment.rb +0 -26
- data/spec/spec_helper.rb +0 -27
- data/spec/support/database.rb +0 -55
- data/spec/support/database.sample.yml +0 -3
- data/spec/support/error_on.rb +0 -12
- data/spec/support/i18n.rb +0 -1
- data/spec/support/protected_params.rb +0 -20
- data/spec/support/time_zone.rb +0 -1
@@ -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
|