Sha256: 3a1347c888abc212daf72a8ba239d7308c9511dd66578d8786ab4fccde243987

Contents?: true

Size: 1.59 KB

Versions: 3

Compression:

Stored size: 1.59 KB

Contents

require 'test_helper'

class BaseExtensionsTest < ActiveSupport::TestCase

  def test_nullify_attributes_failure
    assert_raises ArgumentError do
      klass = address_class(:nullify_attributes, :first_line, :second_line, :third_line)
      assert_not klass.respond_to?(:nullified_attributes)
    end
  end

  def test_nullify_attributes_success
    klass = address_class(:nullify_attributes, :first_line, :second_line)
    assert_equal klass.nullified_attributes.map(&:attribute), [:first_line, :second_line]
  end

  def test_strip_attributes_failure
    assert_raises ArgumentError do
      klass = address_class(:strip_attributes, :first_line, :second_line, :third_line)
      assert_not klass.respond_to?(:stripped_attributes)
    end
  end

  def test_strip_attributes_success
    klass = address_class(:strip_attributes, :first_line, :second_line)
    assert_equal klass.stripped_attributes.map(&:attribute), [:first_line, :second_line]
  end

  def test_truncate_attributes_failure
    assert_raises ArgumentError do
      klass = address_class(:truncate_attributes, :first_line, :second_line, :third_line)
      assert_not klass.respond_to?(:truncated_attributes)
    end
  end

  def test_truncate_attributes_success
    klass = address_class(:truncate_attributes, :first_line, :second_line)
    assert_equal klass.truncated_attributes.map(&:attribute), [:first_line, :second_line]
  end

  private

    # returns a newly created address class
    def address_class(macro, *arguments)
      Class.new(ActiveRecord::Base) do
        self.table_name = 'addresses'
        send(macro, *arguments)
      end
    end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
attribute_extras-0.1.2 test/base_extensions_test.rb
attribute_extras-0.1.1 test/base_extensions_test.rb
attribute_extras-0.1.0 test/base_extensions_test.rb