Commit d687fca1 by Mike Burns

Push attachment definitions into a list of attachments for the rake task

parent 710f658c
...@@ -51,6 +51,7 @@ require 'paperclip/missing_attachment_styles' ...@@ -51,6 +51,7 @@ require 'paperclip/missing_attachment_styles'
require 'paperclip/validators' require 'paperclip/validators'
require 'paperclip/logger' require 'paperclip/logger'
require 'paperclip/helpers' require 'paperclip/helpers'
require 'paperclip/tasks/attachments'
require 'mime/types' require 'mime/types'
require 'logger' require 'logger'
require 'cocaine' require 'cocaine'
......
require 'paperclip/tasks/attachments'
require 'set' require 'set'
module Paperclip module Paperclip
class << self class << self
attr_accessor :classes_with_attachments attr_accessor :classes_with_attachments
......
require 'singleton'
module Paperclip
module Tasks
class Attachments
include Singleton
def self.add(klass, attachment_name, attachment_options)
instance.add(klass, attachment_name, attachment_options)
end
def self.names_for(klass)
instance.names_for(klass)
end
def self.definitions_for(klass)
instance.definitions_for(klass)
end
def add(klass, attachment_name, attachment_options)
@attachments ||= {}
@attachments[klass] ||= {}
@attachments[klass][attachment_name] = attachment_options
end
def names_for(klass)
@attachments[klass].keys
end
def definitions_for(klass)
@attachments[klass]
end
end
end
end
require 'paperclip/tasks/attachments'
module Paperclip module Paperclip
module Task module Task
def self.obtain_class def self.obtain_class
......
...@@ -4,23 +4,35 @@ require 'tasks/attachments' ...@@ -4,23 +4,35 @@ require 'tasks/attachments'
class AttachmentsTest < Test::Unit::TestCase class AttachmentsTest < Test::Unit::TestCase
context '.names_for' do context '.names_for' do
should 'include attachment names for the given class' do should 'include attachment names for the given class' do
Foo = Class.new foo = Class.new
Paperclip::Tasks::Attachments.add(Foo, :avatar, {}) Paperclip::Tasks::Attachments.add(foo, :avatar, {})
assert_equal [:avatar], Paperclip::Tasks::Attachments.names_for(Foo) assert_equal [:avatar], Paperclip::Tasks::Attachments.names_for(foo)
end end
should 'not include attachment names for other classes' do should 'not include attachment names for other classes' do
Foo = Class.new foo = Class.new
Bar = Class.new bar = Class.new
Paperclip::Tasks::Attachments.add(Foo, :avatar, {}) Paperclip::Tasks::Attachments.add(foo, :avatar, {})
Paperclip::Tasks::Attachments.add(Bar, :lover, {}) Paperclip::Tasks::Attachments.add(bar, :lover, {})
assert_equal [:lover], Paperclip::Tasks::Attachments.names_for(Bar) assert_equal [:lover], Paperclip::Tasks::Attachments.names_for(bar)
end end
end end
context '.definitions_for' do context '.definitions_for' do
should 'produce the attachment name and options' do
expected_definitions = {
avatar: { yo: 'greeting' },
greeter: { ciao: 'greeting' }
}
foo = Class.new
Paperclip::Tasks::Attachments.add(foo, :avatar, { yo: 'greeting' })
Paperclip::Tasks::Attachments.add(foo, :greeter, { ciao: 'greeting' })
definitions = Paperclip::Tasks::Attachments.definitions_for(foo)
assert_equal expected_definitions, definitions
end
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment