下面的測試生成錯誤消息未定義的方法錯誤,但只有在測試
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