title: Testing Controller Concerns (in Rails 3.2)
body: <p>I created a in-house gem for managing records called 'record_search', which includes a controller named 'ApiController'  In one app, I needed to hook in authorization behaviors to prevent the data from being publicly accessible, so I added a ActiveSupport::Concern module to allow the app to add a before_filter.  How can I properly test this before_filter? (using rspec)</p>
  
  <p>In Gem:</p>
  
  <p><strong>app/controllers/api_controller.rb</strong></p>
  
  <pre><code>module RecordSearch
    class ApiController &lt; ApplicationController
      respond_to :json
  
      def search
        render json: #app-specific code
      end
  
      def find
        render json: #app-specific code
      end
  
      include Extensions #define any authorization logic here
    end
  end
  </code></pre>
  
  <p>Local app:</p>
  
  <p><strong>app/controllers/concerns/record_search/extensions.rb</strong></p>
  
  <pre><code>module RecordSearch::Extensions
    extend ActiveSupport::Concern
    include ApplicationHelper #defines current_user method
  
    included do
      before_filter :require_premium_user, :only =&gt; [:find,:search]
    end
  
    private
  
    def require_premium_user
      unless current_user
        return render :json =&gt; {"error" =&gt; "not authorized"}
      end
    end
  end
  </code></pre>