Sha256: 384893dc319a772f7b1bc0aa0cb771a7381cbe0e0f52133b8e82f4c8e140894d

Contents?: true

Size: 1.34 KB

Versions: 34

Compression:

Stored size: 1.34 KB

Contents

require 'test_helper'

class Dood
  include ActiveMerchant::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 < Test::Unit::TestCase
  include ActiveMerchant
  
  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

34 entries across 34 versions & 11 rubygems

Version Path
johnideal-activemerchant-1.4.10 test/unit/validateable_test.rb
johnideal-activemerchant-1.4.11 test/unit/validateable_test.rb
johnideal-activemerchant-1.4.4 test/unit/validateable_test.rb
johnideal-activemerchant-1.4.5 test/unit/validateable_test.rb
johnideal-activemerchant-1.4.6 test/unit/validateable_test.rb
johnideal-activemerchant-1.4.7 test/unit/validateable_test.rb
johnideal-activemerchant-1.4.8 test/unit/validateable_test.rb
mattbauer-activemerchant-1.4.2 test/unit/validateable_test.rb
tomriley-active_merchant-1.4.2.3 test/unit/validateable_test.rb
tomriley-active_merchant-1.4.2.4 test/unit/validateable_test.rb
tomriley-active_merchant-1.4.2.5 test/unit/validateable_test.rb
tomriley-active_merchant-1.4.2.6 test/unit/validateable_test.rb
tomriley-active_merchant-1.4.2.7 test/unit/validateable_test.rb
tomriley-active_merchant-1.4.2.8 test/unit/validateable_test.rb
tomriley-tomriley-active_merchant-1.4.2.4 test/unit/validateable_test.rb
goldstar-activemerchant-1.4.2.7 test/unit/validateable_test.rb
goldstar-activemerchant-1.4.2.6 test/unit/validateable_test.rb
tomriley-active_merchant-1.4.2.11 test/unit/validateable_test.rb
tomriley-active_merchant-1.4.2.10 test/unit/validateable_test.rb
smulube-activemerchant-1.5.1.4 test/unit/validateable_test.rb