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
933dc7bd
Commit
933dc7bd
authored
Jan 16, 2010
by
Dan Croak
Committed by
Jon Yurek
Apr 26, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replace deprecated RAILS_ENV and RAILS_ROOT with Rail.env and Rails.root
parent
4c6cf394
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
32 additions
and
40 deletions
+32
-40
lib/paperclip.rb
+2
-2
lib/paperclip/interpolations.rb
+4
-4
lib/paperclip/storage.rb
+1
-1
test/attachment_test.rb
+3
-4
test/helper.rb
+16
-14
test/interpolations_test.rb
+4
-4
test/storage_test.rb
+2
-11
No files found.
lib/paperclip.rb
View file @
933dc7bd
...
@@ -36,8 +36,8 @@ require 'paperclip/storage'
...
@@ -36,8 +36,8 @@ require 'paperclip/storage'
require
'paperclip/interpolations'
require
'paperclip/interpolations'
require
'paperclip/style'
require
'paperclip/style'
require
'paperclip/attachment'
require
'paperclip/attachment'
if
defined?
RAILS_ROOT
if
defined?
(
Rails
.
root
)
&&
Rails
.
root
Dir
.
glob
(
File
.
join
(
File
.
expand_path
(
R
AILS_ROOT
),
"lib"
,
"paperclip_processors"
,
"*.rb"
)).
each
do
|
processor
|
Dir
.
glob
(
File
.
join
(
File
.
expand_path
(
R
ails
.
root
),
"lib"
,
"paperclip_processors"
,
"*.rb"
)).
each
do
|
processor
|
require
processor
require
processor
end
end
end
end
...
...
lib/paperclip/interpolations.rb
View file @
933dc7bd
...
@@ -51,14 +51,14 @@ module Paperclip
...
@@ -51,14 +51,14 @@ module Paperclip
attachment
.
instance_read
(
:updated_at
).
to_s
attachment
.
instance_read
(
:updated_at
).
to_s
end
end
# Returns the R
AILS_ROOT
constant.
# Returns the R
ails.root
constant.
def
rails_root
attachment
,
style_name
def
rails_root
attachment
,
style_name
R
AILS_ROOT
R
ails
.
root
end
end
# Returns the R
AILS_ENV
constant.
# Returns the R
ails.env
constant.
def
rails_env
attachment
,
style_name
def
rails_env
attachment
,
style_name
R
AILS_ENV
R
ails
.
env
end
end
# Returns the underscored, pluralized version of the class name.
# Returns the underscored, pluralized version of the class name.
...
...
lib/paperclip/storage.rb
View file @
933dc7bd
...
@@ -174,7 +174,7 @@ module Paperclip
...
@@ -174,7 +174,7 @@ module Paperclip
def
parse_credentials
creds
def
parse_credentials
creds
creds
=
find_credentials
(
creds
).
stringify_keys
creds
=
find_credentials
(
creds
).
stringify_keys
(
creds
[
R
AILS_ENV
]
||
creds
).
symbolize_keys
(
creds
[
R
ails
.
env
]
||
creds
).
symbolize_keys
end
end
def
exists?
(
style
=
default_style
)
def
exists?
(
style
=
default_style
)
...
...
test/attachment_test.rb
View file @
933dc7bd
...
@@ -11,7 +11,7 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -11,7 +11,7 @@ class AttachmentTest < Test::Unit::TestCase
@model
=
@attachment
.
instance
@model
=
@attachment
.
instance
@model
.
id
=
1234
@model
.
id
=
1234
@model
.
avatar_file_name
=
"fake.jpg"
@model
.
avatar_file_name
=
"fake.jpg"
assert_equal
"
#{
R
AILS_ROOT
}
/public/fake_models/1234/fake"
,
@attachment
.
path
assert_equal
"
#{
R
ails
.
root
}
/public/fake_models/1234/fake"
,
@attachment
.
path
end
end
context
"Attachment default_options"
do
context
"Attachment default_options"
do
...
@@ -106,12 +106,11 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -106,12 +106,11 @@ class AttachmentTest < Test::Unit::TestCase
@dummy
.
stubs
(
:id
).
returns
(
@id
)
@dummy
.
stubs
(
:id
).
returns
(
@id
)
@file
=
StringIO
.
new
(
"."
)
@file
=
StringIO
.
new
(
"."
)
@dummy
.
avatar
=
@file
@dummy
.
avatar
=
@file
Rails
=
stub
(
'Rails'
,
:root
=>
@rails_env
)
end
end
should
"return the proper path"
do
should
"return the proper path"
do
temporary_rails_env
(
@rails_env
)
{
assert_equal
"
#{
@rails_env
}
/
#{
@id
}
.png"
,
@dummy
.
avatar
.
path
assert_equal
"
#{
@rails_env
}
/
#{
@id
}
.png"
,
@dummy
.
avatar
.
path
}
end
end
end
end
...
...
test/helper.rb
View file @
933dc7bd
...
@@ -16,9 +16,22 @@ rescue LoadError
...
@@ -16,9 +16,22 @@ rescue LoadError
puts
"ruby-debug not loaded"
puts
"ruby-debug not loaded"
end
end
ROOT
=
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
)
ROOT
=
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
)
RAILS_ROOT
=
ROOT
RAILS_ENV
=
"test"
def
silence_warnings
old_verbose
,
$VERBOSE
=
$VERBOSE
,
nil
yield
ensure
$VERBOSE
=
old_verbose
end
class
Test
::
Unit
::
TestCase
def
setup
silence_warnings
do
Object
.
const_set
(
:Rails
,
stub
(
'Rails'
,
:root
=>
ROOT
,
:env
=>
'test'
))
end
end
end
$LOAD_PATH
<<
File
.
join
(
ROOT
,
'lib'
)
$LOAD_PATH
<<
File
.
join
(
ROOT
,
'lib'
)
$LOAD_PATH
<<
File
.
join
(
ROOT
,
'lib'
,
'paperclip'
)
$LOAD_PATH
<<
File
.
join
(
ROOT
,
'lib'
,
'paperclip'
)
...
@@ -70,17 +83,6 @@ def rebuild_class options = {}
...
@@ -70,17 +83,6 @@ def rebuild_class options = {}
end
end
end
end
def
temporary_rails_env
(
new_env
)
old_env
=
Object
.
const_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
class
FakeModel
class
FakeModel
attr_accessor
:avatar_file_name
,
attr_accessor
:avatar_file_name
,
:avatar_file_size
,
:avatar_file_size
,
...
...
test/interpolations_test.rb
View file @
933dc7bd
...
@@ -11,12 +11,12 @@ class InterpolationsTest < Test::Unit::TestCase
...
@@ -11,12 +11,12 @@ class InterpolationsTest < Test::Unit::TestCase
end
end
end
end
should
"return the R
AILS_ROOT
"
do
should
"return the R
ails.root
"
do
assert_equal
R
AILS_ROOT
,
Paperclip
::
Interpolations
.
rails_root
(
:attachment
,
:style
)
assert_equal
R
ails
.
root
,
Paperclip
::
Interpolations
.
rails_root
(
:attachment
,
:style
)
end
end
should
"return the R
AILS_ENV
"
do
should
"return the R
ails.env
"
do
assert_equal
R
AILS_ENV
,
Paperclip
::
Interpolations
.
rails_env
(
:attachment
,
:style
)
assert_equal
R
ails
.
env
,
Paperclip
::
Interpolations
.
rails_env
(
:attachment
,
:style
)
end
end
should
"return the class of the Interpolations module when called with no params"
do
should
"return the class of the Interpolations module when called with no params"
do
...
...
test/storage_test.rb
View file @
933dc7bd
...
@@ -4,7 +4,7 @@ require 'aws/s3'
...
@@ -4,7 +4,7 @@ require 'aws/s3'
class
StorageTest
<
Test
::
Unit
::
TestCase
class
StorageTest
<
Test
::
Unit
::
TestCase
def
rails_env
(
env
)
def
rails_env
(
env
)
silence_warnings
do
silence_warnings
do
Object
.
const_set
(
:R
AILS_ENV
,
env
)
Object
.
const_set
(
:R
ails
,
stub
(
'Rails'
,
:env
=>
env
)
)
end
end
end
end
...
@@ -17,12 +17,6 @@ class StorageTest < Test::Unit::TestCase
...
@@ -17,12 +17,6 @@ class StorageTest < Test::Unit::TestCase
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@avatar
=
@dummy
.
avatar
@avatar
=
@dummy
.
avatar
@current_env
=
RAILS_ENV
end
teardown
do
rails_env
(
@current_env
)
end
end
should
"get the correct credentials when RAILS_ENV is production"
do
should
"get the correct credentials when RAILS_ENV is production"
do
...
@@ -96,7 +90,7 @@ class StorageTest < Test::Unit::TestCase
...
@@ -96,7 +90,7 @@ class StorageTest < Test::Unit::TestCase
assert_match
%r{^http://something.something.com/avatars/stringio.txt}
,
@dummy
.
avatar
.
url
assert_match
%r{^http://something.something.com/avatars/stringio.txt}
,
@dummy
.
avatar
.
url
end
end
end
end
context
"Generating a url with an expiration"
do
context
"Generating a url with an expiration"
do
setup
do
setup
do
AWS
::
S3
::
Base
.
stubs
(
:establish_connection!
)
AWS
::
S3
::
Base
.
stubs
(
:establish_connection!
)
...
@@ -133,11 +127,8 @@ class StorageTest < Test::Unit::TestCase
...
@@ -133,11 +127,8 @@ class StorageTest < Test::Unit::TestCase
:development
=>
{
:bucket
=>
"dev_bucket"
}
:development
=>
{
:bucket
=>
"dev_bucket"
}
}
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@old_env
=
RAILS_ENV
end
end
teardown
{
rails_env
(
@old_env
)
}
should
"get the right bucket in production"
do
should
"get the right bucket in production"
do
rails_env
(
"production"
)
rails_env
(
"production"
)
assert_equal
"prod_bucket"
,
@dummy
.
avatar
.
bucket_name
assert_equal
"prod_bucket"
,
@dummy
.
avatar
.
bucket_name
...
...
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