add test cases
This commit is contained in:
@@ -149,9 +149,9 @@ class PostQueryBuilder
|
|||||||
relation = relation.where("(posts.source = '' OR posts.source IS NULL)")
|
relation = relation.where("(posts.source = '' OR posts.source IS NULL)")
|
||||||
elsif q[:source] =~ /^(pixiv\/|%\.?pixiv(\.net(\/img)?)?(%\/|(?=%$)))(.+)$/
|
elsif q[:source] =~ /^(pixiv\/|%\.?pixiv(\.net(\/img)?)?(%\/|(?=%$)))(.+)$/
|
||||||
if $5 == "%"
|
if $5 == "%"
|
||||||
relation = relation.where("substring(posts.source, 'pixiv.net/img.*/([^/]*/[^/]*)$') IS NOT NULL")
|
relation = relation.where("substring(posts.source, 'pixiv.net/img.*/([^/]*/[^/]*)$') IS NOT NULL")
|
||||||
else
|
else
|
||||||
relation = relation.where("substring(posts.source, 'pixiv.net/img.*/([^/]*/[^/]*)$') LIKE ? ESCAPE E'\\\\'", $5)
|
relation = relation.where("substring(posts.source, 'pixiv.net/img.*/([^/]*/[^/]*)$') LIKE ? ESCAPE E'\\\\'", $5)
|
||||||
end
|
end
|
||||||
has_constraints!
|
has_constraints!
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -5851,6 +5851,20 @@ CREATE INDEX index_posts_on_mpixels ON posts USING btree (((((image_width * imag
|
|||||||
CREATE INDEX index_posts_on_parent_id ON posts USING btree (parent_id);
|
CREATE INDEX index_posts_on_parent_id ON posts USING btree (parent_id);
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: index_posts_on_pixiv_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE INDEX index_posts_on_pixiv_id ON posts USING btree ((("substring"((source)::text, 'pixiv.net/img.*/([0-9]+)[^/]*$'::text))::integer));
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: index_posts_on_pixiv_suffix; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE INDEX index_posts_on_pixiv_suffix ON posts USING btree ("substring"((source)::text, 'pixiv.net/img.*/([^/]*/[^/]*)$'::text) text_pattern_ops);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: index_posts_on_source; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
-- Name: index_posts_on_source; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||||
--
|
--
|
||||||
@@ -6210,4 +6224,6 @@ INSERT INTO schema_migrations (version) VALUES ('20130221035518');
|
|||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20130221214811');
|
INSERT INTO schema_migrations (version) VALUES ('20130221214811');
|
||||||
|
|
||||||
|
INSERT INTO schema_migrations (version) VALUES ('20130302214500');
|
||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20130305005138');
|
INSERT INTO schema_migrations (version) VALUES ('20130305005138');
|
||||||
@@ -857,6 +857,12 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
assert_equal(post1.id, relation.first.id)
|
assert_equal(post1.id, relation.first.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "return posts for the <pixiv> metatag" do
|
||||||
|
post = FactoryGirl.create(:post, :source => "http://i1.pixiv.net/img123/img/artist-name/789.png")
|
||||||
|
assert_equal(1, Post.tag_match("pixiv:789").count)
|
||||||
|
assert_equal(0, Post.tag_match("pixiv:790").count)
|
||||||
|
end
|
||||||
|
|
||||||
should "return posts for a list of md5 hashes" do
|
should "return posts for a list of md5 hashes" do
|
||||||
post1 = FactoryGirl.create(:post, :md5 => "abcd")
|
post1 = FactoryGirl.create(:post, :md5 => "abcd")
|
||||||
post2 = FactoryGirl.create(:post)
|
post2 = FactoryGirl.create(:post)
|
||||||
@@ -875,6 +881,14 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
assert_equal(post2.id, relation.first.id)
|
assert_equal(post2.id, relation.first.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "return posts for a pixiv source search" do
|
||||||
|
post = FactoryGirl.create(:post, :source => "http://i1.pixiv.net/img123/img/artist-name/789.png")
|
||||||
|
assert_equal(1, Post.tag_match("source:pixiv/artist-name/*").count)
|
||||||
|
assert_equal(0, Post.tag_match("source:pixiv/artist-fake/*").count)
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
|
||||||
should "return posts for a tag subscription search" do
|
should "return posts for a tag subscription search" do
|
||||||
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
|
||||||
sub = FactoryGirl.create(:tag_subscription, :tag_query => "aaa", :name => "zzz")
|
sub = FactoryGirl.create(:tag_subscription, :tag_query => "aaa", :name => "zzz")
|
||||||
|
|||||||
Reference in New Issue
Block a user