Sha256: 620990780804ee2db27ba8ccc47b21fef03638fbff92bd8b421000f05a419448

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require_relative '../test_helper'


class CodeIdentifierTest < Skr::TestCase


    class CodeIdentifierTestModel
        class_attribute :blocks
        attr_accessor :code

        include Skr::Concerns::CodeIdentifier

        def self.before_validation( opts={}, &block )
            self.blocks||=[]
            self.blocks.push( block )
        end

        def self.validates( *opts )
        end

        def run_validations
            self.class.blocks.each{ |b| self.instance_eval(&b) }
        end

        def [](name)
            :name == name ? 'A Long String of Nonsense' : ''
        end

        has_code_identifier :from => :name
    end

    def test_that_it_uppercases
        ci = CodeIdentifierTestModel.new
        ci.code='test'
        ci.run_validations
        assert_equal 'TEST', ci.code
    end

    def test_that_it_generates
        ci = CodeIdentifierTestModel.new
        ci.run_validations
        assert ci.code.present?, "Code wasn't auto-generated"
        assert_equal 'ALOSTOFNON',  ci.code
    end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stockor-core-0.2 test/concerns/code_identifier_test.rb