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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70205c74f75ca21daa67a8f61fe2d1d929c31190
4
- data.tar.gz: 361d1fad6225d77f2a3c082a07ab455275c1c9d5
3
+ metadata.gz: d3b9c45613e71564c85a31fe61dbe4a568568a23
4
+ data.tar.gz: c45c59c0dab8f9e87e396ef90199c6d4f5f6f852
5
5
  SHA512:
6
- metadata.gz: 4404428e7c93f5afe933a10ff82dbed3c4b9dafb3bb9b9540559d24517c5e8bad1fd5a8299ef82f8e5a0f275ae11af617b0bb39051349470a42fa61cac196005
7
- data.tar.gz: 6fc59f166f9732dfd794b844e631cf037c1afb8e944b308b2cba25df2538866a260598238239e9c8eb93f4d11c6d72fa470048a90b82d3a60f43631cef5f0fcc
6
+ metadata.gz: febbd2e3214f1bd063d68f0e9f93c0a12da75acbe7aefec616892015992cdb2afc4a5a7c31db8bb17200a49032a4daf2f2f10d14247f0018f1f10ee56a101513
7
+ data.tar.gz: 7e83f3bf6be38cd776896fa58b1ff21f39cbb1c5b20bff219c9b1dc3fa181ba5a5bcaa36d38acf7f09ed287a8ae8310b7d175a39f5189d8c1963c98311aa47b3
data/.travis.yml CHANGED
@@ -1,9 +1,10 @@
1
1
  rvm:
2
2
  - 1.9.3
3
- - 2.0.0
3
+ - 2.1.2
4
4
  gemfile:
5
5
  - gemfiles/Gemfile.rails-3.2
6
6
  - gemfiles/Gemfile.rails-4.0
7
+ - gemfiles/Gemfile.rails-4.1
7
8
  notifications:
8
9
  recipients:
9
10
  - michal.lomnicki@gmail.com
data/README.md CHANGED
@@ -317,10 +317,10 @@ use cases that you logged).
317
317
 
318
318
  ## Compatibility
319
319
 
320
- SchemaAssociations supports all combinations of:
320
+ SchemaAssociations is tested on all combinations of:
321
321
 
322
- * Rails 3.2 or rails 4.0
323
- * MRI ruby 1.9.3 or 2.0.0
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
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/lomba/schema_associations/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
397
+
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec :path => File.expand_path('..', __FILE__)
3
+
4
+ gem "byebug" if RUBY_VERSION > "2"
@@ -1,4 +1,3 @@
1
- source "http://rubygems.org"
1
+ eval File.read File.expand_path('../Gemfile.base', __FILE__)
2
2
 
3
- gemspec :path => File.expand_path('../..', __FILE__)
4
3
  gem "rails", "~> 3.2.0"
@@ -1,4 +1,3 @@
1
- source "http://rubygems.org"
1
+ eval File.read File.expand_path('../Gemfile.base', __FILE__)
2
2
 
3
- gemspec :path => File.expand_path('../..', __FILE__)
4
3
  gem "rails", "~> 4.0.0"
@@ -0,0 +1,3 @@
1
+ eval File.read File.expand_path('../Gemfile.base', __FILE__)
2
+
3
+ gem "rails", "~> 4.1.0"
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module SchemaAssociations
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
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.0.0]
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. remove current version from path and current gem path
66
- # so that forked shell will respect RBENV_VERSION variable
67
- ENV['PATH'] = ENV['PATH'].split(':').reject{|dir| dir =~ %r{/rbenv/versions/}}.join(':')
68
- ENV['GEM_PATH'] = nil
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(/^Failed examples/).any?
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
@@ -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-adapter")
29
+ s.add_development_dependency("simplecov-gem-profile")
30
30
  end
31
31
 
@@ -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.should_not be_nil
23
- reflection.macro.should == :belongs_to
24
- reflection.options[:class_name].should == "Post"
25
- reflection.options[:foreign_key].should == "post_id"
26
- reflection.options[:inverse_of].should == :comments
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.should_not be_nil
32
- reflection.macro.should == :belongs_to
33
- reflection.options[:class_name].should == "Post"
34
- reflection.options[:foreign_key].should == "post_id"
35
- reflection.options[:inverse_of].should == :comments
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.should == 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.should == 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.should_not be_nil
53
- reflection.macro.should == :has_many
54
- reflection.options[:class_name].should == "Comment"
55
- reflection.options[:foreign_key].should == "post_id"
56
- reflection.options[:inverse_of].should == :post
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.should_not be_nil
82
- else reflection.should be_nil
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).should be_nil
176
- Comment.reflect_on_association(:post).should_not be_nil
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).should_not be_nil
192
- Comment.reflect_on_association(:post).should be_nil
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).should_not be_nil
207
- Comment.reflect_on_association(:post).should be_nil
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.should_not be_nil
225
- reflection.macro.should == :has_one
226
- reflection.options[:class_name].should == "Comment"
227
- reflection.options[:foreign_key].should == "post_id"
228
- reflection.options[:inverse_of].should == :post
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.should_not be_nil
233
- reflection.macro.should == :belongs_to
234
- reflection.options[:class_name].should == "Post"
235
- reflection.options[:foreign_key].should == "post_id"
236
- reflection.options[:inverse_of].should == :comment
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.should_not be_nil
252
- reflection.macro.should == :belongs_to
253
- reflection.options[:class_name].should == "Post"
254
- reflection.options[:foreign_key].should == "subject_post_id"
255
- reflection.options[:inverse_of].should == :comments_as_subject
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.should_not be_nil
261
- reflection.macro.should == :has_many
262
- reflection.options[:class_name].should == "Comment"
263
- reflection.options[:foreign_key].should == "subject_post_id"
264
- reflection.options[:inverse_of].should == :subject_post
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.should_not be_nil
280
- reflection.macro.should == :belongs_to
281
- reflection.options[:class_name].should == "Post"
282
- reflection.options[:foreign_key].should == "post_cited"
283
- reflection.options[:inverse_of].should == :comments_as_cited
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.should_not be_nil
289
- reflection.macro.should == :has_many
290
- reflection.options[:class_name].should == "Comment"
291
- reflection.options[:foreign_key].should == "post_cited"
292
- reflection.options[:inverse_of].should == :post_cited
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.should_not be_nil
308
- reflection.macro.should == :belongs_to
309
- reflection.options[:class_name].should == "Post"
310
- reflection.options[:foreign_key].should == "subject"
311
- reflection.options[:inverse_of].should == :comments_as_subject
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.should_not be_nil
317
- reflection.macro.should == :has_many
318
- reflection.options[:class_name].should == "Comment"
319
- reflection.options[:foreign_key].should == "subject"
320
- reflection.options[:inverse_of].should == :subject
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.should == "HappyPost"
334
- HappyPost.reflect_on_association(:comments).class_name.should == "HappyComment"
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.should_not be_nil
350
- reflection.macro.should == :has_many
351
- reflection.options[:class_name].should == "Comment"
352
- reflection.options[:foreign_key].should == "post_id"
353
- reflection.options[:inverse_of].should == :post
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].should be_nil
361
+ expect(reflection.options[:order]).to be_nil
356
362
  else
357
- reflection.scope.should be_nil
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.should_not be_nil
374
- reflection.macro.should == :has_many
375
- reflection.options[:class_name].should == "Comment"
376
- reflection.options[:foreign_key].should == "post_id"
377
- reflection.options[:inverse_of].should == :post
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.should == "position"
385
+ expect(reflection.options[:order].to_s).to eq("position")
380
386
  else
381
- reflection.scope.should_not be_nil
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.should_not be_nil
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.should_not be_nil
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.should_not be_nil
484
- reflection.macro.should == :has_many
485
- reflection.options[:class_name].should == "PostComment"
486
- reflection.options[:foreign_key].should == "post_id"
487
- reflection.options[:inverse_of].should == :post
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.should_not be_nil
496
- reflection.macro.should == :has_many
497
- reflection.options[:class_name].should == "CommentPost"
498
- reflection.options[:foreign_key].should == "post_id"
499
- reflection.options[:inverse_of].should == :post
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.should_not be_nil
508
- reflection.macro.should == :has_many
509
- reflection.options[:class_name].should == "BlogPageComment"
510
- reflection.options[:foreign_key].should == "blog_page_post_id"
511
- reflection.options[:inverse_of].should == :post
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.should_not be_nil
520
- reflection.macro.should == :has_many
521
- reflection.options[:class_name].should == "PostComment"
522
- reflection.options[:foreign_key].should == "post_id"
523
- reflection.options[:inverse_of].should == :post
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.should be_nil
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.should_not be_nil
534
- reflection.macro.should == :has_many
535
- reflection.options[:class_name].should == "PostComment"
536
- reflection.options[:foreign_key].should == "post_id"
537
- reflection.options[:inverse_of].should == :post
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.should be_nil
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.should_not be_nil
559
- reflection.macro.should == :has_and_belongs_to_many
560
- reflection.options[:class_name].should == "Tag"
561
- reflection.options[:join_table].should == "posts_tags"
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).should_not be_nil # sanity check for this context
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).should be_nil
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).should be_nil
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).should_not be_nil
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).should be_nil
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
- t.integer column, options
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
@@ -7,5 +7,5 @@ ActiveRecord::Base.configurations = {
7
7
 
8
8
  }
9
9
 
10
- ActiveRecord::Base.establish_connection 'schema_associations'
10
+ ActiveRecord::Base.establish_connection :schema_associations
11
11
  ActiveRecord::Base.connection.execute "PRAGMA synchronous = OFF"
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'simplecov'
2
- require 'simplecov-gem-adapter'
2
+ require 'simplecov-gem-profile'
3
3
  SimpleCov.start "gem"
4
4
 
5
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
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.0
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: 2013-08-14 00:00:00.000000000 Z
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-adapter
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.0.3
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