ruby on rails - ActiveRecord model subclass NoMethodError on 'create' -
i've got rails 4 beta app (on ruby 2) , i'm getting error can't make sense out of.
i've got specs failing because model class has no method 'create', though i'm inheriting activerecord::base. error message calling class module (undefined method 'create' topic:module
), , seems odd.
spec/models/topic_spec.rb:
require "spec_helper" describe topic "should create new topic given valid attributes" topic.create!({:created_by_id => 1, :title => "test" }) end end
app/models/topic.rb
class topic < activerecord::base include activemodel::forbiddenattributesprotection validates :title => :presence => ture validates :created_by_id => :presence => true end
error message:
$ rspec spec/models/topic_spec.rb f failures: 1) topic should create new topic given valid attributes failure/error: topic.create!({:created_by_id => 1, :title => "test" }) nomethoderror: undefined method `create' topic:module # ./spec/models/topic_spec.rrc:15:in `block (2 levels) in <top (required)>'
it sounds have module or namespace named topic getting loaded first , in tests, topic not referring class. there other files have topic in them, class topic::question or similar? if so, try taking them out or being explicit it. example, changing:
class topic::question < activerecord::base
to
class topic class question < activerecord::base
Comments
Post a Comment