Sha256: 4c36bbc4d78a7ecdd48dae5171e5cf06f98c388a10e6cdd3666b44b4d3db7054

Contents?: true

Size: 1.13 KB

Versions: 70

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

70 entries across 70 versions & 1 rubygems

Version Path
rspectacular-0.53.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.52.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.51.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.50.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.49.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.48.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.47.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.46.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.45.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.44.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.43.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.42.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.41.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.40.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.39.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.38.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.37.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.36.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.35.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.34.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb