Skip to content

Commit

Permalink
Fixing bug of first! method on Rails 4.2 / 5
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagopradi committed Oct 14, 2016
1 parent c38360b commit e60f90d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/octopus.rb
Expand Up @@ -98,6 +98,10 @@ def self.rails41?
rails4? && ActiveRecord::VERSION::MINOR >= 1
end

def self.rails42?
rails4? && ActiveRecord::VERSION::MINOR == 2
end

def self.rails5?
ActiveRecord::VERSION::MAJOR == 5
end
Expand Down Expand Up @@ -172,6 +176,7 @@ def self.fully_replicated(&_block)
require 'octopus/log_subscriber'
require 'octopus/abstract_adapter'
require 'octopus/singular_association'
require 'octopus/finder_methods'

require 'octopus/railtie' if defined?(::Rails::Railtie)

Expand Down
8 changes: 8 additions & 0 deletions lib/octopus/finder_methods.rb
@@ -0,0 +1,8 @@
# find_nth / find_nth! must be public here to allow Octopus to call
# them on the scope proxy object
if Octopus.rails42? || Octopus.rails5?
module ActiveRecord::FinderMethods
public :find_nth
public :find_nth!
end
end
2 changes: 2 additions & 0 deletions spec/octopus/association_shard_tracking_spec.rb
Expand Up @@ -73,6 +73,7 @@
expect(@brazil_role.permissions).to eq([@permission_brazil])

expect(@brazil_role.permissions.first).to eq(@permission_brazil)
expect(@brazil_role.permissions.first!).to eq(@permission_brazil)
expect(@brazil_role.permissions.last).to eq(@permission_brazil)
end

Expand All @@ -81,6 +82,7 @@
expect(@permission_brazil.roles).to eq([@brazil_role])

expect(@permission_brazil.roles.first).to eq(@brazil_role)
expect(@permission_brazil.roles.first!).to eq(@brazil_role)
expect(@permission_brazil.roles.last).to eq(@brazil_role)
end

Expand Down

0 comments on commit e60f90d

Please sign in to comment.