Sha256: 29079d1dd7d3b341e87dd4d0e5fbfd7c0ba15d9bf67ea5e3a23261682e969d06

Contents?: true

Size: 1.19 KB

Versions: 63

Compression:

Stored size: 1.19 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.map(&:to_s)
          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

63 entries across 63 versions & 23 rubygems

Version Path
area17-paperclip-2.2.9.2.2 lib/paperclip/matchers/have_attached_file_matcher.rb
area17-paperclip-2.2.9.2.3 lib/paperclip/matchers/have_attached_file_matcher.rb
area17-paperclip-2.2.9.2.4 lib/paperclip/matchers/have_attached_file_matcher.rb
area17-paperclip-2.3.1 lib/paperclip/matchers/have_attached_file_matcher.rb
dancroak-paperclip-2.3.1 lib/paperclip/matchers/have_attached_file_matcher.rb
dejanstrbac-paperclip-2.2.9.2 lib/paperclip/matchers/have_attached_file_matcher.rb
doxo-paperclip-2.3.1 lib/paperclip/matchers/have_attached_file_matcher.rb
heythisisnate-paperclip-2.3.0.1 lib/paperclip/matchers/have_attached_file_matcher.rb
heythisisnate-paperclip-2.3.0.2 lib/paperclip/matchers/have_attached_file_matcher.rb
heythisisnate-paperclip-2.3.0.5 lib/paperclip/matchers/have_attached_file_matcher.rb
joshpuetz-paperclip-2.3.0.1 lib/paperclip/matchers/have_attached_file_matcher.rb
joshpuetz-paperclip-2.3.0.2 lib/paperclip/matchers/have_attached_file_matcher.rb
joshpuetz-paperclip-2.3.0 lib/paperclip/matchers/have_attached_file_matcher.rb
korobkov-paperclip-2.3.1.20090921 lib/paperclip/matchers/have_attached_file_matcher.rb
korobkov-paperclip-2.3.1.200909221442 lib/paperclip/matchers/have_attached_file_matcher.rb
korobkov-paperclip-2.3.1.200909221741 lib/paperclip/matchers/have_attached_file_matcher.rb
korobkov-paperclip-2.3.1.200909222157 lib/paperclip/matchers/have_attached_file_matcher.rb
korobkov-paperclip-2.3.1 lib/paperclip/matchers/have_attached_file_matcher.rb
luke0x-paperclip-2.3.1 lib/paperclip/matchers/have_attached_file_matcher.rb
thoughtbot-paperclip-2.3.0 lib/paperclip/matchers/have_attached_file_matcher.rb