dont recreate artist urls that havent changed
This commit is contained in:
@@ -44,9 +44,14 @@ class Artist < ActiveRecord::Base
|
||||
|
||||
def save_url_string
|
||||
if @url_string
|
||||
urls.clear
|
||||
prev = urls.map(&:url)
|
||||
curr = @url_string.scan(/\S+/)
|
||||
|
||||
@url_string.scan(/\S+/).each do |url|
|
||||
(prev - curr).each do |url|
|
||||
urls.where(:url => url).destroy_all
|
||||
end
|
||||
|
||||
(curr - prev).each do |url|
|
||||
urls.create(:url => url)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -124,6 +124,14 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
assert_equal(["http://not.rembrandt.com/test.jpg"], artist.urls.map(&:to_s).sort)
|
||||
end
|
||||
|
||||
should "not delete urls that have not changed" do
|
||||
artist = FactoryGirl.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg")
|
||||
old_url_ids = ArtistUrl.order("id").pluck(&:id)
|
||||
artist.url_string = "http://rembrandt.com/test.jpg"
|
||||
artist.save
|
||||
assert_equal(old_url_ids, ArtistUrl.order("id").pluck(&:id))
|
||||
end
|
||||
|
||||
should "ignore pixiv.net/ and pixiv.net/img/ url matches" do
|
||||
a1 = FactoryGirl.create(:artist, :name => "yomosaka", :url_string => "http://i2.pixiv.net/img100/img/yomosaka/27618292.jpg")
|
||||
a2 = FactoryGirl.create(:artist, :name => "niwatazumi_bf", :url_string => "http://i2.pixiv.net/img16/img/niwatazumi_bf/35488864_big_p6.jpg")
|
||||
|
||||
Reference in New Issue
Block a user