added artists, comments
This commit is contained in:
7
test/factories/artist.rb
Normal file
7
test/factories/artist.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
Factory.define(:artist) do |f|
|
||||
f.name {Faker::Name.first_name}
|
||||
f.creator {|x| x.association(:user)}
|
||||
f.updater_id {|x| x.creator_id}
|
||||
f.updater_ip_addr "127.0.0.1"
|
||||
f.is_active true
|
||||
end
|
||||
3
test/factories/artist_url.rb
Normal file
3
test/factories/artist_url.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
Factory.define(:artist_url) do |f|
|
||||
f.url {Faker::Internet.domain_name}
|
||||
end
|
||||
7
test/factories/comment.rb
Normal file
7
test/factories/comment.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
Factory.define(:comment) do |f|
|
||||
f.creator {|x| x.association(:user)}
|
||||
f.post {|x| x.association(:post)}
|
||||
f.body {Faker::Lorem.sentences}
|
||||
f.ip_addr "127.0.0.1"
|
||||
f.score 0
|
||||
end
|
||||
91
test/unit/artist_test.rb
Normal file
91
test/unit/artist_test.rb
Normal file
@@ -0,0 +1,91 @@
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class ArtistTest < ActiveSupport::TestCase
|
||||
context "An artist" do
|
||||
setup do
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
should "normalize its name" do
|
||||
artist = Factory.create(:artist, :name => " AAA BBB ")
|
||||
assert_equal("aaa_bbb", artist.name)
|
||||
end
|
||||
|
||||
should "resolve ambiguous urls" do
|
||||
bobross = Factory.create(:artist, :name => "bob_ross", :url_string => "http://artists.com/bobross/image.jpg")
|
||||
bob = Factory.create(:artist, :name => "bob", :url_string => "http://artists.com/bob/image.jpg")
|
||||
matches = Artist.find_all_by_url("http://artists.com/bob/test.jpg")
|
||||
assert_equal(1, matches.size)
|
||||
assert_equal("bob", matches.first.name)
|
||||
end
|
||||
|
||||
should "parse urls" do
|
||||
artist = Factory.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg http://aaa.com")
|
||||
artist.reload
|
||||
assert_equal(["http://aaa.com", "http://rembrandt.com/test.jpg"], artist.artist_urls.map(&:to_s).sort)
|
||||
end
|
||||
|
||||
should "make sure old urls are deleted" do
|
||||
artist = Factory.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg")
|
||||
artist.update_attributes(
|
||||
:updater_id => artist.creator_id,
|
||||
:updater_ip_addr => "127.0.0.1",
|
||||
:url_string => "http://not.rembrandt.com/test.jpg"
|
||||
)
|
||||
artist.reload
|
||||
assert_equal(["http://not.rembrandt.com/test.jpg"], artist.artist_urls.map(&:to_s).sort)
|
||||
end
|
||||
|
||||
should "find matches by url" do
|
||||
a1 = Factory.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg")
|
||||
a2 = Factory.create(:artist, :name => "subway", :url_string => "http://subway.com/test.jpg")
|
||||
|
||||
assert_equal(["rembrandt"], Artist.find_all_by_url("http://rembrandt.com/test.jpg").map(&:name))
|
||||
assert_equal(["rembrandt"], Artist.find_all_by_url("http://rembrandt.com/another.jpg").map(&:name))
|
||||
assert_equal([], Artist.find_all_by_url("http://nonexistent.com/test.jpg").map(&:name))
|
||||
end
|
||||
|
||||
should "not allow duplicates" do
|
||||
Factory.create(:artist, :name => "warhol", :url_string => "http://warhol.com/a/image.jpg\nhttp://warhol.com/b/image.jpg")
|
||||
assert_equal(["warhol"], Artist.find_all_by_url("http://warhol.com/test.jpg").map(&:name))
|
||||
end
|
||||
|
||||
should "hide deleted artists" do
|
||||
Factory.create(:artist, :name => "warhol", :url_string => "http://warhol.com/a/image.jpg", :is_active => false)
|
||||
assert_equal([], Artist.find_all_by_url("http://warhol.com/a/image.jpg").map(&:name))
|
||||
end
|
||||
|
||||
should "normalize its other names" do
|
||||
artist = Factory.create(:artist, :name => "a1", :other_names => "aaa, bbb, ccc ddd")
|
||||
assert_equal("aaa bbb ccc_ddd", artist.other_names)
|
||||
end
|
||||
|
||||
should "search on other names should return matches" do
|
||||
artist = Factory.create(:artist, :name => "artist", :other_names => "aaa, ccc ddd")
|
||||
assert_not_nil(Artist.find_by_any_name("name:artist"))
|
||||
assert_nil(Artist.find_by_any_name("name:aaa"))
|
||||
assert_nil(Artist.find_by_any_name("name:ccc_ddd"))
|
||||
assert_nil(Artist.find_by_any_name("other:artist"))
|
||||
assert_not_nil(Artist.find_by_any_name("other:aaa"))
|
||||
assert_not_nil(Artist.find_by_any_name("other:ccc_ddd"))
|
||||
end
|
||||
|
||||
should "search on group name and return matches" do
|
||||
cat_or_fish = Factory.create(:artist, :name => "cat_or_fish")
|
||||
yuu = Factory.create(:artist, :name => "yuu", :group_name => "cat_or_fish")
|
||||
cat_or_fish.reload
|
||||
assert_equal("yuu", cat_or_fish.member_names)
|
||||
assert_not_nil(Artist.find_by_any_name("group:cat_or_fish"))
|
||||
end
|
||||
|
||||
should "have an associated wiki" do
|
||||
user = Factory.create(:user)
|
||||
artist = Factory.create(:artist, :name => "max", :wiki_page_attributes => {:body => "this is max", :creator_id => user.id, :updater_id => user.id, :updater_ip_addr => "127.0.0.1"})
|
||||
assert_not_nil(artist.wiki_page)
|
||||
assert_equal("this is max", artist.wiki_page.body)
|
||||
|
||||
artist.update_attributes(:wiki_page_attributes => {:id => artist.wiki_page.id, :body => "this is hoge mark ii", :updater_id => user.id, :updater_ip_addr => "127.0.0.1"})
|
||||
assert_equal("this is hoge mark ii", artist.wiki_page(true).body)
|
||||
end
|
||||
end
|
||||
end
|
||||
8
test/unit/artist_url_test.rb
Normal file
8
test/unit/artist_url_test.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ArtistUrlTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
8
test/unit/artist_version_test.rb
Normal file
8
test/unit/artist_version_test.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ArtistVersionTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
60
test/unit/comment_test.rb
Normal file
60
test/unit/comment_test.rb
Normal file
@@ -0,0 +1,60 @@
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class CommentTest < ActiveSupport::TestCase
|
||||
context "A comment" do
|
||||
setup do
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
should "be created" do
|
||||
comment = Factory.build(:comment)
|
||||
comment.save
|
||||
assert(comment.errors.empty?, comment.errors.full_messages.join(", "))
|
||||
end
|
||||
|
||||
should "not bump the parent post" do
|
||||
post = Factory.create(:post)
|
||||
comment = Factory.create(:comment, :do_not_bump_post => "1", :post => post)
|
||||
post.reload
|
||||
assert_nil(post.last_commented_at)
|
||||
|
||||
comment = Factory.create(:comment, :post => post)
|
||||
post.reload
|
||||
assert_not_nil(post.last_commented_at)
|
||||
end
|
||||
|
||||
should "not update the post after exceeding the threshold" do
|
||||
Danbooru.config.stubs(:comment_threshold).returns(1)
|
||||
p = Factory.create(:post)
|
||||
c1 = Factory.create(:comment, :post => p)
|
||||
sleep 1
|
||||
c2 = Factory.create(:comment, :post => p)
|
||||
p.reload
|
||||
assert_equal(c1.created_at.to_s, p.last_commented_at.to_s)
|
||||
end
|
||||
|
||||
should "not allow duplicate votes" do
|
||||
user = Factory.create(:user)
|
||||
post = Factory.create(:post)
|
||||
c1 = Factory.create(:comment, :post => post)
|
||||
assert_nothing_raised {c1.vote!(user, true)}
|
||||
assert_raise(Comment::VotingError) {c1.vote!(user, true)}
|
||||
assert_equal(1, CommentVote.count)
|
||||
|
||||
c2 = Factory.create(:comment, :post => post)
|
||||
assert_nothing_raised {c2.vote!(user, true)}
|
||||
assert_equal(2, CommentVote.count)
|
||||
end
|
||||
|
||||
should "be searchable" do
|
||||
c1 = Factory.create(:comment, :body => "aaa bbb ccc")
|
||||
c2 = Factory.create(:comment, :body => "aaa ddd")
|
||||
c3 = Factory.create(:comment, :body => "eee")
|
||||
|
||||
matches = Comment.search_body("aaa")
|
||||
assert_equal(2, matches.count)
|
||||
assert_equal(c2.id, matches.all[0].id)
|
||||
assert_equal(c1.id, matches.all[1].id)
|
||||
end
|
||||
end
|
||||
end
|
||||
8
test/unit/comment_vote_test.rb
Normal file
8
test/unit/comment_vote_test.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class CommentVoteTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
8
test/unit/wiki_page_test.rb
Normal file
8
test/unit/wiki_page_test.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class WikiPageTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user