goldiloader 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0abf48daca16a3eb1ee9eef6a059d1ff3eb77153
4
- data.tar.gz: 06b4f7f3d16be572b0981c579141de46f363d28b
3
+ metadata.gz: 218ef1dd67241dac5ee6c56cc0fc5e9dc01edd8a
4
+ data.tar.gz: 8dfc1cd8a8a9c7c4e42a7ece035734b6e72d8762
5
5
  SHA512:
6
- metadata.gz: 5fd2ab09fd21e0f18aa97210d9c3f6696bf96a4fa4d07bd5a163237431e24019641ab5586c42b59219f31b0827481364dea662f86c8c50c72e3f34eca5be2c3a
7
- data.tar.gz: bcf2dbf9cc413af86f6dcd0cffafcc435fd52bde9b8e6c9752abe38b5dcae34b42b2952b53dc5af45fbc04ab229f7e13c04a1c6e5728225029bcd4619a543d9d
6
+ metadata.gz: 471b2b2f4ac390b7d31ce55810eadcbc845adb7e5f9a34a5b3f1a63d49430e1f8f8cdd384d445ceb9c4c308c427ae4be3d0297c0e87c9e82609204189ea10a6b
7
+ data.tar.gz: 73120bf84295153faee36635aecb18920c4cf86df13333fcef6c4e857b3715dd0afdf9fe6538dee7e578eb3472694eed1a7fb4077fba80406e3ae84cef8d7cfc
data/.travis.yml CHANGED
@@ -1,9 +1,9 @@
1
1
  language: ruby
2
2
  env:
3
- - RAILS_VERSION="~> 3.2.19" JRUBY_OPTS="$JRUBY_OPTS --debug"
4
- - RAILS_VERSION="~> 4.0.10" JRUBY_OPTS="$JRUBY_OPTS --debug"
5
- - RAILS_VERSION="~> 4.1.6" JRUBY_OPTS="$JRUBY_OPTS --debug"
6
- - RAILS_VERSION="~> 4.2.0.beta2" JRUBY_OPTS="$JRUBY_OPTS --debug"
3
+ - RAILS_VERSION="~> 3.2.20" JRUBY_OPTS="$JRUBY_OPTS --debug"
4
+ - RAILS_VERSION="~> 4.0.11" JRUBY_OPTS="$JRUBY_OPTS --debug"
5
+ - RAILS_VERSION="~> 4.1.7" JRUBY_OPTS="$JRUBY_OPTS --debug"
6
+ - RAILS_VERSION="~> 4.2.0.beta4" JRUBY_OPTS="$JRUBY_OPTS --debug"
7
7
  rvm:
8
8
  - 1.9.3
9
9
  - 2.0.0
@@ -13,4 +13,4 @@ matrix:
13
13
  exclude:
14
14
  # See https://github.com/salsify/goldiloader/issues/22
15
15
  - rvm: jruby-19mode
16
- env: RAILS_VERSION="~> 4.2.0.beta2" JRUBY_OPTS="$JRUBY_OPTS --debug"
16
+ env: RAILS_VERSION="~> 4.2.0.beta4" JRUBY_OPTS="$JRUBY_OPTS --debug"
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.0.8 (unreleased)
4
+ * Fix [issue 23](https://github.com/salsify/goldiloader/issues/23) - Handle polymorphic belongs_to
5
+ associations in Rails 4 that have a mix of non-nil and nil values.
6
+
7
+
3
8
  ### 0.0.7
4
9
  * Fix [issue 20](https://github.com/salsify/goldiloader/issues/20) by not auto-eager loading
5
10
  associations that are instance dependent. Eager loading these associations produces potentially
data/README.md CHANGED
@@ -170,7 +170,7 @@ Goldiloader detects associations with any of these options and disables automati
170
170
 
171
171
  ## Status
172
172
 
173
- This gem is tested with Rails 3.2, 4.0, and 4.1 using MRI 1.9.3, 2.0.0, 2.1.0 and JRuby in 1.9 mode.
173
+ This gem is tested with Rails 3.2, 4.0, 4.1, and 4.2 using MRI 1.9.3, 2.0.0, 2.1.0 and JRuby in 1.9 mode.
174
174
 
175
175
  Let us know if you find any issues or have any other feedback.
176
176
 
@@ -16,32 +16,32 @@ module Goldiloader
16
16
  delegate :association_scope, :reflection, to: :@association
17
17
 
18
18
  def read_only?
19
- association_scope.readonly_value.present?
19
+ association_scope && association_scope.readonly_value.present?
20
20
  end
21
21
 
22
22
  def offset?
23
- association_scope.offset_value.present?
23
+ association_scope && association_scope.offset_value.present?
24
24
  end
25
25
 
26
26
  def limit?
27
- association_scope.limit_value.present?
27
+ association_scope && association_scope.limit_value.present?
28
28
  end
29
29
 
30
30
  def from?
31
- association_scope.from_value.present?
31
+ association_scope && association_scope.from_value.present?
32
32
  end
33
33
 
34
34
  def group?
35
- association_scope.group_values.present?
35
+ association_scope && association_scope.group_values.present?
36
36
  end
37
37
 
38
38
  def joins?
39
39
  # Yuck - Through associations will always have a join for *each* 'through' table
40
- (association_scope.joins_values.size - num_through_joins) > 0
40
+ association_scope && (association_scope.joins_values.size - num_through_joins) > 0
41
41
  end
42
42
 
43
43
  def uniq?
44
- association_scope.uniq_value
44
+ association_scope && association_scope.uniq_value
45
45
  end
46
46
 
47
47
  def instance_dependent?
@@ -50,6 +50,7 @@ module Goldiloader
50
50
 
51
51
  def unscope?
52
52
  Goldiloader::Compatibility.unscope_query_method_enabled? &&
53
+ association_scope &&
53
54
  association_scope.unscope_values.present?
54
55
  end
55
56
 
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Goldiloader
4
- VERSION = '0.0.7'
4
+ VERSION = '0.0.8'
5
5
  end
data/spec/db/schema.rb CHANGED
@@ -10,6 +10,8 @@ ActiveRecord::Schema.define(:version => 0) do
10
10
  t.string :title
11
11
  t.integer :blog_id
12
12
  t.integer :author_id
13
+ t.string :owner_type
14
+ t.integer :owner_id
13
15
  end
14
16
 
15
17
  create_table(:users, force: true) do |t|
@@ -106,6 +108,8 @@ class Post < ActiveRecord::Base
106
108
  has_many :post_tags
107
109
  has_many :tags, through: :post_tags
108
110
 
111
+ belongs_to :owner, polymorphic: true
112
+
109
113
  if ActiveRecord::VERSION::MAJOR >= 4
110
114
  has_many :unique_tags, -> { distinct }, through: :post_tags, source: :tag, class_name: 'Tag'
111
115
  else
@@ -475,13 +475,46 @@ describe Goldiloader do
475
475
  expect(posts.first.unique_tags.to_a).to match_array([child_tag1, child_tag3])
476
476
  end
477
477
 
478
- it "auto eager the association" do
478
+ it "auto eager loads the association" do
479
479
  posts.each do |blog|
480
480
  expect(blog.association(:unique_tags)).to be_loaded
481
481
  end
482
482
  end
483
483
  end
484
484
 
485
+ context "polymorphic associations with nil" do
486
+ let!(:user) { User.create! }
487
+ let!(:group) { Group.create! }
488
+
489
+ let!(:post1) do
490
+ Post.create! { |post| post.owner = user }
491
+ end
492
+
493
+ let!(:post2) do
494
+ Post.create! { |post| post.owner = group }
495
+ end
496
+
497
+ let!(:post3) do
498
+ Post.create!
499
+ end
500
+
501
+ let(:posts) { Post.where(id: [post1, post2, post3].map(&:id)).order(:id).to_a }
502
+
503
+ before do
504
+ posts.first.owner
505
+ end
506
+
507
+ it "loads the association correctly" do
508
+ expect(posts.map(&:owner)).to eq [user, group, nil]
509
+ end
510
+
511
+ it "auto eager loads the association" do
512
+ posts.select(&:owner_id).each do |post|
513
+ expect(post.association(:owner)).to be_loaded
514
+ end
515
+ end
516
+ end
517
+
485
518
  context "when a model is destroyed" do
486
519
  let!(:posts) { Post.where(blog_id: blog1.id).to_a }
487
520
  let(:destroyed_post) { posts.first }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goldiloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Turkel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-25 00:00:00.000000000 Z
11
+ date: 2014-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord