Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
ceb43f1a
Commit
ceb43f1a
authored
Jul 25, 2013
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reintroduce attachment_definitions
parent
f8cf74b9
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
5 deletions
+34
-5
lib/paperclip/has_attached_file.rb
+17
-4
test/attachment_registry_test.rb
+1
-1
test/has_attached_file_test.rb
+16
-0
No files found.
lib/paperclip/has_attached_file.rb
View file @
ceb43f1a
...
...
@@ -12,7 +12,7 @@ module Paperclip
def
define
define_flush_errors
define_getter
define_getter
s
define_setter
define_query
register_new_attachment
...
...
@@ -29,7 +29,12 @@ module Paperclip
end
end
def
define_getter
def
define_getters
define_instance_getter
define_class_getter
end
def
define_instance_getter
name
=
@name
options
=
@options
...
...
@@ -50,9 +55,12 @@ module Paperclip
end
end
def
define_class_getter
@klass
.
extend
(
ClassMethods
)
end
def
define_setter
name
=
@name
@klass
.
send
:define_method
,
"
#{
@name
}
="
do
|
file
|
send
(
name
).
assign
(
file
)
end
...
...
@@ -60,7 +68,6 @@ module Paperclip
def
define_query
name
=
@name
@klass
.
send
:define_method
,
"
#{
@name
}
?"
do
send
(
name
).
file?
end
...
...
@@ -82,5 +89,11 @@ module Paperclip
:define_paperclip_callbacks
,
:post_process
,
:"
#{
@name
}
_post_process"
)
end
module
ClassMethods
def
attachment_definitions
Paperclip
::
AttachmentRegistry
.
definitions_for
(
self
.
class
)
end
end
end
end
test/attachment_registry_test.rb
View file @
ceb43f1a
...
...
@@ -32,7 +32,7 @@ class AttachmentRegistryTest < Test::Unit::TestCase
should
'call the block with the class, attachment name, and options'
do
foo
=
Class
.
new
expected_accumulations
=
[
[
foo
,
:avatar
,
{
yo:
'greeting'
}],
[
foo
,
:avatar
,
{
yo:
'greeting'
}],
[
foo
,
:greeter
,
{
ciao:
'greeting'
}]
]
expected_accumulations
.
each
do
|
args
|
...
...
test/has_attached_file_test.rb
View file @
ceb43f1a
...
...
@@ -15,6 +15,10 @@ class HasAttachedFileTest < Test::Unit::TestCase
assert_adding_attachment
(
'avatar'
).
defines_method
(
'avatar?'
)
end
should
'define a method on the class to get all of its attachments'
do
assert_adding_attachment
(
'avatar'
).
defines_class_method
(
'attachment_definitions'
)
end
should
'flush errors as part of validations'
do
assert_adding_attachment
(
'avatar'
).
defines_validation
end
...
...
@@ -64,6 +68,17 @@ class HasAttachedFileTest < Test::Unit::TestCase
end
end
def
defines_class_method
(
method_name
)
a_class
=
stub_class
a_class
.
class
.
stubs
(
:define_method
)
Paperclip
::
HasAttachedFile
.
define_on
(
a_class
,
@attachment_name
,
{})
assert_received
(
a_class
,
:extend
)
do
|
expect
|
expect
.
with
(
Paperclip
::
HasAttachedFile
::
ClassMethods
)
end
end
def
defines_validation
a_class
=
stub_class
...
...
@@ -103,6 +118,7 @@ class HasAttachedFileTest < Test::Unit::TestCase
before_destroy:
nil
,
after_destroy:
nil
,
define_paperclip_callbacks:
nil
,
extend:
nil
,
name:
'Billy'
)
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment