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'
require 'paperclip/interpolations'
require 'paperclip/style'
require 'paperclip/attachment'
if defined? RAILS_ROOT
Dir.glob(File.join(File.expand_path(RAILS_ROOT), "lib", "paperclip_processors", "*.rb")).each do |processor|
if defined?(Rails.root) && Rails.root
Dir.glob(File.join(File.expand_path(Rails.root), "lib", "paperclip_processors", "*.rb")).each do |processor|
require processor
end
end
......
......@@ -51,14 +51,14 @@ module Paperclip
attachment.instance_read(:updated_at).to_s
end
# Returns the RAILS_ROOT constant.
# Returns the Rails.root constant.
def rails_root attachment, style_name
RAILS_ROOT
Rails.root
end
# Returns the RAILS_ENV constant.
# Returns the Rails.env constant.
def rails_env attachment, style_name
RAILS_ENV
Rails.env
end
# Returns the underscored, pluralized version of the class name.
......
......@@ -174,7 +174,7 @@ module Paperclip
def parse_credentials creds
creds = find_credentials(creds).stringify_keys
(creds[RAILS_ENV] || creds).symbolize_keys
(creds[Rails.env] || creds).symbolize_keys
end
def exists?(style = default_style)
......
......@@ -11,7 +11,7 @@ class AttachmentTest < Test::Unit::TestCase
@model = @attachment.instance
@model.id = 1234
@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
context "Attachment default_options" do
......@@ -106,12 +106,11 @@ class AttachmentTest < Test::Unit::TestCase
@dummy.stubs(:id).returns(@id)
@file = StringIO.new(".")
@dummy.avatar = @file
Rails = stub('Rails', :root => @rails_env)
end
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
......
......@@ -16,9 +16,22 @@ rescue LoadError
puts "ruby-debug not loaded"
end
ROOT = File.join(File.dirname(__FILE__), '..')
RAILS_ROOT = ROOT
RAILS_ENV = "test"
ROOT = File.join(File.dirname(__FILE__), '..')
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', 'paperclip')
......@@ -70,17 +83,6 @@ def rebuild_class options = {}
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
attr_accessor :avatar_file_name,
:avatar_file_size,
......
......@@ -11,12 +11,12 @@ class InterpolationsTest < Test::Unit::TestCase
end
end
should "return the RAILS_ROOT" do
assert_equal RAILS_ROOT, Paperclip::Interpolations.rails_root(:attachment, :style)
should "return the Rails.root" do
assert_equal Rails.root, Paperclip::Interpolations.rails_root(:attachment, :style)
end
should "return the RAILS_ENV" do
assert_equal RAILS_ENV, Paperclip::Interpolations.rails_env(:attachment, :style)
should "return the Rails.env" do
assert_equal Rails.env, Paperclip::Interpolations.rails_env(:attachment, :style)
end
should "return the class of the Interpolations module when called with no params" do
......
......@@ -4,7 +4,7 @@ require 'aws/s3'
class StorageTest < Test::Unit::TestCase
def rails_env(env)
silence_warnings do
Object.const_set(:RAILS_ENV, env)
Object.const_set(:Rails, stub('Rails', :env => env))
end
end
......@@ -17,12 +17,6 @@ class StorageTest < Test::Unit::TestCase
@dummy = Dummy.new
@avatar = @dummy.avatar
@current_env = RAILS_ENV
end
teardown do
rails_env(@current_env)
end
should "get the correct credentials when RAILS_ENV is production" do
......@@ -96,7 +90,7 @@ class StorageTest < Test::Unit::TestCase
assert_match %r{^http://something.something.com/avatars/stringio.txt}, @dummy.avatar.url
end
end
context "Generating a url with an expiration" do
setup do
AWS::S3::Base.stubs(:establish_connection!)
......@@ -133,11 +127,8 @@ class StorageTest < Test::Unit::TestCase
:development => { :bucket => "dev_bucket" }
}
@dummy = Dummy.new
@old_env = RAILS_ENV
end
teardown{ rails_env(@old_env) }
should "get the right bucket in production" do
rails_env("production")
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