SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with restful_authentication and functional test

    I'm struggling with using the restful_authentication plugin in functional tests . The following error turns up in my posts_controller_test.rb;

    1) Error:
    test_should_get_edit_rjs(PostsControllerTest):
    ActionView::TemplateError: You have a nil object when you didn't expect it!
    The error occurred while evaluating nil.login
    On line #4 of posts/_edit.html.erb

    Code HTML4Strict:
        1: <&#37; remote_form_for(@post) do |f| %>
        2: 
        3:          <div class="post_body" id="edit_post_body_<%= @post.id %>">
        4:                  <p><%= link_to "#{@post.user.login}", @post.user %> <%=h @post.created_at.to_s(:short) %></p>

    Code Ruby:
    	require File.dirname(__FILE__) + '/../test_helper'
     
    	class PostsControllerTest < ActionController::TestCase
    	  fixtures :all
     
    	  def test_should_get_edit_rjs
    	    xhr :post, :edit, :id => 2, :login => 'quentin', :password => 'test'
    	    assert_rjs :replace_html, "post_body_#{@post.id}"
    	  end
     
    	end

    Obviously I need to get the test_should_get_edit_rjs to use a user fixtures record 'login' with which to make post.user.login 'true' - but how do I do this if I've already specified it on the same line as the xhr request?

  2. #2
    SitePoint Addict liquidautumn's Avatar
    Join Date
    Nov 2002
    Location
    Kharkov, Ukraine
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your fundamental problem is that your tests seems coupled really tight.
    functional tests, supposed to test controllers only, not models and views
    get rid of fixtures, mock out models and test controllers apart from views.
    another problem, you'll face when start mocking and stubbing, is violation of Law of Demeter.
    and, last, but not least: while it's not too late, try rspec.

  3. #3
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by liquidautumn View Post
    your fundamental problem is that your tests seems coupled really tight.
    functional tests, supposed to test controllers only, not models and views
    get rid of fixtures, mock out models and test controllers apart from views.
    another problem, you'll face when start mocking and stubbing, is violation of Law of Demeter.
    and, last, but not least: while it's not too late, try rspec.

    Thanks. Most of my tests were based on the generated tests, so I thought it would be good to work through getting those to pass first, even if generated code is generally frowned-upon.

    I've been going through the rSpec tutorials on Peepcode. Looks nicer than Test::Unit, but I think I'm going to carry on with the standard approach of build first and test later, at least for my first app. rSpec will lead the next project.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •