From cac5eae3c4a2a87e01b6efb2b8cedaa5d74e557e Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 5 Feb 2017 16:23:56 -0600 Subject: [PATCH] tests: add more tags controller/model tests. --- test/functional/tags_controller_test.rb | 11 ++++++++++- test/unit/tag_test.rb | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/test/functional/tags_controller_test.rb b/test/functional/tags_controller_test.rb index ceebc59f5..b6cebd20e 100644 --- a/test/functional/tags_controller_test.rb +++ b/test/functional/tags_controller_test.rb @@ -26,7 +26,7 @@ class TagsControllerTest < ActionController::TestCase context "index action" do setup do - @tag = FactoryGirl.create(:tag, :name => "aaa") + @tag = FactoryGirl.create(:tag, name: "aaa", post_count: 1) end should "render" do @@ -42,6 +42,15 @@ class TagsControllerTest < ActionController::TestCase end end + context "autocomplete action" do + should "render" do + FactoryGirl.create(:tag, name: "touhou", post_count: 1) + + get :autocomplete, { search: { name_matches: "t" }, format: :json } + assert_response :success + end + end + context "show action" do setup do @tag = FactoryGirl.create(:tag) diff --git a/test/unit/tag_test.rb b/test/unit/tag_test.rb index ce60e0311..a1e253d13 100644 --- a/test/unit/tag_test.rb +++ b/test/unit/tag_test.rb @@ -208,4 +208,14 @@ class TagTest < ActiveSupport::TestCase end end end + + context "A tag with a negative post count" do + should "be fixed" do + tag = FactoryGirl.create(:tag, name: "touhou", post_count: -10) + post = FactoryGirl.create(:post, tag_string: "touhou") + + Tag.clean_up_negative_post_counts! + assert_equal(1, tag.reload.post_count) + end + end end