Sha256: fb6c1e61d0fd0e0e9124c3431e1cccf93353907181efd3e4398fc3312d193f38

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 KB

Contents

module Rspectacular
  module ActiveRecord
    module Matchers
      class PersistenceMatcher
        def initialize(persistable, options)
          @persistable_class  = persistable.is_a?(Class) ? persistable : persistable.class
          @desired_attributes = options[:with] || persistable.attributes
          @desired_attributes = @desired_attributes.reject {|k,v| ['id', 'created_at', 'updated_at'].include? k}
        end

        def matches?(subject)
          @persistable_class.where(@desired_attributes).first
        end

        def failure_message
          "Expected to find an object saved with #{@desired_attributes}, didn't find one."
        end

        def negative_failure_message
          "Didn't expect to find an object saved with #{@desired_attributes}, but got one anyway"
        end

        def description
          "should be an instance of #{@expected_class_name}"
        end
      end

      def persist(desired_object, options = {})
        PersistenceMatcher.new(desired_object, options)
      end

      alias :persist_the :persist
      alias :persist_a   :persist
      alias :persist_an  :persist
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rspectacular-0.59.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.58.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.57.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.56.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.55.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.54.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.53.1 lib/rspectacular/matchers/active_record/persistence_matcher.rb