Skip to content

Commit

Permalink
Merge pull request #30462 from y-yagi/fix_cant_modify_forzen_string_e…
Browse files Browse the repository at this point in the history
…rror_in_db_tasks

Fix `can't modify frozen String` error in `DatabaseTasks`
  • Loading branch information
kamipo committed Aug 30, 2017
2 parents 29db6b3 + c9a084a commit 87eb1a2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
Expand Up @@ -117,7 +117,7 @@ def run_cmd(cmd, args, action)
end

def run_cmd_error(cmd, args, action)
msg = "failed to execute:\n"
msg = "failed to execute:\n".dup
msg << "#{cmd} #{args.join(' ')}\n\n"
msg << "Please check the output above for any errors and make sure that `#{cmd}` is installed in your PATH and has proper permissions.\n\n"
msg
Expand Down
Expand Up @@ -73,7 +73,7 @@ def run_cmd(cmd, args, out)
end

def run_cmd_error(cmd, args)
msg = "failed to execute:\n"
msg = "failed to execute:\n".dup
msg << "#{cmd} #{args.join(' ')}\n\n"
msg << "Please check the output above for any errors and make sure that `#{cmd}` is installed in your PATH and has proper permissions.\n\n"
msg
Expand Down
10 changes: 10 additions & 0 deletions activerecord/test/cases/tasks/postgresql_rake_test.rb
Expand Up @@ -295,6 +295,16 @@ def test_structure_dump_with_dump_schemas_string
end
end

def test_structure_dump_execution_fails
filename = "awesome-file.sql"
Kernel.expects(:system).with("pg_dump", "-s", "-x", "-O", "-f", filename, "my-app-db").returns(nil)

e = assert_raise(RuntimeError) do
ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, filename)
end
assert_match("failed to execute:", e.message)
end

private
def with_dump_schemas(value, &block)
old_dump_schemas = ActiveRecord::Base.dump_schemas
Expand Down
25 changes: 25 additions & 0 deletions activerecord/test/cases/tasks/sqlite_rake_test.rb
Expand Up @@ -215,6 +215,31 @@ def test_structure_dump_with_ignore_tables
FileUtils.rm_f(filename)
FileUtils.rm_f(dbfile)
end

def test_structure_dump_execution_fails
dbfile = @database
filename = "awesome-file.sql"
Kernel.expects(:system).with("sqlite3", "--noop", "db_create.sqlite3", ".schema", out: "awesome-file.sql").returns(nil)

e = assert_raise(RuntimeError) do
with_structure_dump_flags(["--noop"]) do
quietly { ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, filename, "/rails/root") }
end
end
assert_match("failed to execute:", e.message)
ensure
FileUtils.rm_f(filename)
FileUtils.rm_f(dbfile)
end

private
def with_structure_dump_flags(flags)
old = ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = flags
yield
ensure
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = old
end
end

class SqliteStructureLoadTest < ActiveRecord::TestCase
Expand Down

0 comments on commit 87eb1a2

Please sign in to comment.