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

Ticket #10435 (closed defect: fixed)

Opened 5 months ago

Last modified 5 months ago

[PATCH] Functional Test Scaffold Fails with Hardcoded ID of 1

Reported by: boone Assigned to: core
Priority: normal Milestone: 2.x
Component: Railties Version: edge
Severity: normal Keywords: scaffold tests verified
Cc:

Description

Since Foxy Fixtures is built in to Rails 2.0, the default functional test scaffold will fail, because it references hardcoded model IDs of 1.

http://dev.rubyonrails.org/browser/trunk/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb

For example:

def test_should_show_<%= file_name %>
  get :show, :id => 1
  assert_response :success
end

The get line should be changed to reference the fixture. I'm not sure how that's done, but maybe something like this:

def test_should_show_<%= file_name %>
  get :show, :id => <%= file_name.pluralize %>(:one).id
  assert_response :success
end

All of the tests in that file that reference an ID of 1 should be corrected.

Attachments

remove_hardcoded_ids_from_functional_test_scaffold_template.diff (1.2 kB) - added by boone on 12/11/07 20:50:39.

Change History

12/11/07 20:50:39 changed by boone

  • attachment remove_hardcoded_ids_from_functional_test_scaffold_template.diff added.

12/11/07 21:04:38 changed by boone

  • summary changed from Functional Test Scaffold Fails with Hardcoded ID of 1 to [PATCH] Functional Test Scaffold Fails with Hardcoded ID of 1.

I created a patch, and it looks like table_name is the best variable to use as it also gets used in creating the fixture filename.

However, I do not know how to test this with a Ruby test within Railties. I did create a Rails project and created a scaffold using this patch which successfully passes the functional test.

12/12/07 15:25:20 changed by swoop

+1

12/13/07 05:49:58 changed by evolving_jerk

Closed ticket with my patch to this because your approach uses fixtures that is a preferred way for Rails core team.

+1

12/13/07 06:10:51 changed by lawrence

  • keywords changed from scaffold tests to scaffold tests verified.

+1

12/14/07 18:09:17 changed by david

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

(In [8386]) Fixed that functional tests generated for scaffolds should use fixture calls instead of hard-coded IDs (closes #10435) [boone]