spec/config_helpers_spec.rb in pliny-0.19.0 vs spec/config_helpers_spec.rb in pliny-0.20.0
- old
+ new
@@ -2,51 +2,130 @@
require "pliny/config_helpers"
describe Pliny::CastingConfigHelpers do
describe "#rack_env" do
- it "is development if pliny_env is development" do
+ it "is development if app_env is development" do
config = Class.new do
extend Pliny::CastingConfigHelpers
- override :pliny_env, 'development', string
+ override :app_env, 'development', string
end
assert_equal "development", config.rack_env
end
- it "is development if pliny_env is test" do
+ it "is development if app_env is test" do
config = Class.new do
extend Pliny::CastingConfigHelpers
- override :pliny_env, 'test', string
+ override :app_env, 'test', string
end
assert_equal "development", config.rack_env
end
- it "is deployment if pliny_env is production" do
+ it "is deployment if app_env is production" do
config = Class.new do
extend Pliny::CastingConfigHelpers
- override :pliny_env, 'production', string
+ override :app_env, 'production', string
end
assert_equal "deployment", config.rack_env
end
- it "is deployment if pliny_env is nil" do
+ it "is deployment if app_env is nil" do
config = Class.new do
extend Pliny::CastingConfigHelpers
- override :pliny_env, '', string
+ override :app_env, '', string
end
assert_equal "deployment", config.rack_env
end
- it "is deployment if pliny_env is another value" do
+ it "is deployment if app_env is another value" do
config = Class.new do
extend Pliny::CastingConfigHelpers
- override :pliny_env, 'staging', string
+ override :app_env, 'staging', string
end
assert_equal "deployment", config.rack_env
+ end
+
+ context "when legacy PLINY_ENV is still defined" do
+ before do
+ ENV['ORIGINAL_PLINY_ENV'] = ENV['PLINY_ENV']
+ ENV['PLINY_ENV'] = 'staging'
+ end
+
+ after do
+ ENV['PLINY_ENV'] = ENV.delete('ORIGINAL_PLINY_ENV')
+ end
+
+ it "uses PLINY_ENV value instead of APP_ENV" do
+ config = Class.new do
+ extend Pliny::CastingConfigHelpers
+ override :app_env, 'development', string
+ end
+
+ assert_equal "deployment", config.rack_env
+ end
+
+ it "displays deprecation warning" do
+ config = Class.new do
+ extend Pliny::CastingConfigHelpers
+ override :app_env, 'development', string
+ end
+
+ io = StringIO.new
+ $stderr = io
+ config.rack_env
+ $stderr = STDERR
+
+ assert_includes io.string, "PLINY_ENV is deprecated"
+ end
+ end
+ end
+
+ describe "#pliny_env" do
+ it "displays deprecation warning if pliny_env is used" do
+ config = Class.new do
+ extend Pliny::CastingConfigHelpers
+ override :app_env, 'development', string
+ end
+
+ io = StringIO.new
+ $stderr = io
+ config.pliny_env
+ $stderr = STDERR
+
+ assert_includes io.string, "Config.pliny_env is deprecated"
+ end
+
+ it "returns app_env value" do
+ config = Class.new do
+ extend Pliny::CastingConfigHelpers
+ override :app_env, 'foo', string
+ end
+
+ assert_equal "foo", config.pliny_env
+ end
+
+ context "when legacy PLINY_ENV is still defined" do
+ before do
+ ENV['ORIGINAL_PLINY_ENV'] = ENV['PLINY_ENV']
+ ENV['PLINY_ENV'] = 'staging'
+ end
+
+ after do
+ ENV['PLINY_ENV'] = ENV.delete('ORIGINAL_PLINY_ENV')
+ end
+
+ it "returns PLINY_ENV value" do
+ config = Class.new do
+ extend Pliny::CastingConfigHelpers
+ override :app_env, 'development', string
+ end
+
+ assert_equal "staging", config.pliny_env
+ end
end
end
end