class Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher
Public Class Methods
new(attachment_name)
click to toggle source
# File lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 19 def initialize(attachment_name) @attachment_name = attachment_name end
Public Instance Methods
description()
click to toggle source
# File lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 54 def description "validate the size of attachment #{@attachment_name}" end
failure_message()
click to toggle source
# File lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 45 def failure_message "Attachment #{@attachment_name} must be between #{@low} and #{@high} bytes" end
failure_message_when_negated()
click to toggle source
# File lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 49 def failure_message_when_negated "Attachment #{@attachment_name} cannot be between #{@low} and #{@high} bytes" end
Also aliased as: negative_failure_message
greater_than(size)
click to toggle source
# File lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 28 def greater_than(size) @low = size self end
in(range)
click to toggle source
# File lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 33 def in(range) @low = range.first @high = range.last self end
less_than(size)
click to toggle source
# File lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 23 def less_than(size) @high = size self end
matches?(subject)
click to toggle source
# File lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 39 def matches?(subject) @subject = subject @subject = @subject.new if @subject.class == Class lower_than_low? && higher_than_low? && lower_than_high? && higher_than_high? end
Protected Instance Methods
higher_than_high?()
click to toggle source
# File lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 91 def higher_than_high? @high.nil? || @high == Float::INFINITY || !passes_validation_with_size(@high + 1) end
higher_than_low?()
click to toggle source
# File lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 83 def higher_than_low? @low.nil? || passes_validation_with_size(@low + 1) end
lower_than_high?()
click to toggle source
# File lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 87 def lower_than_high? @high.nil? || @high == Float::INFINITY || passes_validation_with_size(@high - 1) end
lower_than_low?()
click to toggle source
# File lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 79 def lower_than_low? @low.nil? || !passes_validation_with_size(@low - 1) end
override_method(object, method, &replacement)
click to toggle source
# File lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 60 def override_method(object, method, &replacement) (class << object; self; end).class_eval do define_method(method, &replacement) end end
passes_validation_with_size(new_size)
click to toggle source
# File lib/paperclip/matchers/validate_attachment_size_matcher.rb, line 66 def passes_validation_with_size(new_size) file = StringIO.new(".") override_method(file, :size) { new_size } override_method(file, :to_tempfile) { file } @subject.send(@attachment_name).post_processing = false @subject.send(@attachment_name).assign(file) @subject.valid? @subject.errors[:"#{@attachment_name}_file_size"].blank? ensure @subject.send(@attachment_name).post_processing = true end