下面的测试生成错误消息未定义的方法错误,但只有在测试
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...
谢谢,的确是这样的夹具滑倒了,通过它解决了这一错误消息。然而,出现了一个新的错误信息,为此我会发布一个新问题。 – Nick