added artist url test

This commit is contained in:
albert 2010-02-15 14:17:08 -05:00
parent e9c2d1e636
commit a7a6395384
3 changed files with 38 additions and 10 deletions

View File

@ -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

View File

@ -1,3 +1,4 @@
Factory.define(:artist_url) do |f|
f.artist {|x| x.association(:artist)}
f.url {Faker::Internet.domain_name}
end

View File

@ -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