Sha256: 058afcb6ebaffb99b79531851e43e3c62b9dd5d36e8f636724973dc661186e1f

Contents?: true

Size: 1.26 KB

Versions: 24

Compression:

Stored size: 1.26 KB

Contents

module MuckEngine # :nodoc:
  module Models # :nodoc:
    module Matchers
      
      # 'newer_than' named scope which retrieves items newer than given date
      # requires that the class have a factory
      # Tests:
      #   scope :newer_than, lambda { |time| {:conditions => ["created_at < ?", time || 1.day.ago] } }
      # Examples:
      #   it { should scope_recent }
      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

24 entries across 24 versions & 1 rubygems

Version Path
muck-engine-3.3.6 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.5 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.4 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.3 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.2 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.1 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.3.0 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.2.10 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.2.9 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.2.8 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.2.7 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.2.6 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.2.5 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.2.4 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.2.3 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.2.1 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.2.0 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.1.0 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.0.8 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb
muck-engine-3.0.7 lib/muck-engine/test/models/matchers/scope_is_public_matchers.rb