現在rails tutorialの13章を学習しています.
そこの「13.3.5フィード画面のマイクロポストをテストする」のリスト 13.57のテストでエラーが出てしまいます.
どうやら,home.html.erbでパーシャルを使用しなければテストはパスできるのですが,その理由がわかりません.
どうか,教えてください…
発生している問題・エラーメッセージ
エラーメッセージ ActionView::Template::Error: ActionView::Template::Error: Missing partial microposts/_user_logged_in, application/_user_logged_in with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}. Searched in: * "/home/ubuntu/environment/sample_app/app/views" * "/home/ubuntu/.rvm/gems/ruby-2.6.3/gems/actiontext-6.0.3/app/views" * "/home/ubuntu/.rvm/gems/ruby-2.6.3/gems/actionmailbox-6.0.3/app/views" app/views/static_pages/home.html.erb:2 app/controllers/microposts_controller.rb:12:in `create' test/integration/microposts_interface_test.rb:15:in `block (2 levels) in <class:MicropostsInterfaceTest>' test/integration/microposts_interface_test.rb:14:in `block in <class:MicropostsInterfaceTest>'
###他参考コード
micropost_controller.rb
class
1 before_action :logged_in_user, only: [:create, :destroy] 2 before_action :correct_user, only: :destroy 3 4 def create 5 @micropost = current_user.microposts.build(micropost_params) 6 if @micropost.save 7 flash[:success] = "Micropost created!" 8 redirect_to root_url 9 else 10 @feed_items = current_user.feed.paginate(page: params[:page]) 11 render 'static_pages/home' 12 end 13 end 14. 15. 16. 17
microposts_interface_test
require 'test_helper' class MicropostsInterfaceTest < ActionDispatch::IntegrationTest def setup @user = users(:michael) end test "micropost interface" do log_in_as(@user) get root_path assert_select 'div.pagination' # 無効な送信 assert_no_difference 'Micropost.count' do post microposts_path, params: { micropost: { content: "" } } end assert_select 'div#error_explanation' assert_select 'a[href=?]', '/?page=2' # 正しいページネーションリンク # 有効な送信 content = "This micropost really ties the room together" assert_difference 'Micropost.count', 1 do post microposts_path, params: { micropost: { content: content } } end assert_redirected_to root_url follow_redirect! assert_match content, response.body # 投稿を削除する assert_select 'a', text: 'delete' first_micropost = @user.microposts.paginate(page: 1).first assert_difference 'Micropost.count', -1 do delete micropost_path(first_micropost) end # 違うユーザーのプロフィールにアクセス(削除リンクがないことを確認) get user_path(users(:archer)) assert_select 'a', text: 'delete', count: 0 end end
_user_info.html.erb
<%= link_to gravatar_for(current_user, size: 50), current_user %> <h1><%= current_user.name %></h1> <span><%= link_to "view my profile", current_user %></span> <span><%= pluralize(current_user.microposts.count, "micropost") %></span>
_micropost_form.html.erb
<%= form_with(model: @micropost, local: true) do |f| %> <%= render 'shared/error_messages', object: f.object %> <div class="field"> <%= f.text_area :content, placeholder: "Compose new micropost..." %> </div> <%= f.submit "Post", class: "btn btn-primary" %> <span class="image"> <%= f.file_field :image %> </span> <% end %>
_feed.html.erb
<% if @feed_items.any? %> <ol class="microposts"> <%= render @feed_items %> </ol> <%= will_paginate @feed_items, params: { controller: :static_pages, action: :home } %> <% end %>
エラーのでるソースコード
/sample_app/app/views/static_pages/home.html.erb
<% if logged_in? %> <%= render 'user_logged_in' %> <% else %> <%= render 'user_not_logged_in' %> <% end %>
/sample_app/app/views/static_pages/_user_logged_in.html.erb
<div class="row"> <aside class="col-md-4"> <section class="user_info"> <%= render 'shared/user_info' %> </section> <section class="micropost_form"> <%= render 'shared/micropost_form' %> </section> </aside> <div class="col-md-8"> <h3>Micropost Feed</h3> <%= render 'shared/feed' %> </div> </div>
/sample_app/app/views/static_pages/_user_not_logged_in.html.erb
<div class="center jumbotron"> <h1>Welcome to the Sample App</h1> <h2> This is the home page for the <a href="https://railstutorial.jp/">Ruby on Rails Tutorial</a> sample application. </h2> <%= link_to "Sign up now!", signup_path, class: "btn btn-lg btn-primary" %> </div>
###エラーのでないソースコード
/sample_app/app/views/static_pages/home.html.erb
<% if logged_in? %> <div class="row"> <aside class="col-md-4"> <section class="user_info"> <%= render 'shared/user_info' %> </section> <section class="micropost_form"> <%= render 'shared/micropost_form' %> </section> </aside> <div class="col-md-8"> <h3>Micropost Feed</h3> <%= render 'shared/feed' %> </div> </div> <% else %> <div class="center jumbotron"> <h1>Welcome to the Sample App</h1> <h2> This is the home page for the <a href="https://railstutorial.jp/">Ruby on Rails Tutorial</a> sample application. </h2> <%= link_to "Sign up now!", signup_path, class: "btn btn-lg btn-primary" %> </div> <%= link_to image_tag("rails.svg", alt: "Rails logo", width: "200px"), "https://rubyonrails.org/" %> <% end %>
回答2件
あなたの回答
tips
プレビュー