cirandas.net

ref: master

test/unit/comment_handler_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
27
28
29
30
31
32
33
34
require_relative "../test_helper"

class CommentHandlerTest < ActiveSupport::TestCase

  should 'receive comment id' do
    handler = CommentHandler.new(99)
    assert_equal 99, handler.comment_id
  end

  should 'not crash with unexisting comment' do
    handler = CommentHandler.new(-1)
    handler.perform
  end

  should 'call Comment#whatever_method' do
    handler = CommentHandler.new(-1, :whatever_method)
    comment = Comment.new
    Comment.stubs(:find).with(-1).returns(comment)
    comment.expects(:whatever_method)

    handler.perform
  end

  should 'save locale from creation context and not change current locale' do
    FastGettext.stubs(:locale).returns("pt")
    handler = CommentHandler.new(5, :whatever_method)

    FastGettext.stubs(:locale).returns("en")
    assert_equal "pt", handler.locale

    handler.perform
    assert_equal "en", FastGettext.locale
  end
end