Open Dakuan opened 12 years ago
I just started seeing a similar issue in my specs yesterday. I'll update this when I have tracked down the code causing this.
Ah cool, I'm glad it's not me being silly then!
I checked again. It is actually happening in functional tests with Test::Unit:
DEPRECATION WARNING: You're trying to create an attribute `project'. Writing arbitrary attributes on a model is deprecated. Please just use `attr_writer` etc. (called from write_enumerated_attribute at /path/to/vendor/gems/ruby/1.9.1/bundler/gems/enumerated_attribute-56c3506a7778/lib/enumerated_attribute/integrations/active_record.rb:24)
DEPRECATION WARNING: You're trying to create an attribute `investor'. Writing arbitrary attributes on a model is deprecated. Please just use `attr_writer` etc. (called from write_enumerated_attribute at /path/to/vendor/gems/ruby/1.9.1/bundler/gems/enumerated_attribute-56c3506a7778/lib/enumerated_attribute/integrations/active_record.rb:24)
Hmm im not using them, only cucumber features and rspec
This code was the culprit. You might have something similar somewhere. A recent update to Rails deprecated specifying models as arguments in mass assignment. I think it may have been a Rails 3 or 3.1 thing.
Interest.create(
project: @project,
investor: companies(:invco),
state: :followed)
The solution, if you need to use mass assignment here, is to do something like this:
Interest.create(
project_id: @project.id,
investor_id: companies(:invco).id,
state: :followed)
or
i = Interest.new
i.project_id = @project.id
i.investor_id = companies(:invco).id
i.state = :followed
i.save
Anyways, I don't think this is an issue with enum_attr, but something that both of us were probably doing wrong. It was on my end at least.
Found the commit in Rails:
https://github.com/rails/rails/commit/b2955edcea63e3daa347dc4e05b9abd380176ac8
Yep, that was exactly the problem. I was pumping a mock object in at create. Leaving that until afterwards made the warnings go away.
Am getting this warning....
"DEPRECATION WARNING: You're trying to create an attribute 'game_category'. Writing arbitrary attributes on a model is deprecated. Please just use 'attr_writer' etc. (called from write_enumerated_attribute at /Users/Dom/.rvm/gems/ruby-1.9.3-p194/bundler/gems/enumerated_attribute-56c3506a7778/lib/enumerated_attribute/integrations/active_record.rb:24)"
... when running RSpec tests. Tests do pass okay, and the code works fine. Is it something I am doing?