forked from e621ng/e621ng
added artist url test
This commit is contained in:
parent
e9c2d1e636
commit
a7a6395384
@ -7,17 +7,17 @@ class ArtistUrl < ActiveRecord::Base
|
||||
if url.nil?
|
||||
nil
|
||||
else
|
||||
url.gsub!(/^http:\/\/blog\d+\.fc2/, "http://blog.fc2")
|
||||
url.gsub!(/^http:\/\/blog-imgs-\d+\.fc2/, "http://blog.fc2")
|
||||
url.gsub!(/^http:\/\/blog-imgs-\d+-\w+\.fc2/, "http://blog.fc2")
|
||||
url.gsub!(/^http:\/\/img\d+\.pixiv\.net/, "http://img.pixiv.net")
|
||||
url.gsub!(/\/+$/, "")
|
||||
url = url.gsub(/^http:\/\/blog\d+\.fc2/, "http://blog.fc2")
|
||||
url = url.gsub(/^http:\/\/blog-imgs-\d+\.fc2/, "http://blog.fc2")
|
||||
url = url.gsub(/^http:\/\/blog-imgs-\d+-\w+\.fc2/, "http://blog.fc2")
|
||||
url = url.gsub(/^http:\/\/img\d+\.pixiv\.net/, "http://img.pixiv.net")
|
||||
url = url.gsub(/\/+\Z/, "")
|
||||
url + "/"
|
||||
end
|
||||
end
|
||||
|
||||
def self.normalize_for_search(url)
|
||||
if url =~ /\.\w+$/ && url =~ /\w\/\w/
|
||||
if url =~ /\.\w+\Z/ && url =~ /\w\/\w/
|
||||
url = File.dirname(url)
|
||||
end
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
Factory.define(:artist_url) do |f|
|
||||
f.artist {|x| x.association(:artist)}
|
||||
f.url {Faker::Internet.domain_name}
|
||||
end
|
||||
|
@ -1,8 +1,35 @@
|
||||
require 'test_helper'
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class ArtistUrlTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
context "An artist url" do
|
||||
setup do
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
should "always add a trailing slash when normalized" do
|
||||
url = Factory.create(:artist_url, :url => "http://monet.com")
|
||||
assert_equal("http://monet.com", url.url)
|
||||
assert_equal("http://monet.com/", url.normalized_url)
|
||||
|
||||
url = Factory.create(:artist_url, :url => "http://monet.com/")
|
||||
assert_equal("http://monet.com/", url.url)
|
||||
assert_equal("http://monet.com/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize fc2 urls" do
|
||||
url = Factory.create(:artist_url, :url => "http://blog55.fc2.com/monet")
|
||||
assert_equal("http://blog55.fc2.com/monet", url.url)
|
||||
assert_equal("http://blog.fc2.com/monet/", url.normalized_url)
|
||||
|
||||
url = Factory.create(:artist_url, :url => "http://blog-imgs-55.fc2.com/monet")
|
||||
assert_equal("http://blog-imgs-55.fc2.com/monet", url.url)
|
||||
assert_equal("http://blog.fc2.com/monet/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize pixiv urls" do
|
||||
url = Factory.create(:artist_url, :url => "http://img55.pixiv.net/monet")
|
||||
assert_equal("http://img55.pixiv.net/monet", url.url)
|
||||
assert_equal("http://img.pixiv.net/monet/", url.normalized_url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user