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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +30 -24
  5. data/CHANGELOG.md +73 -2
  6. data/README.md +56 -11
  7. data/Rakefile +22 -1
  8. data/active_type.gemspec +2 -1
  9. data/gemfiles/Gemfile.3.2.mysql2 +1 -0
  10. data/gemfiles/Gemfile.3.2.mysql2.lock +4 -2
  11. data/gemfiles/Gemfile.3.2.sqlite3 +1 -0
  12. data/gemfiles/Gemfile.3.2.sqlite3.lock +4 -2
  13. data/gemfiles/Gemfile.4.0.sqlite3 +1 -0
  14. data/gemfiles/Gemfile.4.0.sqlite3.lock +4 -2
  15. data/gemfiles/Gemfile.4.1.sqlite3 +1 -0
  16. data/gemfiles/Gemfile.4.1.sqlite3.lock +4 -2
  17. data/gemfiles/Gemfile.4.2.1.mysql2 +1 -0
  18. data/gemfiles/Gemfile.4.2.1.mysql2.lock +4 -2
  19. data/gemfiles/Gemfile.4.2.1.pg +1 -0
  20. data/gemfiles/Gemfile.4.2.1.pg.lock +4 -2
  21. data/gemfiles/Gemfile.4.2.1.sqlite3 +1 -0
  22. data/gemfiles/Gemfile.4.2.1.sqlite3.lock +4 -2
  23. data/gemfiles/Gemfile.5.0.0.mysql2.lock +56 -0
  24. data/gemfiles/Gemfile.5.0.0.pg.lock +56 -0
  25. data/gemfiles/Gemfile.5.0.0.sqlite3 +8 -0
  26. data/gemfiles/Gemfile.5.0.0.sqlite3.lock +56 -0
  27. data/gemfiles/Gemfile.5.1.0.mysql2 +8 -0
  28. data/gemfiles/Gemfile.5.1.0.mysql2.lock +56 -0
  29. data/gemfiles/Gemfile.5.1.0.pg +8 -0
  30. data/gemfiles/Gemfile.5.1.0.pg.lock +56 -0
  31. data/gemfiles/Gemfile.5.1.0.sqlite3 +8 -0
  32. data/gemfiles/Gemfile.5.1.0.sqlite3.lock +56 -0
  33. data/lib/active_type/extended_record/inheritance.rb +41 -6
  34. data/lib/active_type/nested_attributes/association.rb +13 -4
  35. data/lib/active_type/nested_attributes/builder.rb +3 -3
  36. data/lib/active_type/nested_attributes/nests_many_association.rb +5 -1
  37. data/lib/active_type/nested_attributes/nests_one_association.rb +3 -2
  38. data/lib/active_type/no_table.rb +129 -42
  39. data/lib/active_type/type_caster.rb +66 -25
  40. data/lib/active_type/util.rb +21 -6
  41. data/lib/active_type/version.rb +1 -1
  42. data/lib/active_type/virtual_attributes.rb +23 -1
  43. data/lib/active_type.rb +13 -3
  44. metadata +16 -55
  45. data/spec/active_type/extended_record/single_table_inheritance_spec.rb +0 -62
  46. data/spec/active_type/extended_record_spec.rb +0 -233
  47. data/spec/active_type/nested_attributes_spec.rb +0 -700
  48. data/spec/active_type/object_spec.rb +0 -400
  49. data/spec/active_type/record_spec.rb +0 -236
  50. data/spec/active_type/util_spec.rb +0 -128
  51. data/spec/integration/holidays_spec.rb +0 -102
  52. data/spec/integration/shape_spec.rb +0 -110
  53. data/spec/integration/sign_in_spec.rb +0 -101
  54. data/spec/integration/sign_up_spec.rb +0 -102
  55. data/spec/shared_examples/accessors.rb +0 -41
  56. data/spec/shared_examples/belongs_to.rb +0 -17
  57. data/spec/shared_examples/coercible_columns.rb +0 -228
  58. data/spec/shared_examples/constructor.rb +0 -30
  59. data/spec/shared_examples/defaults.rb +0 -60
  60. data/spec/shared_examples/dirty_tracking.rb +0 -40
  61. data/spec/shared_examples/dupable.rb +0 -31
  62. data/spec/shared_examples/mass_assignment.rb +0 -26
  63. data/spec/spec_helper.rb +0 -27
  64. data/spec/support/database.rb +0 -55
  65. data/spec/support/database.sample.yml +0 -3
  66. data/spec/support/error_on.rb +0 -12
  67. data/spec/support/i18n.rb +0 -1
  68. data/spec/support/protected_params.rb +0 -20
  69. 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