class MiniPaperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher

Public Class Methods

new(attachment_name) click to toggle source
# File lib/mini_paperclip/shoulda/matchers/validate_attachment_size_matcher.rb, line 17
def initialize(attachment_name)
  @attachment_name = attachment_name.to_sym
  @less_than_size = nil
end

Public Instance Methods

description() click to toggle source
# File lib/mini_paperclip/shoulda/matchers/validate_attachment_size_matcher.rb, line 52
def description
  "validate the size of attachment :#{@attachment_name}"
end
failure_message() click to toggle source
# File lib/mini_paperclip/shoulda/matchers/validate_attachment_size_matcher.rb, line 43
def failure_message
  "Attachment :#{@attachment_name} should be less than #{human_size}"
end
failure_message_when_negated() click to toggle source
# File lib/mini_paperclip/shoulda/matchers/validate_attachment_size_matcher.rb, line 47
def failure_message_when_negated
  "Attachment :#{@attachment_name} should not be less than #{human_size}"
end
Also aliased as: negative_failure_message
human_size() click to toggle source
# File lib/mini_paperclip/shoulda/matchers/validate_attachment_size_matcher.rb, line 56
def human_size
  ActiveSupport::NumberHelper.number_to_human_size(@less_than_size)
end
less_than(less_than_size) click to toggle source
# File lib/mini_paperclip/shoulda/matchers/validate_attachment_size_matcher.rb, line 22
def less_than(less_than_size)
  @less_than_size = less_than_size
  self
end
matches?(subject) click to toggle source
# File lib/mini_paperclip/shoulda/matchers/validate_attachment_size_matcher.rb, line 27
def matches?(subject)
  @subject = subject.class == Class ? subject.new : subject

  begin
    @subject.write_attribute("#{@attachment_name}_file_size", @less_than_size - 1)
    @subject.write_attribute("#{@attachment_name}_updated_at", Time.now)
    @subject.valid?
    @subject.errors[:"#{@attachment_name}_file_size"].empty?
  end && begin
    @subject.write_attribute("#{@attachment_name}_file_size", @less_than_size)
    @subject.write_attribute("#{@attachment_name}_updated_at", Time.now)
    @subject.valid?
    @subject.errors[:"#{@attachment_name}_file_size"].present?
  end
end
negative_failure_message()