rspec - rails tutorial 10.3.3 feed_item failing test -
i down 10.43 without errors, following errors occurred after attempting create micropost. tutorial says happen , need go , enter blank array @feed_items. despite making said changes, still 2 errors. in advance.
failures: 1) static pages home page signed_in users should render user's feed failure/error: visit root_path actionview::template::error: missing partial shared/feed_item {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. searched in: * "/users/patrick/rails_projects/sample_app/app/views" # ./app/views/shared/_feed.html.erb:3:in `_app_views_shared__feed_html_erb__768030223365309889_70321791671740' # ./app/views/static_pages/home.html.erb:13:in `_app_views_static_pages_home_html_erb___2533148950545762160_70321815481080' # ./spec/requests/static_pages_spec.rb:21:in `block (4 levels) in <top (required)>' 2) micropost pages micropost creation valid information should create micropost failure/error: expect { click_button "post" }.to change(micropost, :count).by(1) actionview::template::error: missing partial shared/feed_item {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. searched in: * "/users/patrick/rails_projects/sample_app/app/views" # ./app/views/shared/_feed.html.erb:3:in `_app_views_shared__feed_html_erb__768030223365309889_70321791671740' # ./app/views/static_pages/home.html.erb:13:in `_app_views_static_pages_home_html_erb___2533148950545762160_70321815481080' # (eval):2:in `click_button' # ./spec/requests/micropost_pages_spec.rb:29:in `block (5 levels) in <top (required)>' # ./spec/requests/micropost_pages_spec.rb:29:in `block (4 levels) in <top (required)>' finished in 11.87 seconds 103 examples, 2 failures failed examples: rspec ./spec/requests/static_pages_spec.rb:24 # static pages home page signed_in users should render user's feed rspec ./spec/requests/micropost_pages_spec.rb:28 # micropost pages micropost creation valid information should create micropost
home.html.erb
<% if signed_in? %> <div class="row"> <aside class="span4"> <section> <%= render 'shared/user_info' %> </section> <section> <%= render 'shared/micropost_form' %> </section> </aside> <div class="span8"> <h3>micropost feed</h3> <%= render 'shared/feed' %> </div> </div> <% else %> <div class="center hero-unit"> <h1>welcome sample app</h1> <h2> home <a href="http://railstutorial.org/">ruby on rails tutorial</a> sample application </h2> <%= link_to "sign now!", signup_path, class: "btn btn-large btn-primary" %> </div> <%= link_to image_tag("rails.png", alt: "rails"), 'http://rubyonrails.org/' %> <% end %>
microposts_controller.rb
class micropostscontroller < applicationcontroller before_filter :signed_in_user, only: [:create, :destroy] def create @micropost = current_user.microposts.build(params[:micropost]) if @micropost.save flash[:success] = "micropost created!" redirect_to root_url else @feed_items = [] render 'static_pages/home' end end def destroy end end
_feed.item.html.erb
<li id="<%= feed_item.id %>"> <%= link_to gravatar_for(feed_item.user), feed_item.user %> <span class="user"> <%= link_to feed_item.user.name, feed_item.user %> </span> <span class="content"><%= feed_item.content %></span> <span class="timestamp"> posted <%= time_ago_in_words(feed_item.created_at) %> ago. </span> <% if current_user?(feed_item.user) %> <%= link_to "delete", feed_item, method: :delete, data: { confirm: "you sure?" }, title: feed_item.content %> <% end %> </li>
_feed.html.erb
<% if @feed_items.any? %> <ol class="microposts"> <%= render partial: 'shared/feed_item', collection: @feed_items %> </ol> <%= will_paginate @feed_items %> <% end %>
in rails partials start underscore letter , extension (actually having 2 extensions, .html.erb) allow select corresponding renderer. @sunxperous suggested need rename file.
Comments
Post a Comment