Sha256: 68c2437ca69a67bfb7a0213325d68894f8604c3c6188df78507fe1ea4408e04a

Contents?: true

Size: 1.18 KB

Versions: 33

Compression:

Stored size: 1.18 KB

Contents

module Paperclip
  module Shoulda
    module Matchers
      def have_attached_file name
        HaveAttachedFileMatcher.new(name)
      end

      class HaveAttachedFileMatcher
        def initialize attachment_name
          @attachment_name = attachment_name
        end

        def matches? subject
          @subject = subject
          responds? && has_column? && included?
        end

        def failure_message
          "Should have an attachment named #{@attachment_name}"
        end

        def negative_failure_message
          "Should not have an attachment named #{@attachment_name}"
        end

        def description
          "have an attachment named #{@attachment_name}"
        end

        protected

        def responds?
          methods = @subject.instance_methods
          methods.include?("#{@attachment_name}") &&
            methods.include?("#{@attachment_name}=") &&
            methods.include?("#{@attachment_name}?")
        end

        def has_column?
          @subject.column_names.include?("#{@attachment_name}_file_name")
        end

        def included?
          @subject.ancestors.include?(Paperclip::InstanceMethods)
        end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 13 rubygems

Version Path
area17-paperclip-2.2.9.1.1 lib/paperclip/matchers/have_attached_file_matcher.rb
area17-paperclip-2.2.9.2.1 lib/paperclip/matchers/have_attached_file_matcher.rb
beaucollins-paperclip-2.2.7 lib/paperclip/matchers/have_attached_file_matcher.rb
betelgeuse-paperclip-2.2.8.1 lib/paperclip/matchers/have_attached_file_matcher.rb
fermion-paperclip-2.2.8 lib/paperclip/matchers/have_attached_file_matcher.rb
lostboy-paperclip-2.2.6.1 lib/paperclip/matchers/have_attached_file_matcher.rb
lostboy-paperclip-2.2.6.2 lib/paperclip/matchers/have_attached_file_matcher.rb
peterpunk-metal-paperclip-2.2.9.1 lib/paperclip/matchers/have_attached_file_matcher.rb
peterpunk-paperclip-2.2.9.1 lib/paperclip/matchers/have_attached_file_matcher.rb
phildarnowsky-paperclip-2.2.10 lib/paperclip/matchers/have_attached_file_matcher.rb
rsturim-paperclip-2.2.9.2 lib/paperclip/matchers/have_attached_file_matcher.rb
thoughtbot-paperclip-2.2.3 shoulda_macros/matchers/have_attached_file_matcher.rb
thoughtbot-paperclip-2.2.4 shoulda_macros/matchers/have_attached_file_matcher.rb
thoughtbot-paperclip-2.2.5 lib/paperclip/matchers/have_attached_file_matcher.rb
thoughtbot-paperclip-2.2.6 lib/paperclip/matchers/have_attached_file_matcher.rb
thoughtbot-paperclip-2.2.7 lib/paperclip/matchers/have_attached_file_matcher.rb
thoughtbot-paperclip-2.2.8 lib/paperclip/matchers/have_attached_file_matcher.rb
thoughtbot-paperclip-2.2.9.1 lib/paperclip/matchers/have_attached_file_matcher.rb
thoughtbot-paperclip-2.2.9.2 lib/paperclip/matchers/have_attached_file_matcher.rb
spree-enriquez-0.9.4 vendor/plugins/paperclip/lib/paperclip/matchers/have_attached_file_matcher.rb