预期响应为 <:redirect>,但为 <200>
我的测试有:
describe "Link POST #create" do
context "with valid attributes" do
it "creates a new link" do
expect{
post :create, link: FactoryGirl.create(:link, :group => @group)
}.to change(Link,:count).by(1)
end
it "redirects to the new link" do
post :create, link: FactoryGirl.create(:link, :group => @group)
# response.should redirect_to @link # Link.unscoped.last
response.should redirect_to Link.unscoped.last # render_template :show
end
end
第一次测试通过但第二次失败。
我的代码是:
def create
@link = Link.new(params[:link])
respond_to do |format|
if @link.save
flash[:notice] = 'Link was successfully created.'
format.html { redirect_to(@link) }
format.xml { render :xml => @link, :status => :created, :location => @link }
else
@selected_group = params[:group_id]
format.html { render :action => "new" }
format.xml { render :xml => @link.errors, :status => :unprocessable_entity }
end
end
end
我尝试过重定向和渲染,但无法通过第二次测试。