2013-03-18 71 views
0

嘿,所以我写了一个新的功能,并通过Spork跑我的测试西装,我有一个失败的视图测试。这将是我第一次看视图测试,所以它有点令人困惑。Rspec路由错误,当重新ajax

我收到以下错误

ActionView::Template::Error: 
    No route matches {:controller=>"employment_equity", :action=>"update_percentage_of_black_youth", :method=>:put, :scorecard_id=>123456, :id=>nil} 

的观点是测试看起来像这样(我用的青菜和HAML使#不是注释它引用的ID标签)

- if current_scorecard.base_charter_is? :transport_public_sector 
    .left 
    #percentage_of_employees_that_are_black_youth_input= f.field :percentage_of_employees_that_are_black_youth, :class => :percentage 
    .left 
    .auto_sum_link= link_to('Percentage from Details', update_percentage_of_black_youth_path(current_scorecard.id, @employment_equity.id), :method => :put, :remote => true) 

正如你所看到的,我将:remote_true添加到我的link_to,这样我就可以得到ajax来填写那个提交的文件。问题是它抱怨没有路线。

当我有它!

match '/scorecards/:scorecard_id/employment_equity/:id/update_percentage_of_black_youth', :controller => 'employment_equity', :action => 'update_percentage_of_black_youth', :method => :put, :as => 'update_percentage_of_black_youth' 

,然后打在外地基本上填满了新的价值我在模型

$("#percentage_of_employees_that_are_black_youth_input input").val(<%= @employment_equity.percentage_of_employees_that_are_black_youth %>).effect("highlight", {color: "#C3EC97"}, 3000); 

这在我的开发环境的所有作品制定出Ajax和我的单元测试所有的工作都无法弄清楚为什么它不会呈现因为传递给ajax的链接?任何一个发现了类似的问题?

回答

0

所以我跟我的脖子beardy朋友我旁边,看看我是正确的冒充这个问题,他想通了,我的路线一直在寻找一个id

match '/scorecards/:scorecard_id/employment_equity/:id/update_percentage_of_black_youth' 

和测试wasnt给人的问题ID因为它不是保存factoried类

No route matches {:controller=>"employment_equity", :action=>"update_percentage_of_black_youth", :method=>:put, :scorecard_id=>123456, id=>nil} 

遗憾的错误是超级不透明。

1

在RSpec/Capybara等默认情况下不支持Ajax。原因是JavaScript只在浏览器中运行。您是否使用Selenium或其他允许测试javascript的框架?

+0

我不知道吗?我们正在使用RSpec和Spork? – TheLegend 2013-03-18 12:06:47

+0

是的,RSpec和Spork不会为您提供测试ajaxy函数的能力。如果你想测试这部分的应用程序 – muttonlamb 2013-03-18 12:08:04

+0

感谢您的信息,你一定想看看硒或茉莉花!我不认为我们的任何js都经过测试,我不知道有测试它的轨道方式。你摇滚袜子 – TheLegend 2013-03-18 12:13:06