lib/riot-mongoid.rb in riot-mongoid-1.1.2 vs lib/riot-mongoid.rb in riot-mongoid-1.1.3

- old
+ new

@@ -1,45 +1,4 @@ require 'riot' require 'mongoid' -Mongoid::Field.module_eval do - attr_reader :accessible -end - -module RiotMongoid - class HasFieldAssertion < Riot::AssertionMacro - register :has_field - - def evaluate(model, *macro_info) - field_name, options = macro_info - field = model.fields[field_name.to_s] - if options.nil? || options.empty? - fail("field options must be specified with this assertion macro") - elsif field.nil? - fail("expected #{model} to have field #{field_name}") - else - options_valid = options.all? { |key,value| field.send(key) == value } - options_valid ? pass("#{model} has field '#{field_name}' with options #{options.inspect}") : - fail("expected model to have options #{options.inspect} on field #{field_name}") - end - end - end # HasFieldAssertion - - class HasAssociationAssertion < Riot::AssertionMacro - register :has_association - - def evaluate(model, *association_macro_info) - assoc_type, assoc_name, options = association_macro_info - assoc = model.associations[assoc_name.to_s] - options ||= {} - if assoc_name.nil? - fail("association name and potential options must be specified with this assertion macro") - elsif assoc.nil? || assoc.macro != assoc_type.to_sym - fail("expected #{model} to have association #{assoc_name} of type #{assoc_type}") - else - options_valid = options.all? { |key,value| assoc.send(key) == value } - options_valid ? pass("#{model} has '#{assoc_type}' association '#{assoc_name}' with options #{options.inspect}") : - fail("expected model to have options #{options.inspect} on association #{assoc_name}") - end - end - end # HasAssociationAssertion -end # RiotMongoid +Dir[File.dirname(__FILE__) + '/riot-mongoid/*.rb'].each {|file| require file } \ No newline at end of file