Topic: Simple Test Fail

Hi Guys

I have coded my Customer controller manually, here is its code:

class CustomersController < ApplicationController
  
  def index
    list
    render('list')
  end
  
  def list
    @cusList = Customer.order("customers.name ASC")
  end
  
  def show
    @customer = Customer.find(params[:id])
  end
  
  def new
    @customer = Customer.new
  end
  
  def create
    # Instantiate a new object using form params
    @customer = Customer.new(params[:customer])
    # Save the object
    if @customer.save
      # If save succeeds, redirect to the list action
      flash[:notice] = "Customer created."
      redirect_to(:action => 'list')
    else
      # If save fails, redisplay the form so user can fix problems
      render('new')
    end
    
  end
  
  def edit
    @customer = Customer.find(params[:id])
  end
  
  def update
    # Find object using form params
    @customer = Customer.find(params[:id])
    # Update the object attributes
    if @customer.update_attributes(params[:customer])
      # If save succeeds, redirect to the list action
      flash[:notice] = "Customer updated."
      redirect_to(:action => 'show', :id => @customer.id)
    else
      # If save fails, redisplay the form so user can fix problems
      render('edit')
    end
  end
  
  def delete
    @customer = Customer.find(params[:id])
  end
  
  def destroy
    # Find object and destroy it.
    Customer.find(params[:id]).destroy
    flash[:notice] = "Customer deleted."
    redirect_to(:action => 'list')
  end
  
end

And here are a couple of simple tests that I am running for it:

require 'test_helper'

class CustomerTest < ActionController::IntegrationTest
  context "CRUD actions" do
    should "be able to create" do
      get "/customers/new"
      assert_response :success
      post "/customers", :post => {}
      assert_redirected_to "/customers/#{assigns(:customer).id}"
    end
    
    context "non-empty Customer model" do
      setup do
        @customer = Customer.first || Customer.create
      end
          
      should "be able to read" do
        get "/customers"
        assert_response :success
        get "/customers/#{@customer.id}"
        assert_response :success
        
      end
        
      should "be able to update" do
          get "/customers/#{@customer.id}/edit"
          assert_response :success
          put "/customers/#{@customer.id}", :post => {}
          assert_redirected_to "/customers/#{@customer.id}"
      end
          
      should "be able to delete" do
        delete "/customers/#{@customer.id}"
        assert_redirected_to "/customers"
      end
    
    end
     
  end
  
end

For some reason however, the tests are failing ! and I can't figure out why ! sad I would greatly appreciate any help.

Thank You.

"Facts do not cease to exist because they are ignored." .... Writer Aldous Huxley (1894 - 1963)

Re: Simple Test Fail

Thank you for sharing the code. I will also used this later.

modern bedroom furniture | modern beds