Sha256: fee5456ffc65001d4a175080d5fd65ca3f074f313f694cdb71f1077bad2acdf8

Contents?: true

Size: 1.19 KB

Versions: 38

Compression:

Stored size: 1.19 KB

Contents

module MuckEngine # :nodoc:
  module Models # :nodoc:
    module Matchers
      
      # Ensures that the model can sort by 'sorted'
      # requires that the class have a factory
      # Tests:
      #   scope :sorted, order("sort ASC")
      # Examples:
      #   it { should scope_sorted }
      def scope_sorted
        OrdinalMatcher.new(:sorted, :sort)
      end

      #   it { should scope_sorted_id }
      def scope_sorted_id
        OrdinalMatcher.new(:sorted_id, :sort)
      end

      class OrdinalMatcher < MuckMatcherBase # :nodoc:

        def initialize(scope, field)
          @scope = scope
          @field = field
        end
        
        def matches?(subject)
          @subject = subject
          @subject.class.delete_all
          @first = Factory(factory_name, @field => 1)
          @second = Factory(factory_name, @field => 2)
          @first == @subject.class.send(@scope)[0] && @second == @subject.class.send(@scope)[1]
        end
        
        def failure_message
          "Expected #{factory_name} to have scope #{@scope} and order by #{@field}"
        end
        
        def description
          "sort by ordinal"
        end
          
      end

    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
muck-engine-3.5.0 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.4.0 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.18 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.17 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.16 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.15 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.14 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.13 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.12 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.11 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.10 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.9 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.8 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.7 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.6 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.5 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.4 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.3 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.2 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb
muck-engine-3.3.1 lib/muck-engine/test/models/matchers/scope_ordinal_matchers.rb