Sha256: 57589ca28258afacd8f4683184bef4ef536e71a78991324e5f310d42b925482b

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

require_relative "test_helper"

class LogBookTest < MiniTest::Unit::TestCase
  def setup
    LogBook::Event.destroy_all
    User.destroy_all
    Item.destroy_all

    @user = User.create!(:name => "User Name")
    @item = Item.create!(:title => "Item Title")
  end

  def test_event
    assert_difference "LogBook::Event.count", 1 do
      LogBook.event(@user, @item, "Item wadus", LogBook::OPERATIONS[:create])
    end

    log_book = LogBook::Event.last
    assert_equal(@user, log_book.historian)
    assert_equal(@item, log_book.historizable)
    assert_equal("Item wadus", log_book.text)
    assert_equal(["user", "item", "create"].sort, log_book.tag_list.sort)
  end

  def test_event_with_nils
    assert_difference "LogBook::Event.count", 1 do
      LogBook.event(nil, nil, "Item wadus", nil)
    end

    log_book = LogBook::Event.last
    assert_equal(nil, log_book.historian)
    assert_equal(nil, log_book.historizable)
    assert_equal("Item wadus", log_book.text)
    assert_equal([], log_book.tag_list)
  end

  def test_created
    LogBook.expects(:event).with("historian", @item, "Item created", LogBook::OPERATIONS[:create])
    LogBook.created("historian", @item)
  end

  def test_updated
    @item.update_attributes!(:title => "Other Title")

    LogBook.expects(:event).with(@user, @item, "Item updated [title[Item Title -> Other Title]]", LogBook::OPERATIONS[:update])
    LogBook.updated(@user, @item)
  end

  def test_item_destroyed
    LogBook.expects(:event).with(@user, @item, "Item destroyed", LogBook::OPERATIONS[:destroy])
    LogBook.destroyed(@user, @item)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
log_book-0.0.1 test/history_event_test.rb