Sha256: ebb02d5bb9ccd6b6b0e7cc526db0d66f1f9d3c61216bf41db5727c07650978ed

Contents?: true

Size: 999 Bytes

Versions: 71

Compression:

Stored size: 999 Bytes

Contents

module RSpectacular
  module ActiveRecord
    module Matchers
      class DatelinessMatcher
        include Shoulda::ActiveRecord::Helpers

        def initialize(date_field)
          @date_field  = date_field.to_s
          @date_method = "#{date_field.to_s}=".to_sym
        end

        def matches?(dateable)
          @dateable = dateable
          dateable.send(@date_method, Date.today)

          dateable.valid?

          !dateable.errors[@date_field].include?("is not a valid date")
        end

        def failure_message
          "Expected #{@date_field} to contain a valid date, got: #{pretty_error_messages(@dateable)}"
        end

        def negative_failure_message
          "Expected #{@date_field} to contain an invalid date, got: #{pretty_error_messages(@dateable)}"
        end

        def description
          "should be contain a valid date"
        end
      end

      def validate_dateliness_of(date)
        DatelinessMatcher.new(date)
      end
    end
  end
end

Version data entries

71 entries across 71 versions & 1 rubygems

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