merge error with 2.0
Closed this issue · 6 comments
I'm getting this error with every model using default_value_for
NoMethodError: undefined method `merge' for []:Array
from /.rvm/gems/ruby-1.9.3-p125/gems/default_value_for-2.0.0/lib/default_value_for.rb:114:in `_all_default_attribute_values_not_allowing_nil'
default_value_for :central_key, :allows_nil => false do
SecureRandom.hex(10)
end
I cannot reproduce this problem. Which Ruby version and which Rails version are you on? Can you add a test to test.rb to reproduce this problem?
Looks like @jeremedia is on 1.9.3, I'm getting the same thing on ree-1.8.7-2011.03 with Rails 3.2.{1,2,3,5}, commenting out all of the default_value_for sections doesn't seem to fix the issue, I can create instances of objects, but finding them causes an error.
Only one model experiences this problem and its an STI subclass of the main model which defines the default_value_for block.
@geoffgarside Can you write a test and post a bigger backtrace?
The below is using ruby 1.9.3-p194
Backtrace
NoMethodError: undefined method `merge' for []:Array
default_value_for/lib/default_value_for.rb:114:in `_all_default_attribute_values_not_allowing_nil'
default_value_for/lib/default_value_for.rb:141:in `block in set_default_values'
default_value_for/lib/default_value_for.rb:140:in `each'
default_value_for/lib/default_value_for.rb:140:in `set_default_values'
default_value_for/.bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/callbacks.rb:405:in `_run__545446435472834699__initialize__3406250606838129900__callbacks'
default_value_for/.bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/callbacks.rb:405:in `__run_callback'
default_value_for/.bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/callbacks.rb:385:in `_run_initialize_callbacks'
default_value_for/.bundle/ruby/1.9.1/gems/activesupport-3.2.5/lib/active_support/callbacks.rb:81:in `run_callbacks'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/base.rb:524:in `init_with'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/inheritance.rb:68:in `instantiate'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/querying.rb:38:in `block (2 levels) in find_by_sql'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/querying.rb:38:in `collect!'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/querying.rb:38:in `block in find_by_sql'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/explain.rb:40:in `logging_query_plan'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/querying.rb:37:in `find_by_sql'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/relation.rb:171:in `exec_queries'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/relation.rb:160:in `block in to_a'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/explain.rb:40:in `logging_query_plan'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/relation.rb:159:in `to_a'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/relation/finder_methods.rb:376:in `find_first'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/relation/finder_methods.rb:122:in `first'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/relation/finder_methods.rb:334:in `find_one'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/relation/finder_methods.rb:310:in `find_with_ids'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/relation/finder_methods.rb:107:in `find'
default_value_for/.bundle/ruby/1.9.1/gems/activerecord-3.2.5/lib/active_record/querying.rb:5:in `find'
test.rb:103:in `test_with_sti'
Failing test case for test.rb
def test_with_sti
Number.default_value_for :number, 5678
define_model_class("SpecialNumber", "Number")
n = SpecialNumber.create
assert_nothing_raised { SpecialNumber.find(n.id) }
end
Should be fixed now. Can you confirm?
My application test cases pass without error now, so yep looks to be fixed. Thanks :)