【发布时间】:2015-04-30 20:02:17
【问题描述】:
下面的测试会产生错误信息
ActionView::Template::Error: undefined method `avatar?' for nil:NilClass
app/views/members/index.html.erb:25:in `block in _app_views_members_index_html_erb___1876261578458959373_9315040'
app/views/members/index.html.erb:22:in `_app_views_members_index_html_erb___1876261578458959373_9315040'
test/integration/site_layout_test.rb:50:in `block in <class:SiteLayoutTest>'
但在开发中它似乎可以工作。头像显示(如果存在)。有人知道原因吗?
测试:
get users_path
assert_template 'users/index'
User.paginate(page: 1).each do |user|
assert_select 'a[href=?]', user_path(user)
get organizations_path
assert_template 'organizations/index'
Organization.paginate(page: 1).each do |organization|
assert_select 'a[href=?]', organization_path(organization)
end
get members_path # THIS IS LINE 50!!
assert_template 'members/index'
Member.paginate(page: 1).each do |member|
assert_select 'a[href=?]', member_path(member)
end
会员索引视图包括:
<% @members.each do |member| %> # THIS IS LINE 22!!
<tr>
<td>
<% if member.organization.avatar? %> # THIS IS LINE 25!!
<%= link_to image_tag(member.organization.avatar.url, alt: "Profile"), member_path(member) %> <%= member.username %>
<% else %>
<%= link_to image_tag("profile.gif", alt: "Profile"), member_path(member) %> <%= member.username %>
<% end %>
</td>
<td><%= member.fullname %></td>
etc...
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 integration-testing