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.9.0 lib/rspectacular/matchers/active_record/dateliness_matcher.rb
rspectacular-0.8.0 lib/rspectacular/matchers/active_record/dateliness_matcher.rb
rspectacular-0.7.0 lib/rspectacular/matchers/active_record/dateliness_matcher.rb
rspectacular-0.6.1 lib/rspectacular/matchers/active_record/dateliness_matcher.rb
rspectacular-0.5.0 lib/rspectacular/matchers/active_record/dateliness_matcher.rb
rspectacular-0.4.0 lib/rspectacular/matchers/active_record/dateliness_matcher.rb
rspectacular-0.3.0 lib/rspectacular/matchers/active_record/dateliness_matcher.rb
rspectacular-0.2.0 lib/rspectacular/matchers/active_record/dateliness_matcher.rb
rspectacular-0.1.0 lib/rspectacular/matchers/active_record/dateliness_matcher.rb
rspectacular-0.0.3 lib/rspectacular/active_record/dateliness_matcher.rb
rspectacular-0.0.2 lib/rspectacular/active_record/dateliness_matcher.rb