ardm 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/Gemfile +1 -2
- data/LICENSE +2 -2
- data/README.md +72 -16
- data/ardm.gemspec +1 -0
- data/lib/ardm.rb +2 -1
- data/lib/ardm/active_record.rb +8 -1
- data/lib/ardm/active_record/associations.rb +33 -4
- data/lib/ardm/active_record/base.rb +2 -0
- data/lib/ardm/active_record/collection.rb +5 -0
- data/lib/ardm/active_record/data_mapper_constant.rb +1 -0
- data/lib/ardm/active_record/data_mapper_constant_proxy.rb +24 -0
- data/lib/ardm/active_record/finalize.rb +18 -0
- data/lib/ardm/active_record/predicate_builder/array_handler.rb +10 -16
- data/lib/ardm/active_record/predicate_builder/rails3.rb +42 -15
- data/lib/ardm/active_record/predicate_builder/rails4.rb +39 -13
- data/lib/ardm/active_record/property.rb +24 -12
- data/lib/ardm/active_record/query.rb +9 -18
- data/lib/ardm/active_record/record.rb +54 -11
- data/lib/ardm/active_record/relation.rb +36 -6
- data/lib/ardm/active_record/repository.rb +6 -2
- data/lib/ardm/data_mapper.rb +2 -0
- data/lib/ardm/data_mapper/record.rb +3 -9
- data/lib/ardm/version.rb +1 -1
- data/spec/ardm/datamapper_constants_spec.rb +31 -0
- data/spec/fixtures/article.rb +2 -0
- data/spec/integration/api_key_spec.rb +3 -3
- data/spec/integration/bcrypt_hash_spec.rb +7 -7
- data/spec/integration/comma_separated_list_spec.rb +11 -11
- data/spec/integration/dirty_minder_spec.rb +23 -39
- data/spec/integration/enum_spec.rb +11 -11
- data/spec/integration/epoch_time_spec.rb +6 -6
- data/spec/integration/file_path_spec.rb +23 -23
- data/spec/integration/flag_spec.rb +11 -13
- data/spec/integration/ip_address_spec.rb +15 -15
- data/spec/integration/json_spec.rb +7 -7
- data/spec/integration/slug_spec.rb +6 -6
- data/spec/integration/uri_spec.rb +11 -11
- data/spec/integration/uuid_spec.rb +16 -16
- data/spec/integration/yaml_spec.rb +8 -8
- data/spec/public/model_spec.rb +193 -0
- data/spec/public/property/binary_spec.rb +4 -4
- data/spec/public/property/boolean_spec.rb +3 -3
- data/spec/public/property/class_spec.rb +2 -2
- data/spec/public/property/date_spec.rb +2 -2
- data/spec/public/property/date_time_spec.rb +2 -2
- data/spec/public/property/decimal_spec.rb +2 -2
- data/spec/public/property/discriminator_spec.rb +21 -20
- data/spec/public/property/float_spec.rb +2 -2
- data/spec/public/property/integer_spec.rb +2 -2
- data/spec/public/property/object_spec.rb +14 -13
- data/spec/public/property/serial_spec.rb +2 -2
- data/spec/public/property/string_spec.rb +2 -2
- data/spec/public/property/text_spec.rb +2 -2
- data/spec/public/property/time_spec.rb +2 -2
- data/spec/public/property_spec.rb +44 -48
- data/spec/public/resource_spec.rb +278 -0
- data/spec/schema.rb +33 -4
- data/spec/semipublic/property/boolean_spec.rb +5 -5
- data/spec/semipublic/property/class_spec.rb +3 -3
- data/spec/semipublic/property/date_spec.rb +8 -8
- data/spec/semipublic/property/date_time_spec.rb +9 -9
- data/spec/semipublic/property/decimal_spec.rb +16 -16
- data/spec/semipublic/property/float_spec.rb +16 -16
- data/spec/semipublic/property/integer_spec.rb +16 -16
- data/spec/semipublic/property/lookup_spec.rb +4 -4
- data/spec/semipublic/property/text_spec.rb +2 -2
- data/spec/semipublic/property/time_spec.rb +10 -10
- data/spec/semipublic/property_spec.rb +4 -4
- data/spec/shared/finder_shared_spec.rb +1151 -0
- data/spec/shared/flags_shared_spec.rb +6 -6
- data/spec/shared/identity_function_group.rb +1 -1
- data/spec/shared/public_property_spec.rb +26 -25
- data/spec/shared/resource_spec.rb +1218 -0
- data/spec/shared/semipublic_property_spec.rb +23 -22
- data/spec/spec_helper.rb +17 -0
- data/spec/unit/bcrypt_hash_spec.rb +15 -15
- data/spec/unit/csv_spec.rb +11 -11
- data/spec/unit/dirty_minder_spec.rb +3 -5
- data/spec/unit/enum_spec.rb +17 -17
- data/spec/unit/epoch_time_spec.rb +8 -8
- data/spec/unit/file_path_spec.rb +9 -9
- data/spec/unit/flag_spec.rb +9 -9
- data/spec/unit/ip_address_spec.rb +9 -9
- data/spec/unit/json_spec.rb +11 -11
- data/spec/unit/paranoid_boolean_spec.rb +19 -17
- data/spec/unit/paranoid_datetime_spec.rb +21 -19
- data/spec/unit/regexp_spec.rb +4 -4
- data/spec/unit/uri_spec.rb +8 -8
- data/spec/unit/yaml_spec.rb +9 -9
- metadata +35 -27
- data/lib/ardm/active_record/not_found.rb +0 -7
- data/lib/ardm/data_mapper/not_found.rb +0 -5
@@ -0,0 +1,193 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ::ModelBlog
|
4
|
+
# FIXME: load order in tests is being problematic
|
5
|
+
class ArticlePublication < Ardm::Record
|
6
|
+
end
|
7
|
+
|
8
|
+
class Article < Ardm::Record
|
9
|
+
self.table_name = "articles"
|
10
|
+
|
11
|
+
property :id, Serial
|
12
|
+
property :title, String, :required => true, :default => 'Default Title'
|
13
|
+
property :body, Text
|
14
|
+
timestamps :at
|
15
|
+
|
16
|
+
belongs_to :original, self, :required => false
|
17
|
+
has n, :revisions, self, :child_key => [ :original_id ]
|
18
|
+
has 1, :previous, self, :child_key => [ :original_id ], :order => [ :id.desc ]
|
19
|
+
has n, :article_publications, model: ::ModelBlog::ArticlePublication
|
20
|
+
has n, :publications, :through => :article_publications
|
21
|
+
end
|
22
|
+
|
23
|
+
class Publication < Ardm::Record
|
24
|
+
self.table_name = "api_users" # same set of fields, so even though it's a little weird, I'm going to reuse for now.
|
25
|
+
|
26
|
+
property :id, Serial
|
27
|
+
property :name, String
|
28
|
+
|
29
|
+
has n, :article_publications, model: ::ModelBlog::ArticlePublication
|
30
|
+
has n, :acticles, :through => :article_publications
|
31
|
+
end
|
32
|
+
|
33
|
+
class ArticlePublication < Ardm::Record
|
34
|
+
self.table_name = "article_publications"
|
35
|
+
|
36
|
+
belongs_to :acticle, model: '::ModelBlog::Article'
|
37
|
+
belongs_to :publication, model: '::ModelBlog::Publication'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'Ardm::Record' do
|
42
|
+
before do
|
43
|
+
@article_model = ModelBlog::Article
|
44
|
+
@publication_model = ModelBlog::Publication
|
45
|
+
end
|
46
|
+
|
47
|
+
def model?; true end
|
48
|
+
|
49
|
+
before do
|
50
|
+
@articles = @article_model
|
51
|
+
|
52
|
+
@original = @articles.create(:title => 'Original Article')
|
53
|
+
@article = @articles.create(:title => 'Sample Article', :body => 'Sample', :original => @original)
|
54
|
+
@other = @articles.create(:title => 'Other Article', :body => 'Other')
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#new' do
|
58
|
+
subject { model.new(*args) }
|
59
|
+
|
60
|
+
let(:model) { @article_model }
|
61
|
+
|
62
|
+
context 'with no arguments' do
|
63
|
+
let(:args) { [] }
|
64
|
+
|
65
|
+
it { is_expected.to be_instance_of(model) }
|
66
|
+
|
67
|
+
it { expect(subject.title).to eq('Default Title') }
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'with an empty Hash' do
|
71
|
+
let(:args) { [ {} ] }
|
72
|
+
|
73
|
+
it { is_expected.to be_instance_of(model) }
|
74
|
+
|
75
|
+
it { expect(subject.title).to eq('Default Title') }
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'with a non-empty Hash' do
|
79
|
+
let(:attributes) { { :title => 'A Title' } }
|
80
|
+
let(:args) { [ attributes ] }
|
81
|
+
|
82
|
+
it { is_expected.to be_instance_of(model) }
|
83
|
+
|
84
|
+
it { expect(subject.title).to eq('A Title') }
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'with nil' do
|
88
|
+
let(:args) { [ nil ] }
|
89
|
+
|
90
|
+
it { is_expected.to be_instance_of(model) }
|
91
|
+
|
92
|
+
it { expect(subject.title).to eq('Default Title') }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
[ :create, :create! ].each do |method|
|
97
|
+
describe "##{method}" do
|
98
|
+
subject { model.send(method, *args) }
|
99
|
+
|
100
|
+
let(:model) { @article_model }
|
101
|
+
|
102
|
+
context 'with no arguments' do
|
103
|
+
let(:args) { [] }
|
104
|
+
|
105
|
+
it { is_expected.to be_instance_of(model) }
|
106
|
+
|
107
|
+
it { is_expected.to be_saved }
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'with an empty Hash' do
|
111
|
+
let(:args) { [ {} ] }
|
112
|
+
|
113
|
+
it { is_expected.to be_instance_of(model) }
|
114
|
+
|
115
|
+
it { is_expected.to be_saved }
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'with a non-empty Hash' do
|
119
|
+
let(:attributes) { { :title => 'A Title' } }
|
120
|
+
let(:args) { [ attributes ] }
|
121
|
+
|
122
|
+
it { is_expected.to be_instance_of(model) }
|
123
|
+
|
124
|
+
it { is_expected.to be_saved }
|
125
|
+
|
126
|
+
it { expect(subject.title).to eq attributes[:title] }
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'with nil' do
|
130
|
+
let(:args) { [ nil ] }
|
131
|
+
|
132
|
+
it { is_expected.to be_instance_of(model) }
|
133
|
+
|
134
|
+
it { is_expected.to be_saved }
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
[ :destroy, :destroy! ].each do |method|
|
140
|
+
describe "##{method}" do
|
141
|
+
it 'should remove all resources', pending: true do
|
142
|
+
expect { @article_model.send(method) }.to change { @article_model.any? }.from(true).to(false)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
[ :update, :update! ].each do |method|
|
148
|
+
describe "##{method}" do
|
149
|
+
subject { model.send(method, *args) }
|
150
|
+
|
151
|
+
let(:model) { @article_model }
|
152
|
+
|
153
|
+
context 'with attributes' do
|
154
|
+
let(:attributes) { { :title => 'Updated Title' } }
|
155
|
+
let(:args) { [ attributes ] }
|
156
|
+
|
157
|
+
it { is_expected.to be(true) }
|
158
|
+
|
159
|
+
it 'should persist the changes' do
|
160
|
+
subject
|
161
|
+
expect(model.all(:fields => [ :title ]).map { |resource| resource.title }.uniq).to eq([ attributes[:title] ])
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'with attributes where one is a parent association' do
|
166
|
+
let(:attributes) { { :original => @other } }
|
167
|
+
let(:args) { [ attributes ] }
|
168
|
+
|
169
|
+
it { is_expected.to be(true) }
|
170
|
+
|
171
|
+
it 'should persist the changes' do
|
172
|
+
subject
|
173
|
+
expect(model.all(:fields => [ :original_id ]).map { |resource| resource.original }.uniq).to eq([ attributes[:original] ])
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'with attributes where a required property is nil' do
|
178
|
+
let(:attributes) { { :title => nil } }
|
179
|
+
let(:args) { [ attributes ] }
|
180
|
+
|
181
|
+
it 'should raise InvalidValueError' do
|
182
|
+
expect { subject }.to(raise_error(Ardm::Property::InvalidValueError) do |error|
|
183
|
+
expect(error.property).to eq(model.properties[:title])
|
184
|
+
end)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
# FIXME: these are very broken right now
|
191
|
+
#it_should_behave_like 'Finder Interface'
|
192
|
+
|
193
|
+
end
|
@@ -15,9 +15,9 @@ describe Ardm::Property::Binary do
|
|
15
15
|
describe '.options' do
|
16
16
|
subject { described_class.options }
|
17
17
|
|
18
|
-
it {
|
18
|
+
it { is_expected.to be_kind_of(Hash) }
|
19
19
|
|
20
|
-
it {
|
20
|
+
it { is_expected.to eql(:load_as => @load_as, :dump_as => @load_as, :coercion_method => :to_string, :length => 50) }
|
21
21
|
end
|
22
22
|
|
23
23
|
if RUBY_VERSION >= "1.9"
|
@@ -30,11 +30,11 @@ describe Ardm::Property::Binary do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'should always dump with BINARY' do
|
33
|
-
model.properties[:bin_data].dump("foo".freeze).encoding.names.
|
33
|
+
expect(model.properties[:bin_data].dump("foo".freeze).encoding.names).to include("BINARY")
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'should always load with BINARY' do
|
37
|
-
model.properties[:bin_data].load("foo".freeze).encoding.names.
|
37
|
+
expect(model.properties[:bin_data].load("foo".freeze).encoding.names).to include("BINARY")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -16,15 +16,15 @@ describe Ardm::Property::Boolean do
|
|
16
16
|
describe '.options' do
|
17
17
|
subject { described_class.options }
|
18
18
|
|
19
|
-
it {
|
19
|
+
it { is_expected.to be_kind_of(Hash) }
|
20
20
|
|
21
|
-
it {
|
21
|
+
it { is_expected.to eql(:load_as => @load_as, :dump_as => @load_as, :coercion_method => :to_boolean) }
|
22
22
|
end
|
23
23
|
|
24
24
|
describe "default" do
|
25
25
|
it "should set has_picture to the default (booleans are specifically weird in rails because presence validation fails for false)" do
|
26
26
|
tshirt = Ardm::Fixtures::TShirt.create!
|
27
|
-
tshirt.
|
27
|
+
expect(tshirt).not_to have_picture
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -21,8 +21,8 @@ describe Ardm::Property::Class do
|
|
21
21
|
describe '.options' do
|
22
22
|
subject { described_class.options }
|
23
23
|
|
24
|
-
it {
|
24
|
+
it { is_expected.to be_kind_of(Hash) }
|
25
25
|
|
26
|
-
it {
|
26
|
+
it { is_expected.to eql(:load_as => @load_as, :dump_as => @load_as, :coercion_method => :to_constant) }
|
27
27
|
end
|
28
28
|
end
|
@@ -15,8 +15,8 @@ describe Ardm::Property::Date do
|
|
15
15
|
describe '.options' do
|
16
16
|
subject { described_class.options }
|
17
17
|
|
18
|
-
it {
|
18
|
+
it { is_expected.to be_kind_of(Hash) }
|
19
19
|
|
20
|
-
it {
|
20
|
+
it { is_expected.to eql(:load_as => @load_as, :dump_as => @load_as, :coercion_method => :to_date) }
|
21
21
|
end
|
22
22
|
end
|
@@ -15,8 +15,8 @@ describe Ardm::Property::DateTime do
|
|
15
15
|
describe '.options' do
|
16
16
|
subject { described_class.options }
|
17
17
|
|
18
|
-
it {
|
18
|
+
it { is_expected.to be_kind_of(Hash) }
|
19
19
|
|
20
|
-
it {
|
20
|
+
it { is_expected.to eql(:load_as => @load_as, :dump_as => @load_as, :coercion_method => :to_datetime) }
|
21
21
|
end
|
22
22
|
end
|
@@ -16,8 +16,8 @@ describe Ardm::Property::Decimal do
|
|
16
16
|
describe '.options' do
|
17
17
|
subject { described_class.options }
|
18
18
|
|
19
|
-
it {
|
19
|
+
it { is_expected.to be_kind_of(Hash) }
|
20
20
|
|
21
|
-
it {
|
21
|
+
it { is_expected.to eql(:load_as => @load_as, :dump_as => @load_as, :coercion_method => :to_decimal, :precision => 10, :scale => 0) }
|
22
22
|
end
|
23
23
|
end
|
@@ -7,6 +7,7 @@ module ::DiscBlog
|
|
7
7
|
property :id, Serial
|
8
8
|
property :title, String, :required => true
|
9
9
|
property :type, Discriminator, :field => "slug"
|
10
|
+
timestamps :at
|
10
11
|
end
|
11
12
|
|
12
13
|
class Article < Content; end
|
@@ -26,13 +27,13 @@ describe Ardm::Property::Discriminator do
|
|
26
27
|
describe '.options' do
|
27
28
|
subject { described_class.options }
|
28
29
|
|
29
|
-
it {
|
30
|
+
it { is_expected.to be_kind_of(Hash) }
|
30
31
|
|
31
|
-
it {
|
32
|
+
it { is_expected.to include(:load_as => Class, :required => true) }
|
32
33
|
end
|
33
34
|
|
34
35
|
it 'should typecast to a Model' do
|
35
|
-
@article_model.properties[:type].typecast('DiscBlog::Release').
|
36
|
+
expect(@article_model.properties[:type].typecast('DiscBlog::Release')).to equal(@release_model)
|
36
37
|
end
|
37
38
|
|
38
39
|
describe 'Model#new' do
|
@@ -42,11 +43,11 @@ describe Ardm::Property::Discriminator do
|
|
42
43
|
end
|
43
44
|
|
44
45
|
it 'should return a Resource' do
|
45
|
-
@resource.
|
46
|
+
expect(@resource).to be_kind_of(Ardm::Record)
|
46
47
|
end
|
47
48
|
|
48
49
|
it 'should be an descendant instance' do
|
49
|
-
@resource.
|
50
|
+
expect(@resource).to be_instance_of(DiscBlog::Release)
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
@@ -56,11 +57,11 @@ describe Ardm::Property::Discriminator do
|
|
56
57
|
end
|
57
58
|
|
58
59
|
it 'should return a Resource' do
|
59
|
-
@resource.
|
60
|
+
expect(@resource).to be_kind_of(Ardm::Record)
|
60
61
|
end
|
61
62
|
|
62
63
|
it 'should be an descendant instance' do
|
63
|
-
@resource.
|
64
|
+
expect(@resource).to be_instance_of(DiscBlog::Release)
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
@@ -70,44 +71,44 @@ describe Ardm::Property::Discriminator do
|
|
70
71
|
end
|
71
72
|
|
72
73
|
it 'should return a Resource' do
|
73
|
-
@resource.
|
74
|
+
expect(@resource).to be_kind_of(Ardm::Record)
|
74
75
|
end
|
75
76
|
|
76
77
|
it 'should be a base model instance' do
|
77
|
-
@resource.
|
78
|
+
expect(@resource).to be_instance_of(@article_model)
|
78
79
|
end
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
82
83
|
describe 'Model#descendants' do
|
83
84
|
it 'should set the descendants for the grandparent model' do
|
84
|
-
@article_model.descendants.to_a.
|
85
|
+
expect(@article_model.descendants.to_a).to match_array([ @announcement_model, @release_model ])
|
85
86
|
end
|
86
87
|
|
87
88
|
it 'should set the descendants for the parent model' do
|
88
|
-
@announcement_model.descendants.to_a.
|
89
|
+
expect(@announcement_model.descendants.to_a).to eq([ @release_model ])
|
89
90
|
end
|
90
91
|
|
91
92
|
it 'should set the descendants for the child model' do
|
92
|
-
@release_model.descendants.to_a.
|
93
|
+
expect(@release_model.descendants.to_a).to eq([])
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
96
97
|
describe 'Model#default_scope', :pending => "I don't understand the intention of these" do
|
97
98
|
it 'should have no default scope for the top level model' do
|
98
|
-
@content_model.default_scope[:type].
|
99
|
+
expect(@content_model.default_scope[:type]).to be_nil
|
99
100
|
end
|
100
101
|
|
101
102
|
it 'should set the default scope for the grandparent model' do
|
102
|
-
@article_model.default_scope[:type].to_a.
|
103
|
+
expect(@article_model.default_scope[:type].to_a).to match_array([ @article_model, @announcement_model, @release_model ])
|
103
104
|
end
|
104
105
|
|
105
106
|
it 'should set the default scope for the parent model' do
|
106
|
-
@announcement_model.default_scope[:type].to_a.
|
107
|
+
expect(@announcement_model.default_scope[:type].to_a).to match_array([ @announcement_model, @release_model ])
|
107
108
|
end
|
108
109
|
|
109
110
|
it 'should set the default scope for the child model' do
|
110
|
-
@release_model.default_scope[:type].to_a.
|
111
|
+
expect(@release_model.default_scope[:type].to_a).to eq([ @release_model ])
|
111
112
|
end
|
112
113
|
end
|
113
114
|
|
@@ -116,18 +117,18 @@ describe Ardm::Property::Discriminator do
|
|
116
117
|
end
|
117
118
|
|
118
119
|
it 'should persist the type' do
|
119
|
-
@announcement.class.find(*@announcement.key).type.
|
120
|
+
expect(@announcement.class.find(*@announcement.key).type).to equal(@announcement_model)
|
120
121
|
end
|
121
122
|
|
122
123
|
it 'should be retrieved as an instance of the correct class' do
|
123
|
-
@announcement.class.find(*@announcement.key).
|
124
|
+
expect(@announcement.class.find(*@announcement.key)).to be_instance_of(@announcement_model)
|
124
125
|
end
|
125
126
|
|
126
127
|
it 'should include descendants in finders' do
|
127
|
-
@article_model.first.
|
128
|
+
expect(@article_model.first).to eql(@announcement)
|
128
129
|
end
|
129
130
|
|
130
131
|
it 'should not include ancestors' do
|
131
|
-
@release_model.first.
|
132
|
+
expect(@release_model.first).to be_nil
|
132
133
|
end
|
133
134
|
end
|
@@ -15,8 +15,8 @@ describe Ardm::Property::Float do
|
|
15
15
|
describe '.options' do
|
16
16
|
subject { described_class.options }
|
17
17
|
|
18
|
-
it {
|
18
|
+
it { is_expected.to be_kind_of(Hash) }
|
19
19
|
|
20
|
-
it {
|
20
|
+
it { is_expected.to eql(:load_as => @load_as, :dump_as => @load_as, :coercion_method => :to_float, :precision => 10, :scale => nil) }
|
21
21
|
end
|
22
22
|
end
|
@@ -15,8 +15,8 @@ describe Ardm::Property::Integer do
|
|
15
15
|
describe '.options' do
|
16
16
|
subject { described_class.options }
|
17
17
|
|
18
|
-
it {
|
18
|
+
it { is_expected.to be_kind_of(Hash) }
|
19
19
|
|
20
|
-
it {
|
20
|
+
it { is_expected.to eql(:load_as => @load_as, :dump_as => @load_as, :coercion_method => :to_integer) }
|
21
21
|
end
|
22
22
|
end
|
@@ -8,6 +8,7 @@ describe Ardm::Property, 'Object type' do
|
|
8
8
|
property :id, Serial
|
9
9
|
property :title, String
|
10
10
|
property :meta, Object, :required => true, :field => 'body'
|
11
|
+
timestamps :at
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
@@ -20,12 +21,12 @@ describe Ardm::Property, 'Object type' do
|
|
20
21
|
describe '.options' do
|
21
22
|
subject { described_class.options }
|
22
23
|
|
23
|
-
it {
|
24
|
+
it { is_expected.to be_kind_of(Hash) }
|
24
25
|
|
25
|
-
it {
|
26
|
+
it { is_expected.to be_empty }
|
26
27
|
end
|
27
28
|
|
28
|
-
it {
|
29
|
+
it { is_expected.to respond_to(:typecast) }
|
29
30
|
|
30
31
|
describe '#typecast' do
|
31
32
|
before do
|
@@ -34,10 +35,10 @@ describe Ardm::Property, 'Object type' do
|
|
34
35
|
|
35
36
|
subject { @property.typecast(@value) }
|
36
37
|
|
37
|
-
it {
|
38
|
+
it { is_expected.to equal(@value) }
|
38
39
|
end
|
39
40
|
|
40
|
-
it {
|
41
|
+
it { is_expected.to respond_to(:dump) }
|
41
42
|
|
42
43
|
describe '#dump' do
|
43
44
|
describe 'with a value' do
|
@@ -47,23 +48,23 @@ describe Ardm::Property, 'Object type' do
|
|
47
48
|
|
48
49
|
subject { @property.dump(@value) }
|
49
50
|
|
50
|
-
it { @property.load(subject).
|
51
|
+
it { expect(@property.load(subject)).to eq(@value) }
|
51
52
|
end
|
52
53
|
|
53
54
|
describe 'with nil' do
|
54
55
|
subject { @property.dump(nil) }
|
55
56
|
|
56
|
-
it {
|
57
|
+
it { is_expected.to be_nil }
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
60
|
-
it {
|
61
|
+
it { is_expected.to respond_to(:valid?) }
|
61
62
|
|
62
63
|
describe '#valid?' do
|
63
64
|
describe 'with a valid load_as' do
|
64
65
|
subject { @property.valid?('lang' => 'en_CA') }
|
65
66
|
|
66
|
-
it {
|
67
|
+
it { is_expected.to be(true) }
|
67
68
|
end
|
68
69
|
|
69
70
|
describe 'with nil and property is not required' do
|
@@ -73,19 +74,19 @@ describe Ardm::Property, 'Object type' do
|
|
73
74
|
|
74
75
|
subject { @property.valid?(nil) }
|
75
76
|
|
76
|
-
it {
|
77
|
+
it { is_expected.to be(true) }
|
77
78
|
end
|
78
79
|
|
79
80
|
describe 'with nil and property is required' do
|
80
81
|
subject { @property.valid?(nil) }
|
81
82
|
|
82
|
-
it {
|
83
|
+
it { is_expected.to be(false) }
|
83
84
|
end
|
84
85
|
|
85
86
|
describe 'with nil and property is required, but validity is negated' do
|
86
87
|
subject { @property.valid?(nil, true) }
|
87
88
|
|
88
|
-
it {
|
89
|
+
it { is_expected.to be(true) }
|
89
90
|
end
|
90
91
|
end
|
91
92
|
|
@@ -97,7 +98,7 @@ describe Ardm::Property, 'Object type' do
|
|
97
98
|
subject { @resource.reload.meta }
|
98
99
|
|
99
100
|
it 'should load the correct value' do
|
100
|
-
|
101
|
+
is_expected.to eq({ 'lang' => 'en_CA' })
|
101
102
|
end
|
102
103
|
end
|
103
104
|
end
|