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.33.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.31.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.30.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.29.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.28.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.27.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.26.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.25.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.24.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.23.1 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.23.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.22.2 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.22.1 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.22.0 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.21.6 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.21.5 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.21.4 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.21.3 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.21.2 lib/rspectacular/matchers/active_record/persistence_matcher.rb
rspectacular-0.21.1 lib/rspectacular/matchers/active_record/persistence_matcher.rb