fixed pixiv tests, added metatag support when tagging fixes #23: Unable to add to pool using "pool:XXX" syntax
This commit is contained in:
@@ -414,7 +414,32 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def filter_metatags(tags)
|
def filter_metatags(tags)
|
||||||
tags.reject {|tag| tag =~ /\A(?:pool|rating|fav):/}
|
metatags, tags = tags.partition {|x| x =~ /\A(?:pool|rating|fav):/}
|
||||||
|
apply_metatags(metatags)
|
||||||
|
return tags
|
||||||
|
end
|
||||||
|
|
||||||
|
def apply_metatags(tags)
|
||||||
|
tags.each do |tag|
|
||||||
|
case tag
|
||||||
|
when /^pool:(\d+)$/
|
||||||
|
pool = Pool.find_by_id($1.to_i)
|
||||||
|
add_pool!(pool) if pool
|
||||||
|
|
||||||
|
when /^pool:(.+)$/
|
||||||
|
pool = Pool.find_by_name($1)
|
||||||
|
if pool.nil?
|
||||||
|
pool = Pool.create(:name => $1, :description => "This pool was automatically generated")
|
||||||
|
end
|
||||||
|
add_pool!(pool)
|
||||||
|
|
||||||
|
when /^rating:([qse])/i
|
||||||
|
self.rating = $1.downcase
|
||||||
|
|
||||||
|
when /^fav:(.+)$/
|
||||||
|
add_favorite!(CurrentUser.user)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_tag?(tag)
|
def has_tag?(tag)
|
||||||
|
|||||||
@@ -4,15 +4,9 @@ require 'test_helper'
|
|||||||
|
|
||||||
class PixivProxyTest < ActiveSupport::TestCase
|
class PixivProxyTest < ActiveSupport::TestCase
|
||||||
context "The proxy" do
|
context "The proxy" do
|
||||||
should "get the profile" do
|
|
||||||
results = PixivProxy.get_profile("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=9646484")
|
|
||||||
assert_equal("シビレ\347\275\240", results[:artist])
|
|
||||||
assert_equal("/member_illust.php?id=9646484", results[:listing_url])
|
|
||||||
end
|
|
||||||
|
|
||||||
should "get a single post" do
|
should "get a single post" do
|
||||||
results = PixivProxy.get_single("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=9646484")
|
results = PixivProxy.get_single("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=9646484")
|
||||||
assert_equal("/member.php?id=4015", results[:profile_url])
|
assert_equal("member.php?id=4015", results[:profile_url])
|
||||||
assert(results[:jp_tags].size > 0)
|
assert(results[:jp_tags].size > 0)
|
||||||
first_tag = results[:jp_tags][0]
|
first_tag = results[:jp_tags][0]
|
||||||
assert_equal(2, first_tag.size)
|
assert_equal(2, first_tag.size)
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ require 'test_helper'
|
|||||||
|
|
||||||
class PostTest < ActiveSupport::TestCase
|
class PostTest < ActiveSupport::TestCase
|
||||||
setup do
|
setup do
|
||||||
user = Factory.create(:user)
|
@user = Factory.create(:user)
|
||||||
CurrentUser.user = user
|
CurrentUser.user = @user
|
||||||
CurrentUser.ip_addr = "127.0.0.1"
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
MEMCACHE.flush_all
|
MEMCACHE.flush_all
|
||||||
end
|
end
|
||||||
@@ -210,6 +210,81 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "Tagging:" do
|
context "Tagging:" do
|
||||||
context "A post" do
|
context "A post" do
|
||||||
|
setup do
|
||||||
|
@post = Factory.create(:post)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "tagged with a metatag" do
|
||||||
|
context "for a pool" do
|
||||||
|
context "id" do
|
||||||
|
setup do
|
||||||
|
@pool = Factory.create(:pool)
|
||||||
|
@post.update_attributes(:tag_string => "aaa pool:#{@pool.id}")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "add the post to the pool" do
|
||||||
|
@post.reload
|
||||||
|
@pool.reload
|
||||||
|
assert_equal("#{@post.id}", @pool.post_ids)
|
||||||
|
assert_equal("pool:#{@pool.id}", @post.pool_string)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "name" do
|
||||||
|
context "that exists" do
|
||||||
|
setup do
|
||||||
|
@pool = Factory.create(:pool, :name => "abc")
|
||||||
|
@post.update_attributes(:tag_string => "aaa pool:abc")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "add the post to the pool" do
|
||||||
|
@post.reload
|
||||||
|
@pool.reload
|
||||||
|
assert_equal("#{@post.id}", @pool.post_ids)
|
||||||
|
assert_equal("pool:#{@pool.id}", @post.pool_string)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "that doesn't exist" do
|
||||||
|
should "create a new pool and add the post to that pool" do
|
||||||
|
@post.update_attributes(:tag_string => "aaa pool:abc")
|
||||||
|
@pool = Pool.find_by_name("abc")
|
||||||
|
@post.reload
|
||||||
|
assert_not_nil(@pool)
|
||||||
|
assert_equal("#{@post.id}", @pool.post_ids)
|
||||||
|
assert_equal("pool:#{@pool.id}", @post.pool_string)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "for a rating" do
|
||||||
|
context "that is valid" do
|
||||||
|
should "update the rating" do
|
||||||
|
@post.update_attributes(:tag_string => "aaa rating:e")
|
||||||
|
@post.reload
|
||||||
|
assert_equal("e", @post.rating)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "that is invalid" do
|
||||||
|
should "not update the rating" do
|
||||||
|
@post.update_attributes(:tag_string => "aaa rating:z")
|
||||||
|
@post.reload
|
||||||
|
assert_equal("q", @post.rating)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "for a fav" do
|
||||||
|
should "add the current user to the post's favorite listing" do
|
||||||
|
@post.update_attributes(:tag_string => "aaa fav:self")
|
||||||
|
@post.reload
|
||||||
|
assert_equal("fav:#{@user.id}", @post.fav_string)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
should "have an array representation of its tags" do
|
should "have an array representation of its tags" do
|
||||||
post = Factory.create(:post)
|
post = Factory.create(:post)
|
||||||
post.set_tag_string("aaa bbb")
|
post.set_tag_string("aaa bbb")
|
||||||
|
|||||||
Reference in New Issue
Block a user