Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby on Rails tutorial Chapter 11: Rspec tests fail on follower/following section
    primarykey
    data
    text
    <p>I'm working on <a href="http://ruby.railstutorial.org/chapters/following-users#top" rel="nofollow">Chapter 11</a> of Hartl's tutorial, trying to get the <code>non-logged-in users in the Users controller visiting the followers and following page</code> to pass. I'm running into an error where Rails would complain about an undefined <code>admin?</code> method despite it being only used in a <code>User</code> partial. </p> <p><strong>Rails local server</strong></p> <pre><code>Rendered users/_user.html.erb (9.4ms) Rendered users/show_follow.html.erb within layouts/application (33.0ms) Completed 500 Internal Server Error in 43ms ActionView::Template::Error (undefined method `admin?' for nil:NilClass): 1: &lt;li&gt; 2: &lt;%= gravatar_for user, size: 52 %&gt; 3: &lt;%= link_to user.name, user %&gt; 4: &lt;% if current_user.admin? &amp;&amp; !current_user?(user) %&gt; 5: | &lt;%= link_to 'delete', user, method: :delete, 6: data: { confirm: 'Are you sure?' } %&gt; 7: &lt;% end %&gt; app/views/users/_user.html.erb:4:in `_app_views_users__user_html_erb___4000670281664801561_70099451578240' app/views/users/show_follow.html.erb:25:in `_app_views_users_show_follow_html_erb__2024448610717183111_70099484108000' app/controllers/users_controller.rb:68:in `followers' </code></pre> <p><strong>RSpec failures</strong></p> <pre><code> 1) Authentication authorization for non-logged-in users in the Users controller visiting the following page Failure/Error: it { should have_selector('title', text: 'Login') } expected css "title" with text "Login" to return something # ./spec/requests/authentication_pages_spec.rb:122:in `block (6 levels) in &lt;top (required)&gt;' 2) Authentication authorization for non-logged-in users in the Users controller visiting the followers page Failure/Error: it { should have_selector('title', text: 'Login') } expected css "title" with text "Login" to return something # ./spec/requests/authentication_pages_spec.rb:127:in `block (6 levels) in &lt;top (required)&gt;' </code></pre> <p><strong>authorization_pages_spec.rb</strong></p> <pre><code> describe "authorization" do . . . describe "for non-logged-in users" do let(:user) { FactoryGirl.create(:user) } . . . describe "in the Users controller" do . . . describe "visiting the following page" do before { visit following_user_path(user) } it { should have_selector('title', text: 'Login') } end describe "visiting the followers page" do before { visit followers_user_path(user) } it { should have_selector('title', text: 'Login') } end end </code></pre> <p><strong>show_follow.html.erb</strong></p> <pre><code>&lt;% provide(:title, @title) %&gt; &lt;div class="row"&gt; &lt;aside class="span4"&gt; &lt;section&gt; &lt;%= gravatar_for @user %&gt; &lt;h1&gt;&lt;%= @user.name %&gt;&lt;/h1&gt; &lt;span&gt;&lt;%= link_to "view my profile", @user %&gt;&lt;/span&gt; &lt;span&gt;&lt;b&gt;Posts:&lt;/b&gt; &lt;%= @user.posts.count %&gt;&lt;/span&gt; &lt;/section&gt; &lt;section&gt; &lt;%= render 'shared/stats' %&gt; &lt;% if @users.any? %&gt; &lt;div class="user_avatars"&gt; &lt;% @users.each do |user| %&gt; &lt;%= link_to gravatar_for(user, size: 30), user %&gt; &lt;% end %&gt; &lt;/div&gt; &lt;% end %&gt; &lt;/section&gt; &lt;/aside&gt; &lt;div class="span8"&gt; &lt;h3&gt;&lt;%= @title %&gt;&lt;/h3&gt; &lt;% if @users.any? %&gt; &lt;ul class="users"&gt; &lt;%= render @users %&gt; &lt;/ul&gt; &lt;%= will_paginate %&gt; &lt;% end %&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>_user.html.erb</strong></p> <pre><code>&lt;li&gt; &lt;%= gravatar_for user, size: 52 %&gt; &lt;%= link_to user.name, user %&gt; &lt;% if current_user.admin? &amp;&amp; !current_user?(user) %&gt; | &lt;%= link_to 'delete', user, method: :delete, data: { confirm: 'Are you sure?' } %&gt; &lt;% end %&gt; &lt;/li&gt; </code></pre> <p>I tried copy and pasting all the problematic files from the tutorial itself to no avail. It's mentioned that by assigning the <code>:admin</code> attribute to the <code>User</code> class, a method <code>admin?</code> is made available to use. I'm guessing it's somehow I'm passing a <code>nil</code> object into the partials, but I'm having trouble debugging where exactly that's happening. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload