Last active
December 12, 2015 12:19
-
-
Save fguillen/4771248 to your computer and use it in GitHub Desktop.
Example code to reproduce the issue: http://stackoverflow.com/q/14838196/316700
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.rvmrc | |
*.sqlite |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rvm use --create ruby-1.9.3-p286@ar_callbacks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "active_record" | |
require "minitest/unit" | |
require "minitest/autorun" | |
require "mocha/setup" | |
ActiveRecord::Base.establish_connection( | |
:adapter => "sqlite3", | |
:database => "#{File.dirname(__FILE__)}/db.sqlite" | |
) | |
ActiveRecord::Schema.define :version => 0 do | |
create_table :users, :force => true do |t| | |
t.string :name | |
end | |
end | |
class User < ActiveRecord::Base | |
after_save :execute_after_save | |
def execute_after_save | |
Kernel.puts "Actual object still not saved" if changed? | |
end | |
end | |
class ARCallbackTest < MiniTest::Unit::TestCase | |
def test_changed_attribute_works_properly_if_called_after_save | |
user = User.create!(:name => "Wadus Name") | |
user.name = "Other Name" | |
assert(user.changed?) | |
user.save! | |
assert(!user.changed?) | |
end | |
def test_no_call_puts_in_after_save | |
user = User.create!(:name => "Wadus Name") | |
user.name = "Other Name" | |
Kernel.expects(:puts).never | |
user.save! | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :rubygems | |
gem "activerecord" | |
gem "sqlite3" | |
gem "mocha" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GEM | |
remote: http://rubygems.org/ | |
specs: | |
activemodel (3.2.11) | |
activesupport (= 3.2.11) | |
builder (~> 3.0.0) | |
activerecord (3.2.11) | |
activemodel (= 3.2.11) | |
activesupport (= 3.2.11) | |
arel (~> 3.0.2) | |
tzinfo (~> 0.3.29) | |
activesupport (3.2.11) | |
i18n (~> 0.6) | |
multi_json (~> 1.0) | |
arel (3.0.2) | |
builder (3.0.4) | |
i18n (0.6.1) | |
metaclass (0.0.1) | |
mocha (0.13.2) | |
metaclass (~> 0.0.1) | |
multi_json (1.5.0) | |
sqlite3 (1.3.7) | |
tzinfo (0.3.35) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
activerecord | |
mocha | |
sqlite3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment