artist urls: add tests for controller + artist url search.
This commit is contained in:
25
test/functional/artist_urls_controller_test.rb
Normal file
25
test/functional/artist_urls_controller_test.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ArtistUrlsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The artist urls controller" do
|
||||
context "index page" do
|
||||
should "render" do
|
||||
get artist_urls_path
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "render for a complex search" do
|
||||
@artist = FactoryBot.create(:artist, name: "bkub", url_string: "-http://bkub.com")
|
||||
|
||||
get artist_urls_path(search: {
|
||||
artist: { name: "bkub", },
|
||||
url_matches: "*bkub*",
|
||||
is_active: "false",
|
||||
order: "created_at"
|
||||
})
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,10 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ArtistUrlTest < ActiveSupport::TestCase
|
||||
def assert_search_equals(results, conditions)
|
||||
assert_equal(results.map(&:id), subject.search(conditions).map(&:id))
|
||||
end
|
||||
|
||||
context "An artist url" do
|
||||
setup do
|
||||
CurrentUser.user = FactoryBot.create(:user)
|
||||
@@ -159,5 +163,36 @@ class ArtistUrlTest < ActiveSupport::TestCase
|
||||
url = FactoryBot.create(:artist_url, url: "https://nijie.info/members.php?id=161703")
|
||||
assert_equal("http://nijie.info/members.php?id=161703/", url.normalized_url)
|
||||
end
|
||||
|
||||
context "#search method" do
|
||||
subject { ArtistUrl }
|
||||
|
||||
should "work" do
|
||||
@bkub = FactoryBot.create(:artist, name: "bkub", is_active: true, url_string: "https://bkub.com")
|
||||
@masao = FactoryBot.create(:artist, name: "masao", is_active: false, url_string: "-https://masao.com")
|
||||
@bkub_url = @bkub.urls.first
|
||||
@masao_url = @masao.urls.first
|
||||
|
||||
assert_search_equals([@bkub_url], is_active: true)
|
||||
assert_search_equals([@bkub_url], artist: { name: "bkub" })
|
||||
|
||||
assert_search_equals([@bkub_url], url_matches: "*bkub*")
|
||||
assert_search_equals([@bkub_url], url_matches: "/^https?://bkub\.com$/")
|
||||
|
||||
assert_search_equals([@bkub_url], normalized_url_matches: "*bkub*")
|
||||
assert_search_equals([@bkub_url], normalized_url_matches: "/^https?://bkub\.com/$/")
|
||||
assert_search_equals([@bkub_url], normalized_url_matches: "https://bkub.com")
|
||||
|
||||
assert_search_equals([@bkub_url], url: "https://bkub.com")
|
||||
assert_search_equals([@bkub_url], url_eq: "https://bkub.com")
|
||||
assert_search_equals([@bkub_url], url_not_eq: "https://masao.com")
|
||||
assert_search_equals([@bkub_url], url_like: "*bkub*")
|
||||
assert_search_equals([@bkub_url], url_ilike: "*BKUB*")
|
||||
assert_search_equals([@bkub_url], url_not_like: "*masao*")
|
||||
assert_search_equals([@bkub_url], url_not_ilike: "*MASAO*")
|
||||
assert_search_equals([@bkub_url], url_regex: "bkub")
|
||||
assert_search_equals([@bkub_url], url_not_regex: "masao")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user