langalex/couch_potato — Issue #54: problem with is_dirty method
Author: phoet
Created: 2012-02-16 14:30:58+00:00
State: open

i want to write a migration where i just try to force save documents to the database, so that defaults, that i intruduced at some point get updated in the documents.

when i try to update my user model `user.is_dirty; user.save!` i get an `NoMethodError: undefined method 'email_changed?' for #` error.

this seems to come from `simple_property.rb` and looks like a validation-callback from active-model:

def dirty?(object)
object.send("#{name}_changed?")
end

i really did not understand how this should be working. are there some magic helper methods generated somewhere that should provide methods like `email_changed?` for all my model classes?

on the other hand if i update the e-mail property everything works fine:

```ruby
1.9.3-p0 :011 > user.email = 'uschi@muschiiiii.de'; user.save!
=> true
```

here is the stack:

```ruby
1.9.3-p0 :009 > u.is_dirty;u.save!
NoMethodError: undefined method `email_changed?' for #
from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/persistence/ghost_attributes.rb:7:in `method_missing'
from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/persistence/dirty_attributes.rb:32:in `method_missing'
from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activemodel-3.1.3/lib/active_model/attribute_methods.rb:385:in `method_missing'
from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:446:in `_run_validate_callbacks'
from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activemodel-3.1.3/lib/active_model/validations.rb:212:in `run_validations!'
from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activemodel-3.1.3/lib/active_model/validations.rb:179:in `valid?'
from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:174:in `valid_document?'
from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:157:in `block (2 levels) in update_document'
from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:390:in `_run_validation_on_update_callbacks'
from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:156:in `block in update_document'
from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:390:in `_run_validation_on_save_callbacks'
from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:155:in `update_document'
from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:81:in `save_document'
from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato/database.rb:88:in `save_document!'
from /Users/uschi/Documents/rails/wlw/lib/gem_ext/couch_potato/concerned_with_persistence.rb:120:in `block in save!'
from /Users/uschi/Documents/rails/wlw/lib/gem_ext/couch_potato/concerned_with_persistence.rb:102:in `block in with_database'
from /Users/uschi/Documents/rails/wlw/vendor/git/couch_potato/lib/couch_potato.rb:44:in `with_database'
from /Users/uschi/Documents/rails/wlw/lib/gem_ext/couch_potato/concerned_with_persistence.rb:101:in `with_database'
from /Users/uschi/Documents/rails/wlw/lib/gem_ext/couch_potato/concerned_with_persistence.rb:119:in `save!'
from (irb):9
from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
from /Users/uschi/.rvm/gems/ruby-1.9.3-p0@wlw/gems/railties-3.1.3/lib/rails/commands.rb:40:in `'
from script/rails:6:in `require'
from scri = User.last
=> #
1.9.3-p0 :011 > u.email = 'uschi@muschiiiii.de';u.save!
=> true
```