Skip to content

Commit

Permalink
Throw :abort instead of returning false while before_save
Browse files Browse the repository at this point in the history
Closes: mbleigh#132

Signed-off-by: Jongmin Kim <[email protected]>
  • Loading branch information
jmkim committed Aug 29, 2019
1 parent 34c054c commit 7ce4ad2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ class SeededModel < ActiveRecord::Base
attr_protected :first_name if self.respond_to?(:protected_attributes)
attr_accessor :fail_to_save

before_save { false if fail_to_save }
# From Rails 5.1, returning 'false' will not implicitly halt a callback chain.
# It was deprecated from Rails 5.0.
if ActiveRecord::VERSION::MAJOR < 5
before_save { false if fail_to_save }
else
before_save { throw :abort if fail_to_save }
end
end

class SeededModelNoPrimaryKey < ActiveRecord::Base
Expand Down

0 comments on commit 7ce4ad2

Please sign in to comment.