Module: MiniPaperclip::Shoulda::Matchers

Defined in:
lib/mini_paperclip/shoulda/matchers/have_attached_file_matcher.rb,
lib/mini_paperclip/shoulda/matchers/validate_attachment_size_matcher.rb,
lib/mini_paperclip/shoulda/matchers/validate_attachment_geometry_matcher.rb,
lib/mini_paperclip/shoulda/matchers/validate_attachment_presence_matcher.rb,
lib/mini_paperclip/shoulda/matchers/validate_attachment_content_type_matcher.rb

Defined Under Namespace

Classes: HaveAttachedFileMatcher, ValidateAttachmentContentTypeMatcher, ValidateAttachmentGeometryMatcher, ValidateAttachmentPresenceMatcher, ValidateAttachmentSizeMatcher

Instance Method Summary collapse

Instance Method Details

#have_attached_file(name) ⇒ Object

Ensures that the given instance or class has an attachment with the given name.

Example:

describe User do
  it { should have_attached_file(:avatar) }
end


13
14
15
# File 'lib/mini_paperclip/shoulda/matchers/have_attached_file_matcher.rb', line 13

def have_attached_file name
  HaveAttachedFileMatcher.new(name)
end

#validate_attachment_content_type(attachment_name) ⇒ Object

Ensures that the given instance or class validates the content type of the given attachment as specified.

Example:

describe User do
  it { should validate_attachment_content_type(:icon).
                allowing('image/png', 'image/gif').
                rejecting('text/plain', 'text/xml') }
end


15
16
17
# File 'lib/mini_paperclip/shoulda/matchers/validate_attachment_content_type_matcher.rb', line 15

def validate_attachment_content_type(attachment_name)
  ValidateAttachmentContentTypeMatcher.new(attachment_name)
end

#validate_attachment_geometry(attachment_name) ⇒ Object

Ensures that the given instance or class validates the geometry of the given attachment as specified.

Example:

describe User do
  it { should validate_attachment_geometry(:icon)
                .format(:png)
                .width(less_than_or_equal_to: 100)
                .height(less_than_or_equal_to: 100)
end


16
17
18
# File 'lib/mini_paperclip/shoulda/matchers/validate_attachment_geometry_matcher.rb', line 16

def validate_attachment_geometry(attachment_name)
  ValidateAttachmentGeometryMatcher.new(attachment_name)
end

#validate_attachment_presence(attachment_name) ⇒ Object

Ensures that the given instance or class validates the presence of the given attachment.

describe User do

it { should validate_attachment_presence(:avatar) }

end



12
13
14
# File 'lib/mini_paperclip/shoulda/matchers/validate_attachment_presence_matcher.rb', line 12

def validate_attachment_presence(attachment_name)
  ValidateAttachmentPresenceMatcher.new(attachment_name)
end

#validate_attachment_size(attachment_name) ⇒ Object

Ensures that the given instance or class validates the size of the given attachment as specified.

Examples:

it { should validate_attachment_size(:avatar).
              less_than(2.megabytes) }


12
13
14
# File 'lib/mini_paperclip/shoulda/matchers/validate_attachment_size_matcher.rb', line 12

def validate_attachment_size(attachment_name)
  ValidateAttachmentSizeMatcher.new(attachment_name)
end