我正在尝试对其进行测试,当我传递一个带有 nil 字段的对象时,我得到了重定向,并且出现了错误:
Failure/Error: }.to assert_redirected_to close_path(@call)
MiniTest::Assertion:
Expected response to be a <redirect>, but was <200>
这是我所做的:
describe "#Close" do
before(:each) { @call = FactoryGirl.create(:call) }
it 'successful closes a call' do
get :close, {:id => @call.to_param}, valid_session
response.status.should eq 200
end
it "redirects to #close if there's no service described" do
expect {
put :done, {:id => @call.to_param,
:call => FactoryGirl.attributes_for(:call, {:service => nil})},
valid_session
}.to assert_redirected_to close_path(@call)
end
end
控制器:
# GET /calls/1/close
def close
@call = Call.find(params[:id])
end
# PUTS /calls/done
def done
respond_to do |format|
if @call.update(call_params) && @call.service != nil
format.html { redirect_to @call, notice: 'Chamada ##{@call.id} foi fechado.' }
format.json { head :no_content }
else
format.html { redirect_to :action => :close, :id => @call.id }
format.json { render json: @call.errors, status: :unprocessable_entity }
end
end
end
为什么总是200?有人知道吗??