fix reltagquery test

This commit is contained in:
Albert Yi
2018-10-25 11:02:07 -07:00
parent a7dd05fc8f
commit 7d0b32d489

View File

@@ -8,7 +8,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
end end
context "#other_wiki_category_tags" do context "#other_wiki_category_tags" do
subject { RelatedTagQuery.new("copyright") } subject { RelatedTagQuery.new(query: "copyright") }
setup do setup do
@copyright = FactoryBot.create(:copyright_tag, name: "copyright") @copyright = FactoryBot.create(:copyright_tag, name: "copyright")
@@ -19,8 +19,8 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
should "return tags from the associated list wiki" do should "return tags from the associated list wiki" do
result = subject.other_wiki_category_tags result = subject.other_wiki_category_tags
assert_not_nil(result[0]) assert_not_nil(result[0])
assert_not_nil(result[0]["wiki_page_tags"]) assert_not_nil(result[0])
assert_equal(%w(alpha beta), result[0]["wiki_page_tags"].map(&:first)) assert_equal(%w(alpha beta), result[0].tags)
end end
end end
@@ -33,7 +33,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
context "for a tag that already exists" do context "for a tag that already exists" do
setup do setup do
Tag.named("aaa").first.update_related Tag.named("aaa").first.update_related
@query = RelatedTagQuery.new("aaa", "") @query = RelatedTagQuery.new(query: "aaa")
end end
should "work" do should "work" do
@@ -41,13 +41,13 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
end end
should "render the json" do should "render the json" do
assert_equal("{\"query\":\"aaa\",\"category\":\"\",\"tags\":[[\"aaa\",0],[\"bbb\",0],[\"ccc\",0]],\"wiki_page_tags\":[],\"other_wikis\":[]}", @query.to_json) assert_equal("{\"query\":\"aaa\",\"category\":null,\"tags\":[[\"aaa\",0],[\"bbb\",0],[\"ccc\",0]],\"wiki_page_tags\":[],\"other_wikis\":[]}", @query.to_json)
end end
end end
context "for a tag that doesn't exist" do context "for a tag that doesn't exist" do
setup do setup do
@query = RelatedTagQuery.new("zzz", "") @query = RelatedTagQuery.new(query: "zzz")
end end
should "work" do should "work" do
@@ -59,7 +59,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
setup do setup do
@ta = FactoryBot.create(:tag_alias, antecedent_name: "xyz", consequent_name: "aaa") @ta = FactoryBot.create(:tag_alias, antecedent_name: "xyz", consequent_name: "aaa")
@wp = FactoryBot.create(:wiki_page, title: "aaa", body: "blah [[foo|blah]] [[FOO]] [[bar]] blah") @wp = FactoryBot.create(:wiki_page, title: "aaa", body: "blah [[foo|blah]] [[FOO]] [[bar]] blah")
@query = RelatedTagQuery.new("xyz", "") @query = RelatedTagQuery.new(query: "xyz")
Tag.named("aaa").first.update_related Tag.named("aaa").first.update_related
end end
@@ -75,7 +75,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
context "for a pattern search" do context "for a pattern search" do
setup do setup do
@query = RelatedTagQuery.new("a*", "") @query = RelatedTagQuery.new(query: "a*")
end end
should "work" do should "work" do
@@ -86,7 +86,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
context "for a tag with a wiki page" do context "for a tag with a wiki page" do
setup do setup do
@wiki_page = FactoryBot.create(:wiki_page, :title => "aaa", :body => "[[bbb]] [[ccc]]") @wiki_page = FactoryBot.create(:wiki_page, :title => "aaa", :body => "[[bbb]] [[ccc]]")
@query = RelatedTagQuery.new("aaa", "") @query = RelatedTagQuery.new(query: "aaa")
end end
should "find any tags embedded in the wiki page" do should "find any tags embedded in the wiki page" do
@@ -100,7 +100,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
@post_1 = FactoryBot.create(:post, :tag_string => "aaa bbb") @post_1 = FactoryBot.create(:post, :tag_string => "aaa bbb")
@post_2 = FactoryBot.create(:post, :tag_string => "aaa art:ccc") @post_2 = FactoryBot.create(:post, :tag_string => "aaa art:ccc")
@post_3 = FactoryBot.create(:post, :tag_string => "aaa copy:ddd") @post_3 = FactoryBot.create(:post, :tag_string => "aaa copy:ddd")
@query = RelatedTagQuery.new("aaa", "artist") @query = RelatedTagQuery.new(query: "aaa", category: "artist")
end end
should "find the related tags" do should "find the related tags" do