Sha256: 2586c59917e2e6b9cbf8f82cb486a3eddcf745128981b99ed0a5b558e8586c8e

Contents?: true

Size: 1.3 KB

Versions: 6

Compression:

Stored size: 1.3 KB

Contents

require File.join(File.dirname(__FILE__), 'CONFIG.rb')

# $DBG = true
require 'rubygems'
require 'facets'

require 'test/unit'

require 'og'

class TC_ValidateUnique < Test::Unit::TestCase # :nodoc: all
  include Og

  class Framework
    property :app_name, String
    property :creator, String
    
    validate_unique :app_name
  end

  $og1.manage_class Framework

  def setup
    @framework = Framework.new
    @app_name = 'Nitro'
    @framework.app_name = @app_name
    @framework.creator = 'gmosx'
    @framework.save
  end

  def teardown
    Framework.all.each { |entry| entry.delete }
  end

  def test_modify_already_created
    # if setup completes, then unique entries are already allowed.
    framework = Framework.find_all_by_app_name(@app_name)
    assert_equal(1, framework.size)
    assert_equal(@app_name, framework[0].app_name)
    framework[0].creator = "George Moschovitis"
    assert(framework[0].valid?)
    assert_equal(0, framework[0].errors.size)
  end

  def test_duplicate
    @dup = Framework.new
    @dup.app_name = @framework.app_name
    assert_equal(false, @dup.valid?)
    assert(@dup.errors.size > 0)
    assert_equal(1, @dup.errors.on(:app_name).size)
    assert_match(/.*?app_name.*?exists.*?/i, @dup.errors.on(:app_name).first)
    assert(@dup.errors.errors.has_key?(:app_name))
  end
end
  

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
og-0.41.0 test/og/tc_validation.rb
og-0.28.0 test/og/tc_validation.rb
og-0.29.0 test/og/tc_validation.rb
og-0.30.0 test/og/tc_validation.rb
og-0.31.0 test/og/tc_validation.rb
og-0.40.0 test/og/tc_validation.rb