Forum: Ruby on Rails Default scaffold makes a test.rb with errors

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aaron D. (Guest)
on 2009-04-25 09:42
(Received via mailing list)
Lines 24, 29, 34, (39 and 40) show errors I received when I used --
trace when I db:migrate all saying:

test_should_show_contact(ContactsControllerTest):
NoMethodError: undefined method `contacts'


Is the default file wrong. I can't see rails making a mistake in
scaffold.

-------------------------------------------------------------------------------------------------------------------------------------------------------

require 'test_helper'

class ContactsControllerTest < ActionController::TestCase
  test "should get index" do
    get :index
    assert_response :success
    assert_not_nil assigns(:contacts)
  end

  test "should get new" do
    get :new
    assert_response :success
  end

  test "should create contact" do
    assert_difference('Contact.count') do
      post :create, :contact => { }
    end

    assert_redirected_to contact_path(assigns(:contact))
  end

  test "should show contact" do
    get :show, :id => contacts(:one).to_param
<-----24
    assert_response :success
  end

  test "should get edit" do
    get :edit, :id => contacts(:one).to_param
<-----29
    assert_response :success
  end

  test "should update contact" do
    put :update, :id => contacts(:one).to_param, :contact =>
{ }             <-----34
    assert_redirected_to contact_path(assigns(:contact))
  end

  test "should destroy contact" do
    assert_difference('Contact.count', -1)
do                                    <-----39
      delete :destroy, :id => contacts
(:one).to_param                       <-----40
    end

    assert_redirected_to contacts_path
  end
end
Frederick C. (Guest)
on 2009-04-25 19:16
(Received via mailing list)
On Apr 25, 6:41 am, "removed_email_address@domain.invalid" 
<removed_email_address@domain.invalid> wrote:
> Lines 24, 29, 34, (39 and 40) show errors I received when I used --
> trace when I db:migrate all saying:
>
> test_should_show_contact(ContactsControllerTest):
> NoMethodError: undefined method `contacts'
>
> Is the default file wrong. I can't see rails making a mistake in
> scaffold.

Normally contacts is a method that is magicked into existance because
you have a contacts.yml fixture file. If you didn't (perhaps it ended
up as contact.yml or something, which might happen if you gave a
generator a plural when it expected a singular ( or vice-versa )) or
if your test_helper.rb didn't say fixtures :all then you might get
that error.

Fred
Aaron D. (Guest)
on 2009-04-25 21:45
(Received via mailing list)
The application works fine in development mode, so I can't really see
anything being wrong but I'll double check. I just keep getting the
error 500 screen every time I deploy and these are the only errors I
can find.
This topic is locked and can not be replied to.