Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat non {test,development} envs as production #366

Merged
merged 1 commit into from
Dec 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
master
------

* Translate Rails environments other than `test` or `development` to
`production`, unless an `EMBER_ENV` is specified. [#366]

[#366]: https://github.com/thoughtbot/ember-cli-rails/pull/366

0.6.1
-----

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,15 @@ EmberCLI runners to clobber each others' work][#94].
[Unicorn]: https://rubygems.org/gems/unicorn
[#94]: https://github.com/thoughtbot/ember-cli-rails/issues/94#issuecomment-77627453

## `EMBER_ENV`

If set on the environment, the value of `EMBER_ENV` will be passed to the
`ember` process as the value of the `--environment` flag.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused on this. Doesn't this code always force the environment passed to --environment to be either development or production?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seanpdoyle Did you see the above comment?


If `EMBER_ENV` is unspecified, the current Rails environment will be passed to
the `ember` process, with the exception of non-standard Rails environments,
which will be replaced with `production`.

## `RAILS_ENV`

While being managed by EmberCLI Rails, EmberCLI process will have
Expand Down
2 changes: 1 addition & 1 deletion lib/ember-cli-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def root
end

def env
@env ||= Helpers.current_environment.inquiry
@env ||= Helpers.current_environment
end

delegate :apps, to: :configuration
Expand Down
8 changes: 7 additions & 1 deletion lib/ember_cli/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ def test

private

delegate :development?, :test?, to: :env
def development?
env.to_s == "development"
end

def test?
env.to_s == "test"
end

def index_file
paths.index_file
Expand Down
18 changes: 4 additions & 14 deletions lib/ember_cli/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,16 @@ def which(cmd)
end

def current_environment
rails_config_for(:ember_cli_rails_mode){ default_environment }.to_s
ENV.fetch("EMBER_ENV") { default_environment }
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.match(/test|development/)
Rails.env
else
yield
"production"
end
end
end
Expand Down
58 changes: 58 additions & 0 deletions spec/lib/ember_cli/helpers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require "ember_cli/helpers"

describe EmberCli::Helpers do
describe ".current_environment" do
context "when EMBER_ENV is set" do
it "returns the value of EMBER_ENV" do
stub_env("EMBER_ENV" => "staging")

current_environment = EmberCli::Helpers.current_environment

expect(current_environment).to eq "staging"
end
end

context "when test" do
it "returns test" do
stub_rails_env("test")

current_environment = EmberCli::Helpers.current_environment

expect(current_environment).to eq "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 eq "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 eq "production"
end
end
end

def stub_env(key_to_value)
allow(ENV).
to receive(:fetch).
with(key_to_value.keys.first).
and_return(key_to_value.values.first)
end

def stub_rails_env(env)
allow(Rails).
to receive(:env).
and_return(env.to_s)
end
end