Sha256: c48afb2a5de645b80f54e3eee859fceb5fb24dafd7b12974cc28fa59c4ec69b2

Contents?: true

Size: 633 Bytes

Versions: 1

Compression:

Stored size: 633 Bytes

Contents

module RiotMongoid
  class HasFieldAssertion < Riot::AssertionMacro
    register :has_field

    def evaluate(model, field_name, options = {})
      fail_msg = "expected #{model.class.to_s} to have field :#{field_name}"
      pass_msg = "#{model.class.to_s} has field :#{field_name}"
      opt_msg  = " with options #{options.inspect}"
      field    = model.fields[field_name.to_s]

      return fail(fail_msg) if field.nil?

      unless options.empty?
        return fail(fail_msg + opt_msg) unless options.all? { |k,v| field.send(k) == v }
        return pass(pass_msg + opt_msg)
      end

      pass pass_msg
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
riot-mongoid-2.1.0 lib/riot-mongoid/has_field.rb