Guest User

Untitled

a guest
Mar 23rd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. ---_like.html.erb---
  2. <% if micropost.like_user(current_user.id) %>
  3. <%= button_to micropost_like_path(likes, micropost_id:
  4. micropost.id), method: :delete, id: "like-button", remote: true do %>
  5. <%= image_tag("icon_red_heard.png") %>
  6. <span>
  7. <%= micropost.likes_count %>
  8. </span>
  9. <% end %>
  10. <% else %>
  11. <%= button_to micropost_likes_path(micropost),id: "like-button",
  12. remote: true do %>
  13. <%= image_tag("icon_red_heart.png") %>
  14. <span>
  15. <%= micropost.likes_count %>
  16. </span>
  17. <% end %>
  18. <% end %>
  19.  
  20. ---_micropost.html.erb---
  21. <li id="micropost-<%= micropost.id %>">
  22. <%= link_to gravatar_for(micropost.user, size: 50), micropost.user %>
  23. <span class="user"><%= link_to micropost.user.name, micropost.user %></span>
  24. <span class="content">
  25. <%= micropost.content %>
  26. <%= image_tag micropost.picture.url if micropost.picture? %>
  27. </span>
  28. <span class="timestamp">
  29. Posted <%= time_ago_in_words(micropost.created_at) %> ago.
  30. <% if current_user?(micropost.user) %>
  31. <%= link_to "delete", micropost, method: :delete,
  32. data: { confirm: "You sure?" } %>
  33. <% end %>
  34. </span>
  35. <!--like拡張機能-->
  36. <%= render partial: 'likes/like', locals: { micropost: micropost,
  37. likes: @likes } %>
  38. </li>
  39.  
  40. ---show.html.erb---
  41. <% provide(:title, @user.name) %>
  42. <div class="row">
  43. <aside class="col-md-4">
  44. <section class="user_info">
  45. <h1>
  46. <%= gravatar_for @user %>
  47. <%= @user.name %>
  48. </h1>
  49. </section>
  50. <section class="stats">
  51. <%= render 'shared/stats' %>
  52. </section>
  53. </aside>
  54.  
  55. <div class="col-md-8">
  56. <%= render 'follow_form' if logged_in? %>
  57. <% if @user.microposts.any? %>
  58. <h3>Microposts (<%= @user.microposts.count %>)</h3>
  59. <ol class="microposts">
  60. <%= render @microposts %>
  61. </ol>
  62. <%= will_paginate @microposts %>
  63. <% end %>
  64. </div>
  65. </div>
  66.  
  67. ---users_profile_test.rb---
  68. require 'test_helper'
  69.  
  70. class UsersProfileTest < ActionDispatch::IntegrationTest
  71. include ApplicationHelper
  72.  
  73. def setup
  74. @user = users(:michael)
  75. end
  76.  
  77. test "profile display" do
  78. get user_path(@user)
  79. assert_template 'users/show'
  80. assert_select 'title', full_title(@user.name)
  81. assert_select 'h1', text: @user.name
  82. assert_select 'h1>img.gravatar'
  83. assert_match @user.microposts.count.to_s, response.body
  84. assert_select 'div.pagination'
  85. @user.microposts.paginate(page: 1).each do |micropost|
  86. assert_match micropost.content, response.body
  87. end
  88. end
  89. end
Add Comment
Please, Sign In to add comment