add support for saved search metatag + tests
This commit is contained in:
@@ -1371,6 +1371,24 @@ class PostTest < ActiveSupport::TestCase
|
||||
assert_equal(1, relation.count)
|
||||
end
|
||||
|
||||
should "return posts for a <search> metatag" do
|
||||
SavedSearch.stubs(:update_listbooru_on_create)
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
sub = FactoryGirl.create(:saved_search, :tag_query => "aaa", :name => "zzz", :user_id => CurrentUser.id)
|
||||
SavedSearch.expects(:post_ids).returns([post1.id])
|
||||
relation = Post.tag_match("search:#{CurrentUser.name}")
|
||||
assert_equal(1, relation.count)
|
||||
end
|
||||
|
||||
should "return posts for a named <search> metatag" do
|
||||
SavedSearch.stubs(:update_listbooru_on_create)
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
sub = FactoryGirl.create(:saved_search, :tag_query => "aaa", :name => "zzz", :user_id => CurrentUser.id)
|
||||
SavedSearch.expects(:post_ids).returns([post1.id])
|
||||
relation = Post.tag_match("search:#{CurrentUser.name}:zzz")
|
||||
assert_equal(1, relation.count)
|
||||
end
|
||||
|
||||
should "return posts for a particular rating" do
|
||||
post1 = FactoryGirl.create(:post, :rating => "s")
|
||||
post2 = FactoryGirl.create(:post, :rating => "q")
|
||||
|
||||
@@ -1,6 +1,31 @@
|
||||
require 'test_helper'
|
||||
|
||||
class SavedSearchTest < ActiveSupport::TestCase
|
||||
context "Fetching the post ids for a search" do
|
||||
setup do
|
||||
Danbooru.config.stubs(:listbooru_auth_key).returns("blahblahblah")
|
||||
Danbooru.config.stubs(:listbooru_server).returns("http://localhost:3001")
|
||||
end
|
||||
|
||||
context "with a name" do
|
||||
should "return a list of ids" do
|
||||
VCR.use_cassette("unit/saved_searches/get-named", :record => :once) do
|
||||
post_ids = SavedSearch.post_ids(1, "blah")
|
||||
assert_equal([1,2,3,4], post_ids)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "without a name" do
|
||||
should "return a list of ids" do
|
||||
VCR.use_cassette("unit/saved_searches/get-unnamed", :record => :once) do
|
||||
post_ids = SavedSearch.post_ids(1)
|
||||
assert_equal([1,2,3,4], post_ids)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "Creating a saved search" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
|
||||
Reference in New Issue
Block a user