* Renamed Post.find_by_tags into Post.tag_match, made into a full fledged scope
* Post.tag_match no longer takes an options hash (use other arel builders instead)
This commit is contained in:
@@ -3,103 +3,13 @@ require "test_helper"
|
||||
class PostsControllerTest < ActionController::TestCase
|
||||
context "The posts controller" do
|
||||
setup do
|
||||
@users = {}
|
||||
@users[:anon] = AnonymousUser.new
|
||||
@users[:member] = Factory.create(:user)
|
||||
CurrentUser.user = @users[:member]
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@users[:banned] = Factory.create(:banned_user)
|
||||
@users[:priv] = Factory.create(:privileged_user)
|
||||
@users[:contrib] = Factory.create(:contributor_user)
|
||||
@users[:janitor] = Factory.create(:janitor_user)
|
||||
@users[:mod] = Factory.create(:moderator_user)
|
||||
@users[:admin] = Factory.create(:admin_user)
|
||||
end
|
||||
|
||||
teardown do
|
||||
@users = nil
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "new action" do
|
||||
should "render" do
|
||||
get :new, {}, {:user_id => @users[:member]}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
should "create a post" do
|
||||
post :create, {:post => {:source => "", :file => upload_jpeg("#{Rails.root}/test/files/test.jpg"), :tag_string => "hoge", :rating => "s"}}, {:user_id => @users[:member].id}
|
||||
p = Post.last
|
||||
assert_equal("hoge", p.tag_string)
|
||||
assert_equal("jpg", p.file_ext)
|
||||
assert_equal("s", p.rating)
|
||||
assert_equal("uploader:#{@users[:member].name}", p.uploader_string)
|
||||
assert_equal(true, File.exists?(p.file_path))
|
||||
assert_equal(true, File.exists?(p.preview_path))
|
||||
end
|
||||
end
|
||||
|
||||
context "update action" do
|
||||
setup do
|
||||
@p1 = Factory.create(:post, :tag_string => "hoge")
|
||||
end
|
||||
context "index action" do
|
||||
|
||||
should "update a post" do
|
||||
put :update, {:post => {:tags => "moge", :rating => "Explicit"}, :id => @p1.id}, {:user_id => @users[:member].id}
|
||||
@p1.reload
|
||||
assert_equal("moge", p1.cached_tags)
|
||||
assert_equal("e", p1.rating)
|
||||
|
||||
assert_equal(2, p1.tag_history.size)
|
||||
post :update, {:post => {:rating => "Safe"}, :id => p1.id}, {:user_id => 3}
|
||||
assert_equal(3, p1.tag_history.size)
|
||||
|
||||
p1.update_attribute(:is_rating_locked, true)
|
||||
post :update, {:post => {:rating => "Questionable"}, :id => p1.id}, {:user_id => 3}
|
||||
p1.reload
|
||||
assert_equal("s", p1.rating)
|
||||
end
|
||||
end
|
||||
|
||||
should "update a post" do
|
||||
end
|
||||
|
||||
should "list posts" do
|
||||
get :index, {}, {:user_id => 3}
|
||||
assert_response :success
|
||||
|
||||
get :index, {:tags => "tag1"}, {:user_id => 3}
|
||||
assert_response :success
|
||||
|
||||
get :index, {:format => "json"}, {:user_id => 3}
|
||||
assert_response :success
|
||||
|
||||
get :index, {:format => "xml"}, {:user_id => 3}
|
||||
assert_response :success
|
||||
|
||||
get :index, {:tags => "-tag1"}, {:user_id => 3}
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "list posts through an atom feed" do
|
||||
get :atom, {}, {:user_id => 3}
|
||||
assert_response :success
|
||||
|
||||
get :atom, {:tags => "tag1"}, {:user_id => 3}
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "display a post" do
|
||||
get :show, {:id => 1}, {:user_id => 3}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
def test_popular
|
||||
get :popular_by_day, {}, {:user_id => 3}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
@@ -417,7 +417,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
post1 = Factory.create(:post, :tag_string => "aaa")
|
||||
post2 = Factory.create(:post, :tag_string => "aaa bbb")
|
||||
post3 = Factory.create(:post, :tag_string => "bbb ccc")
|
||||
relation = Post.find_by_tags("aaa")
|
||||
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)
|
||||
@@ -427,7 +427,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
post1 = Factory.create(:post, :tag_string => "aaa")
|
||||
post2 = Factory.create(:post, :tag_string => "aaa bbb")
|
||||
post3 = Factory.create(:post, :tag_string => "bbb ccc")
|
||||
relation = Post.find_by_tags("aaa bbb")
|
||||
relation = Post.tag_match("aaa bbb")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post2.id, relation.first.id)
|
||||
end
|
||||
@@ -436,7 +436,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
post1 = Factory.create(:post, :tag_string => "aaa")
|
||||
post2 = Factory.create(:post, :tag_string => "aaa bbb")
|
||||
post3 = Factory.create(:post, :tag_string => "bbb ccc")
|
||||
relation = Post.find_by_tags("aaa -bbb")
|
||||
relation = Post.tag_match("aaa -bbb")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
end
|
||||
@@ -445,7 +445,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
post1 = Factory.create(:post, :tag_string => "aaa")
|
||||
post2 = Factory.create(:post, :tag_string => "aaab bbb")
|
||||
post3 = Factory.create(:post, :tag_string => "bbb ccc")
|
||||
relation = Post.find_by_tags("a*")
|
||||
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)
|
||||
@@ -455,7 +455,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
post1 = Factory.create(:post, :tag_string => "aaa")
|
||||
post2 = Factory.create(:post, :tag_string => "aaab bbb")
|
||||
post3 = Factory.create(:post, :tag_string => "bbb ccc")
|
||||
relation = Post.find_by_tags("a* bbb")
|
||||
relation = Post.tag_match("a* bbb")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post2.id, relation.first.id)
|
||||
end
|
||||
@@ -464,13 +464,13 @@ class PostTest < ActiveSupport::TestCase
|
||||
post1 = Factory.create(:post)
|
||||
post2 = Factory.create(:post)
|
||||
post3 = Factory.create(:post)
|
||||
relation = Post.find_by_tags("id:#{post2.id}")
|
||||
relation = Post.tag_match("id:#{post2.id}")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post2.id, relation.first.id)
|
||||
relation = Post.find_by_tags("id:>#{post2.id}")
|
||||
relation = Post.tag_match("id:>#{post2.id}")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post3.id, relation.first.id)
|
||||
relation = Post.find_by_tags("id:<#{post2.id}")
|
||||
relation = Post.tag_match("id:<#{post2.id}")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
end
|
||||
@@ -481,7 +481,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
post3 = Factory.create(:post)
|
||||
user = Factory.create(:user)
|
||||
post1.add_favorite(user)
|
||||
relation = Post.find_by_tags("fav:#{user.name}")
|
||||
relation = Post.tag_match("fav:#{user.name}")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
end
|
||||
@@ -492,7 +492,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
post3 = Factory.create(:post)
|
||||
pool = Factory.create(:pool)
|
||||
post1.add_pool(pool)
|
||||
relation = Post.find_by_tags("pool:#{pool.name}")
|
||||
relation = Post.tag_match("pool:#{pool.name}")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
end
|
||||
@@ -506,7 +506,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
post3 = Factory.create(:post)
|
||||
end
|
||||
|
||||
relation = Post.find_by_tags("uploader:#{CurrentUser.user.name}")
|
||||
relation = Post.tag_match("uploader:#{CurrentUser.user.name}")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
end
|
||||
@@ -515,7 +515,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
post1 = Factory.create(:post, :md5 => "abcd")
|
||||
post2 = Factory.create(:post)
|
||||
post3 = Factory.create(:post)
|
||||
relation = Post.find_by_tags("md5:abcd")
|
||||
relation = Post.tag_match("md5:abcd")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
end
|
||||
@@ -524,7 +524,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
post1 = Factory.create(:post, :source => "abcd")
|
||||
post2 = Factory.create(:post, :source => "abcdefg")
|
||||
post3 = Factory.create(:post, :source => "xyz")
|
||||
relation = Post.find_by_tags("source:abcde")
|
||||
relation = Post.tag_match("source:abcde")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post2.id, relation.first.id)
|
||||
end
|
||||
@@ -535,7 +535,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
post1 = Factory.create(:post, :rating => "s")
|
||||
post2 = Factory.create(:post, :rating => "q")
|
||||
post3 = Factory.create(:post, :rating => "e")
|
||||
relation = Post.find_by_tags("rating:e")
|
||||
relation = Post.tag_match("rating:e")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post3.id, relation.first.id)
|
||||
end
|
||||
@@ -544,7 +544,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
post1 = Factory.create(:post, :rating => "s")
|
||||
post2 = Factory.create(:post, :rating => "s")
|
||||
post3 = Factory.create(:post, :rating => "e")
|
||||
relation = Post.find_by_tags("-rating:s")
|
||||
relation = Post.tag_match("-rating:s")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post3.id, relation.first.id)
|
||||
end
|
||||
@@ -553,11 +553,11 @@ class PostTest < ActiveSupport::TestCase
|
||||
post1 = Factory.create(:post, :rating => "s")
|
||||
post2 = Factory.create(:post, :rating => "s")
|
||||
post3 = Factory.create(:post, :rating => "e", :score => 5, :image_width => 1000)
|
||||
relation = Post.find_by_tags("order:id")
|
||||
relation = Post.tag_match("order:id")
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
relation = Post.find_by_tags("order:mpixels")
|
||||
relation = Post.tag_match("order:mpixels")
|
||||
assert_equal(post3.id, relation.first.id)
|
||||
relation = Post.find_by_tags("order:landscape")
|
||||
relation = Post.tag_match("order:landscape")
|
||||
assert_equal(post3.id, relation.first.id)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user