views:

101

answers:

1

I've got a functional test that errors on the following method, saying that the first "Quality.create!(..." statement has too many arguments, which doesn't make any sense to me at all.

Running Ruby 1.8, Rails 2.3.5

    def reset_quality_lut
      Quality.delete_all

      Quality.create!(:value => 1, :name => "Scrap",      :extended_name => " (only good for parts)"   )
      Quality.create!(:value => 2, :name => "Heavy use",  :extended_name => " (needs work)"            )
      Quality.create!(:value => 3, :name => "Medium use", :extended_name => " (some functional damage)")
      Quality.create!(:value => 4, :name => "Light use",  :extended_name => " (cosmetic damage only)"  )
      Quality.create!(:value => 5, :name => "New",        :extended_name => " (or like new)"           )
      Quality.create!(:value => 0, :name => "Any",        :extended_name => "/all"                     )
    end

What the method is supposed to do is delete, and then re-create all the values in this table.

Here is the requested stack trace (note that I get the same thing if I replace the '.create' with a '.new(....).save':

  1) Error:
test_should_create_an_admin_user_on_app_setup(SetupControllerTest):
ArgumentError: wrong number of arguments (1 for 0)
    app/controllers/setup_controller.rb:43:in `reset_quality_lut'
    app/controllers/setup_controller.rb:23:in `create'
    /test/functional/setup_controller_test.rb:78:in `test_should_create_an_admin_user'

In the app, what this controller does is let you setup the app after initial setup. So...

www.myapp.com/setup/new

Brings you to a page where you enter a username and password for the first admin. When this succeeds, this action becomes inaccessible, so long as there's 1 admin user in the database.

EDIT: If I try "Quality.new.save", I get a nil error. Seems my "new" method is returning nil for some strange reason.

+1  A: 

The create! method should certainly work normally as you've used it. Is there any possibility that something else has defined a create! method on the Quality class? Or indeed on all model classes.

Either that or there may be a conflict between two Quality classes (I'm taking it as read that your Quality class is an ActiveRecord::Base subclass).

Shadwell
I did a search through all the code in the project, and there are no "def create!" references.
normalocity
And yes, the class definition starts with: "class Quality < ActiveRecord::Base". There are no "create", or "create!" methods defined on that class.
normalocity
I edited my code slightly to test your theory. In my test code I replaced the first "Quality.create(...)" call with "Quality.new(...).save)", and I get the same error message, but with "new" instead of "create"
normalocity
Very, very odd! Next theory is that there's a `method_missing` definition on `Quality` that is just consuming every unrecognised class method call. Any chance of that?
Shadwell
Nope. Only method definitions are: def self.newdef self.light, def self.medium, def self.heavy, def self.scrap, def self.any, def self.rebuild_quality_lut, (which I moved to this model for troubleshooting, but still get the same problem.
normalocity
I'm about to abandon this issue. :( My app is not open source, and as such, the likelihood that I would need to run the setup/new action is pretty much nil since my app is already live on the web. the action obviously worked the first time when I needed it to. This is really the lowest of low priorities on my list a the moment. It just bugs me to have it working only 99.99% correct. On the other hand, the reason for this method is essentially the same as a data-only migration. Perhaps I should move it into something like that and call it done.
normalocity
Oh, I see what I did - I was chasing the wrong thing the whole time. I defined "Quality.new" to return the "new" Quality value - when obviously "new" is defined on ActiveRecord::Base. Shadwell, yours is obviously the right answer.
normalocity