Sha256: bd4d569f8f4e676c619116122ff3d37facc4f9d5c21297a6a9dfa7d1935b5e31

Contents?: true

Size: 1.83 KB

Versions: 12

Compression:

Stored size: 1.83 KB

Contents

# -*- encoding : utf-8 -*-
Testing Dao::Errors do

  testing 'that conducer-less error objects scopes keys in a generic fashion' do
    e = Dao::Errors.new

    e.add 'is fucked'
    e.add 'foo is fucked'

    actual = e.to_text 

    expected = <<-__
      ---
      global:
      - is fucked
      - foo is fucked
    __

    assert compress(actual) == compress(expected)
  end

  testing 'that conducer-based error objects scope keys in a model_name based fashion' do
    c = new_foo_conducer

    e = c.errors 

    e.add 'is fucked'
    e.add 'foo is fucked'
    e.add :first_name, 'is fucked'
    e.add :last_name, 'is fucked'

    actual = e.to_text 

    expected = <<-__
      ---
      foo:
      - is fucked
      - foo is fucked
      foo.first_name:
        - is fucked
      foo.last_name:
        - is fucked
    __

    assert compress(actual) == compress(expected)
  end



protected
  def compress(string)
    string.to_s.gsub(/\s/, '')
  end
  def new_foo_conducer_class(&block)
    const = :FooConducer
    Object.send(:remove_const, const) if Object.send(:const_defined?, const)
    name = const.to_s
    c = assert{ Class.new(Dao::Conducer){ self.name = name } }
    Object.send(:const_set, const, c)
    assert{ c.name == 'FooConducer' }
    assert{ c.model_name == 'Foo' }
    assert{ c.table_name == 'foos' && c.collection_name == 'foos' }
    assert{ c.class_eval(&block); true } if block
    c
  end
  alias_method :new_conducer_class, :new_foo_conducer_class

  def new_foo_conducer(*args, &block)
    assert{ new_foo_conducer_class(&block).new(*args) }
  end
  alias_method :new_conducer, :new_foo_conducer
end

BEGIN {
  testdir = File.dirname(File.expand_path(__FILE__))
  rootdir = File.dirname(testdir)
  libdir = File.join(rootdir, 'lib')
  require File.join(libdir, 'dao')
  require File.join(testdir, 'testing')
  require 'stringio'
}

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dao-5.5.2 test/errors_test.rb
dao-5.5.1 test/errors_test.rb
dao-5.5.0 test/errors_test.rb
dao-5.4.0 test/errors_test.rb
dao-5.3.3 test/errors_test.rb
dao-5.3.2 test/errors_test.rb
dao-5.3.0 test/errors_test.rb
dao-5.2.1 test/errors_test.rb
dao-5.1.2 test/errors_test.rb
dao-5.1.1 test/errors_test.rb
dao-5.0.0 test/errors_test.rb
dao-4.6.4 test/errors_test.rb