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

Version Path
muck-engine-3.5.0 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.4.0 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.18 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.17 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.16 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.15 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.14 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.13 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.12 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.11 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.10 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.9 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.8 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.7 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb