Sha256: f87dd46b71a88a4a95ab697cf3696f2683759c843d4139e41cece7083f41ef20

Contents?: true

Size: 933 Bytes

Versions: 22

Compression:

Stored size: 933 Bytes

Contents

require 'helper'

class Nanoc::Int::ItemTest < Nanoc::TestCase
  def test_initialize_with_attributes_with_string_keys
    item = Nanoc::Int::Item.new('foo', { 'abc' => 'xyz' }, '/foo/')

    assert_equal nil,   item.attributes['abc']
    assert_equal 'xyz', item.attributes[:abc]
  end

  def test_reference
    item = Nanoc::Int::Item.new(
      'content',
      { one: 'one in item' },
      '/path/',
    )

    assert_equal([:item, '/path/'], item.reference)
  end

  def test_attributes
    item = Nanoc::Int::Item.new('content', { 'one' => 'one in item' }, '/path/')
    assert_equal({ one: 'one in item' }, item.attributes)
  end

  def test_freeze_should_disallow_changes
    item = Nanoc::Int::Item.new('foo', { a: { b: 123 } }, '/foo/')
    item.freeze

    assert_raises_frozen_error do
      item.attributes[:abc] = '123'
    end

    assert_raises_frozen_error do
      item.attributes[:a][:b] = '456'
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
nanoc-4.4.7 test/base/test_item.rb
nanoc-4.4.6 test/base/test_item.rb