From 87d3da95b122850471a5c17dd59c3a2b6f7f05d7 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 19 Dec 2017 13:02:44 -0800 Subject: [PATCH] add test case for RelatedTagQuery#other_wiki_category_tags --- test/unit/related_tag_query_test.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/unit/related_tag_query_test.rb b/test/unit/related_tag_query_test.rb index 0590d95cf..c26d1ecf6 100644 --- a/test/unit/related_tag_query_test.rb +++ b/test/unit/related_tag_query_test.rb @@ -2,11 +2,29 @@ require 'test_helper' class RelatedTagQueryTest < ActiveSupport::TestCase setup do + User.any_instance.stubs(:validate_sock_puppets).returns(true) user = FactoryGirl.create(:user) CurrentUser.user = user CurrentUser.ip_addr = "127.0.0.1" end + context "#other_wiki_category_tags" do + subject { RelatedTagQuery.new("copyright") } + + setup do + @copyright = FactoryGirl.create(:copyright_tag, name: "copyright") + @wiki = FactoryGirl.create(:wiki_page, title: "copyright", body: "[[list_of_hoges]]") + @list_of_hoges = FactoryGirl.create(:wiki_page, title: "list_of_hoges", body: "[[alpha]] and [[beta]]") + end + + should "return tags from the associated list wiki" do + result = subject.other_wiki_category_tags + assert_not_nil(result[0]) + assert_not_nil(result[0]["wiki_page_tags"]) + assert_equal(%w(alpha beta), result[0]["wiki_page_tags"].map(&:first)) + end + end + context "a related tag query without a category constraint" do setup do @post_1 = FactoryGirl.create(:post, :tag_string => "aaa bbb") @@ -24,7 +42,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase end should "render the json" do - assert_equal("{\"query\":\"aaa\",\"category\":\"\",\"tags\":[[\"aaa\",0],[\"bbb\",0],[\"ccc\",0]],\"wiki_page_tags\":[]}", @query.to_json) + assert_equal("{\"query\":\"aaa\",\"category\":\"\",\"tags\":[[\"aaa\",0],[\"bbb\",0],[\"ccc\",0]],\"wiki_page_tags\":[],\"other_wikis\":[]}", @query.to_json) end end