Commit 5b18dcdf authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'issue#220040-fix-rails-savebang-markdown-cache-module' into 'master'

Fix Rails/SaveBang Rubocop offenses for markdown cache modules

See merge request gitlab-org/gitlab!58063
parents 87f877e7 10e669fb
...@@ -279,8 +279,6 @@ Rails/SaveBang: ...@@ -279,8 +279,6 @@ Rails/SaveBang:
- 'spec/lib/gitlab/import_export/uploads_saver_spec.rb' - 'spec/lib/gitlab/import_export/uploads_saver_spec.rb'
- 'spec/lib/gitlab/import_export/wiki_restorer_spec.rb' - 'spec/lib/gitlab/import_export/wiki_restorer_spec.rb'
- 'spec/lib/gitlab/lets_encrypt/client_spec.rb' - 'spec/lib/gitlab/lets_encrypt/client_spec.rb'
- 'spec/lib/gitlab/markdown_cache/active_record/extension_spec.rb'
- 'spec/lib/gitlab/markdown_cache/redis/store_spec.rb'
- 'spec/lib/gitlab/middleware/go_spec.rb' - 'spec/lib/gitlab/middleware/go_spec.rb'
- 'spec/lib/gitlab/shard_health_cache_spec.rb' - 'spec/lib/gitlab/shard_health_cache_spec.rb'
- 'spec/lib/mattermost/command_spec.rb' - 'spec/lib/mattermost/command_spec.rb'
......
---
title: Fix Rails/SaveBang Rubocop offenses for markdown cache modules
merge_request: 58063
author: Huzaifa Iftikhar @huzaifaiftikhar
type: fixed
...@@ -15,7 +15,7 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do ...@@ -15,7 +15,7 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do
end end
let(:cache_version) { Gitlab::MarkdownCache::CACHE_COMMONMARK_VERSION << 16 } let(:cache_version) { Gitlab::MarkdownCache::CACHE_COMMONMARK_VERSION << 16 }
let(:thing) { klass.create(title: markdown, title_html: html, cached_markdown_version: cache_version) } let(:thing) { klass.create!(title: markdown, title_html: html, cached_markdown_version: cache_version) }
let(:markdown) { '`Foo`' } let(:markdown) { '`Foo`' }
let(:html) { '<p data-sourcepos="1:1-1:5" dir="auto"><code>Foo</code></p>' } let(:html) { '<p data-sourcepos="1:1-1:5" dir="auto"><code>Foo</code></p>' }
...@@ -28,7 +28,7 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do ...@@ -28,7 +28,7 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do
before do before do
thing.title = thing.title thing.title = thing.title
thing.save thing.save!
end end
it { expect(thing.title).to eq(markdown) } it { expect(thing.title).to eq(markdown) }
...@@ -38,11 +38,11 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do ...@@ -38,11 +38,11 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do
end end
context 'a changed markdown field' do context 'a changed markdown field' do
let(:thing) { klass.create(title: markdown, title_html: html, cached_markdown_version: cache_version) } let(:thing) { klass.create!(title: markdown, title_html: html, cached_markdown_version: cache_version) }
before do before do
thing.title = updated_markdown thing.title = updated_markdown
thing.save thing.save!
end end
it { expect(thing.title_html).to eq(updated_html) } it { expect(thing.title_html).to eq(updated_html) }
...@@ -53,9 +53,9 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do ...@@ -53,9 +53,9 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do
it do it do
expect(thing).to receive(:refresh_markdown_cache).once expect(thing).to receive(:refresh_markdown_cache).once
thing.title = '' thing.title = ''
thing.save thing.save!
thing.title = '' thing.title = ''
thing.save thing.save!
end end
end end
...@@ -63,9 +63,9 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do ...@@ -63,9 +63,9 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do
it do it do
expect(thing).to receive(:refresh_markdown_cache).once expect(thing).to receive(:refresh_markdown_cache).once
thing.title = '[//]: # (This is also a comment.)' thing.title = '[//]: # (This is also a comment.)'
thing.save thing.save!
thing.title = '[//]: # (This is also a comment.)' thing.title = '[//]: # (This is also a comment.)'
thing.save thing.save!
end end
end end
...@@ -74,7 +74,7 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do ...@@ -74,7 +74,7 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do
before do before do
thing.state_id = 2 thing.state_id = 2
thing.save thing.save!
end end
it { expect(thing.state_id).to eq(2) } it { expect(thing.state_id).to eq(2) }
...@@ -87,7 +87,7 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do ...@@ -87,7 +87,7 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do
let(:thing) { klass.new(title: updated_markdown, title_html: html, cached_markdown_version: nil) } let(:thing) { klass.new(title: updated_markdown, title_html: html, cached_markdown_version: nil) }
before do before do
thing.save thing.save!
end end
it { expect(thing.title_html).to eq(updated_html) } it { expect(thing.title_html).to eq(updated_html) }
...@@ -99,7 +99,7 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do ...@@ -99,7 +99,7 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do
thing.project = :new_project thing.project = :new_project
allow(Banzai::Renderer).to receive(:cacheless_render_field).and_return(updated_html) allow(Banzai::Renderer).to receive(:cacheless_render_field).and_return(updated_html)
thing.save thing.save!
expect(thing.title_html).to eq(updated_html) expect(thing.title_html).to eq(updated_html)
expect(thing.description_html).to eq(updated_html) expect(thing.description_html).to eq(updated_html)
...@@ -110,7 +110,7 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do ...@@ -110,7 +110,7 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do
thing.author = :new_author thing.author = :new_author
allow(Banzai::Renderer).to receive(:cacheless_render_field).and_return(updated_html) allow(Banzai::Renderer).to receive(:cacheless_render_field).and_return(updated_html)
thing.save thing.save!
expect(thing.title_html).to eq(updated_html) expect(thing.title_html).to eq(updated_html)
expect(thing.description_html).to eq(updated_html) expect(thing.description_html).to eq(updated_html)
...@@ -125,7 +125,7 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do ...@@ -125,7 +125,7 @@ RSpec.describe Gitlab::MarkdownCache::ActiveRecord::Extension do
end end
describe '#cached_html_up_to_date?' do describe '#cached_html_up_to_date?' do
let(:thing) { klass.create(title: updated_markdown, title_html: html, cached_markdown_version: nil) } let(:thing) { klass.create!(title: updated_markdown, title_html: html, cached_markdown_version: nil) }
subject { thing.cached_html_up_to_date?(:title) } subject { thing.cached_html_up_to_date?(:title) }
......
...@@ -40,7 +40,7 @@ RSpec.describe Gitlab::MarkdownCache::Redis::Store, :clean_gitlab_redis_cache do ...@@ -40,7 +40,7 @@ RSpec.describe Gitlab::MarkdownCache::Redis::Store, :clean_gitlab_redis_cache do
describe '.bulk_read' do describe '.bulk_read' do
before do before do
store.save(field_1_html: "hello", field_2_html: "world", cached_markdown_version: 1) store.save(field_1_html: "hello", field_2_html: "world", cached_markdown_version: 1) # rubocop:disable Rails/SaveBang
end end
it 'returns a hash of values from store' do it 'returns a hash of values from store' do
...@@ -59,7 +59,7 @@ RSpec.describe Gitlab::MarkdownCache::Redis::Store, :clean_gitlab_redis_cache do ...@@ -59,7 +59,7 @@ RSpec.describe Gitlab::MarkdownCache::Redis::Store, :clean_gitlab_redis_cache do
it 'stores updates to html fields and version' do it 'stores updates to html fields and version' do
values_to_store = { field_1_html: "hello", field_2_html: "world", cached_markdown_version: 1 } values_to_store = { field_1_html: "hello", field_2_html: "world", cached_markdown_version: 1 }
store.save(values_to_store) store.save(values_to_store) # rubocop:disable Rails/SaveBang
expect(read_values) expect(read_values)
.to eq(field_1_html: "hello", field_2_html: "world", cached_markdown_version: "1") .to eq(field_1_html: "hello", field_2_html: "world", cached_markdown_version: "1")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment