diff --git a/app/controllers/artist_urls_controller.rb b/app/controllers/artist_urls_controller.rb index 34a94cc47..6ef492640 100644 --- a/app/controllers/artist_urls_controller.rb +++ b/app/controllers/artist_urls_controller.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -class ArtistUrlsController < ApplicationController +class ArtistURLsController < ApplicationController respond_to :js, :json, :xml, :html def index - @artist_urls = ArtistUrl.paginated_search(params) + @artist_urls = ArtistURL.paginated_search(params) @artist_urls = @artist_urls.includes(:artist) if request.format.html? respond_with(@artist_urls) diff --git a/app/logical/artist_finder.rb b/app/logical/artist_finder.rb index 916bec996..74bf0e650 100644 --- a/app/logical/artist_finder.rb +++ b/app/logical/artist_finder.rb @@ -149,7 +149,7 @@ module ArtistFinder # @param url [String] the artist profile URL # @return [Array] the list of matching artists def find_artists(url) - url = ArtistUrl.normalize_normalized_url(url) + url = ArtistURL.normalize_normalized_url(url) artists = [] while artists.empty? && url.size > 10 diff --git a/app/models/artist.rb b/app/models/artist.rb index 4a80cd493..d225d12d3 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -21,7 +21,7 @@ class Artist < ApplicationRecord after_save :clear_url_string_changed has_many :members, :class_name => "Artist", :foreign_key => "group_name", :primary_key => "name" - has_many :urls, :dependent => :destroy, :class_name => "ArtistUrl", :autosave => true + has_many :urls, dependent: :destroy, class_name: "ArtistURL", autosave: true has_many :versions, -> {order("artist_versions.id ASC")}, :class_name => "ArtistVersion" has_one :wiki_page, -> { active }, foreign_key: "title", primary_key: "name" has_one :tag_alias, -> { active }, foreign_key: "antecedent_name", primary_key: "name" @@ -51,7 +51,7 @@ class Artist < ApplicationRecord url_string_was = url_string self.urls = string.to_s.scan(/[^[:space:]]+/).map do |url| - is_active, url = ArtistUrl.parse_prefix(url) + is_active, url = ArtistURL.parse_prefix(url) self.urls.find_or_initialize_by(url: url, is_active: is_active) end.uniq(&:url) @@ -238,13 +238,13 @@ class Artist < ApplicationRecord query = query.strip if query =~ %r{\A/(.*)/\z} - where(id: ArtistUrl.where_regex(:url, $1).select(:artist_id)) + where(id: ArtistURL.where_regex(:url, $1).select(:artist_id)) elsif query.include?("*") - where(id: ArtistUrl.where_like(:url, query).select(:artist_id)) + where(id: ArtistURL.where_like(:url, query).select(:artist_id)) elsif query =~ %r{\Ahttps?://}i ArtistFinder.find_artists(query) else - where(id: ArtistUrl.where_like(:url, "*#{query}*").select(:artist_id)) + where(id: ArtistURL.where_like(:url, "*#{query}*").select(:artist_id)) end end diff --git a/app/models/artist_url.rb b/app/models/artist_url.rb index 3112f4328..a9aa11881 100644 --- a/app/models/artist_url.rb +++ b/app/models/artist_url.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class ArtistUrl < ApplicationRecord +class ArtistURL < ApplicationRecord normalize :url, :normalize_url validates :url, presence: true, uniqueness: { scope: :artist_id } diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index bb36bfc5f..fef5847da 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -6,6 +6,8 @@ ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.uncountable "general" inflect.acronym "FFmpeg" + inflect.acronym "URL" + inflect.acronym "URLs" # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' diff --git a/test/functional/artist_urls_controller_test.rb b/test/functional/artist_urls_controller_test.rb index 1cbe927db..99461b6ac 100644 --- a/test/functional/artist_urls_controller_test.rb +++ b/test/functional/artist_urls_controller_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ArtistUrlsControllerTest < ActionDispatch::IntegrationTest +class ArtistURLsControllerTest < ActionDispatch::IntegrationTest context "The artist urls controller" do setup do @artist = create(:artist, name: "bkub", url_string: "-http://bkub.com") diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index 0cb9d40e4..bc55d6dbb 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -152,10 +152,10 @@ class ArtistTest < ActiveSupport::TestCase should "not delete urls that have not changed" do artist = FactoryBot.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg") - old_url_ids = ArtistUrl.order("id").pluck(&:id) + 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)) + assert_equal(old_url_ids, ArtistURL.order("id").pluck(&:id)) end should "normalize urls before removing duplicates" do diff --git a/test/unit/artist_url_test.rb b/test/unit/artist_url_test.rb index c9301eecf..561c3f888 100644 --- a/test/unit/artist_url_test.rb +++ b/test/unit/artist_url_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ArtistUrlTest < ActiveSupport::TestCase +class ArtistURLTest < ActiveSupport::TestCase def assert_search_equals(results, conditions) assert_equal(results.map(&:id), subject.search(conditions).map(&:id)) end @@ -196,7 +196,7 @@ class ArtistUrlTest < ActiveSupport::TestCase end context "#search method" do - subject { ArtistUrl } + subject { ArtistURL } should "work" do @bkub = create(:artist, name: "bkub", is_deleted: false, url_string: "https://bkub.com")