public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
mephisto / test / unit / comment_drop_test.rb
100644 77 lines (64 sloc) 3.014 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require File.dirname(__FILE__) + '/../test_helper'
 
class CommentDropTest < Test::Unit::TestCase
  fixtures :contents, :sites
  
  def setup
    @comment = contents(:welcome_comment).to_liquid
    @mock_comment = [:published_at, :created_at, :author, :author_email, :author_ip, :title, :approved?].inject({:body_html => 'foo'}) { |h, i| h.update i => true }
  end
  
  def test_should_convert_comment_to_drop
    assert_kind_of Liquid::Drop, contents(:welcome_comment).to_liquid
  end
  
  def test_should_output_author_name_only_if_no_url
    assert_equal '<span>rico</span>', @comment.author_link
  end
  
  def test_should_output_author_link_if_url_given
    @comment.source.author_url = 'http://test'
    assert_equal '<a href="http://test">rico</a>', @comment.author_link
  end
 
  def test_should_check_for_existance_of_author_url
    @comment.source.author_url = nil
    assert_nil @comment.author_url
    @comment.source.author_url = ''
    assert_nil @comment.author_url
  end
 
  def test_should_return_correct_author_link
    assert_equal '<span>rico</span>', @comment.author_link
    @comment.source.author_url = 'abc'
    assert_equal %Q{<a href="http://abc">rico</a>}, @comment.author_link
    @comment.source.author_url = 'https://abc'
    assert_equal %Q{<a href="https://abc">rico</a>}, @comment.author_link
    @comment.source.author = '<strong>rico</strong>'
    @comment.source.author_url = '<strong>https://abc</strong>'
    @comment.source.send(:sanitize_attributes)
    assert_equal %Q{<a href="http://&lt;strong&gt;https://abc&lt;/strong&gt;">&lt;strong&gt;rico&lt;/strong&gt;</a>}, @comment.author_link
  end
  
  def test_should_show_filtered_text
    comment = contents(:welcome).comments.create :body => '*test* comment', :author => 'bob', :author_ip => '127.0.0.1'
    assert_valid comment
    assert_equal 'textile_filter', comment.filter
    liquid = comment.to_liquid
    assert_equal '<p><strong>test</strong> comment</p>', liquid.before_method(:body)
  end
  
  def test_comment_url
    t = Time.now.utc - 3.days
    assert_equal "/#{t.year}/#{t.month}/#{t.day}/welcome-to-mephisto", @comment.url
  end
  
  def test_should_return_correct_presentation_class_for_article_author
    @comment = CommentDrop.new(create_comment_stub(:user_id => 5, :article => stub(:user_id => 5)))
    assert_equal 'by-author', @comment.presentation_class
  end
  
  def test_should_return_correct_presentation_class_for_guest
    @comment = CommentDrop.new(create_comment_stub(:user_id => nil, :article => stub(:user_id => 5)))
    assert_equal 'by-guest', @comment.presentation_class
  end
  
  def test_should_return_correct_presentation_class_for_user
    @comment = CommentDrop.new(create_comment_stub(:user_id => 3, :article => stub(:user_id => 5)))
    assert_equal 'by-user', @comment.presentation_class
  end
  
  private
    def create_comment_stub(options)
      returning stub(@mock_comment.merge(options)) do |stub|
        def stub.id() 55; end
      end
    end
end