From 62d7990b9bb30cf33ed87017c5c633d1cccc75c2 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Thu, 28 Feb 2019 19:57:34 +0100 Subject: Ran standardrb --fix on the whole codebase Inspired by https://twitter.com/searls/status/1101137953743613952 I decided to try https://github.com/testdouble/standard on our codebase. It's opinionated, but at least it's a _standard_. --- spec/models/commit_spec.rb | 310 ++++++++++++++++++++++----------------------- 1 file changed, 155 insertions(+), 155 deletions(-) (limited to 'spec/models/commit_spec.rb') diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb index baad8352185..058397a9f32 100644 --- a/spec/models/commit_spec.rb +++ b/spec/models/commit_spec.rb @@ -1,10 +1,10 @@ -require 'spec_helper' +require "spec_helper" describe Commit do let(:project) { create(:project, :public, :repository) } let(:commit) { project.commit } - describe 'modules' do + describe "modules" do subject { described_class } it { is_expected.to include_module(Mentionable) } @@ -14,52 +14,52 @@ describe Commit do it { is_expected.to include_module(Presentable) } end - describe '.lazy' do + describe ".lazy" do set(:project) { create(:project, :repository) } - context 'when the commits are found' do + context "when the commits are found" do let(:oids) do - %w( + %w[ 498214de67004b1da3d820901307bed2a68a8ef6 c642fe9b8b9f28f9225d7ea953fe14e74748d53b 6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9 048721d90c449b244b7b4c53a9186b04330174ec 281d3a76f31c812dbf48abce82ccf6860adedd81 - ) + ] end subject { oids.map { |oid| described_class.lazy(project, oid) } } - it 'batches requests for commits' do + it "batches requests for commits" do expect(project.repository).to receive(:commits_by).once.and_call_original subject.first.title subject.last.title end - it 'maintains ordering' do + it "maintains ordering" do subject.each_with_index do |commit, i| expect(commit.id).to eq(oids[i]) end end end - context 'when not found' do - it 'returns nil as commit' do - commit = described_class.lazy(project, 'deadbeef').__sync + context "when not found" do + it "returns nil as commit" do + commit = described_class.lazy(project, "deadbeef").__sync expect(commit).to be_nil end end end - describe '#author', :request_store do - it 'looks up the author in a case-insensitive way' do + describe "#author", :request_store do + it "looks up the author in a case-insensitive way" do user = create(:user, email: commit.author_email.upcase) expect(commit.author).to eq(user) end - it 'caches the author' do + it "caches the author" do user = create(:user, email: commit.author_email) expect(commit.author).to eq(user) @@ -70,14 +70,14 @@ describe Commit do expect(commit.author).to eq(user) end - context 'using eager loading' do - let!(:alice) { create(:user, email: 'alice@example.com') } - let!(:bob) { create(:user, email: 'hunter2@example.com') } + context "using eager loading" do + let!(:alice) { create(:user, email: "alice@example.com") } + let!(:bob) { create(:user, email: "hunter2@example.com") } let!(:jeff) { create(:user) } let(:alice_commit) do described_class.new(RepoHelpers.sample_commit, project).tap do |c| - c.author_email = 'alice@example.com' + c.author_email = "alice@example.com" end end @@ -85,13 +85,13 @@ describe Commit do # The commit for Bob uses one of his alternative Emails, instead of the # primary one. described_class.new(RepoHelpers.sample_commit, project).tap do |c| - c.author_email = 'bob@example.com' + c.author_email = "bob@example.com" end end let(:eve_commit) do described_class.new(RepoHelpers.sample_commit, project).tap do |c| - c.author_email = 'eve@example.com' + c.author_email = "eve@example.com" end end @@ -105,11 +105,11 @@ describe Commit do let!(:commits) { [alice_commit, bob_commit, eve_commit, jeff_commit] } before do - create(:email, user: bob, email: 'bob@example.com') + create(:email, user: bob, email: "bob@example.com") end - it 'executes only two SQL queries' do - recorder = ActiveRecord::QueryRecorder.new do + it "executes only two SQL queries" do + recorder = ActiveRecord::QueryRecorder.new { # Running this first ensures we don't run one query for every # commit. commits.each(&:lazy_author) @@ -117,7 +117,7 @@ describe Commit do # This forces the execution of the SQL queries necessary to load the # data. commits.each { |c| c.author.try(:id) } - end + } expect(recorder.count).to eq(2) end @@ -141,71 +141,71 @@ describe Commit do end it "preloads the authors for Commits using a User's outdated private commit Email" do - jeff.update!(username: 'new-username') + jeff.update!(username: "new-username") commits.each(&:lazy_author) expect(jeff_commit.author).to eq(jeff) end - it 'sets the author to Nil if an author could not be found for a Commit' do + it "sets the author to Nil if an author could not be found for a Commit" do commits.each(&:lazy_author) expect(eve_commit.author).to be_nil end - it 'does not execute SQL queries once the authors are preloaded' do + it "does not execute SQL queries once the authors are preloaded" do commits.each(&:lazy_author) commits.each { |c| c.author.try(:id) } - recorder = ActiveRecord::QueryRecorder.new do + recorder = ActiveRecord::QueryRecorder.new { alice_commit.author bob_commit.author eve_commit.author - end + } expect(recorder.count).to be_zero end end end - describe '#to_reference' do - let(:project) { create(:project, :repository, path: 'sample-project') } + describe "#to_reference" do + let(:project) { create(:project, :repository, path: "sample-project") } - it 'returns a String reference to the object' do + it "returns a String reference to the object" do expect(commit.to_reference).to eq commit.id end - it 'supports a cross-project reference' do - another_project = build(:project, :repository, name: 'another-project', namespace: project.namespace) + it "supports a cross-project reference" do + another_project = build(:project, :repository, name: "another-project", namespace: project.namespace) expect(commit.to_reference(another_project)).to eq "sample-project@#{commit.id}" end end - describe '#reference_link_text' do - let(:project) { create(:project, :repository, path: 'sample-project') } + describe "#reference_link_text" do + let(:project) { create(:project, :repository, path: "sample-project") } - it 'returns a String reference to the object' do + it "returns a String reference to the object" do expect(commit.reference_link_text).to eq commit.short_id end - it 'supports a cross-project reference' do - another_project = build(:project, :repository, name: 'another-project', namespace: project.namespace) + it "supports a cross-project reference" do + another_project = build(:project, :repository, name: "another-project", namespace: project.namespace) expect(commit.reference_link_text(another_project)).to eq "sample-project@#{commit.short_id}" end end - describe '#title' do + describe "#title" do it "returns no_commit_message when safe_message is blank" do - allow(commit).to receive(:safe_message).and_return('') + allow(commit).to receive(:safe_message).and_return("") expect(commit.title).to eq("--no commit message") end - it 'truncates a message without a newline at natural break to 80 characters' do - message = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit. Vivamus egestas lacinia lacus, sed rutrum mauris.' + it "truncates a message without a newline at natural break to 80 characters" do + message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id felis id blandit. Vivamus egestas lacinia lacus, sed rutrum mauris." allow(commit).to receive(:safe_message).and_return(message) - expect(commit.title).to eq('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id...') + expect(commit.title).to eq("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales id...") end it "truncates a message with a newline before 80 characters at the newline" do @@ -216,24 +216,24 @@ describe Commit do end it "does not truncates a message with a newline after 80 but less 100 characters" do - message = <