- 
      
 - 
        
Save gbelote/3010690 to your computer and use it in GitHub Desktop.  
    undefined method `read_attribute_for_validation' for nil:NilClass
  
        
  
    
      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
    
  
  
    
  | class A < ActiveRecord::Base | |
| attr_accessible :data | |
| serialize :data, B | |
| validate :custom | |
| def custom | |
| errors.add :data, "whoopsies!" unless data.valid? | |
| 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
    
  
  
    
  | require 'test_helper' | |
| class ATest < ActiveSupport::TestCase | |
| test "weird failure" do | |
| a = A.new | |
| b = B.new | |
| b.foo = 'bar' | |
| a.data = b | |
| assert a.valid? | |
| assert b.valid? | |
| assert a.save | |
| assert a.valid? # -> throws exception | |
| 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
    
  
  
    
  | class B | |
| include ActiveModel::Validations | |
| attr_accessor :foo | |
| validates_presence_of :foo | |
| 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
    
  
  
    
  | NoMethodError: undefined method `read_attribute_for_validation' for nil:NilClass | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activemodel-3.2.6/lib/active_model/errors.rb:254:in `block in add_on_blank' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activemodel-3.2.6/lib/active_model/errors.rb:253:in `each' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activemodel-3.2.6/lib/active_model/errors.rb:253:in `add_on_blank' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activemodel-3.2.6/lib/active_model/validations/presence.rb:8:in `validate' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:310:in `_callback_before_7' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:407:in `_run__2107971919899649095__validate__2662006763039653414__callbacks' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:405:in `__run_callback' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:385:in `_run_validate_callbacks' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activemodel-3.2.6/lib/active_model/validations.rb:226:in `run_validations!' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activemodel-3.2.6/lib/active_model/validations.rb:193:in `valid?' | |
| /Users/gbelote/tmp/serialize-fail/app/models/a.rb:8:in `custom' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:407:in `_run__3204678033069886840__validate__2662006763039653414__callbacks' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:405:in `__run_callback' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:385:in `_run_validate_callbacks' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activemodel-3.2.6/lib/active_model/validations.rb:226:in `run_validations!' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activemodel-3.2.6/lib/active_model/validations/callbacks.rb:53:in `block in run_validations!' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:403:in `_run__3204678033069886840__validation__2662006763039653414__callbacks' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:405:in `__run_callback' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:385:in `_run_validation_callbacks' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activemodel-3.2.6/lib/active_model/validations/callbacks.rb:53:in `run_validations!' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activemodel-3.2.6/lib/active_model/validations.rb:193:in `valid?' | |
| /Users/gbelote/.rvm/gems/ruby-1.9.2-p290@serialize-fail/gems/activerecord-3.2.6/lib/active_record/validations.rb:69:in `valid?' | |
| /Users/gbelote/tmp/serialize-fail/test/unit/a_test.rb:14:in `block in <class:ATest>' | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment