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
a1adaf31
Commit
a1adaf31
authored
Sep 05, 2008
by
Brian Tatnall
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added :rails_env as a path/url interpolation variable. Useful for networked storage.
parent
8164a6fe
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
0 deletions
+33
-0
lib/paperclip/attachment.rb
+1
-0
test/attachment_test.rb
+20
-0
test/helper.rb
+12
-0
No files found.
lib/paperclip/attachment.rb
View file @
a1adaf31
...
@@ -161,6 +161,7 @@ module Paperclip
...
@@ -161,6 +161,7 @@ module Paperclip
def
self
.
interpolations
def
self
.
interpolations
@interpolations
||=
{
@interpolations
||=
{
:rails_root
=>
lambda
{
|
attachment
,
style
|
RAILS_ROOT
},
:rails_root
=>
lambda
{
|
attachment
,
style
|
RAILS_ROOT
},
:rails_env
=>
lambda
{
|
attachment
,
style
|
RAILS_ENV
},
:class
=>
lambda
do
|
attachment
,
style
|
:class
=>
lambda
do
|
attachment
,
style
|
attachment
.
instance
.
class
.
name
.
underscore
.
pluralize
attachment
.
instance
.
class
.
name
.
underscore
.
pluralize
end
,
end
,
...
...
test/attachment_test.rb
View file @
a1adaf31
...
@@ -86,6 +86,26 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -86,6 +86,26 @@ class AttachmentTest < Test::Unit::TestCase
end
end
end
end
context
"An attachment with a :rails_env interpolation"
do
setup
do
@rails_env
=
"blah"
@id
=
1024
rebuild_model
:path
=>
":rails_env/:id.png"
@dummy
=
Dummy
.
new
@dummy
.
stubs
(
:id
).
returns
(
@id
)
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"5k.png"
))
@dummy
.
avatar
=
@file
end
should
"return the proper path"
do
temporary_rails_env
(
@rails_env
)
{
assert_equal
"
#{
@rails_env
}
/
#{
@id
}
.png"
,
@dummy
.
avatar
.
path
}
end
end
context
"Assigning an attachment"
do
context
"Assigning an attachment"
do
setup
do
setup
do
rebuild_model
rebuild_model
...
...
test/helper.rb
View file @
a1adaf31
...
@@ -5,6 +5,7 @@ require 'mocha'
...
@@ -5,6 +5,7 @@ require 'mocha'
require
'tempfile'
require
'tempfile'
require
'active_record'
require
'active_record'
require
'active_support'
begin
begin
require
'ruby-debug'
require
'ruby-debug'
rescue
LoadError
rescue
LoadError
...
@@ -43,3 +44,14 @@ def rebuild_model options = {}
...
@@ -43,3 +44,14 @@ def rebuild_model options = {}
has_attached_file
:avatar
,
options
has_attached_file
:avatar
,
options
end
end
end
end
def
temporary_rails_env
(
new_env
)
old_env
=
defined?
(
RAILS_ENV
)
?
RAILS_ENV
:
nil
silence_warnings
do
Object
.
const_set
(
"RAILS_ENV"
,
new_env
)
end
yield
silence_warnings
do
Object
.
const_set
(
"RAILS_ENV"
,
old_env
)
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