Skip to content

Commit

Permalink
Don't write database.yml if using ActiveRecord >= 4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
damonmorgan authored and schneems committed Aug 5, 2015
1 parent e8be1e1 commit be1ac0d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
3 changes: 2 additions & 1 deletion hatchet.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"sharpstone/ruby_193_jruby_17161_jdk8",
"sharpstone/jruby-minimal",
"sharpstone/empty-procfile",
"sharpstone/bad_ruby_version"
"sharpstone/bad_ruby_version",
"sharpstone/activerecord41_scaffold"
],
"rack": [
"sharpstone/default_ruby",
Expand Down
5 changes: 0 additions & 5 deletions lib/language_pack/rails41.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ def self.use?
end
end

def create_database_yml
instrument 'ruby.create_database_yml' do
end
end

def setup_profiled
instrument 'setup_profiled' do
super
Expand Down
15 changes: 9 additions & 6 deletions lib/language_pack/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,13 @@ def syck_hack
# writes ERB based database.yml for Rails. The database.yml uses the DATABASE_URL from the environment during runtime.
def create_database_yml
instrument 'ruby.create_database_yml' do
log("create_database_yml") do
return unless File.directory?("config")
topic("Writing config/database.yml to read from DATABASE_URL")
File.open("config/database.yml", "w") do |file|
file.puts <<-DATABASE_YML
active_record_version = bundler.gem_version('activerecord')
unless active_record_version && active_record_version >= Gem::Version.new('4.1.0')
log("create_database_yml") do
return unless File.directory?("config")
topic("Writing config/database.yml to read from DATABASE_URL")
File.open("config/database.yml", "w") do |file|
file.puts <<-DATABASE_YML
<%
require 'cgi'
Expand Down Expand Up @@ -686,7 +688,8 @@ def attribute(name, value, force_string = false)
<% params.each do |key, value| %>
<%= key %>: <%= value.first %>
<% end %>
DATABASE_YML
DATABASE_YML
end
end
end
end
Expand Down
26 changes: 26 additions & 0 deletions spec/ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,30 @@
end
end
end

describe "database configuration" do
context "no active record" do
it "writes a heroku specific database.yml" do
Hatchet::Runner.new("default_ruby").deploy do |app, heroku|
expect(app.output).to include("Writing config/database.yml to read from DATABASE_URL")
end
end
end

context "active record 4.0-" do
it "writes a heroku specific database.yml" do
Hatchet::Runner.new("rails4-manifest").deploy do |app, heroku|
expect(app.output).to include("Writing config/database.yml to read from DATABASE_URL")
end
end
end

context "active record 4.1+" do
it "doesn't write a heroku specific database.yml" do
Hatchet::Runner.new("activerecord41_scaffold").deploy do |app, heroku|
expect(app.output).not_to include("Writing config/database.yml to read from DATABASE_URL")
end
end
end
end
end

0 comments on commit be1ac0d

Please sign in to comment.