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? if url.nil?
nil nil
else else
url.gsub!(/^http:\/\/blog\d+\.fc2/, "http://blog.fc2") url = url.gsub(/^http:\/\/blog\d+\.fc2/, "http://blog.fc2")
url.gsub!(/^http:\/\/blog-imgs-\d+\.fc2/, "http://blog.fc2") url = url.gsub(/^http:\/\/blog-imgs-\d+\.fc2/, "http://blog.fc2")
url.gsub!(/^http:\/\/blog-imgs-\d+-\w+\.fc2/, "http://blog.fc2") url = url.gsub(/^http:\/\/blog-imgs-\d+-\w+\.fc2/, "http://blog.fc2")
url.gsub!(/^http:\/\/img\d+\.pixiv\.net/, "http://img.pixiv.net") url = url.gsub(/^http:\/\/img\d+\.pixiv\.net/, "http://img.pixiv.net")
url.gsub!(/\/+$/, "") url = url.gsub(/\/+\Z/, "")
url + "/" url + "/"
end end
end end
def self.normalize_for_search(url) def self.normalize_for_search(url)
if url =~ /\.\w+$/ && url =~ /\w\/\w/ if url =~ /\.\w+\Z/ && url =~ /\w\/\w/
url = File.dirname(url) url = File.dirname(url)
end end

View File

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

View File

@@ -1,8 +1,35 @@
require 'test_helper' require File.dirname(__FILE__) + '/../test_helper'
class ArtistUrlTest < ActiveSupport::TestCase class ArtistUrlTest < ActiveSupport::TestCase
# Replace this with your real tests. context "An artist url" do
test "the truth" do setup do
assert true 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
end end