Sha256: b7c37815a6cc300465f7450a1579a7825e526851fb7681cc08024107370d196d

Contents?: true

Size: 1.25 KB

Versions: 14

Compression:

Stored size: 1.25 KB

Contents

module MuckEngine # :nodoc:
  module Models # :nodoc:
    module Matchers
      
      # 'active' named scope which indicates whether an item is active or not
      # requires that the class have a factory
      # Tests:
      #   scope :newer_than, lambda { |time| {:conditions => ["created_at < ?", time || 1.day.ago] } }
      # Examples:
      #   it { should scope_active }
      def scope_active
        ActiveMatcher.new(:active)
      end
            
      class ActiveMatcher < MuckMatcherBase # :nodoc:

        def initialize(scope, field = :active)
          @scope = scope
          @field = field
        end
        
        def matches?(subject)
          @subject = subject
          @subject.class.delete_all
          active_item = Factory(factory_name, @field => true)
          not_active_item = Factory(factory_name, @field => false)
          @subject.class.send(@scope).include?(active_item) &&
            !@subject.class.send(@scope).include?(not_active_item)
        end
        
        def failure_message
          "Expected #{factory_name} to scope by #{@scope} on #{@field} and only find active items. But the call failed"
        end
        
        def description
          "active 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_active_matchers.rb
muck-engine-3.4.0 lib/muck-engine/test/models/matchers/scope_active_matchers.rb
muck-engine-3.3.18 lib/muck-engine/test/models/matchers/scope_active_matchers.rb
muck-engine-3.3.17 lib/muck-engine/test/models/matchers/scope_active_matchers.rb
muck-engine-3.3.16 lib/muck-engine/test/models/matchers/scope_active_matchers.rb
muck-engine-3.3.15 lib/muck-engine/test/models/matchers/scope_active_matchers.rb
muck-engine-3.3.14 lib/muck-engine/test/models/matchers/scope_active_matchers.rb
muck-engine-3.3.13 lib/muck-engine/test/models/matchers/scope_active_matchers.rb
muck-engine-3.3.12 lib/muck-engine/test/models/matchers/scope_active_matchers.rb
muck-engine-3.3.11 lib/muck-engine/test/models/matchers/scope_active_matchers.rb
muck-engine-3.3.10 lib/muck-engine/test/models/matchers/scope_active_matchers.rb
muck-engine-3.3.9 lib/muck-engine/test/models/matchers/scope_active_matchers.rb
muck-engine-3.3.8 lib/muck-engine/test/models/matchers/scope_active_matchers.rb
muck-engine-3.3.7 lib/muck-engine/test/models/matchers/scope_active_matchers.rb