rails: add 'URL' inflection.
Make it so we can write `ArtistURL` instead of `ArtistUrl`.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -149,7 +149,7 @@ module ArtistFinder
|
||||
# @param url [String] the artist profile URL
|
||||
# @return [Array<Artist>] 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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user