1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
Description: Make compatible with ActiveRecord 5.1+
Throw :abort instead of returning false while before_save.
Author: Jongmin Kim <jmkim@pukyong.ac.kr>
Bug: https://github.com/mbleigh/seed-fu/issues/132
Bug-Debian: https://bugs.debian.org/918595
Forwarded: https://github.com/mbleigh/seed-fu/pull/137
Last-Update: 2019-08-29
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -35,7 +35,13 @@
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
|