Sha256: 0e1edf978f95589eecd10f3bab64930a7de37567d3a85906881a7cf4c292d48b

Contents?: true

Size: 1.27 KB

Versions: 32

Compression:

Stored size: 1.27 KB

Contents

require 'test_helper'

class Dood
  include ActiveUtils::Validateable

  attr_accessor :name, :email, :country

  def validate
    errors.add "name", "cannot be empty" if name.blank?
    errors.add "email", "cannot be empty" if email.blank?
    errors.add_to_base "The country cannot be blank" if country.blank?
  end

end

class ValidateableTest < Minitest::Test

  def setup
    @dood = Dood.new
  end

  def test_validation
    assert ! @dood.valid?
    assert ! @dood.errors.empty?
  end

  def test_assigns
    @dood = Dood.new(:name => "tobi", :email => "tobi@neech.de", :country => 'DE')

    assert_equal "tobi", @dood.name
    assert_equal "tobi@neech.de", @dood.email
    assert @dood.valid?
  end

  def test_multiple_calls
    @dood.name = "tobi"
    assert !@dood.valid?

    @dood.email = "tobi@neech.de"
    assert !@dood.valid?

    @dood.country = 'DE'
    assert @dood.valid?
  end

  def test_messages
    @dood.valid?
    assert_equal "cannot be empty", @dood.errors.on('name')
    assert_equal "cannot be empty", @dood.errors.on('email')
    assert_equal nil, @dood.errors.on('doesnt_exist')

  end

  def test_full_messages
    @dood.valid?
    assert_equal ["Email cannot be empty", "Name cannot be empty", "The country cannot be blank"], @dood.errors.full_messages.sort
  end

end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
active_utils-3.4.1 test/unit/validateable_test.rb
active_utils-3.4.0 test/unit/validateable_test.rb
active_utils-3.3.19 test/unit/validateable_test.rb
active_utils-3.3.18 test/unit/validateable_test.rb
active_utils-3.3.17 test/unit/validateable_test.rb
active_utils-3.3.16 test/unit/validateable_test.rb
active_utils-3.3.15 test/unit/validateable_test.rb
active_utils-3.3.14 test/unit/validateable_test.rb
active_utils-3.3.13 test/unit/validateable_test.rb
active_utils-3.3.12 test/unit/validateable_test.rb
active_utils-3.3.11 test/unit/validateable_test.rb
active_utils-3.3.10 test/unit/validateable_test.rb
active_utils-3.3.9 test/unit/validateable_test.rb
active_utils-3.3.8 test/unit/validateable_test.rb
active_utils-3.3.7 test/unit/validateable_test.rb
active_utils-3.3.6 test/unit/validateable_test.rb
active_utils-3.3.5 test/unit/validateable_test.rb
active_utils-3.3.4 test/unit/validateable_test.rb
active_utils-3.3.3 test/unit/validateable_test.rb
active_utils-3.3.2 test/unit/validateable_test.rb