Class: MiniPaperclip::Shoulda::Matchers::ValidateAttachmentGeometryMatcher
- Inherits:
-
Object
- Object
- MiniPaperclip::Shoulda::Matchers::ValidateAttachmentGeometryMatcher
- Defined in:
- lib/mini_paperclip/shoulda/matchers/validate_attachment_geometry_matcher.rb
Constant Summary collapse
- CallError =
Class.new(StandardError)
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
- #format(format) ⇒ Object
- #height(less_than_or_equal_to:) ⇒ Object
-
#initialize(attachment_name) ⇒ ValidateAttachmentGeometryMatcher
constructor
A new instance of ValidateAttachmentGeometryMatcher.
- #matches?(subject) ⇒ Boolean
- #width(less_than_or_equal_to:) ⇒ Object
Constructor Details
#initialize(attachment_name) ⇒ ValidateAttachmentGeometryMatcher
Returns a new instance of ValidateAttachmentGeometryMatcher.
23 24 25 26 27 28 |
# File 'lib/mini_paperclip/shoulda/matchers/validate_attachment_geometry_matcher.rb', line 23 def initialize() = .to_sym @width = {} @height = {} @format = nil end |
Instance Method Details
#failure_message ⇒ Object
61 62 63 64 65 66 |
# File 'lib/mini_paperclip/shoulda/matchers/validate_attachment_geometry_matcher.rb', line 61 def [ "Attachment :#{@attachment_name} got details", @subject.errors.details[] ].join("\n") end |
#failure_message_when_negated ⇒ Object
68 69 70 71 72 73 |
# File 'lib/mini_paperclip/shoulda/matchers/validate_attachment_geometry_matcher.rb', line 68 def [ "Attachment :#{@attachment_name} got details", @subject.errors.details[] ].join("\n") end |
#format(format) ⇒ Object
30 31 32 33 |
# File 'lib/mini_paperclip/shoulda/matchers/validate_attachment_geometry_matcher.rb', line 30 def format(format) @format = format self end |
#height(less_than_or_equal_to:) ⇒ Object
40 41 42 43 |
# File 'lib/mini_paperclip/shoulda/matchers/validate_attachment_geometry_matcher.rb', line 40 def height(less_than_or_equal_to:) @height[:less_than_or_equal_to] = less_than_or_equal_to self end |
#matches?(subject) ⇒ Boolean
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mini_paperclip/shoulda/matchers/validate_attachment_geometry_matcher.rb', line 45 def matches?(subject) @subject = subject.class == Class ? subject.new : subject unless @format && !@width.empty? && !@height.empty? raise CallError, [ "should call like this", " it { should validate_attachment_geometry(:image)", " .format(:png)", " .width(less_than_or_equal_to: 3000)", " .height(less_than_or_equal_to: 3000) }" ].join("\n") end when_valid && when_invalid end |
#width(less_than_or_equal_to:) ⇒ Object
35 36 37 38 |
# File 'lib/mini_paperclip/shoulda/matchers/validate_attachment_geometry_matcher.rb', line 35 def width(less_than_or_equal_to:) @width[:less_than_or_equal_to] = less_than_or_equal_to self end |