Sha256: 917440f691c554ffcdb92064fc37f24c1d57f537bfae511698a2a664c3884e4b

Contents?: true

Size: 872 Bytes

Versions: 3

Compression:

Stored size: 872 Bytes

Contents

require "minitest"

module Minitest
  module Checks
    class Models < Base
      def self.valid(params)
        valids([params])
      end

      def self.valids(arr)
        arr.each { |params| one_valid(params) }
      end

      def self.invalid(params)
        invalids([params])
      end

      def self.invalids(arr)
        arr.each { |params| one_invalid(params) }
      end

      def self.one_valid(params)
        row, msg = create_model(params)
        @minitest.assert row.valid?, "#{msg} #{row.errors.full_messages}"
      end

      def self.one_invalid(params)
        row, msg = create_model(params)
        @minitest.refute row.valid?, "#{msg} expected to be invalid"
      end

      def self.create_model(params)
        # row = @klass.create(params)
        row = @klass.new(params)
        [row, "#{@klass}: #{params}"]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mimoco-1.0.3 lib/mimoco_valid.rb
mimoco-1.0.2 lib/mimoco_valid.rb
mimoco-1.0.1 lib/mimoco_valid.rb