Guest User

Untitled

a guest
Jun 10th, 2018
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. ## the test
  2. def test_should_assign_dashboard_items
  3. login_as :aaron
  4. get :index
  5. assert_response :success
  6. assert_not_nil assigns(:post), "Did not assign a news posting"
  7. assert_not_nil assigns(:shifts), "Did not assign shifts for the calendar."
  8. id = Post.find(:first, :order => "created_at DESC", :limit => 1).id
  9. assert_select "div#post-#{id}", true, "div#post-#{id} should be assigned."
  10. assert_select "div#calendar", true, "div#calendar should be assigned."
  11. end
  12.  
  13. ## the error
  14. fails inside the partial that renders the post on post.user.name
  15. ActionView::TemplateError: You have a nil object when you didn't expect it!
  16. The error occurred while evaluating nil.name
  17. On line #3 of shared/_post.html.erb
  18.  
  19. 1: <div id="post-<%= post.id %>">
  20. 2: <h2><%= post.title %></h2>
  21. 3: <p><strong>Posted on: <%= post.posted_on %></strong> by <strong><%= post.user.name %></strong>
  22. 4: <% if current_user.is_admin? %>
  23. 5: <strong>[ <%= link_to 'Edit', edit_admin_post_path(post) %> <%= link_to 'Delete', {:controller => 'admin/posts', :action => 'destroy', :id => post.id}, :confirm => 'Are you sure?', :method => :delete %> ]</strong>
  24. 6: <% end %>
  25.  
  26.  
  27. ## posts.yml
  28. one:
  29. id: 1
  30. title: MyString
  31. content: MyText
  32. user: brandon
  33.  
  34. two:
  35. id: 2
  36. title: MyString
  37. content: MyText
  38. user: brandon
  39.  
  40. ## users.yml
  41. brandon:
  42. id: 4
  43. login: brandon
  44. email: fake@fake.com
  45. salt: da4b9237bacccdf19c0760cab7aec4a8359010b0 # SHA1('1')
  46. crypted_password: 7006b28985f1682bf1a75b0ce4871eea60d39627 # 'monkey'
  47. first_name: brandon
  48. last_name: george
Add Comment
Please, Sign In to add comment