Commit 933dc7bd by Dan Croak Committed by Jon Yurek

replace deprecated RAILS_ENV and RAILS_ROOT with Rail.env and Rails.root

parent 4c6cf394
...@@ -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(RAILS_ROOT), "lib", "paperclip_processors", "*.rb")).each do |processor| Dir.glob(File.join(File.expand_path(Rails.root), "lib", "paperclip_processors", "*.rb")).each do |processor|
require processor require processor
end end
end end
......
...@@ -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 RAILS_ROOT constant. # Returns the Rails.root constant.
def rails_root attachment, style_name def rails_root attachment, style_name
RAILS_ROOT Rails.root
end end
# Returns the RAILS_ENV constant. # Returns the Rails.env constant.
def rails_env attachment, style_name def rails_env attachment, style_name
RAILS_ENV Rails.env
end end
# Returns the underscored, pluralized version of the class name. # Returns the underscored, pluralized version of the class name.
......
...@@ -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[RAILS_ENV] || creds).symbolize_keys (creds[Rails.env] || creds).symbolize_keys
end end
def exists?(style = default_style) def exists?(style = default_style)
......
...@@ -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 "#{RAILS_ROOT}/public/fake_models/1234/fake", @attachment.path assert_equal "#{Rails.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
......
...@@ -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,
......
...@@ -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 RAILS_ROOT" do should "return the Rails.root" do
assert_equal RAILS_ROOT, Paperclip::Interpolations.rails_root(:attachment, :style) assert_equal Rails.root, Paperclip::Interpolations.rails_root(:attachment, :style)
end end
should "return the RAILS_ENV" do should "return the Rails.env" do
assert_equal RAILS_ENV, Paperclip::Interpolations.rails_env(:attachment, :style) assert_equal Rails.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
......
...@@ -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(:RAILS_ENV, env) Object.const_set(:Rails, 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
......
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