Makes tags count only visible debates and proposals
This commit is contained in:
@@ -122,6 +122,14 @@ class Debate < ActiveRecord::Base
|
||||
cached_votes_up/flags_count.to_f < 5
|
||||
end
|
||||
|
||||
def after_hide
|
||||
self.tags.each{ |t| t.decrement_custom_counter_for('Debate') }
|
||||
end
|
||||
|
||||
def after_restore
|
||||
self.tags.each{ |t| t.increment_custom_counter_for('Debate') }
|
||||
end
|
||||
|
||||
def self.title_max_length
|
||||
@@title_max_length ||= self.columns.find { |c| c.name == 'title' }.limit || 80
|
||||
end
|
||||
|
||||
@@ -105,6 +105,14 @@ class Proposal < ActiveRecord::Base
|
||||
cached_votes_up)
|
||||
end
|
||||
|
||||
def after_hide
|
||||
self.tags.each{ |t| t.decrement_custom_counter_for('Proposal') }
|
||||
end
|
||||
|
||||
def after_restore
|
||||
self.tags.each{ |t| t.increment_custom_counter_for('Proposal') }
|
||||
end
|
||||
|
||||
def self.title_max_length
|
||||
@@title_max_length ||= self.columns.find { |c| c.name == 'title' }.limit || 80
|
||||
end
|
||||
|
||||
@@ -4,6 +4,7 @@ module ActsAsParanoidAliases
|
||||
base.extend(ClassMethods)
|
||||
|
||||
def hide
|
||||
return false if hidden?
|
||||
update_attribute(:hidden_at, Time.now)
|
||||
after_hide
|
||||
end
|
||||
@@ -24,8 +25,13 @@ module ActsAsParanoidAliases
|
||||
end
|
||||
|
||||
def restore(opts={})
|
||||
return false unless hidden?
|
||||
super(opts)
|
||||
update_attribute(:confirmed_hide_at, nil)
|
||||
after_restore
|
||||
end
|
||||
|
||||
def after_restore
|
||||
end
|
||||
end
|
||||
|
||||
@@ -48,12 +54,12 @@ module ActsAsParanoidAliases
|
||||
|
||||
def hide_all(ids)
|
||||
return if ids.blank?
|
||||
where(id: ids).update_all(hidden_at: Time.now)
|
||||
where(id: ids).each(&:hide)
|
||||
end
|
||||
|
||||
def restore_all(ids)
|
||||
return if ids.blank?
|
||||
only_hidden.where(id: ids).update_all(hidden_at: nil)
|
||||
only_hidden.where(id: ids).each(&:restore)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -350,6 +350,20 @@ describe Debate do
|
||||
end
|
||||
end
|
||||
|
||||
describe "custom tag counters when hiding/restoring" do
|
||||
it "decreases the tag counter when hiden, and increases it when restored" do
|
||||
debate = create(:debate, tag_list: "foo")
|
||||
tag = ActsAsTaggableOn::Tag.where(name: 'foo').first
|
||||
expect(tag.debates_count).to eq(1)
|
||||
|
||||
debate.hide
|
||||
expect(tag.reload.debates_count).to eq(0)
|
||||
|
||||
debate.restore
|
||||
expect(tag.reload.debates_count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe "conflictive debates" do
|
||||
|
||||
it "should return true when it has more than 1 flag for 5 positive votes" do
|
||||
|
||||
@@ -193,6 +193,20 @@ describe Proposal do
|
||||
end
|
||||
end
|
||||
|
||||
describe "custom tag counters when hiding/restoring" do
|
||||
it "decreases the tag counter when hiden, and increases it when restored" do
|
||||
proposal = create(:proposal, tag_list: "foo")
|
||||
tag = ActsAsTaggableOn::Tag.where(name: 'foo').first
|
||||
expect(tag.proposals_count).to eq(1)
|
||||
|
||||
proposal.hide
|
||||
expect(tag.reload.proposals_count).to eq(0)
|
||||
|
||||
proposal.restore
|
||||
expect(tag.reload.proposals_count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#confidence_score" do
|
||||
|
||||
it "takes into account votes" do
|
||||
|
||||
Reference in New Issue
Block a user