Files
danbooru/test/functional/artist_versions_controller_test.rb
evazion 10dac3ee51 artists: normalize urls added to artist entries.
When a URL is added to an artist entry, normalize it to a standard form.

Artist URLs have both a `url` column and a `normalized_url` column. The
`normalized_url` is used for artist finding and the `url` is the raw URL
entered by the user. Previously only the `normalized_url` field was
normalized; now the URL entered by the user is also converted to a
normalized form.

This means that if an URL like this is added to an artist entry:

* http://www.pixiv.net/member.php?id=1234
* http://www.pixiv.net/en/users/1234
* http://www.twitter.com/DanbooruBot/
* http://mobile.twitter.com/DanbooruBot/

It will get normalized to this:

* https://www.pixiv.net/users/1234
* https://twitter.com/DanbooruBot

This fixes problems with duplicate URLs being added to artist entries
because URLs weren't normalized to a single form.
2022-03-18 02:06:50 -05:00

50 lines
2.1 KiB
Ruby

require 'test_helper'
class ArtistVersionsControllerTest < ActionDispatch::IntegrationTest
context "An artist versions controller" do
setup do
@user = create(:gold_user, id: 100)
@builder = create(:builder_user, name: "danbo")
as(@builder) { @artist = create(:artist, name: "masao", url_string: "https://masao.deviantart.com") }
as(@user) { @artist.update(name: "masao_(deleted)", is_deleted: true) }
as(@builder) { @artist.update(name: "masao", is_deleted: false, group_name: "the_best", url_string: "https://www.deviantart.com/masao") }
end
context "index action" do
setup do
@versions = @artist.versions
end
should "render" do
get artist_versions_path
assert_response :success
end
should respond_to_search({}).with { @versions.reverse }
should respond_to_search(name: "masao").with { [@versions[2], @versions[0]] }
should respond_to_search(name_matches: "(deleted)").with { @versions[1] }
should respond_to_search(group_name_matches: "the_best").with { @versions[2] }
should respond_to_search(urls_include_any: "https://www.deviantart.com/masao").with { [@versions[2], @versions[1], @versions[0]] }
should respond_to_search(is_deleted: "true").with { @versions[1] }
context "using includes" do
should respond_to_search(updater_id: 100).with { @versions[1] }
should respond_to_search(updater_name: "danbo").with { [@versions[2], @versions[0]] }
should respond_to_search(updater: {level: User::Levels::BUILDER}).with { [@versions[2], @versions[0]] }
should respond_to_search(artist: {name: "masao"}).with { @versions.reverse }
should respond_to_search(artist: {name: "doesntexist"}).with { [] }
end
end
context "show action" do
should "work" do
get artist_version_path(@artist.versions.first)
assert_redirected_to artist_versions_path(search: { artist_id: @artist.id })
get artist_version_path(@artist.versions.first), as: :json
assert_response :success
end
end
end
end