0

我有一个失败的测试,即使当我在浏览器中测试它时操作确实有效。我的测试有问题,看起来像。

我正在使用应该和固定装置。

require 'test_helper'

class AddressesControllerTest < ActionController::TestCase
  context 'on PUT to :update' do
    setup do
      put(:update, {
          :id => addresses(:mary_publics_address).id,
          :street1 => '123 Now St.'
        }, { :user_id => users(:stan).id})
    end
    should 'update the Address' do
      a = Address.find(addresses(:mary_publics_address).id)
      assert(a.street1 == '123 Now St.', 'Attribute did not get updated.')
    end
  end
end

因“属性未更新”而失败。

这是正在测试的控制器代码:

class AddressesController < ApplicationController
  def update
    @address = Address.find(params[:id])
    @address.update_attributes!(params[:address])
    render(:text => "Address with ID #{params[:id]} updated")
  end
end
4

1 回答 1

2

我看不到您在测试中传递给您的操作的参数中指定的 params[:address]。在我看来它应该是:

put(:update, {
        :id => addresses(:mary_publics_address).id,
        :address => { :street1 => '123 Now St.' }
      }, { :user_id => users(:stan).id})

我怀疑您的street1地址字段在您的表单中正确命名,address[street1]这就是它通过浏览器工作的原因。

于 2009-07-29T19:15:21.690 回答