schema_associations 1.2.0 → 1.2.1
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/.travis.yml +2 -1
- data/README.md +12 -3
- data/gemfiles/Gemfile.base +4 -0
- data/gemfiles/Gemfile.rails-3.2 +1 -2
- data/gemfiles/Gemfile.rails-4.0 +1 -2
- data/gemfiles/Gemfile.rails-4.1 +3 -0
- data/lib/schema_associations/active_record/associations.rb +7 -0
- data/lib/schema_associations/version.rb +1 -1
- data/runspecs +13 -7
- data/schema_associations.gemspec +1 -1
- data/spec/association_spec.rb +144 -120
- data/spec/connection.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +24 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3b9c45613e71564c85a31fe61dbe4a568568a23
|
4
|
+
data.tar.gz: c45c59c0dab8f9e87e396ef90199c6d4f5f6f852
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: febbd2e3214f1bd063d68f0e9f93c0a12da75acbe7aefec616892015992cdb2afc4a5a7c31db8bb17200a49032a4daf2f2f10d14247f0018f1f10ee56a101513
|
7
|
+
data.tar.gz: 7e83f3bf6be38cd776896fa58b1ff21f39cbb1c5b20bff219c9b1dc3fa181ba5a5bcaa36d38acf7f09ed287a8ae8310b7d175a39f5189d8c1963c98311aa47b3
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -317,10 +317,10 @@ use cases that you logged).
|
|
317
317
|
|
318
318
|
## Compatibility
|
319
319
|
|
320
|
-
SchemaAssociations
|
320
|
+
SchemaAssociations is tested on all combinations of:
|
321
321
|
|
322
|
-
* Rails 3.2 or
|
323
|
-
* MRI ruby 1.9.3 or 2.
|
322
|
+
* Rails 3.2, 4.0, or 4.1
|
323
|
+
* MRI ruby 1.9.3 or 2.1.2
|
324
324
|
|
325
325
|
Note: As of version 1.0.0, ruby 1.8.7 and rails < 3.2 are no longer supported. As of version 1.2.0, ruby 1.9.2 is no longer supported.
|
326
326
|
|
@@ -353,6 +353,11 @@ Code coverage results will be in coverage/index.html -- it should be at 100% cov
|
|
353
353
|
|
354
354
|
## Release notes:
|
355
355
|
|
356
|
+
### 1.2.1
|
357
|
+
|
358
|
+
* Works with Rails 4.1
|
359
|
+
* Test against MRI ruby 2.1.2
|
360
|
+
|
356
361
|
### 1.2.0
|
357
362
|
|
358
363
|
* Works with Rails 4, thanks to [@tovodeverett](https://github.com/tovodeverett)
|
@@ -386,3 +391,7 @@ Code coverage results will be in coverage/index.html -- it should be at 100% cov
|
|
386
391
|
## License
|
387
392
|
|
388
393
|
This gem is released under the MIT license.
|
394
|
+
|
395
|
+
|
396
|
+
[](https://bitdeli.com/free "Bitdeli Badge")
|
397
|
+
|
data/gemfiles/Gemfile.rails-3.2
CHANGED
data/gemfiles/Gemfile.rails-4.0
CHANGED
@@ -18,6 +18,7 @@ module SchemaAssociations
|
|
18
18
|
def self.extended(base) #:nodoc:
|
19
19
|
class << base
|
20
20
|
alias_method_chain :reflect_on_association, :schema_associations
|
21
|
+
alias_method_chain :_reflect_on_association, :schema_associations if method_defined? :_reflect_on_association
|
21
22
|
alias_method_chain :reflect_on_all_associations, :schema_associations
|
22
23
|
end
|
23
24
|
::ActiveRecord::Relation.send :include, Relation if defined? ::ActiveRecord::Relation
|
@@ -28,6 +29,12 @@ module SchemaAssociations
|
|
28
29
|
reflect_on_association_without_schema_associations(*args)
|
29
30
|
end
|
30
31
|
|
32
|
+
# introduced in rails 4.1
|
33
|
+
def _reflect_on_association_with_schema_associations(*args) #:nodoc:
|
34
|
+
_load_schema_associations_associations
|
35
|
+
_reflect_on_association_without_schema_associations(*args)
|
36
|
+
end
|
37
|
+
|
31
38
|
def reflect_on_all_associations_with_schema_associations(*args) #:nodoc:
|
32
39
|
_load_schema_associations_associations
|
33
40
|
reflect_on_all_associations_without_schema_associations(*args)
|
data/runspecs
CHANGED
@@ -5,8 +5,8 @@ require 'ostruct'
|
|
5
5
|
require 'shellwords'
|
6
6
|
require 'tempfile'
|
7
7
|
|
8
|
-
RUBY_VERSIONS = %W[1.9.3 2.
|
9
|
-
RAILS_VERSIONS = %W[3.2 4.0]
|
8
|
+
RUBY_VERSIONS = %W[1.9.3 2.1.2]
|
9
|
+
RAILS_VERSIONS = %W[3.2 4.0 4.1]
|
10
10
|
|
11
11
|
o = OpenStruct.new
|
12
12
|
o.ruby_versions = RUBY_VERSIONS
|
@@ -62,10 +62,16 @@ if system("which -s rvm")
|
|
62
62
|
"rvm #{ruby} do"
|
63
63
|
end
|
64
64
|
else
|
65
|
-
# using rbenv.
|
66
|
-
#
|
67
|
-
|
68
|
-
|
65
|
+
# using rbenv.
|
66
|
+
#
|
67
|
+
# because we're running within a ruby program that was launched by
|
68
|
+
# rbenv, we already have various environment variables set up. need
|
69
|
+
# strip those out so that the forked shell can run a diifferent ruby
|
70
|
+
# version than the one we're in now.
|
71
|
+
ENV['PATH'] = ENV['PATH'].split(':').reject{|dir| dir =~ %r{/\.?rbenv/(?!shims)}}.join(':')
|
72
|
+
ENV['GEM_PATH'] = ENV['GEM_PATH'].split(':').reject{|dir| dir =~ %r{/\.?rbenv}}.join(':') unless ENV['GEM_PATH'].nil?
|
73
|
+
ENV['RBENV_DIR'] = nil
|
74
|
+
ENV['RBENV_HOOK_PATH'] = nil
|
69
75
|
|
70
76
|
def ruby_version_selector(ruby)
|
71
77
|
@versions ||= `rbenv versions --bare`.split
|
@@ -100,7 +106,7 @@ combos.each_with_index do |combo, n|
|
|
100
106
|
Tempfile.open('runspecs') do |file|
|
101
107
|
system("(#{command}) 2>&1 | tee #{file.path}")
|
102
108
|
file.rewind
|
103
|
-
errs << "ruby #{ruby}, rails #{rails}" if file.readlines.grep(
|
109
|
+
errs << "ruby #{ruby}, rails #{rails}" if file.readlines.grep(/(^Failed examples)|(rake aborted)/).any?
|
104
110
|
end
|
105
111
|
end
|
106
112
|
puts errs.any? ? "\n*** #{errs.size} failures:\n\t#{errs.join("\n\t")}" : "\n*** #{combos.size > 1 ? 'all versions' : 'spec'} succeeded ***" unless o.dry_run
|
data/schema_associations.gemspec
CHANGED
@@ -26,6 +26,6 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_development_dependency("rspec")
|
27
27
|
s.add_development_dependency("sqlite3")
|
28
28
|
s.add_development_dependency("simplecov")
|
29
|
-
s.add_development_dependency("simplecov-gem-
|
29
|
+
s.add_development_dependency("simplecov-gem-profile")
|
30
30
|
end
|
31
31
|
|
data/spec/association_spec.rb
CHANGED
@@ -19,41 +19,47 @@ describe ActiveRecord::Base do
|
|
19
19
|
|
20
20
|
it "should create belongs_to association when reflecting on it" do
|
21
21
|
reflection = Comment.reflect_on_association(:post)
|
22
|
-
reflection.
|
23
|
-
reflection.macro.
|
24
|
-
reflection.options[:class_name].
|
25
|
-
reflection.options[:foreign_key].
|
26
|
-
reflection.options[:inverse_of].
|
22
|
+
expect(reflection).not_to be_nil
|
23
|
+
expect(reflection.macro).to eq(:belongs_to)
|
24
|
+
expect(reflection.options[:class_name]).to eq("Post")
|
25
|
+
expect(reflection.options[:foreign_key]).to eq("post_id")
|
26
|
+
expect(reflection.options[:inverse_of]).to eq(:comments)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should create association when reflecting on all associations" do
|
30
30
|
reflection = Comment.reflect_on_all_associations.first
|
31
|
-
reflection.
|
32
|
-
reflection.macro.
|
33
|
-
reflection.options[:class_name].
|
34
|
-
reflection.options[:foreign_key].
|
35
|
-
reflection.options[:inverse_of].
|
31
|
+
expect(reflection).not_to be_nil
|
32
|
+
expect(reflection.macro).to eq(:belongs_to)
|
33
|
+
expect(reflection.options[:class_name]).to eq("Post")
|
34
|
+
expect(reflection.options[:foreign_key]).to eq("post_id")
|
35
|
+
expect(reflection.options[:inverse_of]).to eq(:comments)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should create association when accepts_nested_attributes_for is called" do
|
39
|
+
expect {
|
40
|
+
Post.class_eval { accepts_nested_attributes_for :comments }
|
41
|
+
}.to_not raise_error
|
36
42
|
end
|
37
43
|
|
38
44
|
it "should create association when accessing it" do
|
39
45
|
post = Post.create
|
40
46
|
comment = Comment.create(:post_id => post.id)
|
41
|
-
comment.post.id.
|
47
|
+
expect(comment.post.id).to eq(post.id)
|
42
48
|
end
|
43
49
|
|
44
50
|
it "should create association when creating record" do
|
45
51
|
post = Post.create
|
46
52
|
comment = Comment.create(:post => post)
|
47
|
-
comment.reload.post.id.
|
53
|
+
expect(comment.reload.post.id).to eq(post.id)
|
48
54
|
end
|
49
55
|
|
50
56
|
it "should create has_many association" do
|
51
57
|
reflection = Post.reflect_on_association(:comments)
|
52
|
-
reflection.
|
53
|
-
reflection.macro.
|
54
|
-
reflection.options[:class_name].
|
55
|
-
reflection.options[:foreign_key].
|
56
|
-
reflection.options[:inverse_of].
|
58
|
+
expect(reflection).not_to be_nil
|
59
|
+
expect(reflection.macro).to eq(:has_many)
|
60
|
+
expect(reflection.options[:class_name]).to eq("Comment")
|
61
|
+
expect(reflection.options[:foreign_key]).to eq("post_id")
|
62
|
+
expect(reflection.options[:inverse_of]).to eq(:post)
|
57
63
|
end
|
58
64
|
it "shouldn't raise an exception when model is instantiated" do
|
59
65
|
expect { Post.new }.to_not raise_error
|
@@ -78,8 +84,8 @@ describe ActiveRecord::Base do
|
|
78
84
|
hash.each do |key, val|
|
79
85
|
reflection = Widget.reflect_on_association(key)
|
80
86
|
case val
|
81
|
-
when true then reflection.
|
82
|
-
else reflection.
|
87
|
+
when true then expect(reflection).not_to be_nil
|
88
|
+
else expect(reflection).to be_nil
|
83
89
|
end
|
84
90
|
end
|
85
91
|
end
|
@@ -172,8 +178,8 @@ describe ActiveRecord::Base do
|
|
172
178
|
schema_associations :auto_create => false
|
173
179
|
end
|
174
180
|
class Comment < ActiveRecord::Base ; end
|
175
|
-
Post.reflect_on_association(:comments).
|
176
|
-
Comment.reflect_on_association(:post).
|
181
|
+
expect(Post.reflect_on_association(:comments)).to be_nil
|
182
|
+
expect(Comment.reflect_on_association(:post)).not_to be_nil
|
177
183
|
end
|
178
184
|
end
|
179
185
|
|
@@ -188,8 +194,8 @@ describe ActiveRecord::Base do
|
|
188
194
|
schema_associations :auto_create => true
|
189
195
|
end
|
190
196
|
class Comment < ActiveRecord::Base ; end
|
191
|
-
Post.reflect_on_association(:comments).
|
192
|
-
Comment.reflect_on_association(:post).
|
197
|
+
expect(Post.reflect_on_association(:comments)).not_to be_nil
|
198
|
+
expect(Comment.reflect_on_association(:post)).to be_nil
|
193
199
|
end
|
194
200
|
end
|
195
201
|
|
@@ -203,8 +209,8 @@ describe ActiveRecord::Base do
|
|
203
209
|
schema_associations
|
204
210
|
end
|
205
211
|
class Comment < ActiveRecord::Base ; end
|
206
|
-
Post.reflect_on_association(:comments).
|
207
|
-
Comment.reflect_on_association(:post).
|
212
|
+
expect(Post.reflect_on_association(:comments)).not_to be_nil
|
213
|
+
expect(Comment.reflect_on_association(:post)).to be_nil
|
208
214
|
end
|
209
215
|
end
|
210
216
|
end
|
@@ -221,19 +227,19 @@ describe ActiveRecord::Base do
|
|
221
227
|
end
|
222
228
|
it "should create has_one association" do
|
223
229
|
reflection = Post.reflect_on_association(:comment)
|
224
|
-
reflection.
|
225
|
-
reflection.macro.
|
226
|
-
reflection.options[:class_name].
|
227
|
-
reflection.options[:foreign_key].
|
228
|
-
reflection.options[:inverse_of].
|
230
|
+
expect(reflection).not_to be_nil
|
231
|
+
expect(reflection.macro).to eq(:has_one)
|
232
|
+
expect(reflection.options[:class_name]).to eq("Comment")
|
233
|
+
expect(reflection.options[:foreign_key]).to eq("post_id")
|
234
|
+
expect(reflection.options[:inverse_of]).to eq(:post)
|
229
235
|
end
|
230
236
|
it "should create belongs_to association with singular inverse" do
|
231
237
|
reflection = Comment.reflect_on_association(:post)
|
232
|
-
reflection.
|
233
|
-
reflection.macro.
|
234
|
-
reflection.options[:class_name].
|
235
|
-
reflection.options[:foreign_key].
|
236
|
-
reflection.options[:inverse_of].
|
238
|
+
expect(reflection).not_to be_nil
|
239
|
+
expect(reflection.macro).to eq(:belongs_to)
|
240
|
+
expect(reflection.options[:class_name]).to eq("Post")
|
241
|
+
expect(reflection.options[:foreign_key]).to eq("post_id")
|
242
|
+
expect(reflection.options[:inverse_of]).to eq(:comment)
|
237
243
|
end
|
238
244
|
end
|
239
245
|
|
@@ -248,20 +254,20 @@ describe ActiveRecord::Base do
|
|
248
254
|
end
|
249
255
|
it "should name belongs_to according to column" do
|
250
256
|
reflection = Comment.reflect_on_association(:subject_post)
|
251
|
-
reflection.
|
252
|
-
reflection.macro.
|
253
|
-
reflection.options[:class_name].
|
254
|
-
reflection.options[:foreign_key].
|
255
|
-
reflection.options[:inverse_of].
|
257
|
+
expect(reflection).not_to be_nil
|
258
|
+
expect(reflection.macro).to eq(:belongs_to)
|
259
|
+
expect(reflection.options[:class_name]).to eq("Post")
|
260
|
+
expect(reflection.options[:foreign_key]).to eq("subject_post_id")
|
261
|
+
expect(reflection.options[:inverse_of]).to eq(:comments_as_subject)
|
256
262
|
end
|
257
263
|
|
258
264
|
it "should name has_many using 'as column'" do
|
259
265
|
reflection = Post.reflect_on_association(:comments_as_subject)
|
260
|
-
reflection.
|
261
|
-
reflection.macro.
|
262
|
-
reflection.options[:class_name].
|
263
|
-
reflection.options[:foreign_key].
|
264
|
-
reflection.options[:inverse_of].
|
266
|
+
expect(reflection).not_to be_nil
|
267
|
+
expect(reflection.macro).to eq(:has_many)
|
268
|
+
expect(reflection.options[:class_name]).to eq("Comment")
|
269
|
+
expect(reflection.options[:foreign_key]).to eq("subject_post_id")
|
270
|
+
expect(reflection.options[:inverse_of]).to eq(:subject_post)
|
265
271
|
end
|
266
272
|
end
|
267
273
|
|
@@ -276,20 +282,20 @@ describe ActiveRecord::Base do
|
|
276
282
|
end
|
277
283
|
it "should name belongs_to according to column" do
|
278
284
|
reflection = Comment.reflect_on_association(:post_cited)
|
279
|
-
reflection.
|
280
|
-
reflection.macro.
|
281
|
-
reflection.options[:class_name].
|
282
|
-
reflection.options[:foreign_key].
|
283
|
-
reflection.options[:inverse_of].
|
285
|
+
expect(reflection).not_to be_nil
|
286
|
+
expect(reflection.macro).to eq(:belongs_to)
|
287
|
+
expect(reflection.options[:class_name]).to eq("Post")
|
288
|
+
expect(reflection.options[:foreign_key]).to eq("post_cited")
|
289
|
+
expect(reflection.options[:inverse_of]).to eq(:comments_as_cited)
|
284
290
|
end
|
285
291
|
|
286
292
|
it "should name has_many using 'as column'" do
|
287
293
|
reflection = Post.reflect_on_association(:comments_as_cited)
|
288
|
-
reflection.
|
289
|
-
reflection.macro.
|
290
|
-
reflection.options[:class_name].
|
291
|
-
reflection.options[:foreign_key].
|
292
|
-
reflection.options[:inverse_of].
|
294
|
+
expect(reflection).not_to be_nil
|
295
|
+
expect(reflection.macro).to eq(:has_many)
|
296
|
+
expect(reflection.options[:class_name]).to eq("Comment")
|
297
|
+
expect(reflection.options[:foreign_key]).to eq("post_cited")
|
298
|
+
expect(reflection.options[:inverse_of]).to eq(:post_cited)
|
293
299
|
end
|
294
300
|
end
|
295
301
|
|
@@ -304,20 +310,20 @@ describe ActiveRecord::Base do
|
|
304
310
|
end
|
305
311
|
it "should name belongs_to according to column" do
|
306
312
|
reflection = Comment.reflect_on_association(:subject)
|
307
|
-
reflection.
|
308
|
-
reflection.macro.
|
309
|
-
reflection.options[:class_name].
|
310
|
-
reflection.options[:foreign_key].
|
311
|
-
reflection.options[:inverse_of].
|
313
|
+
expect(reflection).not_to be_nil
|
314
|
+
expect(reflection.macro).to eq(:belongs_to)
|
315
|
+
expect(reflection.options[:class_name]).to eq("Post")
|
316
|
+
expect(reflection.options[:foreign_key]).to eq("subject")
|
317
|
+
expect(reflection.options[:inverse_of]).to eq(:comments_as_subject)
|
312
318
|
end
|
313
319
|
|
314
320
|
it "should name has_many using 'as column'" do
|
315
321
|
reflection = Post.reflect_on_association(:comments_as_subject)
|
316
|
-
reflection.
|
317
|
-
reflection.macro.
|
318
|
-
reflection.options[:class_name].
|
319
|
-
reflection.options[:foreign_key].
|
320
|
-
reflection.options[:inverse_of].
|
322
|
+
expect(reflection).not_to be_nil
|
323
|
+
expect(reflection.macro).to eq(:has_many)
|
324
|
+
expect(reflection.options[:class_name]).to eq("Comment")
|
325
|
+
expect(reflection.options[:foreign_key]).to eq("subject")
|
326
|
+
expect(reflection.options[:inverse_of]).to eq(:subject)
|
321
327
|
end
|
322
328
|
end
|
323
329
|
|
@@ -330,8 +336,8 @@ describe ActiveRecord::Base do
|
|
330
336
|
class HappyPost < ActiveRecord::Base ; self.table_name = 'wooga_posts' ; end
|
331
337
|
class HappyComment < ActiveRecord::Base ; self.table_name = 'wooga_comments' ; end
|
332
338
|
# Kernel.warn HappyPost.reflect_on_all_associations.inspect
|
333
|
-
HappyComment.reflect_on_association(:post).class_name.
|
334
|
-
HappyPost.reflect_on_association(:comments).class_name.
|
339
|
+
expect(HappyComment.reflect_on_association(:post).class_name).to eq("HappyPost")
|
340
|
+
expect(HappyPost.reflect_on_association(:comments).class_name).to eq("HappyComment")
|
335
341
|
end
|
336
342
|
end
|
337
343
|
|
@@ -346,15 +352,15 @@ describe ActiveRecord::Base do
|
|
346
352
|
end
|
347
353
|
it "should create unordered has_many association" do
|
348
354
|
reflection = Post.reflect_on_association(:comments)
|
349
|
-
reflection.
|
350
|
-
reflection.macro.
|
351
|
-
reflection.options[:class_name].
|
352
|
-
reflection.options[:foreign_key].
|
353
|
-
reflection.options[:inverse_of].
|
355
|
+
expect(reflection).not_to be_nil
|
356
|
+
expect(reflection.macro).to eq(:has_many)
|
357
|
+
expect(reflection.options[:class_name]).to eq("Comment")
|
358
|
+
expect(reflection.options[:foreign_key]).to eq("post_id")
|
359
|
+
expect(reflection.options[:inverse_of]).to eq(:post)
|
354
360
|
if ::ActiveRecord::VERSION::MAJOR.to_i < 4
|
355
|
-
reflection.options[:order].
|
361
|
+
expect(reflection.options[:order]).to be_nil
|
356
362
|
else
|
357
|
-
reflection.scope.
|
363
|
+
expect(reflection.scope).to be_nil
|
358
364
|
end
|
359
365
|
end
|
360
366
|
end
|
@@ -370,15 +376,15 @@ describe ActiveRecord::Base do
|
|
370
376
|
end
|
371
377
|
it "should create ordered has_many association" do
|
372
378
|
reflection = Post.reflect_on_association(:comments)
|
373
|
-
reflection.
|
374
|
-
reflection.macro.
|
375
|
-
reflection.options[:class_name].
|
376
|
-
reflection.options[:foreign_key].
|
377
|
-
reflection.options[:inverse_of].
|
379
|
+
expect(reflection).not_to be_nil
|
380
|
+
expect(reflection.macro).to eq(:has_many)
|
381
|
+
expect(reflection.options[:class_name]).to eq("Comment")
|
382
|
+
expect(reflection.options[:foreign_key]).to eq("post_id")
|
383
|
+
expect(reflection.options[:inverse_of]).to eq(:post)
|
378
384
|
if ::ActiveRecord::VERSION::MAJOR.to_i < 4
|
379
|
-
reflection.options[:order].to_s.
|
385
|
+
expect(reflection.options[:order].to_s).to eq("position")
|
380
386
|
else
|
381
|
-
reflection.scope.
|
387
|
+
expect(reflection.scope).not_to be_nil
|
382
388
|
scope_tester = Object.new
|
383
389
|
expect(scope_tester).to receive(:order).with(:position)
|
384
390
|
scope_tester.instance_exec(&reflection.scope)
|
@@ -433,7 +439,7 @@ describe ActiveRecord::Base do
|
|
433
439
|
it "should use children as the inverse of parent" do
|
434
440
|
class Node < ActiveRecord::Base ; end
|
435
441
|
reflection = Node.reflect_on_association(:children)
|
436
|
-
reflection.
|
442
|
+
expect(reflection).not_to be_nil
|
437
443
|
end
|
438
444
|
|
439
445
|
it "should use child as the singular inverse of parent" do
|
@@ -442,7 +448,7 @@ describe ActiveRecord::Base do
|
|
442
448
|
end
|
443
449
|
class Node < ActiveRecord::Base ; end
|
444
450
|
reflection = Node.reflect_on_association(:child)
|
445
|
-
reflection.
|
451
|
+
expect(reflection).not_to be_nil
|
446
452
|
end
|
447
453
|
end
|
448
454
|
|
@@ -480,11 +486,11 @@ describe ActiveRecord::Base do
|
|
480
486
|
with_associations_config(:auto_create => true, :concise_names => true) do
|
481
487
|
prefix_one
|
482
488
|
reflection = Post.reflect_on_association(:comments)
|
483
|
-
reflection.
|
484
|
-
reflection.macro.
|
485
|
-
reflection.options[:class_name].
|
486
|
-
reflection.options[:foreign_key].
|
487
|
-
reflection.options[:inverse_of].
|
489
|
+
expect(reflection).not_to be_nil
|
490
|
+
expect(reflection.macro).to eq(:has_many)
|
491
|
+
expect(reflection.options[:class_name]).to eq("PostComment")
|
492
|
+
expect(reflection.options[:foreign_key]).to eq("post_id")
|
493
|
+
expect(reflection.options[:inverse_of]).to eq(:post)
|
488
494
|
end
|
489
495
|
end
|
490
496
|
|
@@ -492,11 +498,11 @@ describe ActiveRecord::Base do
|
|
492
498
|
with_associations_config(:auto_create => true, :concise_names => true) do
|
493
499
|
suffix_one
|
494
500
|
reflection = Post.reflect_on_association(:comments)
|
495
|
-
reflection.
|
496
|
-
reflection.macro.
|
497
|
-
reflection.options[:class_name].
|
498
|
-
reflection.options[:foreign_key].
|
499
|
-
reflection.options[:inverse_of].
|
501
|
+
expect(reflection).not_to be_nil
|
502
|
+
expect(reflection.macro).to eq(:has_many)
|
503
|
+
expect(reflection.options[:class_name]).to eq("CommentPost")
|
504
|
+
expect(reflection.options[:foreign_key]).to eq("post_id")
|
505
|
+
expect(reflection.options[:inverse_of]).to eq(:post)
|
500
506
|
end
|
501
507
|
end
|
502
508
|
|
@@ -504,11 +510,11 @@ describe ActiveRecord::Base do
|
|
504
510
|
with_associations_config(:auto_create => true, :concise_names => true) do
|
505
511
|
prefix_both
|
506
512
|
reflection = BlogPagePost.reflect_on_association(:comments)
|
507
|
-
reflection.
|
508
|
-
reflection.macro.
|
509
|
-
reflection.options[:class_name].
|
510
|
-
reflection.options[:foreign_key].
|
511
|
-
reflection.options[:inverse_of].
|
513
|
+
expect(reflection).not_to be_nil
|
514
|
+
expect(reflection.macro).to eq(:has_many)
|
515
|
+
expect(reflection.options[:class_name]).to eq("BlogPageComment")
|
516
|
+
expect(reflection.options[:foreign_key]).to eq("blog_page_post_id")
|
517
|
+
expect(reflection.options[:inverse_of]).to eq(:post)
|
512
518
|
end
|
513
519
|
end
|
514
520
|
|
@@ -516,13 +522,13 @@ describe ActiveRecord::Base do
|
|
516
522
|
with_associations_config(:auto_create => true, :concise_names => false) do
|
517
523
|
prefix_one
|
518
524
|
reflection = Post.reflect_on_association(:post_comments)
|
519
|
-
reflection.
|
520
|
-
reflection.macro.
|
521
|
-
reflection.options[:class_name].
|
522
|
-
reflection.options[:foreign_key].
|
523
|
-
reflection.options[:inverse_of].
|
525
|
+
expect(reflection).not_to be_nil
|
526
|
+
expect(reflection.macro).to eq(:has_many)
|
527
|
+
expect(reflection.options[:class_name]).to eq("PostComment")
|
528
|
+
expect(reflection.options[:foreign_key]).to eq("post_id")
|
529
|
+
expect(reflection.options[:inverse_of]).to eq(:post)
|
524
530
|
reflection = Post.reflect_on_association(:comments)
|
525
|
-
reflection.
|
531
|
+
expect(reflection).to be_nil
|
526
532
|
end
|
527
533
|
end
|
528
534
|
|
@@ -530,13 +536,13 @@ describe ActiveRecord::Base do
|
|
530
536
|
with_associations_config(:auto_create => true, :concise_names => true) do
|
531
537
|
prefix_one
|
532
538
|
reflection = Post.reflect_on_association(:comments)
|
533
|
-
reflection.
|
534
|
-
reflection.macro.
|
535
|
-
reflection.options[:class_name].
|
536
|
-
reflection.options[:foreign_key].
|
537
|
-
reflection.options[:inverse_of].
|
539
|
+
expect(reflection).not_to be_nil
|
540
|
+
expect(reflection.macro).to eq(:has_many)
|
541
|
+
expect(reflection.options[:class_name]).to eq("PostComment")
|
542
|
+
expect(reflection.options[:foreign_key]).to eq("post_id")
|
543
|
+
expect(reflection.options[:inverse_of]).to eq(:post)
|
538
544
|
reflection = Post.reflect_on_association(:post_comments)
|
539
|
-
reflection.
|
545
|
+
expect(reflection).to be_nil
|
540
546
|
end
|
541
547
|
end
|
542
548
|
|
@@ -555,10 +561,10 @@ describe ActiveRecord::Base do
|
|
555
561
|
end
|
556
562
|
it "should create has_and_belongs_to_many association" do
|
557
563
|
reflection = Post.reflect_on_association(:tags)
|
558
|
-
reflection.
|
559
|
-
reflection.macro.
|
560
|
-
reflection.options[:class_name].
|
561
|
-
reflection.options[:join_table].
|
564
|
+
expect(reflection).not_to be_nil
|
565
|
+
expect(reflection.macro).to eq(:has_and_belongs_to_many)
|
566
|
+
expect(reflection.options[:class_name]).to eq("Tag")
|
567
|
+
expect(reflection.options[:join_table]).to eq("posts_tags")
|
562
568
|
end
|
563
569
|
end
|
564
570
|
|
@@ -571,7 +577,7 @@ describe ActiveRecord::Base do
|
|
571
577
|
end
|
572
578
|
it "should define association normally if no existing method is defined" do
|
573
579
|
class Type < ActiveRecord::Base ; end
|
574
|
-
Type.reflect_on_association(:posts).
|
580
|
+
expect(Type.reflect_on_association(:posts)).not_to be_nil # sanity check for this context
|
575
581
|
end
|
576
582
|
it "should not define association over existing public method" do
|
577
583
|
class Type < ActiveRecord::Base
|
@@ -579,7 +585,7 @@ describe ActiveRecord::Base do
|
|
579
585
|
:existing
|
580
586
|
end
|
581
587
|
end
|
582
|
-
Type.reflect_on_association(:posts).
|
588
|
+
expect(Type.reflect_on_association(:posts)).to be_nil
|
583
589
|
end
|
584
590
|
it "should not define association over existing private method" do
|
585
591
|
class Type < ActiveRecord::Base
|
@@ -588,11 +594,11 @@ describe ActiveRecord::Base do
|
|
588
594
|
:existing
|
589
595
|
end
|
590
596
|
end
|
591
|
-
Type.reflect_on_association(:posts).
|
597
|
+
expect(Type.reflect_on_association(:posts)).to be_nil
|
592
598
|
end
|
593
599
|
it "should define association :type over (deprecated) kernel method" do
|
594
600
|
class Post < ActiveRecord::Base ; end
|
595
|
-
Post.reflect_on_association(:type).
|
601
|
+
expect(Post.reflect_on_association(:type)).not_to be_nil
|
596
602
|
end
|
597
603
|
it "should not define association :type over model method" do
|
598
604
|
class Post < ActiveRecord::Base
|
@@ -600,10 +606,27 @@ describe ActiveRecord::Base do
|
|
600
606
|
:existing
|
601
607
|
end
|
602
608
|
end
|
603
|
-
Post.reflect_on_association(:type).
|
609
|
+
expect(Post.reflect_on_association(:type)).to be_nil
|
610
|
+
end
|
611
|
+
end
|
612
|
+
|
613
|
+
context "regarding STI" do
|
614
|
+
before(:each) do
|
615
|
+
create_tables(
|
616
|
+
"posts", {}, {},
|
617
|
+
"comments", {}, { :post_id => {}, :type => {coltype: :string} }
|
618
|
+
)
|
619
|
+
class Post < ActiveRecord::Base ; end
|
620
|
+
class Comment < ActiveRecord::Base ; end
|
621
|
+
class SubComment < Comment ; end
|
622
|
+
end
|
623
|
+
|
624
|
+
it "defines association for subclass" do
|
625
|
+
expect(SubComment.reflect_on_association(:post)).not_to be_nil
|
604
626
|
end
|
605
627
|
end
|
606
628
|
|
629
|
+
|
607
630
|
if defined? ::ActiveRecord::Relation
|
608
631
|
|
609
632
|
context "regarding relations" do
|
@@ -648,7 +671,8 @@ describe ActiveRecord::Base do
|
|
648
671
|
table_defs.each_slice(3) do |table_name, opts, columns_with_options|
|
649
672
|
ActiveRecord::Migration.create_table table_name, opts do |t|
|
650
673
|
columns_with_options.each_pair do |column, options|
|
651
|
-
|
674
|
+
coltype = options.delete(:coltype) || :integer
|
675
|
+
t.send coltype, column, options
|
652
676
|
end
|
653
677
|
end
|
654
678
|
end
|
data/spec/connection.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_associations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronen Barzel
|
@@ -9,104 +9,104 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-07-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: schema_plus
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 1.2.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 1.2.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rdoc
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rspec
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: sqlite3
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: simplecov
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- -
|
88
|
+
- - ">="
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- -
|
95
|
+
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
|
-
name: simplecov-gem-
|
99
|
+
name: simplecov-gem-profile
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- -
|
109
|
+
- - ">="
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
description: SchemaAssociations extends ActiveRecord to automatically create associations
|
@@ -121,13 +121,15 @@ executables: []
|
|
121
121
|
extensions: []
|
122
122
|
extra_rdoc_files: []
|
123
123
|
files:
|
124
|
-
- .gitignore
|
125
|
-
- .travis.yml
|
124
|
+
- ".gitignore"
|
125
|
+
- ".travis.yml"
|
126
126
|
- MIT-LICENSE
|
127
127
|
- README.md
|
128
128
|
- Rakefile
|
129
|
+
- gemfiles/Gemfile.base
|
129
130
|
- gemfiles/Gemfile.rails-3.2
|
130
131
|
- gemfiles/Gemfile.rails-4.0
|
132
|
+
- gemfiles/Gemfile.rails-4.1
|
131
133
|
- init.rb
|
132
134
|
- lib/schema_associations.rb
|
133
135
|
- lib/schema_associations/active_record/associations.rb
|
@@ -147,17 +149,17 @@ require_paths:
|
|
147
149
|
- lib
|
148
150
|
required_ruby_version: !ruby/object:Gem::Requirement
|
149
151
|
requirements:
|
150
|
-
- -
|
152
|
+
- - ">="
|
151
153
|
- !ruby/object:Gem::Version
|
152
154
|
version: '0'
|
153
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
156
|
requirements:
|
155
|
-
- -
|
157
|
+
- - ">="
|
156
158
|
- !ruby/object:Gem::Version
|
157
159
|
version: '0'
|
158
160
|
requirements: []
|
159
161
|
rubyforge_project: schema_associations
|
160
|
-
rubygems_version: 2.
|
162
|
+
rubygems_version: 2.2.2
|
161
163
|
signing_key:
|
162
164
|
specification_version: 4
|
163
165
|
summary: ActiveRecord extension that automatically (DRY) creates associations based
|