diff options
Diffstat (limited to 'activerecord/test')
| -rw-r--r-- | activerecord/test/cases/dirty_test.rb | 16 | 
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index 216f228142..f5aaf22e13 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -703,6 +703,22 @@ class DirtyTest < ActiveRecord::TestCase      assert pirate.catchphrase_changed?(from: "arrrr", to: "arrrr matey!")    end +  test "getters with side effects are allowed" do +    klass = Class.new(Pirate) do +      def catchphrase +        if super.blank? +          update_attribute(:catchphrase, "arr") # what could possibly go wrong? +        end +        super +      end +    end + +    pirate = klass.create!(catchphrase: "lol") +    pirate.update_attribute(:catchphrase, nil) + +    assert_equal "arr", pirate.catchphrase +  end +    private      def with_partial_writes(klass, on = true)        old = klass.partial_writes?  | 
