Default inspection on Rails projects raises warnings of incorrect call argument counts on model constructors

As an observation I opened a project and then signalled that it were a rails project by choosing 'Rails' from the dropdown.
Then I ran an inspection and was alerted with warnings that I had multiple paramaters being passed to my initialize constructors when I had no such declarations in my models.
The reason for this is because I let active record do any mapping based on the input params. I could add the following onto all of my model declarations to make it go away:

def initialize(*args)
    super(*args)
end 


This would introduce redundancy. So my question is should the default code inspection template not turn off this check?
Also, I noticed that when you right click on the code inspection results then choose to undo the particular check, your new changes are not immedietly applied and instead you remain on the 'default' code inspections preferences. This may be a bug or maybe just a piece of as of yet overlooked functionality.

  
2 comments
Comment actions Permalink

Hi Kevin,

Please show me some example of false positive from your project.

RubyMine understands that Model classes overrides ActiveRecord::Base class and thus knows uses parent initializer method initialize(attributes = nil) (activerecord-2.2.2/lib/active_record/base.rb)  will be used by default. This methods accepts no more than one argument (including hash). So

Person.new    
Person.new(params)
Person.new(:name => Mike, :age => 5)

are valid and will not be highlighted.

0
Comment actions Permalink

I have a similar problem, possibly caused by my ineritance hierarchy i.e.

class Animal < ActiveRecored::Base
end

class Person < Animal
end

I get warnings on things like

p = Person.name(:name => 'John')


John

0

Please sign in to leave a comment.