Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6829 (closed defect: fixed)

Opened 2 years ago

Last modified 4 months ago

[PATCH] new inflection rules are not used in resource routes

Reported by: Nate Assigned to: core
Priority: normal Milestone: 1.2.7
Component: Railties Version: 1.2.6
Severity: normal Keywords: scaffold_resource routes inflections
Cc:

Description

Functional test code generated by scaffold_resource fails with custom inflections while the user interface behaves as expected.

Here are the steps to reproduce this error:

rails rest_test

cd rest_test

rake rails:freeze:edge TAG=rel_1-2-0_RC1

Edit config/environment.rb and add a custom inflection:

  Inflector.inflections do |inflect|
    inflect.irregular "goose", "geese"
  end

Generate the REST interface:

script/generate scaffold_resource Goose title:string

Create databases:

mysqladmin -uroot create rest_test_development
mysqladmin -uroot create rest_test_test

Run generated migration:

rake db:migrate

Kick off the tests:

rake test

I get errors like:

7 tests, 4 assertions, 0 failures, 5 errors

NoMethodError: undefined method `goose_path' for #<GeeseController:0xb71e2a88>

ActionView::TemplateError: undefined method `goose_path' for #<#<Class:0xb73e6a58>:0xb710fb94>

ActionView::TemplateError: undefined method `goose_path' for #<#<Class:0xb73e6a58>:0xb70a0adc>

ActionView::TemplateError: undefined method `edit_goose_path' for #<#<Class:0xb73e6a58>:0xb6f4b628>

NoMethodError: undefined method `goose_path' for #<GeeseController:0xb6e39488>

If I start the server:

script/server

I can create, show, update, and destroy Geese by hand. I also do not encounter this problem with built in inflections like Person and People.

I get the same results on Edge Rails (revision 5714) as well.

Attachments

inflect_in_initializer_block.diff (1.2 kB) - added by dcmanges on 01/14/07 21:45:52.
set inflections before initializing routes
reload_routes_after_inflect.diff (0.5 kB) - added by dcmanges on 01/14/07 21:46:16.
reload routes after inflect

Change History

01/12/07 10:22:48 changed by smeade

  • summary changed from scaffold_resource generated functional tests fail with custom inflections (while user interface works as expected) to new inflection rules in environment.rb are not used in testing (unless also added to test.rb).

put the custom inflection in test.rb as well and it will work. need a patch to have it picked up from environment.rb

(in reply to: ↑ description ) 01/12/07 14:55:35 changed by eljo

The same thing happens to me in production environment: accessing somehost.com/lokale fails with NoMethodError, while it works in development.

routes.rb: ... map.resources :lokale ...

environment.rb: ... inflect.irregular 'lokal', 'lokale' ...

After putting the inflection in environments/production.rb everything works as it should.

01/14/07 21:25:50 changed by dcmanges

I think the problem is that the routes are generated before you specify the inflection.

You could also use this: ActionController::Routing::Routes.reload after you specify the inflection.

01/14/07 21:45:52 changed by dcmanges

  • attachment inflect_in_initializer_block.diff added.

set inflections before initializing routes

01/14/07 21:46:16 changed by dcmanges

  • attachment reload_routes_after_inflect.diff added.

reload routes after inflect

01/14/07 21:47:52 changed by dcmanges

  • keywords changed from scaffold_resource, map.resources, test:functionals to scaffold_resource routes inflections.
  • summary changed from new inflection rules in environment.rb are not used in testing (unless also added to test.rb) to [PATCH] new inflection rules are not used in resource routes.
  • component changed from ActionPack to RailTies.
  • version changed from 1.2.0rc1 to edge.
  • milestone changed from 1.2 to 1.x.

Changing the configuration fixes this.

01/20/07 18:38:56 changed by dcmanges

also reported in #7100

10/05/07 15:03:54 changed by david

  • keywords changed from scaffold_resource routes inflections to scaffold_resource routes inflections rails2.

10/08/07 01:23:00 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [7786]) Move custom inflections example so available before route generation. Closes #6829.

10/08/07 01:25:04 changed by bitsweat

  • milestone changed from 2.x to 1.2.5.

11/13/07 02:13:35 changed by chuyeow

  • status changed from closed to reopened.
  • resolution deleted.

#10145 reports a problem with the inflections in 1.2.5. It's not well formatted so lemme summarize.

Basically if the example Inflector block is uncommented in the generated environment.rb, a NameError is thrown:

config/environment.rb:46: uninitialized constant Inflector (NameError)

I can confirm this happening after running something like:

script/generate controller anime

This is with a newly generated Rails app generated from gem Rails 1.2.5. Can anyone confirm this before we start working on a patch?

11/18/07 05:36:11 changed by chuyeow

  • keywords changed from scaffold_resource routes inflections rails2 to scaffold_resource routes inflections.

11/18/07 05:37:30 changed by chuyeow

  • milestone changed from 1.2.5 to 1.2.6.

03/09/08 16:24:09 changed by zilkey

  • status changed from reopened to closed.
  • resolution set to fixed.

This is no longer an issue for edge - even with the fix from 9815 removed (as per the patch from zilkey). For example:

rails rest_test
cd rest_test
rake rails:freeze:edge

Add this to config/initializers/inflection.rb

Inflector.inflections do |inflect|
  inflect.irregular "goose", "geese"
end

Then run

script/generate scaffold Goose title:string
rake db:migrate
rake test
>.......
>Finished in 0.141374 seconds.
>
>7 tests, 13 assertions, 0 failures, 0 errors
rake routes
> geese GET    /geese etc...

Initializers fixed this. I'm closing it.

03/09/08 16:34:41 changed by chuyeow

  • version changed from edge to 1.2.6.

Well, this is a 1.2 branch ticket, not an edge issue.