Skip to content

Commit

Permalink
Fixes to tag counting logic (publiclab#8245)
Browse files Browse the repository at this point in the history
* Update tag_test.rb

* Update tag_test.rb

* Update tag_test.rb

* Update tag.rb
  • Loading branch information
jywarren authored and lagunasmel committed Mar 2, 2021
1 parent 32c66d5 commit 2eaf711
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def path
end

def run_count
self.count = NodeTag.where(tid: tid).count
self.count = NodeTag.joins(:node).where(tid: tid).where('node.status = 1').count
save
end

Expand Down
14 changes: 14 additions & 0 deletions test/unit/tag_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ def setup
assert_not_nil tag.nodes
end

test 'tag counting' do
tag = tags(:awesome)
assert_nil tag.count
assert_not_nil tag.run_count
assert_not_nil tag.count
assert_equal 3, tag.count

tag = tags(:spam)
assert_nil tag.count
assert_not_nil tag.run_count
assert_not_nil tag.count
assert_equal 0, tag.count # even if used, it should not count spam tags
end

test 'tag followers' do
followers = Tag.followers(node_tags(:awesome).name)
assert !followers.empty?
Expand Down

0 comments on commit 2eaf711

Please sign in to comment.