cirandas.net

ref: master

plugins/comment_group/test/unit/comment_test.rb


 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
require_relative '../test_helper'

class CommentTest < ActiveSupport::TestCase

  def setup
    profile = fast_create(Community)
    @article = fast_create(Article, :profile_id => profile.id)
  end

  attr_reader :article

  should 'return comments that belongs to a specified group' do
    comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id)
    comment2 = fast_create(Comment, :group_id => nil, :source_id => article.id)
    comment3 = fast_create(Comment, :group_id => 2, :source_id => article.id)
    assert_equal [comment1], article.comments.in_group(1)
  end

  should 'return comments that do not belongs to any group' do
    comment1 = fast_create(Comment, :group_id => 1, :source_id => article.id)
    comment2 = fast_create(Comment, :group_id => nil, :source_id => article.id)
    comment3 = fast_create(Comment, :group_id => 2, :source_id => article.id)
    assert_equal [comment2], article.comments.without_group
  end

end