jeffp / enumerated_attribute

Easy enum for your models, objects and views
MIT License
190 stars 64 forks source link

Deprecation warning when running RSpec tests #50

Open Dakuan opened 12 years ago

Dakuan commented 12 years ago

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?

calebhearth commented 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.

Dakuan commented 12 years ago

Ah cool, I'm glad it's not me being silly then!

calebhearth commented 12 years ago

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)
Dakuan commented 12 years ago

Hmm im not using them, only cucumber features and rspec

calebhearth commented 12 years ago

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.

calebhearth commented 12 years ago

Found the commit in Rails:

https://github.com/rails/rails/commit/b2955edcea63e3daa347dc4e05b9abd380176ac8

Dakuan commented 12 years ago

Yep, that was exactly the problem. I was pumping a mock object in at create. Leaving that until afterwards made the warnings go away.