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

[Fix #515] Fix an error for Rails/BulkChangeTable #516

Merged
merged 1 commit into from
Jul 1, 2021
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#515](https://github.com/rubocop/rubocop-rails/issues/515): Fix an error for `Rails/BulkChangeTable` when using Psych 4.0. ([@koic][])

## 2.11.1 (2021-06-25)

### Bug fixes
Expand Down
6 changes: 5 additions & 1 deletion lib/rubocop/cop/rails/bulk_change_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ def database_from_yaml
def database_yaml
return nil unless File.exist?('config/database.yml')

yaml = YAML.load_file('config/database.yml')
yaml = if YAML.respond_to?(:unsafe_load_file)
YAML.unsafe_load_file('config/database.yml')
else
YAML.load_file('config/database.yml')
end
return nil unless yaml.is_a? Hash

config = yaml['development']
Expand Down
12 changes: 6 additions & 6 deletions spec/rubocop/cop/rails/bulk_change_table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,12 @@ def change
let(:yaml) { nil }

before do
allow(File).to receive(:exist?)
.with('config/database.yml')
.and_return(true)
allow(YAML).to receive(:load_file)
.with('config/database.yml')
.and_return(yaml)
allow(File).to receive(:exist?).with('config/database.yml').and_return(true)
if YAML.respond_to?(:unsafe_load_file)
allow(YAML).to receive(:unsafe_load_file).with('config/database.yml').and_return(yaml)
else
allow(YAML).to receive(:load_file).with('config/database.yml').and_return(yaml)
end
end

context 'mysql2' do
Expand Down