Removes Debate.search & uses Debate.tagged_by when appropriate
Using `params` was wrong here because if given an inexistent tag, @tag_filter was nil but the debates were still filtered by it (so the listing and what the page title said were different)
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
class DebatesController < ApplicationController
|
||||
before_action :parse_order, :parse_tag_filter, only: :index
|
||||
before_action :parse_order, only: :index
|
||||
before_action :parse_tag_filter, only: :index
|
||||
before_action :authenticate_user!, except: [:index, :show]
|
||||
|
||||
load_and_authorize_resource
|
||||
respond_to :html, :js
|
||||
|
||||
def index
|
||||
@debates = Debate.search(params).page(params[:page]).for_render.send("sort_by_#{@order}")
|
||||
@tags = ActsAsTaggableOn::Tag.all
|
||||
@debates = Debate.all
|
||||
@debates = @debates.tagged_with(@tag_filter) if @tag_filter
|
||||
@debates = @debates.page(params[:page]).for_render.send("sort_by_#{@order}")
|
||||
@tag_cloud = Debate.tag_counts.order('count desc, name asc')
|
||||
set_debate_votes(@debates)
|
||||
end
|
||||
|
||||
@@ -35,14 +35,6 @@ class Debate < ActiveRecord::Base
|
||||
# Ahoy setup
|
||||
visitable # Ahoy will automatically assign visit_id on create
|
||||
|
||||
def self.search(params)
|
||||
if params[:tag]
|
||||
tagged_with(params[:tag])
|
||||
else
|
||||
all
|
||||
end
|
||||
end
|
||||
|
||||
def likes
|
||||
cached_votes_up
|
||||
end
|
||||
|
||||
@@ -174,21 +174,6 @@ describe Debate do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#search" do
|
||||
let!(:economy) { create(:debate, tag_list: "Economy") }
|
||||
let!(:health) { create(:debate, tag_list: "Health") }
|
||||
|
||||
it "returns debates tagged with params tag" do
|
||||
params = {tag: "Economy"}
|
||||
expect(Debate.search(params)).to match_array([economy])
|
||||
end
|
||||
|
||||
it "returns all debates if no parameters" do
|
||||
params = {}
|
||||
expect(Debate.search(params)).to match_array([economy, health])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#default_order' do
|
||||
let!(:economy) { create(:debate) }
|
||||
let!(:health) { create(:debate) }
|
||||
|
||||
Reference in New Issue
Block a user