Skip to content

Commit

Permalink
Properly scope search results (prevent rejected questions showing)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Prebble committed Sep 13, 2014
1 parent 9d604e1 commit f541bac
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/search_controller.rb
@@ -1,6 +1,6 @@
class SearchController < ApplicationController
def index
@questions = Question.search(params[:q]).page(params[:page])
@questions = policy_scope(Question).search(params[:q]).page(params[:page])
respond_to do |format|
format.html
format.json{ render 'questions/index' }
Expand Down
2 changes: 2 additions & 0 deletions spec/controllers/search_controller_spec.rb
Expand Up @@ -2,6 +2,7 @@

RSpec.describe SearchController, :type => :controller do
let(:question){ FactoryGirl.create(:question, body: "Wes Anderson biodiesel.") }
let(:bad_question){ FactoryGirl.create(:question, body: "What the fuck") }
let(:answer){ FactoryGirl.create(:answer, body: "Wes Anderson biodiesel.") }

describe "GET 'index'" do
Expand All @@ -22,6 +23,7 @@
let(:query){ "Wes Anderson" }
it{ expect(assigns(:questions)).to include(question) }
it{ expect(assigns(:questions)).to include(answer.question) }
it{ expect(assigns(:questions)).not_to include(bad_question) }
end
end

Expand Down

0 comments on commit f541bac

Please sign in to comment.