Add artist finding tests for new Pixiv URLs.
* Add tests for finding artists using the new Pixiv URLs in Artist#find_all_by_url. * Add tests for the artist finder JSON API in ArtistsController#finder. * Add tests for the artist page search form in ArtistsController#index.
This commit is contained in:
@@ -1,12 +1,34 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ArtistsControllerTest < ActionController::TestCase
|
||||
def assert_artist_found(expected_artist, source_url)
|
||||
VCR.use_cassette("functional/artists_controller/#{source_url}", :record => :once) do
|
||||
get :finder, { :format => :json, :url => source_url }, { :user_id => @user.id }
|
||||
end
|
||||
|
||||
assert_response :success
|
||||
assert_equal(1, assigns(:artists).size, "Testing URL: #{source_url}")
|
||||
assert_equal(expected_artist, assigns(:artists).first.name)
|
||||
end
|
||||
|
||||
def assert_artist_not_found(source_url)
|
||||
VCR.use_cassette("functional/artists_controller/#{source_url}", :record => :once) do
|
||||
get :finder, { :format => :json, :url => source_url }, { :user_id => @user.id }
|
||||
end
|
||||
|
||||
assert_response :success
|
||||
assert_equal(0, assigns(:artists).size, "Testing URL: #{source_url}")
|
||||
end
|
||||
|
||||
context "An artists controller" do
|
||||
setup do
|
||||
CurrentUser.user = FactoryGirl.create(:user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@artist = FactoryGirl.create(:artist)
|
||||
@user = FactoryGirl.create(:user)
|
||||
|
||||
FactoryGirl.create(:artist, :name => "masao", :url_string => "http://i2.pixiv.net/img04/img/syounen_no_uta/")
|
||||
FactoryGirl.create(:artist, :name => "artgerm", :url_string => "http://artgerm.deviantart.com/")
|
||||
end
|
||||
|
||||
teardown do
|
||||
@@ -40,6 +62,35 @@ class ArtistsControllerTest < ActionController::TestCase
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
context "when searching the index page" do
|
||||
should "find artists by name" do
|
||||
get :index, { :name => "masao" }
|
||||
|
||||
assert_response :success
|
||||
assert_equal(1, assigns(:artists).size)
|
||||
assert_equal("masao", assigns(:artists).first.name)
|
||||
end
|
||||
|
||||
should "find artists by image URL" do
|
||||
get :index, { :name => "http://i2.pixiv.net/img04/img/syounen_no_uta/46170939_m.jpg" }
|
||||
|
||||
assert_response :success
|
||||
assert_equal(1, assigns(:artists).size)
|
||||
assert_equal("masao", assigns(:artists).first.name)
|
||||
end
|
||||
|
||||
should "find artists by page URL" do
|
||||
url = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46170939"
|
||||
VCR.use_cassette("functional/artists_controller/#{url}", :record => :once) do
|
||||
get :index, { :name => url }
|
||||
end
|
||||
|
||||
assert_response :success
|
||||
assert_equal(1, assigns(:artists).size)
|
||||
assert_equal("masao", assigns(:artists).first.name)
|
||||
end
|
||||
end
|
||||
|
||||
should "create an artist" do
|
||||
assert_difference("Artist.count", 1) do
|
||||
attributes = FactoryGirl.attributes_for(:artist)
|
||||
@@ -85,5 +136,34 @@ class ArtistsControllerTest < ActionController::TestCase
|
||||
version = @artist.versions.first
|
||||
post :revert, {:id => @artist.id, :version_id => version.id}
|
||||
end
|
||||
|
||||
context "when finding an artist" do
|
||||
should "find nothing for unknown URLs" do
|
||||
assert_artist_not_found("http://www.example.com")
|
||||
end
|
||||
|
||||
should "find deviantart artists" do
|
||||
assert_artist_found("artgerm", "http://artgerm.deviantart.com/art/Peachy-Princess-Ver-2-457220550")
|
||||
end
|
||||
|
||||
should_eventually "find deviantart artists for image URLs" do
|
||||
assert_artist_found("artgerm", "http://fc06.deviantart.net/fs71/f/2014/150/d/c/peachy_princess_by_artgerm-d7k7tmu.jpg")
|
||||
end
|
||||
|
||||
should "find pixiv artists" do
|
||||
assert_artist_found("masao", "http://i2.pixiv.net/img04/img/syounen_no_uta/46170939.jpg")
|
||||
assert_artist_found("masao", "http://i2.pixiv.net/img-original/img/2014/09/25/00/57/24/46170939_p0.jpg")
|
||||
assert_artist_found("masao", "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46170939")
|
||||
end
|
||||
|
||||
should "not fail for malformed Pixiv URLs" do
|
||||
assert_artist_not_found("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=herpderp")
|
||||
assert_artist_not_found("http://www.pixiv.net/wharrgarbl")
|
||||
end
|
||||
|
||||
should "not fail for Pixiv bad IDs" do
|
||||
assert_artist_not_found("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=32049358")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user