artist urls: add tests for controller + artist url search.

This commit is contained in:
evazion
2018-09-15 13:03:51 -05:00
parent 3afc0b3a78
commit c9b3c8d217
2 changed files with 60 additions and 0 deletions

View 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

View File

@@ -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