From d0c25de3e0edd61fccceeb0121ac79fd1aa48891 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Sat, 19 Dec 2015 19:35:18 -0500 Subject: [PATCH] Treat non `{test,development}` envs as `production` Closes [#361]. When the Rails environment is neither `test` nor `development` ([two environments handled by EmberCLI out-of-the-box][ember-cli-env]), treat it as `production`. [#361]: https://github.com/thoughtbot/ember-cli-rails/issues/361 [ember-cli-env]: http://ember-cli.com/user-guide/#Environments --- lib/ember_cli/helpers.rb | 22 +++------------- spec/lib/ember_cli/helpers_spec.rb | 41 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 spec/lib/ember_cli/helpers_spec.rb diff --git a/lib/ember_cli/helpers.rb b/lib/ember_cli/helpers.rb index 3c303f1a..d50bf6bf 100644 --- a/lib/ember_cli/helpers.rb +++ b/lib/ember_cli/helpers.rb @@ -16,26 +16,10 @@ def which(cmd) end def current_environment - rails_config_for(:ember_cli_rails_mode){ default_environment }.to_s - end - - private - - def default_environment - if Rails.env.test? - "test" - elsif Rails.env.production? || !rails_config_for(:consider_all_requests_local) - "production" - else - "development" - end - end - - def rails_config_for(key) - if Rails.configuration.respond_to?(key) - Rails.configuration.public_send(key) + if Rails.env.to_s =~ /test|development/ + Rails.env else - yield + "production".inquiry end end end diff --git a/spec/lib/ember_cli/helpers_spec.rb b/spec/lib/ember_cli/helpers_spec.rb new file mode 100644 index 00000000..7177bebc --- /dev/null +++ b/spec/lib/ember_cli/helpers_spec.rb @@ -0,0 +1,41 @@ +require "ember_cli/helpers" + +describe EmberCli::Helpers do + describe ".current_environment" do + context "when test" do + it "returns test" do + stub_rails_env("test") + + current_environment = EmberCli::Helpers.current_environment + + expect(current_environment).to be_test + end + end + + context "when development" do + it "returns development" do + stub_rails_env("development") + + current_environment = EmberCli::Helpers.current_environment + + expect(current_environment).to be_development + end + end + + context "when anything else" do + it "returns production" do + stub_rails_env("staging") + + current_environment = EmberCli::Helpers.current_environment + + expect(current_environment).to be_production + end + end + end + + def stub_rails_env(env) + allow(Rails). + to receive(:env). + and_return(env.to_s.inquiry) + end +end