Skip to content

Commit

Permalink
Start working on Rails 5 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jturkel committed Dec 28, 2015
1 parent 7cea9ec commit f34993d
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 8 deletions.
15 changes: 13 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@ sudo: false
env:
- RAILS_VERSION="~> 3.2.22" JRUBY_OPTS="$JRUBY_OPTS --debug"
- RAILS_VERSION="~> 4.0.13" JRUBY_OPTS="$JRUBY_OPTS --debug"
- RAILS_VERSION="~> 4.1.13" JRUBY_OPTS="$JRUBY_OPTS --debug"
- RAILS_VERSION="~> 4.2.4" JRUBY_OPTS="$JRUBY_OPTS --debug"
- RAILS_VERSION="~> 4.1.14" JRUBY_OPTS="$JRUBY_OPTS --debug"
- RAILS_VERSION="~> 4.2.5" JRUBY_OPTS="$JRUBY_OPTS --debug"
- RAILS_VERSION="~> 5.0.0.beta1" JRUBY_OPTS="$JRUBY_OPTS --debug"
rvm:
- 1.9.3
- 2.0.0
- 2.1.6
- 2.2.2
- jruby-19mode
matrix:
exclude:
- rvm: 1.9.3
env: RAILS_VERSION="~> 5.0.0.beta1" JRUBY_OPTS="$JRUBY_OPTS --debug"
- rvm: 2.0.0
env: RAILS_VERSION="~> 5.0.0.beta1" JRUBY_OPTS="$JRUBY_OPTS --debug"
- rvm: 2.1.6
env: RAILS_VERSION="~> 5.0.0.beta1" JRUBY_OPTS="$JRUBY_OPTS --debug"
- rvm: jruby-19mode
env: RAILS_VERSION="~> 5.0.0.beta1" JRUBY_OPTS="$JRUBY_OPTS --debug"
4 changes: 2 additions & 2 deletions goldiloader.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Gem::Specification.new do |spec|
spec.test_files = Dir.glob('spec/**/*')
spec.require_paths = ['lib']

spec.add_dependency 'activerecord', ENV.fetch('RAILS_VERSION', ['>= 3.2', '< 4.3'])
spec.add_dependency 'activesupport', ENV.fetch('RAILS_VERSION', ['>= 3.2', '< 4.3'])
spec.add_dependency 'activerecord', ENV.fetch('RAILS_VERSION', ['>= 3.2', '< 5.1'])
spec.add_dependency 'activesupport', ENV.fetch('RAILS_VERSION', ['>= 3.2', '< 5.1'])

spec.add_development_dependency 'coveralls'
spec.add_development_dependency 'database_cleaner', '>= 1.2'
Expand Down
4 changes: 4 additions & 0 deletions lib/goldiloader/active_record_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def exec_queries_with_auto_include
models
end

# TODO: alias_method_chain is deprecated in Rails 5
alias_method_chain :exec_queries, :auto_include
end

Expand Down Expand Up @@ -90,6 +91,7 @@ def find_target_with_auto_include(*args)
load_with_auto_include(:find_target, *args)
end

# TODO: alias_method_chain is deprecated in Rails 5
alias_method_chain :find_target, :auto_include
end

Expand All @@ -105,6 +107,7 @@ def find_target_with_auto_include(*args)
send("#{aliased_target}_without_fully_load#{punctuation}", *args, &block)
end

# TODO: alias_method_chain is deprecated in Rails 5
alias_method_chain method, :fully_load
end

Expand All @@ -114,6 +117,7 @@ def load_target_with_auto_include(*args)
load_with_auto_include(:load_target, *args)
end

# TODO: alias_method_chain is deprecated in Rails 5
alias_method_chain :load_target, :auto_include

end
Expand Down
6 changes: 5 additions & 1 deletion lib/goldiloader/association_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def limit?
end

def from?
association_scope && association_scope.from_value.present?
if ActiveRecord::VERSION::MAJOR >= 5
association_scope && association_scope.from_clause.present?
else
association_scope && association_scope.from_value.present?
end
end

def group?
Expand Down
17 changes: 15 additions & 2 deletions lib/goldiloader/association_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@ module Goldiloader
module AssociationOptions
extend self

OPTIONS = [:auto_include, :fully_load]
OPTIONS = [:auto_include, :fully_load].freeze

# This is only used in Rails 5+
module AssociationBuilderExtension
def self.build(model, reflection)
# TODO: Should we do anything here?
end

def self.valid_options
OPTIONS
end
end

def register
if ::ActiveRecord::VERSION::MAJOR >= 4
if ::ActiveRecord::VERSION::MAJOR >= 5
ActiveRecord::Associations::Builder::Association.extensions << AssociationBuilderExtension
elsif ::ActiveRecord::VERSION::MAJOR >= 4
ActiveRecord::Associations::Builder::Association.valid_options.concat(OPTIONS)
else
# Each subclass of CollectionAssociation will have its own copy of valid_options so we need
Expand Down
2 changes: 1 addition & 1 deletion lib/goldiloader/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: UTF-8

module Goldiloader
VERSION = '0.0.10'
VERSION = '0.0.10'.freeze
end
1 change: 1 addition & 0 deletions spec/goldiloader/goldiloader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@
end

if ActiveRecord::VERSION::MAJOR >= 4
# TODO: This is broken in Rails 5
context "associations with an overridden from" do
before do
blogs.first.from_posts.to_a
Expand Down

0 comments on commit f34993d

Please sign in to comment.