ardm 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby-version +1 -0
- data/Gemfile +14 -2
- data/ardm.gemspec +1 -1
- data/lib/ardm.rb +8 -0
- data/lib/ardm/active_record.rb +0 -5
- data/lib/ardm/active_record/associations.rb +27 -10
- data/lib/ardm/active_record/predicate_builder/rails4.rb +12 -5
- data/lib/ardm/active_record/property.rb +4 -3
- data/lib/ardm/active_record/record.rb +10 -6
- data/lib/ardm/active_record/relation.rb +67 -2
- data/lib/ardm/data_mapper.rb +2 -0
- data/lib/ardm/data_mapper/record.rb +19 -22
- data/lib/ardm/property/support/paranoid_base.rb +1 -1
- data/lib/ardm/query/expression.rb +5 -15
- data/lib/ardm/query/operator.rb +3 -3
- data/lib/ardm/version.rb +1 -1
- data/spec/fixtures/article.rb +1 -1
- data/spec/fixtures/resource_blog.rb +53 -0
- data/spec/integration/comma_separated_list_spec.rb +4 -4
- data/spec/integration/dirty_minder_spec.rb +1 -1
- data/spec/integration/enum_spec.rb +2 -2
- data/spec/integration/epoch_time_spec.rb +2 -2
- data/spec/integration/file_path_spec.rb +4 -4
- data/spec/integration/flag_spec.rb +5 -3
- data/spec/integration/json_spec.rb +3 -3
- data/spec/public/model_spec.rb +78 -8
- data/spec/public/property_spec.rb +10 -6
- data/spec/public/resource_spec.rb +9 -64
- data/spec/shared/{finder_shared_spec.rb → finder_shared.rb} +134 -128
- data/spec/shared/{flags_shared_spec.rb → flags_shared.rb} +0 -0
- data/spec/shared/{public_property_spec.rb → public_property.rb} +0 -0
- data/spec/shared/{resource_spec.rb → resource.rb} +46 -31
- data/spec/shared/{semipublic_property_spec.rb → semipublic_property.rb} +0 -0
- data/spec/spec_helper.rb +11 -5
- data/spec/support/logger.rb +38 -0
- data/spec/unit/dirty_minder_spec.rb +4 -2
- data/spec/unit/paranoid_boolean_spec.rb +3 -3
- data/spec/unit/paranoid_datetime_spec.rb +3 -3
- metadata +59 -30
- checksums.yaml +0 -7
data/lib/ardm/version.rb
CHANGED
data/spec/fixtures/article.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
module ::ResourceBlog
|
2
|
+
class User < Ardm::Record
|
3
|
+
self.table_name = "users"
|
4
|
+
|
5
|
+
property :name, String, key: true
|
6
|
+
property :age, Integer
|
7
|
+
property :summary, Text
|
8
|
+
property :description, Text
|
9
|
+
property :admin, Boolean, :accessor => :private
|
10
|
+
|
11
|
+
belongs_to :parent, self, :required => false
|
12
|
+
has n, :children, self, :inverse => :parent
|
13
|
+
|
14
|
+
belongs_to :referrer, self, :required => false
|
15
|
+
has n, :comments
|
16
|
+
|
17
|
+
# FIXME: figure out a different approach than stubbing things out
|
18
|
+
def comment=(*)
|
19
|
+
# do nothing with comment
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Author < User; end
|
24
|
+
|
25
|
+
class Comment < Ardm::Record
|
26
|
+
self.table_name = "comments"
|
27
|
+
|
28
|
+
property :id, Serial
|
29
|
+
property :body, Text
|
30
|
+
|
31
|
+
belongs_to :user
|
32
|
+
end
|
33
|
+
|
34
|
+
class Article < Ardm::Record
|
35
|
+
self.table_name = "articles"
|
36
|
+
|
37
|
+
property :id, Serial
|
38
|
+
property :body, Text
|
39
|
+
|
40
|
+
has n, :paragraphs
|
41
|
+
end
|
42
|
+
|
43
|
+
class Paragraph < Ardm::Record
|
44
|
+
self.table_name = "paragraphs"
|
45
|
+
|
46
|
+
property :id, Serial
|
47
|
+
property :text, String
|
48
|
+
|
49
|
+
belongs_to :article
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
Ardm::Record.finalize
|
@@ -16,7 +16,7 @@ try_spec do
|
|
16
16
|
|
17
17
|
describe 'when dumped and loaded again' do
|
18
18
|
before do
|
19
|
-
expect(@resource.save).to
|
19
|
+
expect(@resource.save).to be_truthy
|
20
20
|
@resource.reload
|
21
21
|
end
|
22
22
|
|
@@ -33,7 +33,7 @@ try_spec do
|
|
33
33
|
|
34
34
|
describe 'when dumped and loaded again' do
|
35
35
|
before do
|
36
|
-
expect(@resource.save).to
|
36
|
+
expect(@resource.save).to be_truthy
|
37
37
|
@resource.reload
|
38
38
|
end
|
39
39
|
|
@@ -60,7 +60,7 @@ try_spec do
|
|
60
60
|
|
61
61
|
describe 'when dumped and loaded again' do
|
62
62
|
before do
|
63
|
-
expect(@resource.save).to
|
63
|
+
expect(@resource.save).to be_truthy
|
64
64
|
@resource.reload
|
65
65
|
end
|
66
66
|
|
@@ -77,7 +77,7 @@ try_spec do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'has blank entries removed' do
|
80
|
-
expect(@resource.interests.any? { |i| Ardm::Ext.blank?(i) }).to
|
80
|
+
expect(@resource.interests.any? { |i| Ardm::Ext.blank?(i) }).to be_falsey
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
@@ -14,7 +14,7 @@ try_spec do
|
|
14
14
|
:status => 'confirmed'
|
15
15
|
)
|
16
16
|
|
17
|
-
expect(@resource.save).to
|
17
|
+
expect(@resource.save).to be_truthy
|
18
18
|
@resource.reload
|
19
19
|
end
|
20
20
|
|
@@ -41,7 +41,7 @@ try_spec do
|
|
41
41
|
:body => "Note that at the very least, there should be a check to see whether or not the user is created before chown'ing a file to the user.",
|
42
42
|
:status => 'confirmed'
|
43
43
|
)
|
44
|
-
expect(@resource.save).to
|
44
|
+
expect(@resource.save).to be_truthy
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'supports queries with equality operator on enumeration property' do
|
@@ -22,7 +22,7 @@ try_spec do
|
|
22
22
|
|
23
23
|
describe 'when dumped and loaded again' do
|
24
24
|
before do
|
25
|
-
expect(@resource.save).to
|
25
|
+
expect(@resource.save).to be_truthy
|
26
26
|
@resource.reload
|
27
27
|
end
|
28
28
|
|
@@ -45,7 +45,7 @@ try_spec do
|
|
45
45
|
|
46
46
|
describe 'when dumped and loaded again' do
|
47
47
|
before do
|
48
|
-
expect(@resource.save).to
|
48
|
+
expect(@resource.save).to be_truthy
|
49
49
|
@resource.reload
|
50
50
|
end
|
51
51
|
|
@@ -53,7 +53,7 @@ try_spec do
|
|
53
53
|
|
54
54
|
describe 'when saved and reloaded' do
|
55
55
|
before do
|
56
|
-
expect(@resource.save).to
|
56
|
+
expect(@resource.save).to be_truthy
|
57
57
|
@resource.reload
|
58
58
|
end
|
59
59
|
|
@@ -95,7 +95,7 @@ try_spec do
|
|
95
95
|
|
96
96
|
describe 'when saved and reloaded' do
|
97
97
|
before do
|
98
|
-
expect(@resource.save).to
|
98
|
+
expect(@resource.save).to be_truthy
|
99
99
|
@resource.reload
|
100
100
|
end
|
101
101
|
|
@@ -113,7 +113,7 @@ try_spec do
|
|
113
113
|
|
114
114
|
describe 'when saved and reloaded' do
|
115
115
|
before do
|
116
|
-
expect(@resource.save).to
|
116
|
+
expect(@resource.save).to be_truthy
|
117
117
|
@resource.reload
|
118
118
|
end
|
119
119
|
|
@@ -131,7 +131,7 @@ try_spec do
|
|
131
131
|
|
132
132
|
describe 'when saved and reloaded' do
|
133
133
|
before do
|
134
|
-
expect(@resource.save).to
|
134
|
+
expect(@resource.save).to be_truthy
|
135
135
|
@resource.reload
|
136
136
|
end
|
137
137
|
|
@@ -16,7 +16,9 @@ try_spec do
|
|
16
16
|
|
17
17
|
describe 'with the default value' do
|
18
18
|
it 'returns it as an array', skip: true do
|
19
|
-
|
19
|
+
skip "FIXME: This probably should pass" do
|
20
|
+
expect(@resource.size).to eq([Ardm::Fixtures::TShirt.properties[:size].default])
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
@@ -24,7 +26,7 @@ try_spec do
|
|
24
26
|
describe 'dumped and loaded' do
|
25
27
|
before do
|
26
28
|
@resource.size = [ :xs, :medium ]
|
27
|
-
expect(@resource.save).to
|
29
|
+
expect(@resource.save).to be_truthy
|
28
30
|
@resource.reload
|
29
31
|
end
|
30
32
|
|
@@ -41,7 +43,7 @@ try_spec do
|
|
41
43
|
|
42
44
|
describe 'dumped and loaded' do
|
43
45
|
before do
|
44
|
-
expect(@resource.save).to
|
46
|
+
expect(@resource.save).to be_truthy
|
45
47
|
@resource.reload
|
46
48
|
end
|
47
49
|
|
@@ -16,7 +16,7 @@ try_spec do
|
|
16
16
|
|
17
17
|
describe 'when dumped and loaded again' do
|
18
18
|
before do
|
19
|
-
expect(@resource.save).to
|
19
|
+
expect(@resource.save).to be_truthy
|
20
20
|
@resource.reload
|
21
21
|
end
|
22
22
|
|
@@ -36,7 +36,7 @@ try_spec do
|
|
36
36
|
|
37
37
|
describe 'when dumped and loaded again' do
|
38
38
|
before do
|
39
|
-
expect(@resource.save).to
|
39
|
+
expect(@resource.save).to be_truthy
|
40
40
|
@resource.reload
|
41
41
|
end
|
42
42
|
|
@@ -56,7 +56,7 @@ try_spec do
|
|
56
56
|
|
57
57
|
describe 'when dumped and loaded again' do
|
58
58
|
before do
|
59
|
-
expect(@resource.save).to
|
59
|
+
expect(@resource.save).to be_truthy
|
60
60
|
@resource.reload
|
61
61
|
end
|
62
62
|
|
data/spec/public/model_spec.rb
CHANGED
@@ -3,6 +3,12 @@ require 'spec_helper'
|
|
3
3
|
module ::ModelBlog
|
4
4
|
# FIXME: load order in tests is being problematic
|
5
5
|
class ArticlePublication < Ardm::Record
|
6
|
+
self.table_name = "article_publications"
|
7
|
+
|
8
|
+
property :id, Serial
|
9
|
+
|
10
|
+
belongs_to :article, model: 'ModelBlog::Article'
|
11
|
+
belongs_to :publication, model: 'ModelBlog::Publication'
|
6
12
|
end
|
7
13
|
|
8
14
|
class Article < Ardm::Record
|
@@ -16,7 +22,7 @@ module ::ModelBlog
|
|
16
22
|
belongs_to :original, self, :required => false
|
17
23
|
has n, :revisions, self, :child_key => [ :original_id ]
|
18
24
|
has 1, :previous, self, :child_key => [ :original_id ], :order => [ :id.desc ]
|
19
|
-
has n, :article_publications, model:
|
25
|
+
has n, :article_publications, model: 'ArticlePublication'
|
20
26
|
has n, :publications, :through => :article_publications
|
21
27
|
end
|
22
28
|
|
@@ -26,18 +32,20 @@ module ::ModelBlog
|
|
26
32
|
property :id, Serial
|
27
33
|
property :name, String
|
28
34
|
|
29
|
-
has n, :article_publications, model:
|
30
|
-
has n, :
|
35
|
+
has n, :article_publications, model: ArticlePublication
|
36
|
+
has n, :articles, :through => :article_publications
|
31
37
|
end
|
32
38
|
|
33
39
|
class ArticlePublication < Ardm::Record
|
34
40
|
self.table_name = "article_publications"
|
35
41
|
|
36
|
-
belongs_to :
|
42
|
+
belongs_to :article, model: '::ModelBlog::Article'
|
37
43
|
belongs_to :publication, model: '::ModelBlog::Publication'
|
38
44
|
end
|
39
45
|
end
|
40
46
|
|
47
|
+
Ardm::Record.finalize
|
48
|
+
|
41
49
|
describe 'Ardm::Record' do
|
42
50
|
before do
|
43
51
|
@article_model = ModelBlog::Article
|
@@ -51,6 +59,7 @@ describe 'Ardm::Record' do
|
|
51
59
|
|
52
60
|
@original = @articles.create(:title => 'Original Article')
|
53
61
|
@article = @articles.create(:title => 'Sample Article', :body => 'Sample', :original => @original)
|
62
|
+
expect(@article.reload.original).to eq(@original)
|
54
63
|
@other = @articles.create(:title => 'Other Article', :body => 'Other')
|
55
64
|
end
|
56
65
|
|
@@ -138,8 +147,10 @@ describe 'Ardm::Record' do
|
|
138
147
|
|
139
148
|
[ :destroy, :destroy! ].each do |method|
|
140
149
|
describe "##{method}" do
|
141
|
-
|
142
|
-
|
150
|
+
let(:model) { @article_model }
|
151
|
+
|
152
|
+
it 'should remove all resources' do
|
153
|
+
expect { model.send(method) }.to change { model.any? }.from(true).to(false)
|
143
154
|
end
|
144
155
|
end
|
145
156
|
end
|
@@ -187,7 +198,66 @@ describe 'Ardm::Record' do
|
|
187
198
|
end
|
188
199
|
end
|
189
200
|
|
190
|
-
|
191
|
-
|
201
|
+
describe "finders" do
|
202
|
+
before(:each) do
|
203
|
+
ModelBlog::Article.destroy
|
204
|
+
@articles = ModelBlog::Article.all
|
205
|
+
@original = @articles.create(:title => 'Original Article')
|
206
|
+
@article = @articles.create(:title => 'Sample Article', :body => 'Sample', :original => @original)
|
207
|
+
end
|
208
|
+
|
209
|
+
include_examples 'Finder Interface'
|
210
|
+
end
|
192
211
|
|
212
|
+
it 'Ardm::Record should respond to raise_on_save_failure' do
|
213
|
+
Ardm::Record.should respond_to(:raise_on_save_failure)
|
214
|
+
end
|
215
|
+
|
216
|
+
describe '.raise_on_save_failure' do
|
217
|
+
subject { Ardm::Record.raise_on_save_failure }
|
218
|
+
|
219
|
+
it { should be(false) }
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'Ardm::Record should respond to raise_on_save_failure=' do
|
223
|
+
Ardm::Record.should respond_to(:raise_on_save_failure=)
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'A model should respond to raise_on_save_failure' do
|
227
|
+
@article_model.should respond_to(:raise_on_save_failure)
|
228
|
+
end
|
229
|
+
|
230
|
+
describe '#raise_on_save_failure' do
|
231
|
+
after do
|
232
|
+
# reset to the default value
|
233
|
+
reset_raise_on_save_failure(Ardm::Record)
|
234
|
+
reset_raise_on_save_failure(@article_model)
|
235
|
+
end
|
236
|
+
|
237
|
+
subject { @article_model.raise_on_save_failure }
|
238
|
+
|
239
|
+
describe 'when Ardm::Record.raise_on_save_failure has not been set' do
|
240
|
+
it { should be(false) }
|
241
|
+
end
|
242
|
+
|
243
|
+
describe 'when Ardm::Record.raise_on_save_failure has been set to true' do
|
244
|
+
before do
|
245
|
+
Ardm::Record.raise_on_save_failure = true
|
246
|
+
end
|
247
|
+
|
248
|
+
it { should be(true) }
|
249
|
+
end
|
250
|
+
|
251
|
+
describe 'when model.raise_on_save_failure has been set to true' do
|
252
|
+
before do
|
253
|
+
@article_model.raise_on_save_failure = true
|
254
|
+
end
|
255
|
+
|
256
|
+
it { should be(true) }
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'A model should respond to raise_on_save_failure=' do
|
261
|
+
@article_model.should respond_to(:raise_on_save_failure=)
|
262
|
+
end
|
193
263
|
end
|
@@ -72,10 +72,12 @@ describe Ardm::Property do
|
|
72
72
|
@image.instance_variable_set(:@description, 'Is set by magic')
|
73
73
|
end
|
74
74
|
|
75
|
-
it 'gets instance variable value from the resource directly'
|
76
|
-
|
77
|
-
|
78
|
-
|
75
|
+
it 'gets instance variable value from the resource directly' do
|
76
|
+
skip "support for this in ActiveRecord is questionable" do
|
77
|
+
# if you know a better way to test direct instance variable access,
|
78
|
+
# go ahead and make changes to this example
|
79
|
+
expect(Image.properties[:description].get!(@image)).to eq('Is set by magic')
|
80
|
+
end
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
@@ -283,8 +285,10 @@ describe Ardm::Property do
|
|
283
285
|
expect(Track.properties[:musicbrainz_hash].unique?).to be(true)
|
284
286
|
end
|
285
287
|
|
286
|
-
it 'is true for serial fields'
|
287
|
-
|
288
|
+
it 'is true for serial fields' do
|
289
|
+
skip do
|
290
|
+
expect(Track.properties[:title].unique?).should be(true)
|
291
|
+
end
|
288
292
|
end
|
289
293
|
|
290
294
|
it 'is true for keys' do
|
@@ -1,66 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module ::ResourceBlog
|
4
|
-
class User < Ardm::Record
|
5
|
-
self.table_name = "users"
|
6
|
-
|
7
|
-
property :name, String, :key => true
|
8
|
-
property :age, Integer
|
9
|
-
property :summary, Text
|
10
|
-
property :description, Text
|
11
|
-
property :admin, Boolean, :accessor => :private
|
12
|
-
|
13
|
-
belongs_to :parent, self, :required => false
|
14
|
-
has n, :children, self, :inverse => :parent
|
15
|
-
|
16
|
-
belongs_to :referrer, self, :required => false
|
17
|
-
has n, :comments
|
18
|
-
|
19
|
-
# FIXME: figure out a different approach than stubbing things out
|
20
|
-
def comment=(*)
|
21
|
-
# do nothing with comment
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class Author < User; end
|
26
|
-
|
27
|
-
class Comment < Ardm::Record
|
28
|
-
self.table_name = "comments"
|
29
|
-
|
30
|
-
property :id, Serial
|
31
|
-
property :body, Text
|
32
|
-
|
33
|
-
belongs_to :user
|
34
|
-
end
|
35
|
-
|
36
|
-
class Article < Ardm::Record
|
37
|
-
self.table_name = "articles"
|
38
|
-
|
39
|
-
property :id, Serial
|
40
|
-
property :body, Text
|
41
|
-
timestamps :at
|
42
|
-
|
43
|
-
has n, :paragraphs
|
44
|
-
end
|
45
|
-
|
46
|
-
class Paragraph < Ardm::Record
|
47
|
-
self.table_name = "paragraphs"
|
48
|
-
|
49
|
-
property :id, Serial
|
50
|
-
property :text, String
|
51
|
-
|
52
|
-
belongs_to :article
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
Ardm::Record.finalize
|
57
|
-
|
58
|
-
# TODO: unused?
|
59
|
-
#class ::ResourceDefault < Ardm::Record
|
60
|
-
# property :name, String, :key => true, :default => 'a default value'
|
61
|
-
#end
|
62
|
-
|
63
3
|
describe Ardm::Record do
|
4
|
+
require './spec/fixtures/resource_blog'
|
5
|
+
|
64
6
|
before do
|
65
7
|
@user_model = ResourceBlog::User
|
66
8
|
@author_model = ResourceBlog::Author
|
@@ -91,7 +33,7 @@ describe Ardm::Record do
|
|
91
33
|
subject { @user.raise_on_save_failure }
|
92
34
|
|
93
35
|
describe 'when model.raise_on_save_failure has not been set' do
|
94
|
-
it { is_expected.to
|
36
|
+
it { is_expected.to be_falsey }
|
95
37
|
end
|
96
38
|
|
97
39
|
describe 'when model.raise_on_save_failure has been set to true' do
|
@@ -165,11 +107,14 @@ describe Ardm::Record do
|
|
165
107
|
|
166
108
|
describe 'and it is an invalid resource', pending: true do
|
167
109
|
before do
|
110
|
+
Ardm::Record.any_instance.stub(:save).and_return(false)
|
168
111
|
expect(@user).to receive(:save_self).and_return(false)
|
169
112
|
end
|
170
113
|
|
171
114
|
it 'should raise an exception' do
|
172
|
-
expect { subject }.to raise_error(Ardm::SaveFailureError, "Blog::User##{method} returned false, Blog::User was not saved")
|
115
|
+
expect { subject }.to raise_error(Ardm::SaveFailureError, "Blog::User##{method} returned false, Blog::User was not saved") { |error|
|
116
|
+
error.resource.should equal(@user)
|
117
|
+
}
|
173
118
|
end
|
174
119
|
end
|
175
120
|
end
|
@@ -177,7 +122,7 @@ describe Ardm::Record do
|
|
177
122
|
end
|
178
123
|
|
179
124
|
[ :update, :update! ].each do |method|
|
180
|
-
describe 'with attributes where one is a foreign key' do
|
125
|
+
describe 'with attributes where one is a foreign key', :pending => "#relationships not needed" do
|
181
126
|
before do
|
182
127
|
@dkubb = @user_model.create(:name => 'dkubb', :age => 33)
|
183
128
|
@user.referrer = @dkubb
|
@@ -247,7 +192,7 @@ describe Ardm::Record do
|
|
247
192
|
describe '#attribute_set' do
|
248
193
|
subject { object.attribute_set(name, value) }
|
249
194
|
|
250
|
-
let(:object) { @user }
|
195
|
+
let(:object) { @user.clone }
|
251
196
|
|
252
197
|
context 'with a known property' do
|
253
198
|
let(:name) { :name }
|