From 06054e5eb23cc339fe413593b90c2383380b4450 Mon Sep 17 00:00:00 2001 From: albert Date: Thu, 29 Sep 2011 12:11:30 -0400 Subject: [PATCH] added source tests --- app/logical/sources/site.rb | 2 +- test/unit/sources/default_test.rb | 0 test/unit/sources/nico_seiga_test.rb | 28 +++++++++++++++ test/unit/sources/pixa_test.rb | 28 +++++++++++++++ test/unit/sources/pixiv_test.rb | 29 ++++++++++++++++ test/unit/sources/site_test.rb | 51 ---------------------------- test/unit/sources/tinami_test.rb | 29 ++++++++++++++++ 7 files changed, 115 insertions(+), 52 deletions(-) create mode 100644 test/unit/sources/default_test.rb create mode 100644 test/unit/sources/nico_seiga_test.rb create mode 100644 test/unit/sources/pixa_test.rb create mode 100644 test/unit/sources/pixiv_test.rb delete mode 100644 test/unit/sources/site_test.rb create mode 100644 test/unit/sources/tinami_test.rb diff --git a/app/logical/sources/site.rb b/app/logical/sources/site.rb index 4c6c7520f..06e6d75cf 100644 --- a/app/logical/sources/site.rb +++ b/app/logical/sources/site.rb @@ -4,7 +4,7 @@ module Sources delegate :get, :site_name, :artist_name, :artist_alias, :profile_url, :image_url, :tags, :artist_record, :unique_id, :to => :strategy def self.strategies - [Strategies::Fc2, Strategies::NicoSeiga, Strategies::Pixa, Strategies::Pixiv, Strategies::Tinami, Strategies::Default] + [Strategies::NicoSeiga, Strategies::Pixa, Strategies::Pixiv, Strategies::Tinami, Strategies::Default] end def initialize(url) diff --git a/test/unit/sources/default_test.rb b/test/unit/sources/default_test.rb new file mode 100644 index 000000000..e69de29bb diff --git a/test/unit/sources/nico_seiga_test.rb b/test/unit/sources/nico_seiga_test.rb new file mode 100644 index 000000000..22815ce52 --- /dev/null +++ b/test/unit/sources/nico_seiga_test.rb @@ -0,0 +1,28 @@ +# encoding: UTF-8 + +require 'test_helper' + +module Sources + class NicoSeigaTest < ActiveSupport::TestCase + context "The source site for nico seiga" do + setup do + @site = Sources::Site.new("http://seiga.nicovideo.jp/seiga/im1464351?track=ranking") + @site.get + end + + should "get a single post" do + assert_equal("http://seiga.nicovideo.jp/user/illust/20446930?target=seiga", @site.profile_url) + assert(@site.tags.size > 0) + first_tag = @site.tags.first + assert_equal(2, first_tag.size) + assert(first_tag[0] =~ /./) + end + + should "convert a page into a json representation" do + assert_nothing_raised do + @site.to_json + end + end + end + end +end diff --git a/test/unit/sources/pixa_test.rb b/test/unit/sources/pixa_test.rb new file mode 100644 index 000000000..3dc8145a4 --- /dev/null +++ b/test/unit/sources/pixa_test.rb @@ -0,0 +1,28 @@ +# encoding: UTF-8 + +require 'test_helper' + +module Sources + class PixaTest < ActiveSupport::TestCase + context "The source site for nico seiga" do + setup do + @site = Sources::Site.new("http://www.pixa.cc/illustrations/show/75575") + @site.get + end + + should "get a single post" do + assert_equal("http://www.pixa.cc/profiles/show/9191", @site.profile_url) + assert(@site.tags.size > 0) + first_tag = @site.tags.first + assert_equal(2, first_tag.size) + assert(first_tag[0] =~ /./) + end + + should "convert a page into a json representation" do + assert_nothing_raised do + @site.to_json + end + end + end + end +end diff --git a/test/unit/sources/pixiv_test.rb b/test/unit/sources/pixiv_test.rb new file mode 100644 index 000000000..4c970904f --- /dev/null +++ b/test/unit/sources/pixiv_test.rb @@ -0,0 +1,29 @@ +# encoding: UTF-8 + +require 'test_helper' + +module Sources + class PixivTest < ActiveSupport::TestCase + context "The source site for pixiv" do + setup do + @site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=9646484") + @site.get + end + + should "get a single post" do + assert_equal("http://www.pixiv.net/member.php?id=4015", @site.profile_url) + assert(@site.tags.size > 0) + first_tag = @site.tags.first + assert_equal(2, first_tag.size) + assert(first_tag[0] =~ /./) + assert(first_tag[1] =~ /tags\.php\?tag=/) + end + + should "convert a page into a json representation" do + assert_nothing_raised do + @site.to_json + end + end + end + end +end diff --git a/test/unit/sources/site_test.rb b/test/unit/sources/site_test.rb deleted file mode 100644 index f64b8d3d1..000000000 --- a/test/unit/sources/site_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -# encoding: UTF-8 - -require 'test_helper' - -module Sources - class SiteTest < ActiveSupport::TestCase - context "The source site" do - context "for tinami" do - setup do - @site = Sources::Site.new("http://www.tinami.com/view/308311") - @site.get - end - - should "get a single post" do - assert_equal("http://www.tinami.com/creator/profile/29399", @site.profile_url) - assert_match(/ROM/, @site.artist_name) - assert_equal("http://img.tinami.com/illust2/img/336/4e80b9773c084.png", @site.image_url) - assert(@site.tags.size > 0) - end - - should "convert a page into a json representation" do - assert_nothing_raised do - @site.to_json - end - end - end - - context "for pixiv" do - setup do - @site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=9646484") - @site.get - end - - should "get a single post" do - assert_equal("http://www.pixiv.net/member.php?id=4015", @site.profile_url) - assert(@site.tags.size > 0) - first_tag = @site.tags.first - assert_equal(2, first_tag.size) - assert(first_tag[0] =~ /./) - assert(first_tag[1] =~ /tags\.php\?tag=/) - end - - should "convert a page into a json representation" do - assert_nothing_raised do - @site.to_json - end - end - end - end - end -end diff --git a/test/unit/sources/tinami_test.rb b/test/unit/sources/tinami_test.rb new file mode 100644 index 000000000..a1dae8f01 --- /dev/null +++ b/test/unit/sources/tinami_test.rb @@ -0,0 +1,29 @@ +# encoding: UTF-8 + +require 'test_helper' + +module Sources + class TinamiTest < ActiveSupport::TestCase + context "The source site for tinami" do + context "for tinami" do + setup do + @site = Sources::Site.new("http://www.tinami.com/view/308311") + @site.get + end + + should "get a single post" do + assert_equal("http://www.tinami.com/creator/profile/29399", @site.profile_url) + assert_match(/ROM/, @site.artist_name) + assert_equal("http://img.tinami.com/illust2/img/336/4e80b9773c084.png", @site.image_url) + assert(@site.tags.size > 0) + end + + should "convert a page into a json representation" do + assert_nothing_raised do + @site.to_json + end + end + end + end + end +end