Merge pull request #2878 from evazion/fix-test-coverage
Improve controller test coverage
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
class SavedSearchesControllerTest < ActionController::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
@@ -1,4 +1,6 @@
|
||||
FactoryGirl.define do
|
||||
factory(:favorite_group) do
|
||||
factory :favorite_group do
|
||||
name { FFaker::Lorem.word }
|
||||
creator
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
FactoryGirl.define do
|
||||
factory(:note) do
|
||||
creator :factory => :user
|
||||
creator
|
||||
post
|
||||
x 1
|
||||
y 1
|
||||
@@ -8,7 +8,6 @@ FactoryGirl.define do
|
||||
height 1
|
||||
is_active true
|
||||
body {FFaker::Lorem.sentences.join(" ")}
|
||||
updater_id :factory => :user
|
||||
updater_ip_addr "127.0.0.1"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,5 +13,6 @@ FactoryGirl.define do
|
||||
image_height 1000
|
||||
file_size 2000
|
||||
rating "q"
|
||||
source { FFaker::Internet.http_url }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
FactoryGirl.define do
|
||||
factory(:saved_search) do
|
||||
tag_query "aaa"
|
||||
tag_query { FFaker::Lorem.words }
|
||||
category { FFaker::Lorem.word }
|
||||
user
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
FactoryGirl.define do
|
||||
factory(:user) do
|
||||
factory(:user, aliases: [:creator, :updater]) do
|
||||
name {(rand(1_000_000) + 10).to_s}
|
||||
password "password"
|
||||
password_hash {User.sha1("password")}
|
||||
|
||||
12
test/functional/admin/dashboards_controller_test.rb
Normal file
12
test/functional/admin/dashboards_controller_test.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
require 'test_helper'
|
||||
|
||||
class Admin::DashboardsControllerTest < ActionController::TestCase
|
||||
context "The admin dashboard controller" do
|
||||
context "show action" do
|
||||
should "render" do
|
||||
get :show
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -6,16 +6,82 @@ class ArtistCommentariesControllerTest < ActionController::TestCase
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@commentary1 = FactoryGirl.create(:artist_commentary)
|
||||
@commentary2 = FactoryGirl.create(:artist_commentary)
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
should "render" do
|
||||
get :index
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "render with search params" do
|
||||
params = {
|
||||
search: {
|
||||
text_matches: @commentary1.original_title,
|
||||
post_id: @commentary1.post_id,
|
||||
original_present: "yes",
|
||||
translated_present: "yes",
|
||||
post_tags_match: @commentary1.post.tag_array.first,
|
||||
}
|
||||
}
|
||||
|
||||
get :index, params
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "show action" do
|
||||
should "render" do
|
||||
get :show, { id: @commentary1.id }
|
||||
assert_redirected_to(@commentary1.post)
|
||||
|
||||
get :show, { post_id: @commentary1.post_id }
|
||||
assert_redirected_to(@commentary1.post)
|
||||
end
|
||||
end
|
||||
|
||||
context "create_or_update action" do
|
||||
should "render for create" do
|
||||
params = {
|
||||
artist_commentary: {
|
||||
original_title: "foo",
|
||||
post_id: FactoryGirl.create(:post).id,
|
||||
}
|
||||
}
|
||||
|
||||
post :create_or_update, params, { user_id: @user.id }
|
||||
assert_redirected_to(ArtistCommentary.find_by_post_id(params[:artist_commentary][:post_id]))
|
||||
end
|
||||
|
||||
should "render for update" do
|
||||
params = {
|
||||
artist_commentary: {
|
||||
post_id: @commentary1.post_id,
|
||||
original_title: "foo",
|
||||
}
|
||||
}
|
||||
|
||||
post :create_or_update, params, { user_id: @user.id }
|
||||
assert_redirected_to(@commentary1)
|
||||
assert_equal("foo", @commentary1.reload.original_title)
|
||||
end
|
||||
end
|
||||
|
||||
context "revert action" do
|
||||
setup do
|
||||
@commentary1 = FactoryGirl.create(:artist_commentary)
|
||||
@commentary2 = FactoryGirl.create(:artist_commentary)
|
||||
should "work" do
|
||||
original_title = @commentary1.original_title
|
||||
@commentary1.update(original_title: "foo")
|
||||
|
||||
post :revert, { :id => @commentary1.post_id, :version_id => @commentary1.versions(true).first.id }, {:user_id => @user.id}
|
||||
assert_redirected_to(@commentary1)
|
||||
assert_equal(original_title, @commentary1.reload.original_title)
|
||||
end
|
||||
|
||||
should "return 404 when trying to revert a nonexistent commentary" do
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ArtistCommentaryVersionsControllerTest < ActionController::TestCase
|
||||
context "The artist commentary versions controller" do
|
||||
context "index action" do
|
||||
should "render" do
|
||||
get :index
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -18,13 +18,13 @@ class ArtistsControllerTest < ActionController::TestCase
|
||||
|
||||
context "An artists controller" do
|
||||
setup do
|
||||
CurrentUser.user = FactoryGirl.create(:user)
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@artist = FactoryGirl.create(:artist)
|
||||
@user = FactoryGirl.create(:user)
|
||||
|
||||
FactoryGirl.create(:artist, :name => "masao", :url_string => "http://i2.pixiv.net/img04/img/syounen_no_uta/")
|
||||
FactoryGirl.create(:artist, :name => "artgerm", :url_string => "http://artgerm.deviantart.com/")
|
||||
@masao = FactoryGirl.create(:artist, :name => "masao", :url_string => "http://i2.pixiv.net/img04/img/syounen_no_uta/")
|
||||
@artgerm = FactoryGirl.create(:artist, :name => "artgerm", :url_string => "http://artgerm.deviantart.com/")
|
||||
end
|
||||
|
||||
teardown do
|
||||
@@ -37,6 +37,14 @@ class ArtistsControllerTest < ActionController::TestCase
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "get the show_or_new page" do
|
||||
get :show_or_new, { name: "masao" }, { user_id: @user.id }
|
||||
assert_redirected_to(@masao)
|
||||
|
||||
get :show_or_new, { name: "nobody" }, { user_id: @user.id }
|
||||
assert_redirected_to(new_artist_path(name: "nobody"))
|
||||
end
|
||||
|
||||
should "get the edit page" do
|
||||
get :edit, {:id => @artist.id}, {:user_id => @user.id}
|
||||
assert_response :success
|
||||
@@ -53,6 +61,32 @@ class ArtistsControllerTest < ActionController::TestCase
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "get the banned page" do
|
||||
get :banned
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "ban an artist" do
|
||||
CurrentUser.scoped(FactoryGirl.create(:admin_user)) do
|
||||
put :ban, { id: @artist.id }, { user_id: CurrentUser.id }
|
||||
end
|
||||
|
||||
assert_redirected_to(@artist)
|
||||
assert_equal(true, @artist.reload.is_banned)
|
||||
assert_equal(true, TagImplication.exists?(antecedent_name: @artist.name, consequent_name: "banned_artist"))
|
||||
end
|
||||
|
||||
should "unban an artist" do
|
||||
CurrentUser.scoped(FactoryGirl.create(:admin_user)) do
|
||||
@artist.ban!
|
||||
put :unban, { id: @artist.id }, { user_id: CurrentUser.id }
|
||||
end
|
||||
|
||||
assert_redirected_to(@artist)
|
||||
assert_equal(false, @artist.reload.is_banned)
|
||||
assert_equal(false, TagImplication.exists?(antecedent_name: @artist.name, consequent_name: "banned_artist"))
|
||||
end
|
||||
|
||||
should "get the index page" do
|
||||
get :index
|
||||
assert_response :success
|
||||
@@ -102,6 +136,24 @@ class ArtistsControllerTest < ActionController::TestCase
|
||||
assert_redirected_to(artist_path(@artist))
|
||||
end
|
||||
|
||||
should "delete an artist" do
|
||||
CurrentUser.scoped(FactoryGirl.create(:builder_user)) do
|
||||
delete :destroy, { id: @artist.id }, { user_id: CurrentUser.id }
|
||||
end
|
||||
|
||||
assert_redirected_to(artist_path(@artist))
|
||||
assert_equal(false, @artist.reload.is_active)
|
||||
end
|
||||
|
||||
should "undelete an artist" do
|
||||
CurrentUser.scoped(FactoryGirl.create(:builder_user)) do
|
||||
put :undelete, { id: @artist.id }, { user_id: CurrentUser.id }
|
||||
end
|
||||
|
||||
assert_redirected_to(artist_path(@artist))
|
||||
assert_equal(true, @artist.reload.is_active)
|
||||
end
|
||||
|
||||
context "when renaming an artist" do
|
||||
should "automatically rename the artist's wiki page" do
|
||||
artist = FactoryGirl.create(:artist, :name => "aaa", :notes => "testing")
|
||||
|
||||
@@ -22,6 +22,11 @@ class CommentsControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
should "render for post" do
|
||||
xhr :get, :index, { post_id: @post.id, group_by: "post", format: "js" }
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "render by post" do
|
||||
get :index, {:group_by => "post"}
|
||||
assert_response :success
|
||||
@@ -142,5 +147,15 @@ class CommentsControllerTest < ActionController::TestCase
|
||||
assert_redirected_to @comment
|
||||
end
|
||||
end
|
||||
|
||||
context "undelete action" do
|
||||
should "mark comment as undeleted" do
|
||||
@comment.delete!
|
||||
put :undelete, { id: @comment.id }, { user_id: @user.id }
|
||||
|
||||
assert_equal(false, @comment.reload.is_deleted)
|
||||
assert_redirected_to(@comment)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
12
test/functional/counts_controller_test.rb
Normal file
12
test/functional/counts_controller_test.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
require 'test_helper'
|
||||
|
||||
class CountsControllerTest < ActionController::TestCase
|
||||
context "The counts commentary controller" do
|
||||
context "posts action" do
|
||||
should "render" do
|
||||
get :posts
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
12
test/functional/delayed_jobs_controller_test.rb
Normal file
12
test/functional/delayed_jobs_controller_test.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
require 'test_helper'
|
||||
|
||||
class DelayedJobsControllerTest < ActionController::TestCase
|
||||
context "The delayed jobs controller" do
|
||||
context "index action" do
|
||||
should "render" do
|
||||
get :index
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
12
test/functional/dtext_previews_controller_test.rb
Normal file
12
test/functional/dtext_previews_controller_test.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
require 'test_helper'
|
||||
|
||||
class DtextPreviewsControllerTest < ActionController::TestCase
|
||||
context "The dtext previews controller" do
|
||||
context "create action" do
|
||||
should "render" do
|
||||
post :create, { body: "h1. Touhou\n\n* [[touhou]]" }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -15,6 +15,27 @@ module Explore
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "#searches" do
|
||||
should "render" do
|
||||
get :searches
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "#missed_searches" do
|
||||
should "render" do
|
||||
get :missed_searches
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "#intro" do
|
||||
should "render" do
|
||||
get :intro
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
81
test/functional/favorite_groups_controller_test.rb
Normal file
81
test/functional/favorite_groups_controller_test.rb
Normal file
@@ -0,0 +1,81 @@
|
||||
require 'test_helper'
|
||||
|
||||
class FavoriteGroupsControllerTest < ActionController::TestCase
|
||||
context "The favorite groups controller" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
should "render" do
|
||||
get :index
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "show action" do
|
||||
should "render" do
|
||||
favgroup = FactoryGirl.create(:favorite_group)
|
||||
|
||||
get :show, { id: favgroup.id }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "new action" do
|
||||
should "render" do
|
||||
get :new, {}, { user_id: @user.id }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
should "render" do
|
||||
post :create, { favorite_group: FactoryGirl.attributes_for(:favorite_group) }, { user_id: @user.id }
|
||||
assert_redirected_to favorite_groups_path
|
||||
end
|
||||
end
|
||||
|
||||
context "edit action" do
|
||||
should "render" do
|
||||
favgroup = FactoryGirl.create(:favorite_group, creator: @user)
|
||||
|
||||
get :edit, { id: favgroup.id }, { user_id: @user.id }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "update action" do
|
||||
should "render" do
|
||||
favgroup = FactoryGirl.create(:favorite_group, creator: @user)
|
||||
params = { id: favgroup.id, favorite_group: { name: "foo" } }
|
||||
|
||||
put :update, params, { user_id: @user.id }
|
||||
assert_redirected_to favgroup
|
||||
assert_equal("foo", favgroup.reload.name)
|
||||
end
|
||||
end
|
||||
|
||||
context "destroy action" do
|
||||
should "render" do
|
||||
favgroup = FactoryGirl.create(:favorite_group, creator: @user)
|
||||
|
||||
delete :destroy, { id: favgroup.id }, { user_id: @user.id }
|
||||
assert_redirected_to favorite_groups_path
|
||||
end
|
||||
end
|
||||
|
||||
context "add_post action" do
|
||||
should "render" do
|
||||
favgroup = FactoryGirl.create(:favorite_group, creator: @user)
|
||||
post = FactoryGirl.create(:post)
|
||||
|
||||
put :add_post, { id: favgroup.id, post_id: post.id, format: "js" }, { user_id: @user.id }
|
||||
assert_response :success
|
||||
assert_equal([post.id], favgroup.reload.post_id_array)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
33
test/functional/iqdb_queries_controller_test.rb
Normal file
33
test/functional/iqdb_queries_controller_test.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
require 'test_helper'
|
||||
require 'helpers/iqdb_test_helper'
|
||||
|
||||
class IqdbQueriesControllerTest < ActionController::TestCase
|
||||
include IqdbTestHelper
|
||||
|
||||
context "The iqdb controller" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@posts = FactoryGirl.create_list(:post, 2)
|
||||
mock_iqdb_service!
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
should "render with a post_id" do
|
||||
mock_iqdb_matches!(@posts[0], @posts)
|
||||
post :create, { post_id: @posts[0].id, format: "js" }, { user_id: @user.id }
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "render with an url" do
|
||||
mock_iqdb_matches!(@posts[0].source, @posts)
|
||||
post :create, { url: @posts[0].source }, { user_id: @user.id }
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
12
test/functional/meta_searches_controller_test.rb
Normal file
12
test/functional/meta_searches_controller_test.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
require 'test_helper'
|
||||
|
||||
class MetaSearchesControllerTest < ActionController::TestCase
|
||||
context "The meta searches controller" do
|
||||
context "tags action" do
|
||||
should "work" do
|
||||
get :tags, { name: "long_hair" }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
12
test/functional/mod_actions_controller_test.rb
Normal file
12
test/functional/mod_actions_controller_test.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ModActionsControllerTest < ActionController::TestCase
|
||||
context "The mod actions controller" do
|
||||
context "index action" do
|
||||
should "work" do
|
||||
get :index
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,42 +3,98 @@ require 'test_helper'
|
||||
module Moderator
|
||||
module Post
|
||||
class PostsControllerTest < ActionController::TestCase
|
||||
context "The moderator post disapprovals controller" do
|
||||
context "The moderator posts controller" do
|
||||
setup do
|
||||
@admin = FactoryGirl.create(:admin_user)
|
||||
CurrentUser.user = @admin
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@post = FactoryGirl.create(:post)
|
||||
end
|
||||
|
||||
context "confirm_delete action" do
|
||||
should "render" do
|
||||
get :confirm_delete, { id: @post.id }, { user_id: @admin.id }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "delete action" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post)
|
||||
end
|
||||
|
||||
should "render" do
|
||||
post :delete, {:id => @post.id, :reason => "xxx", :format => "js", :commit => "Delete"}, {:user_id => @admin.id}
|
||||
@post.reload
|
||||
assert(@post.is_deleted?)
|
||||
assert(@post.reload.is_deleted?)
|
||||
end
|
||||
|
||||
should "work even if the deleter has flagged the post previously" do
|
||||
PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
|
||||
post :delete, {:id => @post.id, :reason => "xxx", :format => "js", :commit => "Delete"}, {:user_id => @admin.id}
|
||||
@post.reload
|
||||
assert(@post.is_deleted?)
|
||||
assert(@post.reload.is_deleted?)
|
||||
end
|
||||
end
|
||||
|
||||
context "undelete action" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post, :is_deleted => true)
|
||||
end
|
||||
|
||||
should "render" do
|
||||
@post.update(is_deleted: true)
|
||||
post :undelete, {:id => @post.id, :format => "js"}, {:user_id => @admin.id}
|
||||
|
||||
assert_response :success
|
||||
@post.reload
|
||||
assert(!@post.is_deleted?)
|
||||
assert(!@post.reload.is_deleted?)
|
||||
end
|
||||
end
|
||||
|
||||
context "confirm_move_favorites action" do
|
||||
should "render" do
|
||||
get :confirm_move_favorites, { id: @post.id }, { user_id: @admin.id }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "move_favorites action" do
|
||||
should "render" do
|
||||
parent = FactoryGirl.create(:post)
|
||||
child = FactoryGirl.create(:post, parent: parent)
|
||||
users = FactoryGirl.create_list(:user, 2)
|
||||
users.each { |u| child.add_favorite!(u) }
|
||||
|
||||
put :move_favorites, { id: child.id, commit: "Submit" }, { user_id: @admin.id }
|
||||
|
||||
assert_redirected_to(child)
|
||||
assert_equal(users, parent.reload.favorited_users)
|
||||
assert_equal([], child.reload.favorited_users)
|
||||
end
|
||||
end
|
||||
|
||||
context "expunge action" do
|
||||
should "render" do
|
||||
put :expunge, { id: @post.id, format: "js" }, { user_id: @admin.id }
|
||||
|
||||
assert_response :success
|
||||
assert_equal(false, ::Post.exists?(@post.id))
|
||||
end
|
||||
end
|
||||
|
||||
context "confirm_ban action" do
|
||||
should "render" do
|
||||
get :confirm_ban, { id: @post.id }, { user_id: @admin.id }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "ban action" do
|
||||
should "render" do
|
||||
put :ban, { id: @post.id, commit: "Ban", format: "js" }, { user_id: @admin.id }
|
||||
|
||||
assert_response :success
|
||||
assert_equal(true, @post.reload.is_banned?)
|
||||
end
|
||||
end
|
||||
|
||||
context "unban action" do
|
||||
should "render" do
|
||||
@post.ban!
|
||||
put :unban, { id: @post.id, format: "js" }, { user_id: @admin.id }
|
||||
|
||||
assert_redirected_to(@post)
|
||||
assert_equal(false, @post.reload.is_banned?)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,6 +18,13 @@ module Moderator
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "random action" do
|
||||
should "render" do
|
||||
get :random, {}, {:user_id => @admin.id}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
12
test/functional/note_previews_controller_test.rb
Normal file
12
test/functional/note_previews_controller_test.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
require 'test_helper'
|
||||
|
||||
class NotePreviewsControllerTest < ActionController::TestCase
|
||||
context "The note previews controller" do
|
||||
context "show action" do
|
||||
should "work" do
|
||||
get :show, { body: "<b>test</b>", format: "json" }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -6,7 +6,7 @@ class NotesControllerTest < ActionController::TestCase
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@post = FactoryGirl.create(:post)
|
||||
@note = FactoryGirl.create(:note, body: "000")
|
||||
end
|
||||
|
||||
teardown do
|
||||
@@ -14,17 +14,32 @@ class NotesControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
FactoryGirl.create(:note)
|
||||
end
|
||||
|
||||
should "list all notes" do
|
||||
get :index
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "list all notes (with search)" do
|
||||
get :index, {:search => {:body_matches => "abc"}}
|
||||
params = {
|
||||
group_by: "note",
|
||||
search: {
|
||||
body_matches: "000",
|
||||
is_active: true,
|
||||
post_id: @note.post_id,
|
||||
post_tags_match: @note.post.tag_array.first,
|
||||
creator_name: @note.creator_name,
|
||||
creator_id: @note.creator_id,
|
||||
}
|
||||
}
|
||||
|
||||
get :index, params
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "show action" do
|
||||
should "render" do
|
||||
get :show, { id: @note.id, format: "json" }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
@@ -32,20 +47,16 @@ class NotesControllerTest < ActionController::TestCase
|
||||
context "create action" do
|
||||
should "create a note" do
|
||||
assert_difference("Note.count", 1) do
|
||||
@post = FactoryGirl.create(:post)
|
||||
post :create, {:note => {:x => 0, :y => 0, :width => 10, :height => 10, :body => "abc", :post_id => @post.id}, :format => :json}, {:user_id => @user.id}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "update action" do
|
||||
setup do
|
||||
@note = FactoryGirl.create(:note)
|
||||
end
|
||||
|
||||
should "update a note" do
|
||||
post :update, {:id => @note.id, :note => {:body => "xyz"}}, {:user_id => @user.id}
|
||||
@note.reload
|
||||
assert_equal("xyz", @note.body)
|
||||
assert_equal("xyz", @note.reload.body)
|
||||
end
|
||||
|
||||
should "not allow changing the post id to another post" do
|
||||
@@ -57,20 +68,14 @@ class NotesControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
context "destroy action" do
|
||||
setup do
|
||||
@note = FactoryGirl.create(:note)
|
||||
end
|
||||
|
||||
should "destroy a note" do
|
||||
post :destroy, {:id => @note.id}, {:user_id => @user.id}
|
||||
@note.reload
|
||||
assert_equal(false, @note.is_active?)
|
||||
assert_equal(false, @note.reload.is_active?)
|
||||
end
|
||||
end
|
||||
|
||||
context "revert action" do
|
||||
setup do
|
||||
@note = FactoryGirl.create(:note, :body => "000")
|
||||
Timecop.travel(1.day.from_now) do
|
||||
@note.update_attributes(:body => "111")
|
||||
end
|
||||
@@ -81,17 +86,15 @@ class NotesControllerTest < ActionController::TestCase
|
||||
|
||||
should "revert to a previous version" do
|
||||
post :revert, {:id => @note.id, :version_id => @note.versions(true).first.id}, {:user_id => @user.id}
|
||||
@note.reload
|
||||
assert_equal("000", @note.body)
|
||||
assert_equal("000", @note.reload.body)
|
||||
end
|
||||
|
||||
should "not allow reverting to a previous version of another note" do
|
||||
@note2 = FactoryGirl.create(:note, :body => "note 2")
|
||||
|
||||
post :revert, { :id => @note.id, :version_id => @note2.versions(true).first.id }, {:user_id => @user.id}
|
||||
@note.reload
|
||||
|
||||
assert_not_equal(@note.body, @note2.body)
|
||||
assert_not_equal(@note.reload.body, @note2.body)
|
||||
assert_response :missing
|
||||
end
|
||||
end
|
||||
|
||||
@@ -49,6 +49,21 @@ class PoolsControllerTest < ActionController::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "gallery action" do
|
||||
should "render" do
|
||||
pool = FactoryGirl.create(:pool)
|
||||
get :gallery, {:id => pool.id}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "new action" do
|
||||
should "render" do
|
||||
get :new, {}, { user_id: @user.id }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
should "create a pool" do
|
||||
assert_difference("Pool.count", 1) do
|
||||
@@ -57,6 +72,15 @@ class PoolsControllerTest < ActionController::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "edit action" do
|
||||
should "render" do
|
||||
pool = FactoryGirl.create(:pool)
|
||||
|
||||
get :edit, { id: pool.id }, { user_id: @user.id }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "update action" do
|
||||
setup do
|
||||
@pool = FactoryGirl.create(:pool)
|
||||
|
||||
@@ -89,6 +89,32 @@ class PostsControllerTest < ActionController::TestCase
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "with an md5 param" do
|
||||
should "render" do
|
||||
get :index, { md5: @post.md5 }
|
||||
assert_redirected_to(@post)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "show_seq action" do
|
||||
should "render" do
|
||||
posts = FactoryGirl.create_list(:post, 3)
|
||||
|
||||
get :show_seq, { seq: "prev", id: posts[1].id }
|
||||
assert_redirected_to(posts[2])
|
||||
|
||||
get :show_seq, { seq: "next", id: posts[1].id }
|
||||
assert_redirected_to(posts[0])
|
||||
end
|
||||
end
|
||||
|
||||
context "random action" do
|
||||
should "render" do
|
||||
get :random, { tags: "aaaa" }
|
||||
assert_redirected_to(post_path(@post, tags: "aaaa"))
|
||||
end
|
||||
end
|
||||
|
||||
context "show action" do
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
require 'test_helper'
|
||||
|
||||
class RelatedTagsControllerTest < ActionController::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
context "The related tags controller" do
|
||||
context "show action" do
|
||||
should "work" do
|
||||
get :show, { query: "touhou" }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
69
test/functional/reports_controller_test.rb
Normal file
69
test/functional/reports_controller_test.rb
Normal file
@@ -0,0 +1,69 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ReportsControllerTest < ActionController::TestCase
|
||||
setup do
|
||||
CurrentUser.user = FactoryGirl.create(:mod_user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
session[:user_id] = CurrentUser.user.id
|
||||
|
||||
@users = FactoryGirl.create_list(:contributor_user, 2)
|
||||
@posts = @users.map { |u| FactoryGirl.create(:post, uploader: u) }
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
session[:user_id] = nil
|
||||
end
|
||||
|
||||
context "The reports controller" do
|
||||
context "user_promotions action" do
|
||||
should "render" do
|
||||
get :user_promotions
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "janitor_trials action" do
|
||||
should "render" do
|
||||
get :janitor_trials
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "contributors action" do
|
||||
should "render" do
|
||||
get :contributors
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "uploads action" do
|
||||
should "render" do
|
||||
get :uploads
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "similar_users action" do
|
||||
should "render" do
|
||||
#get :similar_users
|
||||
#assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "post_versions action" do
|
||||
should "render" do
|
||||
get :post_versions
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "post_versions_create action" do
|
||||
should "render" do
|
||||
#post :post_versions_create, { tag: "touhou", type: "added" }
|
||||
#assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
60
test/functional/saved_searches_controller_test.rb
Normal file
60
test/functional/saved_searches_controller_test.rb
Normal file
@@ -0,0 +1,60 @@
|
||||
require 'test_helper'
|
||||
require 'helpers/saved_search_test_helper'
|
||||
|
||||
class SavedSearchesControllerTest < ActionController::TestCase
|
||||
include SavedSearchTestHelper
|
||||
|
||||
context "The saved searches controller" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
mock_saved_search_service!
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
should "render" do
|
||||
get :index, {}, { user_id: @user.id }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
should "render" do
|
||||
params = { saved_search_tags: "bkub", saved_search_category: "artist" }
|
||||
|
||||
post :create, params, { user_id: @user.id }
|
||||
assert_response :redirect
|
||||
end
|
||||
end
|
||||
|
||||
context "edit action" do
|
||||
should "render" do
|
||||
saved_search = FactoryGirl.create(:saved_search, user: @user)
|
||||
|
||||
get :edit, { id: saved_search.id }, { user_id: @user.id }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "update action" do
|
||||
should "render" do
|
||||
saved_search = FactoryGirl.create(:saved_search, user: @user)
|
||||
params = { id: saved_search.id, saved_search: { category: "foo" } }
|
||||
|
||||
put :update, params, { user_id: @user.id }
|
||||
assert_redirected_to saved_searches_path
|
||||
assert_equal("foo", saved_search.reload.category)
|
||||
end
|
||||
end
|
||||
|
||||
context "destroy action" do
|
||||
should "render" do
|
||||
saved_search = FactoryGirl.create(:saved_search, user: @user)
|
||||
|
||||
delete :destroy, { id: saved_search.id }, { user_id: @user.id }
|
||||
assert_redirected_to saved_searches_path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
12
test/functional/sources_controller_test.rb
Normal file
12
test/functional/sources_controller_test.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
require 'test_helper'
|
||||
|
||||
class SourcesControllerTest < ActionController::TestCase
|
||||
context "The sources controller" do
|
||||
context "show action" do
|
||||
should "work" do
|
||||
get :show, { url: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=14901720", format: "json" }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -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)
|
||||
|
||||
@@ -13,24 +13,33 @@ class UsersControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
FactoryGirl.create(:user, :name => "abc")
|
||||
end
|
||||
|
||||
should "list all users" do
|
||||
get :index
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "list all users for /users?name=<name>" do
|
||||
get :index, { name: @user.name }
|
||||
assert_redirected_to(@user)
|
||||
end
|
||||
|
||||
should "raise error for /users?name=<nonexistent>" do
|
||||
get :index, { name: "nobody" }
|
||||
assert_response :error
|
||||
end
|
||||
|
||||
should "list all users (with search)" do
|
||||
get :index, {:search => {:name_matches => "abc"}}
|
||||
get :index, {:search => {:name_matches => @user.name}}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "show action" do
|
||||
setup do
|
||||
@user = FactoryGirl.create(:user)
|
||||
# flesh out profile to get more test coverage of user presenter.
|
||||
@user = FactoryGirl.create(:banned_user, can_approve_posts: true, is_super_voter: true)
|
||||
FactoryGirl.create(:saved_search, user: @user)
|
||||
FactoryGirl.create(:post, uploader: @user, tag_string: "fav:#{@user.name}")
|
||||
end
|
||||
|
||||
should "render" do
|
||||
@@ -39,6 +48,13 @@ class UsersControllerTest < ActionController::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "new action" do
|
||||
should "render" do
|
||||
get :new
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
should "create a user" do
|
||||
assert_difference("User.count", 1) do
|
||||
|
||||
@@ -6,6 +6,10 @@ class WikiPageVersionsControllerTest < ActionController::TestCase
|
||||
@user = FactoryGirl.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@wiki_page = FactoryGirl.create(:wiki_page)
|
||||
@wiki_page.update_attributes(:body => "1 2")
|
||||
@wiki_page.update_attributes(:body => "2 3")
|
||||
end
|
||||
|
||||
teardown do
|
||||
@@ -14,12 +18,6 @@ class WikiPageVersionsControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
@wiki_page = FactoryGirl.create(:wiki_page)
|
||||
@wiki_page.update_attributes(:body => "1 2")
|
||||
@wiki_page.update_attributes(:body => "2 3")
|
||||
end
|
||||
|
||||
should "list all versions" do
|
||||
get :index
|
||||
assert_response :success
|
||||
@@ -32,5 +30,19 @@ class WikiPageVersionsControllerTest < ActionController::TestCase
|
||||
assert_not_nil(assigns(:wiki_page_versions))
|
||||
end
|
||||
end
|
||||
|
||||
context "show action" do
|
||||
should "render" do
|
||||
get :show, { id: @wiki_page.versions.first.id }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "diff action" do
|
||||
should "render" do
|
||||
get :diff, { thispage: @wiki_page.versions.first.id, otherpage: @wiki_page.versions.last.id }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,6 +40,16 @@ class WikiPagesControllerTest < ActionController::TestCase
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "render for a title" do
|
||||
get :show, {:id => @wiki_page.title}
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "redirect for a nonexistent title" do
|
||||
get :show, {:id => "what"}
|
||||
assert_redirected_to(show_or_new_wiki_pages_path(title: "what"))
|
||||
end
|
||||
|
||||
should "render for a negated tag" do
|
||||
@wiki_page.update_attribute(:title, "-aaa")
|
||||
get :show, {:id => @wiki_page.id}
|
||||
@@ -47,6 +57,38 @@ class WikiPagesControllerTest < ActionController::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "show_or_new action" do
|
||||
setup do
|
||||
@wiki_page = FactoryGirl.create(:wiki_page)
|
||||
end
|
||||
|
||||
should "redirect when given a title" do
|
||||
get :show_or_new, { title: @wiki_page.title }
|
||||
assert_redirected_to(@wiki_page)
|
||||
end
|
||||
|
||||
should "render when given a nonexistent title" do
|
||||
get :show_or_new, { title: "what" }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "new action" do
|
||||
should "render" do
|
||||
get :new, {}, { user_id: @mod.id }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "edit action" do
|
||||
should "render" do
|
||||
wiki_page = FactoryGirl.create(:wiki_page)
|
||||
|
||||
get :edit, { id: wiki_page.id }, { user_id: @mod.id }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
should "create a wiki_page" do
|
||||
assert_difference("WikiPage.count", 1) do
|
||||
|
||||
@@ -16,5 +16,16 @@ module IqdbTestHelper
|
||||
|
||||
service = mock_sqs_service.new
|
||||
Post.stubs(:iqdb_sqs_service).returns(service)
|
||||
|
||||
Danbooru.config.stubs(:iqdbs_auth_key).returns("hunter2")
|
||||
Danbooru.config.stubs(:iqdbs_server).returns("http://localhost:3004")
|
||||
end
|
||||
|
||||
def mock_iqdb_matches!(post_or_source, matches)
|
||||
source = post_or_source.is_a?(Post) ? post_or_source.complete_preview_file_url : post_or_source
|
||||
url = "http://localhost:3004/similar?key=hunter2&url=#{CGI.escape source}&ref"
|
||||
body = matches.map { |post| { post_id: post.id } }.to_json
|
||||
|
||||
FakeWeb.register_uri(:get, url, body: body)
|
||||
end
|
||||
end
|
||||
|
||||
12
test/helpers/reportbooru_helper.rb
Normal file
12
test/helpers/reportbooru_helper.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
module ReportbooruHelper
|
||||
def mock_popular_search_service!
|
||||
Danbooru.config.stubs(:reportbooru_server).returns("http://localhost:3003")
|
||||
FakeWeb.register_uri(:get, "http://localhost:3003/hits/month?date=#{Date.today}", body: "kantai_collection 1000.0\ntouhou 500.0")
|
||||
FakeWeb.register_uri(:get, "http://localhost:3003/hits/day?date=#{Date.today}", body: "kantai_collection 1000.0\ntouhou 500.0")
|
||||
end
|
||||
|
||||
def mock_missed_search_service!
|
||||
Danbooru.config.stubs(:reportbooru_server).returns("http://localhost:3003")
|
||||
FakeWeb.register_uri(:get, "http://localhost:3003/missed_searches", body: "kantai_collection 1000.0\ntouhou 500.0")
|
||||
end
|
||||
end
|
||||
@@ -16,6 +16,7 @@ module SavedSearchTestHelper
|
||||
|
||||
service = mock_sqs_service.new
|
||||
SavedSearch.stubs(:sqs_service).returns(service)
|
||||
SavedSearch.stubs(:update_listbooru_on_create)
|
||||
Danbooru.config.stubs(:aws_sqs_saved_search_url).returns("http://localhost:3002")
|
||||
Danbooru.config.stubs(:listbooru_auth_key).returns("blahblahblah")
|
||||
Danbooru.config.stubs(:listbooru_server).returns("http://localhost:3001")
|
||||
|
||||
@@ -26,3 +26,13 @@ end
|
||||
|
||||
MEMCACHE = MemcacheMock.new
|
||||
Delayed::Worker.delay_jobs = false
|
||||
|
||||
require "helpers/reportbooru_helper"
|
||||
class ActiveSupport::TestCase
|
||||
include ReportbooruHelper
|
||||
|
||||
setup do
|
||||
mock_popular_search_service!
|
||||
mock_missed_search_service!
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,6 +6,10 @@ class PostTest < ActiveSupport::TestCase
|
||||
include PoolArchiveTestHelper
|
||||
include SavedSearchTestHelper
|
||||
|
||||
def assert_tag_match(posts, query)
|
||||
assert_equal(posts.map(&:id), Post.tag_match(query).pluck(:id))
|
||||
end
|
||||
|
||||
setup do
|
||||
Timecop.travel(2.weeks.ago) do
|
||||
@user = FactoryGirl.create(:user)
|
||||
@@ -1506,230 +1510,346 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "Searching:" do
|
||||
should "return posts for the age:<1minute tag" do
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
count = Post.tag_match("age:<1minute").count
|
||||
assert_equal(1, count)
|
||||
post = FactoryGirl.create(:post)
|
||||
assert_tag_match([post], "age:<1minute")
|
||||
end
|
||||
|
||||
should "return posts for the age:<1minute tag when the user is in Pacific time zone" do
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
post = FactoryGirl.create(:post)
|
||||
Time.zone = "Pacific Time (US & Canada)"
|
||||
count = Post.tag_match("age:<1minute").count
|
||||
assert_equal(1, count)
|
||||
assert_tag_match([post], "age:<1minute")
|
||||
Time.zone = "Eastern Time (US & Canada)"
|
||||
end
|
||||
|
||||
should "return posts for the age:<1minute tag when the user is in Tokyo time zone" do
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
post = FactoryGirl.create(:post)
|
||||
Time.zone = "Asia/Tokyo"
|
||||
count = Post.tag_match("age:<1minute").count
|
||||
assert_equal(1, count)
|
||||
assert_tag_match([post], "age:<1minute")
|
||||
Time.zone = "Eastern Time (US & Canada)"
|
||||
end
|
||||
|
||||
should "return posts for the ' tag" do
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "'")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
count = Post.tag_match("'").count
|
||||
assert_equal(1, count)
|
||||
|
||||
assert_tag_match([post1], "'")
|
||||
end
|
||||
|
||||
should "return posts for the \\ tag" do
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "\\")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
count = Post.tag_match("\\").count
|
||||
assert_equal(1, count)
|
||||
|
||||
assert_tag_match([post1], "\\")
|
||||
end
|
||||
|
||||
should "return posts for the ( tag" do
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "(")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
count = Post.tag_match("(").count
|
||||
assert_equal(1, count)
|
||||
|
||||
assert_tag_match([post1], "(")
|
||||
end
|
||||
|
||||
should "return posts for the ? tag" do
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "?")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
count = Post.tag_match("?").count
|
||||
assert_equal(1, count)
|
||||
|
||||
assert_tag_match([post1], "?")
|
||||
end
|
||||
|
||||
should "return posts for 1 tag" do
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
post3 = FactoryGirl.create(:post, :tag_string => "bbb ccc")
|
||||
relation = Post.tag_match("aaa")
|
||||
assert_equal(2, relation.count)
|
||||
assert_equal(post2.id, relation.all[0].id)
|
||||
assert_equal(post1.id, relation.all[1].id)
|
||||
|
||||
assert_tag_match([post2, post1], "aaa")
|
||||
end
|
||||
|
||||
should "return posts for a 2 tag join" do
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
post3 = FactoryGirl.create(:post, :tag_string => "bbb ccc")
|
||||
relation = Post.tag_match("aaa bbb")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post2.id, relation.first.id)
|
||||
|
||||
assert_tag_match([post2], "aaa bbb")
|
||||
end
|
||||
|
||||
should "return posts for a 2 tag union" do
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "aaab bbb")
|
||||
post3 = FactoryGirl.create(:post, :tag_string => "bbb ccc")
|
||||
|
||||
assert_tag_match([post3, post1], "~aaa ~ccc")
|
||||
end
|
||||
|
||||
should "return posts for 1 tag with exclusion" do
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
|
||||
post3 = FactoryGirl.create(:post, :tag_string => "bbb ccc")
|
||||
relation = Post.tag_match("aaa -bbb")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
|
||||
assert_tag_match([post1], "aaa -bbb")
|
||||
end
|
||||
|
||||
should "return posts for 1 tag with a pattern" do
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "aaab bbb")
|
||||
post3 = FactoryGirl.create(:post, :tag_string => "bbb ccc")
|
||||
relation = Post.tag_match("a*")
|
||||
assert_equal(2, relation.count)
|
||||
assert_equal(post2.id, relation.all[0].id)
|
||||
assert_equal(post1.id, relation.all[1].id)
|
||||
|
||||
assert_tag_match([post2, post1], "a*")
|
||||
end
|
||||
|
||||
should "return posts for 2 tags, one with a pattern" do
|
||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||
post2 = FactoryGirl.create(:post, :tag_string => "aaab bbb")
|
||||
post3 = FactoryGirl.create(:post, :tag_string => "bbb ccc")
|
||||
relation = Post.tag_match("a* bbb")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post2.id, relation.first.id)
|
||||
|
||||
assert_tag_match([post2], "a* bbb")
|
||||
end
|
||||
|
||||
should "return posts for the <id> metatag" do
|
||||
post1 = FactoryGirl.create(:post)
|
||||
post2 = FactoryGirl.create(:post)
|
||||
post3 = FactoryGirl.create(:post)
|
||||
relation = Post.tag_match("id:#{post2.id}")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post2.id, relation.first.id)
|
||||
relation = Post.tag_match("id:>#{post2.id}")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post3.id, relation.first.id)
|
||||
relation = Post.tag_match("id:<#{post2.id}")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
should "return posts for the id:<N> metatag" do
|
||||
posts = FactoryGirl.create_list(:post, 3)
|
||||
|
||||
assert_tag_match([posts[1]], "id:#{posts[1].id}")
|
||||
assert_tag_match([posts[2]], "id:>#{posts[1].id}")
|
||||
assert_tag_match([posts[0]], "id:<#{posts[1].id}")
|
||||
|
||||
assert_tag_match([posts[2], posts[0]], "-id:#{posts[1].id}")
|
||||
assert_tag_match([posts[2], posts[1]], "id:>=#{posts[1].id}")
|
||||
assert_tag_match([posts[1], posts[0]], "id:<=#{posts[1].id}")
|
||||
assert_tag_match([posts[2], posts[0]], "id:#{posts[0].id},#{posts[2].id}")
|
||||
assert_tag_match(posts.reverse, "id:#{posts[0].id}..#{posts[2].id}")
|
||||
end
|
||||
|
||||
should "return posts for the <fav> metatag" do
|
||||
post1 = FactoryGirl.create(:post)
|
||||
post2 = FactoryGirl.create(:post)
|
||||
post3 = FactoryGirl.create(:post)
|
||||
user = FactoryGirl.create(:user)
|
||||
post1.add_favorite!(user)
|
||||
relation = Post.tag_match("fav:#{user.name}")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
end
|
||||
|
||||
should "return posts for the <pool> metatag" do
|
||||
SqsService.any_instance.stubs(:send_message)
|
||||
|
||||
post1 = FactoryGirl.create(:post)
|
||||
post2 = FactoryGirl.create(:post)
|
||||
post3 = FactoryGirl.create(:post)
|
||||
pool = FactoryGirl.create(:pool, :name => "xxx")
|
||||
post1.add_pool!(pool)
|
||||
relation = Post.tag_match("pool:xxx")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
end
|
||||
|
||||
should "return posts for the <pool> metatag with a wildcard" do
|
||||
SqsService.any_instance.stubs(:send_message)
|
||||
|
||||
post1 = FactoryGirl.create(:post)
|
||||
post2 = FactoryGirl.create(:post)
|
||||
post3 = FactoryGirl.create(:post)
|
||||
pool1 = FactoryGirl.create(:pool, :name => "test_a")
|
||||
pool2 = FactoryGirl.create(:pool, :name => "test_b")
|
||||
post1.add_pool!(pool1)
|
||||
post3.add_pool!(pool2)
|
||||
relation = Post.tag_match("pool:test*")
|
||||
assert_equal(2, relation.count)
|
||||
assert_equal([post3.id, post1.id], relation.all.map(&:id))
|
||||
end
|
||||
|
||||
should "return posts for the <user> metatag" do
|
||||
second_user = FactoryGirl.create(:user)
|
||||
post1 = FactoryGirl.create(:post, :uploader => CurrentUser.user)
|
||||
|
||||
assert_equal(CurrentUser.id, post1.uploader_id)
|
||||
|
||||
CurrentUser.scoped(second_user, "127.0.0.2") do
|
||||
post2 = FactoryGirl.create(:post)
|
||||
post3 = FactoryGirl.create(:post)
|
||||
should "return posts for the fav:<name> metatag" do
|
||||
users = FactoryGirl.create_list(:user, 2)
|
||||
posts = users.map do |u|
|
||||
CurrentUser.scoped(u) { FactoryGirl.create(:post, tag_string: "fav:#{u.name}") }
|
||||
end
|
||||
|
||||
relation = Post.tag_match("user:#{CurrentUser.user.name}")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
assert_tag_match([posts[0]], "fav:#{users[0].name}")
|
||||
assert_tag_match([posts[1]], "-fav:#{users[0].name}")
|
||||
end
|
||||
|
||||
should "return posts for a list of md5 hashes" do
|
||||
should "return posts for the ordfav:<name> metatag" do
|
||||
post1 = FactoryGirl.create(:post, tag_string: "fav:#{CurrentUser.name}")
|
||||
post2 = FactoryGirl.create(:post, tag_string: "fav:#{CurrentUser.name}")
|
||||
|
||||
assert_tag_match([post2, post1], "ordfav:#{CurrentUser.name}")
|
||||
end
|
||||
|
||||
should "return posts for the pool:<name> metatag" do
|
||||
SqsService.any_instance.stubs(:send_message)
|
||||
|
||||
FactoryGirl.create(:pool, name: "test_a", category: "series")
|
||||
FactoryGirl.create(:pool, name: "test_b", category: "collection")
|
||||
post1 = FactoryGirl.create(:post, tag_string: "pool:test_a")
|
||||
post2 = FactoryGirl.create(:post, tag_string: "pool:test_b")
|
||||
|
||||
assert_tag_match([post1], "pool:test_a")
|
||||
assert_tag_match([post2], "-pool:test_a")
|
||||
assert_tag_match([], "-pool:test_a -pool:test_b")
|
||||
assert_tag_match([post2, post1], "pool:test*")
|
||||
|
||||
assert_tag_match([post2, post1], "pool:any")
|
||||
assert_tag_match([], "pool:none")
|
||||
|
||||
assert_tag_match([post1], "pool:series")
|
||||
assert_tag_match([post2], "-pool:series")
|
||||
assert_tag_match([post2], "pool:collection")
|
||||
assert_tag_match([post1], "-pool:collection")
|
||||
end
|
||||
|
||||
should "return posts for the ordpool:<name> metatag" do
|
||||
posts = FactoryGirl.create_list(:post, 2, tag_string: "newpool:test")
|
||||
|
||||
assert_tag_match(posts, "ordpool:test")
|
||||
end
|
||||
|
||||
should "return posts for the parent:<N> metatag" do
|
||||
parent = FactoryGirl.create(:post)
|
||||
child = FactoryGirl.create(:post, tag_string: "parent:#{parent.id}")
|
||||
|
||||
assert_tag_match([parent], "parent:none")
|
||||
assert_tag_match([child], "-parent:none")
|
||||
assert_tag_match([child, parent], "parent:#{parent.id}")
|
||||
assert_tag_match([child], "parent:#{child.id}")
|
||||
|
||||
assert_tag_match([child], "child:none")
|
||||
assert_tag_match([parent], "child:any")
|
||||
end
|
||||
|
||||
should "return posts for the favgroup:<name> metatag" do
|
||||
favgroups = FactoryGirl.create_list(:favorite_group, 2, creator: CurrentUser.user)
|
||||
posts = favgroups.map { |g| FactoryGirl.create(:post, tag_string: "favgroup:#{g.name}") }
|
||||
|
||||
assert_tag_match([posts[0]], "favgroup:#{favgroups[0].name}")
|
||||
assert_tag_match([posts[1]], "-favgroup:#{favgroups[0].name}")
|
||||
assert_tag_match([], "-favgroup:#{favgroups[0].name} -favgroup:#{favgroups[1].name}")
|
||||
end
|
||||
|
||||
should "return posts for the user:<name> metatag" do
|
||||
users = FactoryGirl.create_list(:user, 2)
|
||||
posts = users.map { |u| FactoryGirl.create(:post, uploader: u) }
|
||||
|
||||
assert_tag_match([posts[0]], "user:#{users[0].name}")
|
||||
assert_tag_match([posts[1]], "-user:#{users[0].name}")
|
||||
end
|
||||
|
||||
should "return posts for the approver:<name> metatag" do
|
||||
users = FactoryGirl.create_list(:user, 2)
|
||||
posts = users.map { |u| FactoryGirl.create(:post, approver: u) }
|
||||
posts << FactoryGirl.create(:post, approver: nil)
|
||||
|
||||
assert_tag_match([posts[0]], "approver:#{users[0].name}")
|
||||
assert_tag_match([posts[1]], "-approver:#{users[0].name}")
|
||||
assert_tag_match([posts[1], posts[0]], "approver:any")
|
||||
assert_tag_match([posts[2]], "approver:none")
|
||||
end
|
||||
|
||||
should "return posts for the noter:<name> metatag" do
|
||||
users = FactoryGirl.create_list(:user, 2)
|
||||
posts = FactoryGirl.create_list(:post, 2)
|
||||
notes = users.zip(posts).map { |u, p| FactoryGirl.create(:note, creator: u, post: p) }
|
||||
|
||||
assert_tag_match([posts[0]], "noter:#{users[0].name}")
|
||||
assert_tag_match([posts[1]], "noter:#{users[1].name}")
|
||||
end
|
||||
|
||||
should "return posts for the artcomm:<name> metatag" do
|
||||
users = FactoryGirl.create_list(:user, 2)
|
||||
posts = FactoryGirl.create_list(:post, 2)
|
||||
users.zip(posts).map do |u, p|
|
||||
CurrentUser.scoped(u) { FactoryGirl.create(:artist_commentary, post: p) }
|
||||
end
|
||||
|
||||
assert_tag_match([posts[0]], "artcomm:#{users[0].name}")
|
||||
assert_tag_match([posts[1]], "artcomm:#{users[1].name}")
|
||||
end
|
||||
|
||||
should "return posts for the date:<d> metatag" do
|
||||
post = FactoryGirl.create(:post, created_at: Time.parse("2017-01-01"))
|
||||
|
||||
assert_tag_match([post], "date:2017-01-01")
|
||||
end
|
||||
|
||||
should "return posts for the age:<n> metatag" do
|
||||
post = FactoryGirl.create(:post)
|
||||
|
||||
assert_tag_match([post], "age:<60")
|
||||
assert_tag_match([post], "age:<60s")
|
||||
assert_tag_match([post], "age:<1mi")
|
||||
assert_tag_match([post], "age:<1h")
|
||||
assert_tag_match([post], "age:<1d")
|
||||
assert_tag_match([post], "age:<1w")
|
||||
assert_tag_match([post], "age:<1mo")
|
||||
assert_tag_match([post], "age:<1y")
|
||||
end
|
||||
|
||||
should "return posts for the ratio:<x:y> metatag" do
|
||||
post = FactoryGirl.create(:post, image_width: 1000, image_height: 500)
|
||||
|
||||
assert_tag_match([post], "ratio:2:1")
|
||||
assert_tag_match([post], "ratio:2.0")
|
||||
end
|
||||
|
||||
should "return posts for the status:<type> metatag" do
|
||||
pending = FactoryGirl.create(:post, is_pending: true)
|
||||
flagged = FactoryGirl.create(:post, is_flagged: true)
|
||||
deleted = FactoryGirl.create(:post, is_deleted: true)
|
||||
banned = FactoryGirl.create(:post, is_banned: true)
|
||||
all = [banned, deleted, flagged, pending]
|
||||
|
||||
assert_tag_match([pending], "status:pending")
|
||||
assert_tag_match([flagged], "status:flagged")
|
||||
assert_tag_match([deleted], "status:deleted")
|
||||
assert_tag_match([banned], "status:banned")
|
||||
assert_tag_match([flagged], "status:active")
|
||||
assert_tag_match(all, "status:any")
|
||||
assert_tag_match(all, "status:all")
|
||||
|
||||
assert_tag_match(all - [pending], "-status:pending")
|
||||
assert_tag_match(all - [flagged], "-status:flagged")
|
||||
assert_tag_match(all - [deleted], "-status:deleted")
|
||||
assert_tag_match(all - [banned], "-status:banned")
|
||||
assert_tag_match(all - [flagged], "-status:active")
|
||||
end
|
||||
|
||||
should "return posts for the filetype:<ext> metatag" do
|
||||
png = FactoryGirl.create(:post, file_ext: "png")
|
||||
jpg = FactoryGirl.create(:post, file_ext: "jpg")
|
||||
|
||||
assert_tag_match([png], "filetype:png")
|
||||
assert_tag_match([jpg], "-filetype:png")
|
||||
end
|
||||
|
||||
should "return posts for the tagcount:<n> metatags" do
|
||||
post = FactoryGirl.create(:post, tag_string: "artist:wokada copyright:vocaloid char:hatsune_miku twintails")
|
||||
|
||||
assert_tag_match([post], "tagcount:4")
|
||||
assert_tag_match([post], "arttags:1")
|
||||
assert_tag_match([post], "copytags:1")
|
||||
assert_tag_match([post], "chartags:1")
|
||||
assert_tag_match([post], "gentags:1")
|
||||
end
|
||||
|
||||
should "return posts for the md5:<md5> metatag" do
|
||||
post1 = FactoryGirl.create(:post, :md5 => "abcd")
|
||||
post2 = FactoryGirl.create(:post)
|
||||
post3 = FactoryGirl.create(:post)
|
||||
relation = Post.tag_match("md5:abcd")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
|
||||
assert_tag_match([post1], "md5:abcd")
|
||||
end
|
||||
|
||||
should "return posts for a source search" do
|
||||
post1 = FactoryGirl.create(:post, :source => "abcd")
|
||||
post2 = FactoryGirl.create(:post, :source => "abcdefg")
|
||||
post3 = FactoryGirl.create(:post, :source => "xyz")
|
||||
relation = Post.tag_match("source:abcde")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post2.id, relation.first.id)
|
||||
post3 = FactoryGirl.create(:post, :source => "")
|
||||
|
||||
assert_tag_match([post2], "source:abcde")
|
||||
assert_tag_match([post3, post1], "-source:abcde")
|
||||
|
||||
assert_tag_match([post3], "source:none")
|
||||
assert_tag_match([post2, post1], "-source:none")
|
||||
end
|
||||
|
||||
should "return posts for a case insensitive source search" do
|
||||
post1 = FactoryGirl.create(:post, :source => "ABCD")
|
||||
post2 = FactoryGirl.create(:post, :source => "1234")
|
||||
relation = Post.tag_match("source:abcd")
|
||||
assert_equal(1, relation.count)
|
||||
|
||||
assert_tag_match([post1], "source:abcd")
|
||||
end
|
||||
|
||||
should "return posts for a pixiv source search" do
|
||||
url = "http://i1.pixiv.net/img123/img/artist-name/789.png"
|
||||
post = FactoryGirl.create(:post, :source => url)
|
||||
assert_equal(1, Post.tag_match("source:*.pixiv.net/img*/artist-name/*").count)
|
||||
assert_equal(0, Post.tag_match("source:*.pixiv.net/img*/artist-fake/*").count)
|
||||
assert_equal(1, Post.tag_match("source:http://*.pixiv.net/img*/img/artist-name/*").count)
|
||||
assert_equal(0, Post.tag_match("source:http://*.pixiv.net/img*/img/artist-fake/*").count)
|
||||
assert_equal(1, Post.tag_match("source:pixiv/artist-name/*").count)
|
||||
assert_equal(0, Post.tag_match("source:pixiv/artist-fake/*").count)
|
||||
|
||||
assert_tag_match([post], "source:*.pixiv.net/img*/artist-name/*")
|
||||
assert_tag_match([], "source:*.pixiv.net/img*/artist-fake/*")
|
||||
assert_tag_match([post], "source:http://*.pixiv.net/img*/img/artist-name/*")
|
||||
assert_tag_match([], "source:http://*.pixiv.net/img*/img/artist-fake/*")
|
||||
assert_tag_match([post], "source:pixiv/artist-name/*")
|
||||
assert_tag_match([], "source:pixiv/artist-fake/*")
|
||||
end
|
||||
|
||||
should "return posts for a pixiv id search (type 1)" do
|
||||
url = "http://i1.pixiv.net/img-inf/img/2013/03/14/03/02/36/34228050_s.jpg"
|
||||
post = FactoryGirl.create(:post, :source => url)
|
||||
assert_equal(1, Post.tag_match("pixiv_id:34228050").count)
|
||||
assert_tag_match([post], "pixiv_id:34228050")
|
||||
end
|
||||
|
||||
should "return posts for a pixiv id search (type 2)" do
|
||||
url = "http://i1.pixiv.net/img123/img/artist-name/789.png"
|
||||
post = FactoryGirl.create(:post, :source => url)
|
||||
assert_equal(1, Post.tag_match("pixiv_id:789").count)
|
||||
assert_tag_match([post], "pixiv_id:789")
|
||||
end
|
||||
|
||||
should "return posts for a pixiv id search (type 3)" do
|
||||
url = "http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=19113635&page=0"
|
||||
post = FactoryGirl.create(:post, :source => url)
|
||||
assert_equal(1, Post.tag_match("pixiv_id:19113635").count)
|
||||
assert_tag_match([post], "pixiv_id:19113635")
|
||||
end
|
||||
|
||||
should "return posts for a pixiv id search (type 4)" do
|
||||
url = "http://i2.pixiv.net/img70/img/disappearedstump/34551381_p3.jpg?1364424318"
|
||||
post = FactoryGirl.create(:post, :source => url)
|
||||
assert_equal(1, Post.tag_match("pixiv_id:34551381").count)
|
||||
assert_tag_match([post], "pixiv_id:34551381")
|
||||
end
|
||||
|
||||
# should "return posts for a pixiv novel id search" do
|
||||
@@ -1746,52 +1866,103 @@ 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)
|
||||
should "return posts for a search:<category> metatag" do
|
||||
post1 = FactoryGirl.create(:post, tag_string: "aaa")
|
||||
post2 = FactoryGirl.create(:post, tag_string: "bbb")
|
||||
FactoryGirl.create(:saved_search, tag_query: "aaa", category: "zzz", user: CurrentUser.user)
|
||||
FactoryGirl.create(:saved_search, tag_query: "bbb", category: nil, user: CurrentUser.user)
|
||||
|
||||
SavedSearch.expects(:post_ids).with(CurrentUser.id, "zzz").returns([post1.id])
|
||||
SavedSearch.expects(:post_ids).with(CurrentUser.id, "uncategorized").returns([post2.id])
|
||||
SavedSearch.expects(:post_ids).with(CurrentUser.id).returns([post1.id, post2.id])
|
||||
|
||||
assert_tag_match([post1], "search:zzz")
|
||||
assert_tag_match([post2], "search:uncategorized")
|
||||
assert_tag_match([post2, post1], "search:all")
|
||||
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)
|
||||
should "return posts for a rating:<s|q|e> metatag" do
|
||||
s = FactoryGirl.create(:post, :rating => "s")
|
||||
q = FactoryGirl.create(:post, :rating => "q")
|
||||
e = FactoryGirl.create(:post, :rating => "e")
|
||||
all = [e, q, s]
|
||||
|
||||
assert_tag_match([s], "rating:s")
|
||||
assert_tag_match([q], "rating:q")
|
||||
assert_tag_match([e], "rating:e")
|
||||
|
||||
assert_tag_match(all - [s], "-rating:s")
|
||||
assert_tag_match(all - [q], "-rating:q")
|
||||
assert_tag_match(all - [e], "-rating:e")
|
||||
end
|
||||
|
||||
should "return posts for a particular rating" do
|
||||
post1 = FactoryGirl.create(:post, :rating => "s")
|
||||
post2 = FactoryGirl.create(:post, :rating => "q")
|
||||
post3 = FactoryGirl.create(:post, :rating => "e")
|
||||
relation = Post.tag_match("rating:e")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post3.id, relation.first.id)
|
||||
should "return posts for a locked:<rating|note|status> metatag" do
|
||||
rating_locked = FactoryGirl.create(:post, is_rating_locked: true)
|
||||
note_locked = FactoryGirl.create(:post, is_note_locked: true)
|
||||
status_locked = FactoryGirl.create(:post, is_status_locked: true)
|
||||
all = [status_locked, note_locked, rating_locked]
|
||||
|
||||
assert_tag_match([rating_locked], "locked:rating")
|
||||
assert_tag_match([note_locked], "locked:note")
|
||||
assert_tag_match([status_locked], "locked:status")
|
||||
|
||||
assert_tag_match(all - [rating_locked], "-locked:rating")
|
||||
assert_tag_match(all - [note_locked], "-locked:note")
|
||||
assert_tag_match(all - [status_locked], "-locked:status")
|
||||
end
|
||||
|
||||
should "return posts for a particular negated rating" do
|
||||
post1 = FactoryGirl.create(:post, :rating => "s")
|
||||
post2 = FactoryGirl.create(:post, :rating => "s")
|
||||
post3 = FactoryGirl.create(:post, :rating => "e")
|
||||
relation = Post.tag_match("-rating:s")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post3.id, relation.first.id)
|
||||
should "return posts for a upvote:<user>, downvote:<user> metatag" do
|
||||
CurrentUser.scoped(FactoryGirl.create(:mod_user)) do
|
||||
upvoted = FactoryGirl.create(:post, tag_string: "upvote:self")
|
||||
downvoted = FactoryGirl.create(:post, tag_string: "downvote:self")
|
||||
|
||||
assert_tag_match([upvoted], "upvote:#{CurrentUser.name}")
|
||||
assert_tag_match([downvoted], "downvote:#{CurrentUser.name}")
|
||||
end
|
||||
end
|
||||
|
||||
should "return posts ordered by a particular attribute" do
|
||||
post1 = FactoryGirl.create(:post, :rating => "s")
|
||||
post2 = FactoryGirl.create(:post, :rating => "s")
|
||||
post3 = FactoryGirl.create(:post, :rating => "e", :score => 5, :image_width => 10_000)
|
||||
relation = Post.tag_match("order:id")
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
relation = Post.tag_match("order:mpixels")
|
||||
assert_equal(post3.id, relation.first.id)
|
||||
relation = Post.tag_match("order:landscape")
|
||||
assert_equal(post3.id, relation.first.id)
|
||||
posts = (1..2).map do |n|
|
||||
p = FactoryGirl.create(
|
||||
:post,
|
||||
score: n,
|
||||
fav_count: n,
|
||||
file_size: 1.megabyte * n,
|
||||
# posts[0] is portrait, posts[1] is landscape. posts[1].mpixels > posts[0].mpixels.
|
||||
image_height: 100*n*n,
|
||||
image_width: 100*(3-n)*n,
|
||||
)
|
||||
|
||||
FactoryGirl.create(:artist_commentary, post: p)
|
||||
FactoryGirl.create(:comment, post: p, do_not_bump_post: false)
|
||||
FactoryGirl.create(:note, post: p)
|
||||
p
|
||||
end
|
||||
|
||||
assert_tag_match(posts.reverse, "order:id_desc")
|
||||
assert_tag_match(posts.reverse, "order:score")
|
||||
assert_tag_match(posts.reverse, "order:favcount")
|
||||
assert_tag_match(posts.reverse, "order:change")
|
||||
assert_tag_match(posts.reverse, "order:comment")
|
||||
assert_tag_match(posts.reverse, "order:comment_bumped")
|
||||
assert_tag_match(posts.reverse, "order:note")
|
||||
assert_tag_match(posts.reverse, "order:artcomm")
|
||||
assert_tag_match(posts.reverse, "order:mpixels")
|
||||
assert_tag_match(posts.reverse, "order:portrait")
|
||||
assert_tag_match(posts.reverse, "order:filesize")
|
||||
assert_tag_match(posts.reverse, "order:rank")
|
||||
|
||||
assert_tag_match(posts, "order:id_asc")
|
||||
assert_tag_match(posts, "order:score_asc")
|
||||
assert_tag_match(posts, "order:favcount_asc")
|
||||
assert_tag_match(posts, "order:change_asc")
|
||||
assert_tag_match(posts, "order:comment_asc")
|
||||
assert_tag_match(posts, "order:comment_bumped_asc")
|
||||
assert_tag_match(posts, "order:artcomm_asc")
|
||||
assert_tag_match(posts, "order:note_asc")
|
||||
assert_tag_match(posts, "order:mpixels_asc")
|
||||
assert_tag_match(posts, "order:landscape")
|
||||
assert_tag_match(posts, "order:filesize_asc")
|
||||
end
|
||||
|
||||
should "return posts for order:comment_bumped" do
|
||||
@@ -1805,21 +1976,23 @@ class PostTest < ActiveSupport::TestCase
|
||||
comment3 = FactoryGirl.create(:comment, :post => post3)
|
||||
end
|
||||
|
||||
assert_equal([post3.id, post1.id, post2.id], Post.tag_match("order:comment_bumped").map(&:id))
|
||||
assert_equal([post1.id, post3.id, post2.id], Post.tag_match("order:comment_bumped_asc").map(&:id))
|
||||
assert_tag_match([post3, post1, post2], "order:comment_bumped")
|
||||
assert_tag_match([post1, post3, post2], "order:comment_bumped_asc")
|
||||
end
|
||||
|
||||
should "return posts for a filesize search" do
|
||||
post = FactoryGirl.create(:post, :file_size => 1.megabyte)
|
||||
assert_equal(1, Post.tag_match("filesize:1mb").count)
|
||||
assert_equal(1, Post.tag_match("filesize:1000kb").count)
|
||||
assert_equal(1, Post.tag_match("filesize:1048576b").count)
|
||||
|
||||
assert_tag_match([post], "filesize:1mb")
|
||||
assert_tag_match([post], "filesize:1000kb")
|
||||
assert_tag_match([post], "filesize:1048576b")
|
||||
end
|
||||
|
||||
should "not perform fuzzy matching for an exact filesize search" do
|
||||
post = FactoryGirl.create(:post, :file_size => 1.megabyte)
|
||||
assert_equal(0, Post.tag_match("filesize:1048000b").count)
|
||||
assert_equal(0, Post.tag_match("filesize:1048000").count)
|
||||
|
||||
assert_tag_match([], "filesize:1048000b")
|
||||
assert_tag_match([], "filesize:1048000")
|
||||
end
|
||||
|
||||
should "fail for more than 6 tags" do
|
||||
@@ -2039,7 +2212,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "a post that has been updated" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post, :rating => "q", :tag_string => "aaa")
|
||||
@post = FactoryGirl.create(:post, :rating => "q", :tag_string => "aaa", :source => nil)
|
||||
@post.stubs(:merge_version?).returns(false)
|
||||
@post.update_attributes(:tag_string => "aaa bbb ccc ddd")
|
||||
@post.update_attributes(:tag_string => "bbb xxx yyy", :source => "xyz")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user