Skip to content

Commit

Permalink
Merge pull request #4427 from estolfo/MONGOID-4440-rails-5-1
Browse files Browse the repository at this point in the history
MONGOID-4440 Support Rails 5.1
  • Loading branch information
estolfo authored Jun 7, 2017
2 parents 19d51f9 + 26e6368 commit 95a25a7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ source 'https://rubygems.org'
gemspec

gem 'rake'
gem 'actionpack', '~> 5.0.0'
gem 'activemodel', '~> 5.0.0'
gem 'actionpack', '~> 5.1'
gem 'activemodel', '~> 5.1'


group :test do
Expand Down
4 changes: 2 additions & 2 deletions gemfiles/driver_master.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ gem 'bson', github: "mongodb/bson-ruby"
gem 'mongo', github: "mongodb/mongo-ruby-driver"

gem 'rake'
gem 'actionpack', '~> 5.0.0'
gem 'activemodel', '~> 5.0.0'
gem 'actionpack', '~> 5.1'
gem 'activemodel', '~> 5.1'

group :test do
gem 'rspec', '~> 3.4.0'
Expand Down
8 changes: 6 additions & 2 deletions lib/mongoid/interceptable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,12 @@ def run_targeted_callbacks(place, kind)
chain.append(callback) if callback.kind == place
end
self.class.send :define_method, name do
runner = ActiveSupport::Callbacks::Filters::Environment.new(self, false, nil)
chain.compile.call(runner).value
env = ActiveSupport::Callbacks::Filters::Environment.new(self, false, nil)
sequence = chain.compile
sequence.invoke_before(env)
env.value = !env.halted
sequence.invoke_after(env)
env.value
end
self.class.send :protected, name
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: utf-8
module Mongoid
VERSION = "6.1.1"
VERSION = "6.2.0"
end
2 changes: 1 addition & 1 deletion mongoid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = ">= 1.3.6"
s.rubyforge_project = "mongoid"

s.add_dependency("activemodel", ["~> 5.0"])
s.add_dependency("activemodel", ["~> 5.1"])
s.add_dependency("mongo", ['>=2.4.1', '<3.0.0'])

s.files = Dir.glob("lib/**/*") + %w(CHANGELOG.md LICENSE README.md Rakefile)
Expand Down
24 changes: 16 additions & 8 deletions spec/mongoid/interceptable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,32 +484,40 @@ class TestClass

context "when the child does not have the same callback defined" do

let(:band) do
Band.new
let(:exhibition) do
Exhibition.new
end

let!(:record) do
band.records.build
let!(:exhibitor) do
exhibition.exhibitors.build
end

context "when running the callbacks directly" do

before(:all) do
Band.define_model_callbacks(:rearrange)
Band.after_rearrange { }
Exhibition.define_model_callbacks(:rearrange)
Exhibition.after_rearrange { }
end

after(:all) do
Band.reset_callbacks(:rearrange)
Exhibition.reset_callbacks(:rearrange)
end

it "does not cascade to the child" do
expect(band.run_callbacks(:rearrange)).to be true
expect(exhibition.run_callbacks(:rearrange)).to be true
end
end

context "when the callbacks get triggered by a destroy" do

let(:band) do
Band.new
end

let!(:record) do
band.records.build
end

before(:all) do
Band.define_model_callbacks(:rearrange)
Band.set_callback(:validation, :before) do
Expand Down

0 comments on commit 95a25a7

Please sign in to comment.