Skip to content

Commit

Permalink
Update regex to match multiline config.action_mailer.
Browse files Browse the repository at this point in the history
Updated regex can now properly match config.action_mailer settings like:

config.action_mailer.raise_delivery_errors = false

and multiline:

config.action_mailer.raise_delivery_errors = false
config.action_mailer.smtp_settings = {
    address: "test.com",
    port: 123,
    domain: "example.com"
}
  • Loading branch information
ugisozols authored and parndt committed Dec 5, 2012
1 parent a63bf97 commit 3895597
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/lib/generators/refinery/cms/cms_generator.rb
Expand Up @@ -164,9 +164,9 @@ def ensure_environments_are_sane!
# we may not always require it (currently only the authentication extension).
# Rails, however, will optimistically place config entries for action_mailer.
insert_into_file env, " if config.respond_to?(:action_mailer)\n ",
:before => %r{^[^#]+config\.action_mailer\.}, :verbose => false
:before => %r{^\s*config\.action_mailer\..+([\w\W]*\})?}, :verbose => false
insert_into_file env, "\n end",
:after => %r{^[^#]+config\.action_mailer\..*}, :verbose => false
:after => %r{^\s*config\.action_mailer\..+([\w\W]*\})?}, :verbose => false

gsub_file env, "config.assets.compile = false", "config.assets.compile = true", :verbose => false
end
Expand Down
71 changes: 71 additions & 0 deletions core/spec/lib/generators/refinery/cms/cms_generator_spec.rb
Expand Up @@ -9,6 +9,37 @@ module Refinery

before do
prepare_destination

dir = "#{destination_root}/config/environments"
FileUtils.mkdir_p(dir)
File.open("#{dir}/development.rb", "w") do |file|
file.write <<-SPEC
Dummy::Application.configure do
config.action_mailer.test = true
end
SPEC
end

File.open("#{dir}/test.rb", "w") do |file|
file.write <<-SPEC
Dummy::Application.configure do
# config.action_mailer.test = true
end
SPEC
end

File.open("#{dir}/production.rb", "w") do |file|
file.write <<-SPEC
Dummy::Application.configure do
config.action_mailer.test = true
config.action_mailer.check = {
:test => true,
:check => true
}
end
SPEC
end

run_generator %w[--skip-db --skip-migrations]
end

Expand Down Expand Up @@ -40,5 +71,45 @@ module Refinery
end
}
end

describe "#ensure_environments_are_sane" do
it "wraps single line config.action_mailer setting" do
File.open("#{destination_root}/config/environments/development.rb") do |file|
file.read.should eq <<-SPEC
Dummy::Application.configure do
if config.respond_to?(:action_mailer)
config.action_mailer.test = true
end
end
SPEC
end
end

it "wraps multi line config.action_mailer settings" do
File.open("#{destination_root}/config/environments/production.rb") do |file|
file.read.should eq <<-SPEC
Dummy::Application.configure do
if config.respond_to?(:action_mailer)
config.action_mailer.test = true
config.action_mailer.check = {
:test => true,
:check => true
}
end
end
SPEC
end
end

it "leaves commented config.action_mailer alone" do
File.open("#{destination_root}/config/environments/test.rb") do |file|
file.read.should eq <<-SPEC
Dummy::Application.configure do
# config.action_mailer.test = true
end
SPEC
end
end
end
end
end

0 comments on commit 3895597

Please sign in to comment.