2013-02-17 159 views
0

我想设置一个RESTful API的重定向链接数据库。我在黄瓜里设置了很多测试,其中一个是用户在/ links /:id上执行GET操作。这应该是将用户重定向到链接。它在浏览器中工作,但我在黄瓜中设置此测试时遇到了一些麻烦。红宝石轨道︰黄瓜瓦特/水豚去applicationController on redirect_to

Given /^The link id part of the URL matches an existing entry in the links table$/ do 
FactoryGirl.create(:users) 
FactoryGirl.create(:links, :OWNER_USERID => Users.first.id) 
Users.count.should==1 
Links.count.should==1 
end 

When /^you use GET on link$/ do 
visit link_path(Links.first.id) 
end 

指定的link_path送我去这个节目的方法:

def show 
redir=Links.find_by_id(params[:id]) 
redirect_to redir.target, :status=>307 
end 

的问题是在这一点黄瓜失败,当部分抱怨我没有对应用程序/索引的模板。由于某种原因,它不会重定向我,而是会转到我自己站点的root_path。任何人都知道如何检查这种重定向是否真的有效?

回答

0

你有没有尝试在RSpec而不是黄瓜测试它?尝试这样的事情,看看它的工作原理:

describe "testing links" do 
    subject { page } 
    describe "use GET on link" do 
    let(:links) { Links.first } 
    before { get link_path(Links.first.id) } 
    specify { response.should redirect_to("http://example.com") } 
    end 
end 

另外,还要确保你的测试数据库,如果正确配置,做测试之前填充。

rake db:migrate and rake db:test:prepare