Sha256: 5a9cd6a056218b36ce60a4f148c55f430610a5b393505183d794386c4bf74bd4
Contents?: true
Size: 1.26 KB
Versions: 14
Compression:
Stored size: 1.26 KB
Contents
module MuckEngine # :nodoc: module Models # :nodoc: module Matchers # 'is_public' named scope which retrieves items that are marked public # requires that the class have a factory # Tests: # scope :newer_than, lambda { |time| {:conditions => ["created_at < ?", time || 1.day.ago] } } # Examples: # it { should scope_is_public } def scope_is_public IsPublicMatcher.new(:is_public) end class IsPublicMatcher < MuckMatcherBase # :nodoc: def initialize(scope, field = :is_public) @scope = scope @field = field end def matches?(subject) @subject = subject @subject.class.delete_all public_item = Factory(factory_name, @field => true) not_public_item = Factory(factory_name, @field => false) @subject.class.send(@scope).include?(public_item) && !@subject.class.send(@scope).include?(not_public_item) end def failure_message "Expected #{factory_name} to scope by #{@scope} on #{@field} and only find public items. But the call failed" end def description "public items" end end end end end
Version data entries
14 entries across 14 versions & 1 rubygems