active_data 0.1.0 → 0.2.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.
- data/.rspec +1 -0
- data/.travis.yml +1 -1
- data/Gemfile +5 -7
- data/Guardfile +8 -3
- data/active_data.gemspec +2 -2
- data/lib/active_data/attributes/base.rb +10 -5
- data/lib/active_data/attributes/localized.rb +1 -1
- data/lib/active_data/model/associations/{many.rb → association.rb} +9 -3
- data/lib/active_data/model/associations/embeds_many.rb +33 -0
- data/lib/active_data/model/associations/embeds_one.rb +30 -0
- data/lib/active_data/model/associations.rb +19 -22
- data/lib/active_data/model/attributable.rb +35 -29
- data/lib/active_data/model/collectionizable.rb +13 -12
- data/lib/active_data/model/extensions/array.rb +3 -3
- data/lib/active_data/model/extensions/big_decimal.rb +2 -2
- data/lib/active_data/model/extensions/date.rb +1 -8
- data/lib/active_data/model/extensions/date_time.rb +17 -0
- data/lib/active_data/model/extensions/float.rb +1 -1
- data/lib/active_data/model/extensions/hash.rb +1 -1
- data/lib/active_data/model/extensions/integer.rb +1 -1
- data/lib/active_data/model/extensions/localized.rb +2 -2
- data/lib/active_data/model/extensions/object.rb +17 -0
- data/lib/active_data/model/extensions/time.rb +17 -0
- data/lib/active_data/model/localizable.rb +3 -3
- data/lib/active_data/model/nested_attributes.rb +10 -4
- data/lib/active_data/model.rb +17 -11
- data/lib/active_data/validations/associated.rb +17 -0
- data/lib/active_data/validations.rb +7 -0
- data/lib/active_data/version.rb +1 -1
- data/lib/active_data.rb +1 -1
- data/spec/lib/active_data/model/associations/embeds_many_spec.rb +93 -0
- data/spec/lib/active_data/model/associations/embeds_one_spec.rb +57 -0
- data/spec/lib/active_data/model/attributable_spec.rb +118 -2
- data/spec/lib/active_data/model/attributes/localized_spec.rb +1 -0
- data/spec/lib/active_data/model/collectionizable_spec.rb +41 -15
- data/spec/lib/active_data/model/nested_attributes_spec.rb +47 -26
- data/spec/lib/active_data/model/type_cast_spec.rb +31 -3
- data/spec/lib/active_data/model_spec.rb +26 -7
- data/spec/lib/active_data/validations/associated_spec.rb +88 -0
- metadata +27 -16
- data/spec/lib/active_data/model/associations_spec.rb +0 -35
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveData::Validations do
|
4
|
+
let(:main) do
|
5
|
+
Class.new do
|
6
|
+
def self.model_name
|
7
|
+
ActiveModel::Name.new(self, nil, "Main")
|
8
|
+
end
|
9
|
+
|
10
|
+
include ActiveData::Model
|
11
|
+
include ActiveData::Validations
|
12
|
+
|
13
|
+
attribute :name
|
14
|
+
|
15
|
+
validates_presence_of :name
|
16
|
+
validates_associated :validated_one, :unvalidated_one, :validated_many, :unvalidated_many
|
17
|
+
|
18
|
+
embeds_one :validated_one, class_name: ValidatedAssoc
|
19
|
+
embeds_one :unvalidated_one, class_name: UnvalidatedAssoc
|
20
|
+
embeds_many :validated_many, class_name: ValidatedAssoc
|
21
|
+
embeds_many :unvalidated_many, class_name: UnvalidatedAssoc
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class ValidatedAssoc
|
26
|
+
include ActiveData::Model
|
27
|
+
|
28
|
+
attribute :name
|
29
|
+
|
30
|
+
validates_presence_of :name
|
31
|
+
end
|
32
|
+
|
33
|
+
class UnvalidatedAssoc
|
34
|
+
include ActiveData::Model
|
35
|
+
|
36
|
+
attribute :name
|
37
|
+
end
|
38
|
+
|
39
|
+
context do
|
40
|
+
subject(:instance) { main.new name: 'hello', validated_one: { name: 'name' } }
|
41
|
+
it { should be_valid }
|
42
|
+
end
|
43
|
+
|
44
|
+
context do
|
45
|
+
subject(:instance) { main.new name: 'hello', validated_one: { } }
|
46
|
+
it { should_not be_valid }
|
47
|
+
end
|
48
|
+
|
49
|
+
context do
|
50
|
+
subject(:instance) { main.new name: 'hello', unvalidated_one: { name: 'name' } }
|
51
|
+
it { should be_valid }
|
52
|
+
end
|
53
|
+
|
54
|
+
context do
|
55
|
+
subject(:instance) { main.new name: 'hello', unvalidated_one: { } }
|
56
|
+
it { should be_valid }
|
57
|
+
end
|
58
|
+
|
59
|
+
context do
|
60
|
+
subject(:instance) { main.new name: 'hello', validated_many: [{ name: 'name' }] }
|
61
|
+
it { should be_valid }
|
62
|
+
end
|
63
|
+
|
64
|
+
context do
|
65
|
+
subject(:instance) { main.new name: 'hello', validated_many: [{ }] }
|
66
|
+
it { should_not be_valid }
|
67
|
+
end
|
68
|
+
|
69
|
+
context do
|
70
|
+
subject(:instance) { main.new name: 'hello', unvalidated_many: [{ name: 'name' }] }
|
71
|
+
it { should be_valid }
|
72
|
+
end
|
73
|
+
|
74
|
+
context do
|
75
|
+
subject(:instance) { main.new name: 'hello', unvalidated_many: [{ }] }
|
76
|
+
it { should be_valid }
|
77
|
+
end
|
78
|
+
|
79
|
+
context do
|
80
|
+
subject(:instance) { main.new name: 'hello', validated_many: [{ name: 'name' }], validated_one: { } }
|
81
|
+
it { should_not be_valid }
|
82
|
+
end
|
83
|
+
|
84
|
+
context do
|
85
|
+
subject(:instance) { main.new name: 'hello', validated_many: [{ }], validated_one: { name: 'name' } }
|
86
|
+
it { should_not be_valid }
|
87
|
+
end
|
88
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-06-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -48,33 +48,33 @@ dependencies:
|
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
53
|
+
version: '3.0'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '3.0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: activemodel
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
69
|
+
version: '3.0'
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
|
-
- -
|
75
|
+
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
77
|
+
version: '3.0'
|
78
78
|
description: Making object from any hash or hash array
|
79
79
|
email:
|
80
80
|
- kinwizard@gmail.com
|
@@ -97,7 +97,9 @@ files:
|
|
97
97
|
- lib/active_data/attributes/localized.rb
|
98
98
|
- lib/active_data/model.rb
|
99
99
|
- lib/active_data/model/associations.rb
|
100
|
-
- lib/active_data/model/associations/
|
100
|
+
- lib/active_data/model/associations/association.rb
|
101
|
+
- lib/active_data/model/associations/embeds_many.rb
|
102
|
+
- lib/active_data/model/associations/embeds_one.rb
|
101
103
|
- lib/active_data/model/attributable.rb
|
102
104
|
- lib/active_data/model/collectionizable.rb
|
103
105
|
- lib/active_data/model/collectionizable/proxy.rb
|
@@ -106,22 +108,29 @@ files:
|
|
106
108
|
- lib/active_data/model/extensions/big_decimal.rb
|
107
109
|
- lib/active_data/model/extensions/boolean.rb
|
108
110
|
- lib/active_data/model/extensions/date.rb
|
111
|
+
- lib/active_data/model/extensions/date_time.rb
|
109
112
|
- lib/active_data/model/extensions/float.rb
|
110
113
|
- lib/active_data/model/extensions/hash.rb
|
111
114
|
- lib/active_data/model/extensions/integer.rb
|
112
115
|
- lib/active_data/model/extensions/localized.rb
|
116
|
+
- lib/active_data/model/extensions/object.rb
|
113
117
|
- lib/active_data/model/extensions/string.rb
|
118
|
+
- lib/active_data/model/extensions/time.rb
|
114
119
|
- lib/active_data/model/localizable.rb
|
115
120
|
- lib/active_data/model/nested_attributes.rb
|
116
121
|
- lib/active_data/model/parameterizable.rb
|
122
|
+
- lib/active_data/validations.rb
|
123
|
+
- lib/active_data/validations/associated.rb
|
117
124
|
- lib/active_data/version.rb
|
118
|
-
- spec/lib/active_data/model/
|
125
|
+
- spec/lib/active_data/model/associations/embeds_many_spec.rb
|
126
|
+
- spec/lib/active_data/model/associations/embeds_one_spec.rb
|
119
127
|
- spec/lib/active_data/model/attributable_spec.rb
|
120
128
|
- spec/lib/active_data/model/attributes/localized_spec.rb
|
121
129
|
- spec/lib/active_data/model/collectionizable_spec.rb
|
122
130
|
- spec/lib/active_data/model/nested_attributes_spec.rb
|
123
131
|
- spec/lib/active_data/model/type_cast_spec.rb
|
124
132
|
- spec/lib/active_data/model_spec.rb
|
133
|
+
- spec/lib/active_data/validations/associated_spec.rb
|
125
134
|
- spec/spec_helper.rb
|
126
135
|
homepage: ''
|
127
136
|
licenses: []
|
@@ -137,7 +146,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
137
146
|
version: '0'
|
138
147
|
segments:
|
139
148
|
- 0
|
140
|
-
hash:
|
149
|
+
hash: -2124483537595095240
|
141
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
151
|
none: false
|
143
152
|
requirements:
|
@@ -146,19 +155,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
155
|
version: '0'
|
147
156
|
segments:
|
148
157
|
- 0
|
149
|
-
hash:
|
158
|
+
hash: -2124483537595095240
|
150
159
|
requirements: []
|
151
160
|
rubyforge_project:
|
152
|
-
rubygems_version: 1.8.
|
161
|
+
rubygems_version: 1.8.25
|
153
162
|
signing_key:
|
154
163
|
specification_version: 3
|
155
164
|
summary: Working with hashes in AR style
|
156
165
|
test_files:
|
157
|
-
- spec/lib/active_data/model/
|
166
|
+
- spec/lib/active_data/model/associations/embeds_many_spec.rb
|
167
|
+
- spec/lib/active_data/model/associations/embeds_one_spec.rb
|
158
168
|
- spec/lib/active_data/model/attributable_spec.rb
|
159
169
|
- spec/lib/active_data/model/attributes/localized_spec.rb
|
160
170
|
- spec/lib/active_data/model/collectionizable_spec.rb
|
161
171
|
- spec/lib/active_data/model/nested_attributes_spec.rb
|
162
172
|
- spec/lib/active_data/model/type_cast_spec.rb
|
163
173
|
- spec/lib/active_data/model_spec.rb
|
174
|
+
- spec/lib/active_data/validations/associated_spec.rb
|
164
175
|
- spec/spec_helper.rb
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe ActiveData::Model::Associations do
|
5
|
-
|
6
|
-
class Assoc
|
7
|
-
include ActiveData::Model
|
8
|
-
|
9
|
-
attribute :name
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:klass) do
|
13
|
-
Class.new do
|
14
|
-
include ActiveData::Model
|
15
|
-
|
16
|
-
attribute :name
|
17
|
-
embeds_many :assocs
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
let(:instance){klass.new(:name => 'world')}
|
22
|
-
|
23
|
-
context do
|
24
|
-
specify { instance.assocs.should be_empty }
|
25
|
-
specify { instance.assocs.should be_instance_of Assoc::Collection }
|
26
|
-
specify { instance.assocs.count.should == 0 }
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'accessor' do
|
30
|
-
before { instance.assocs = [Assoc.new(:name => 'foo'), Assoc.new(:name => 'bar')] }
|
31
|
-
specify { instance.assocs.count.should == 2 }
|
32
|
-
specify { instance.assocs[0].name.should == 'foo' }
|
33
|
-
specify { instance.assocs[1].name.should == 'bar' }
|
34
|
-
end
|
35
|
-
end
|