Skip to content

Commit

Permalink
Configures action mailer asset host (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
delphaber authored and nickcharlton committed Jul 30, 2017
1 parent 3fbdc34 commit c2f02ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/suspenders/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def action_mailer_host(rails_env, host)
configure_environment(rails_env, config)
end

def action_mailer_asset_host(rails_env, host)
config = "config.action_mailer.asset_host = { host: #{host} }"
configure_environment(rails_env, config)
end

def configure_application_file(config)
inject_into_file(
"config/application.rb",
Expand Down
6 changes: 6 additions & 0 deletions lib/suspenders/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,14 @@ def configure_simple_form

def configure_action_mailer
action_mailer_host "development", %{"localhost:3000"}
action_mailer_asset_host "development", %{"localhost:3000"}
action_mailer_host "test", %{"www.example.com"}
action_mailer_asset_host "test", %{"www.example.com"}
action_mailer_host "production", %{ENV.fetch("APPLICATION_HOST")}
action_mailer_asset_host(
"production",
%{ENV.fetch("ASSET_HOST", ENV.fetch("APPLICATION_HOST"))},
)
end

def configure_active_job
Expand Down
7 changes: 7 additions & 0 deletions spec/features/new_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@
to match(/^ +config.action_mailer.delivery_method = :file$/)
end

it "sets action mailer default host and asset host" do
config_key = 'config\.action_mailer\.asset_host'
config_value =
'{ host: ENV\.fetch\("ASSET_HOST", ENV\.fetch\("APPLICATION_HOST"\)\) }'
expect(production_config).to match(/#{config_key} = #{config_value}/)
end

it "uses APPLICATION_HOST, not HOST in the production config" do
expect(production_config).to match(/"APPLICATION_HOST"/)
expect(production_config).not_to match(/"HOST"/)
Expand Down

0 comments on commit c2f02ae

Please sign in to comment.