Sha256: 88d30c15900c05ef5c04219e8f41a8da539b0a37e6090cefb5724b0cf34f4757

Contents?: true

Size: 827 Bytes

Versions: 3

Compression:

Stored size: 827 Bytes

Contents

require 'remarkable/active_record'

module Remarkable
  module ActiveRecord
    module Matchers
      class ValidateAsCnpjMatcher < Remarkable::ActiveRecord::Base
        arguments :cnpj

        collection_assertions :cnpj_valid?, :allow_nil?, :formatted_number?

        protected

        def cnpj_valid?
          @subject.cnpj = '123456'
          @subject.valid?.errors[:cnpj].should == ['is invalid']
        end

        def allow_nil?
          @subject.cnpj = nil
          @subject.valid?.errors[:cnpj].should == []
        end

        def formatted_number?
          @subject.cnpj = '51114450000146'
          @subject.valid?.cnpj.should == '51.114.450/0001-46'
        end
      end

      def validate_as_cnpj(*args, &block)
        ValidateAsCnpjMatcher.new(*args, &block).spec(self)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
validates_cnpj-0.1.2 lib/validates_cnpj/remarkable/validate_as_cnpj_matcher.rb
validates_cnpj-0.1.1 lib/remarkable/validate_as_cnpj_matcher.rb
validates_cnpj-0.1.0 lib/remarkable/validate_as_cnpj_matcher.rb