title: RoR - Testing errors - expecting <"categories/new"> but rendering with <[]>
body: <p>I have a problem with my app testing. It's been hanging around for too long now and I'm even wondering, why am I testing this at all (since outside the tests, it works perfectly!)??</p>
  
  <p>So here's the errors: </p>
  
  <blockquote>
    <p>$ rake test 
    Run options: --seed 1855</p>
    
    <p>`# Running:</p>
    
    <p>.F</p>
    
    <p>Failure:
    CreateCategoriesTest#test_invalid_category_submission_results_in_failure
    [/Users/user/Documents/ruby_project/rails_projects/alpha-blog/test/integration/create_categories_test.rb:17]:
    expecting &lt;"categories/new"> but rendering with &lt;[]></p>
    
    <p>bin/rails test test/integration/create_categories_test.rb:15</p>
    
    <p>F</p>
    
    <p>Failure:
    CreateCategoriesTest#test_get_new_category_form_and_create_category
    [/Users/user/Documents/ruby_project/rails_projects/alpha-blog/test/integration/create_categories_test.rb:7]:
    expecting &lt;"categories/new"> but rendering with &lt;[]></p>
    
    <p>bin/rails test test/integration/create_categories_test.rb:5</p>
    
    <p>.........</p>
    
    <p>Finished in 0.638134s, 18.8048 runs/s, 25.0731 assertions/s. 12 runs,
    16 assertions, 2 failures, 0 errors, 0 skips</p>
  </blockquote>
  
  <p>The test looks like: </p>
  
  <pre><code>require 'test_helper'
  
  class CreateCategoriesTest &lt; ActionDispatch::IntegrationTest
  
    test "get new category form and create category" do
      get new_category_path
      assert_template 'categories/new'
      assert_difference 'Category.count', 1 do
      post categories_path, params: { category: {name: "sports"}}
      follow_redirect!
      end
      assert_template 'categories/index'
      assert_match 'sports', response.body
    end
  
    test "invalid category submission results in failure" do
      get new_category_path
      assert_template 'categories/new'
      assert_no_difference 'Category.count' do
      post categories_path, params: { category: {name: " "}}
      end
      assert_template 'categories/new'
      assert_select 'h3.panel-title'
      assert_select 'div.panel-body'
    end
  end
  </code></pre>
  
  <p>and the controller: </p>
  
  <pre><code>class CategoriesController &lt; ApplicationController
  
    before_action :require_admin, except: [:index, :show]
  
    def index
      @categories = Category.paginate(page: params[:page], per_page: 5)
    end
  
    def new
      @category = Category.new
    end
  
    def create
      @category = Category.new(category_params)
      if @category.save
        flash[:success] = "La nueva categoria se creó correctamente"
        redirect_to categories_path
      else 
        render 'new'
      end
    end
  
    def index
       @categories = Category.paginate(page: params[:page], per_page: 5)
    end
  
    def show
    end
  
    private
  
    def category_params
      params.require(:category).permit(:name)
    end
  
    def require_admin
      if !logged_in? || logged_in? and !current_user.try(:admin?)
        flash[:danger] = "Solamente el admin puede acceder a esta seccion"
      redirect_to categories_path
      end
    end
  
  
  end
  </code></pre>
  
  <p>Just to give you a few heads up on what I've done so far to resolve my problem (because it appeared before), I have replaced this portion of the "get new category form and create category": </p>
  
  <pre><code>post_via_redirect categories_path, category: {name: "sports"}
  </code></pre>
  
  <p>by: </p>
  
  <pre><code>post categories_path, params: { category: {name: "sports"}}
  follow_redirect!
  </code></pre>
  
  <p>as for the "invalid category submission results in failure" test I replaced: </p>
  
  <pre><code>post categories_path, category: {name: " "}
  </code></pre>
  
  <p>by:</p>
  
  <pre><code>post categories_path, params: { category: {name: " "}}
  </code></pre>
  
  <p>and it worked before I placed a limitation to the use of the app (in the controller): </p>
  
  <pre><code>before_action :require_admin, except: [:index, :show]
  [...]
    def require_admin
      if !logged_in? || logged_in? and !current_user.try(:admin?)
        flash[:danger] = "Solamente el admin puede acceder a esta seccion"
      redirect_to categories_path
      end
    end
  </code></pre>
  
  <p>Does anyone have any idea on what's happening? Thanks in advance! </p>