Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Default generator for ActiveModel

#3123

When generating an scaffold, Rails now requires that custom ORMs define their API, so the controller knows how to call the model. This makes perfectly sense to ORMs that don't implement ActiveModel, like DataMapper, but not for ORMs that do implement ActiveModel, because the coolest part of implementing ActiveModel is that you could just plug the code and it will work with Rails defaults.

I have attached a patch that uses Rails::Generators::ActiveModelDefault in case none generator has been specified for the model, so people implementing ActiveModel dont have to worry about the API definition.

cheers

Reported by Diego Carrion · August 31st, 2009 @ 11:36 PM

State: resolved
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: none

Activity

  1. José Valim
    José Valim
    • Assigned user set to José Valim

    August 31st, 2009 @ 11:43 PM

  2. Diego Carrion
  3. José Valim
    José Valim
    • Milestone cleared.

    Good patch. Just some small changes required:

    1) Tests does not pass. The current test fails (ScaffoldControllerGeneratorTest):

    def test_error_is_shown_if_orm_does_not_provide_interface

    error = capture(:stderr){ run_generator ["User", "--orm=unknown"] }
    assert_equal "Could not load Unknown::Generators::ActiveModel, skipping controller. " <<
                 "Error: no such file to load -- generators/unknown.\n", error
    

    end

    It can be removed and replaced by a test that ensures that ORM::Generators::ActiveModel is loaded (instead of Rails::Generators::ActiveModel).

    2) ActiveRecord::Generators::ActiveModel can now be removed.

    Thanks Carrion!

    September 1st, 2009 @ 10:08 AM

  4. Diego Carrion
    Diego Carrion

    My fault, test were not running correctly in my machine.

    I fixed the test and removed ActiveRecord::Generators::ActiveModel.

    September 1st, 2009 @ 09:02 PM

  5. Diego Carrion
    Diego Carrion

    Hi, any feedback on this?

    September 8th, 2009 @ 06:41 PM

  6. José Valim
    José Valim

    I need some time to apply it on a fork and add more tests. Showing that no error is raised is not actually testing that an ActiveModel subclass can be loaded.

    September 8th, 2009 @ 07:22 PM

  7. Diego Carrion
    Diego Carrion

    The test that tests that the code is loaded is the scaffold test. Before the updates, it tested that the ActiveRecord generator was being loaded but that generator doesnt exists anymore, so tests will fail now unless the default generator is being loaded correctly.

    September 8th, 2009 @ 09:25 PM

  8. José Valim
    José Valim

    Exactly, so right now, we don't have any test that ensures that ORM::Generators::ActiveModel is loaded, because ActiveRecord is now using the default Rails::Generators::ActiveModel. In other words, we are just testing the fallback.

    September 8th, 2009 @ 09:27 PM

  9. Repository
  10. José Valim
    José Valim
    • State changed from new to resolved

    November 1st, 2009 @ 12:16 PM

  11. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to

    October 15th, 2010 @ 11:01 PM