Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-09-13 21:06:03 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-09-13 21:06:03 +0300
commit40d3d574132d2849646c20eb9d8742b159d9bfc8 (patch)
tree431dee6675639da4421dbb1d6f50b7734a3190c3 /spec/rubocop
parent5939b09fd3db37ec98dfce0345162617d9d1d313 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/cop/migration/add_reference_spec.rb84
-rw-r--r--spec/rubocop/cop/qa/ambiguous_page_object_name_spec.rb54
2 files changed, 120 insertions, 18 deletions
diff --git a/spec/rubocop/cop/migration/add_reference_spec.rb b/spec/rubocop/cop/migration/add_reference_spec.rb
index c348fc0efac..0b56fe8ed83 100644
--- a/spec/rubocop/cop/migration/add_reference_spec.rb
+++ b/spec/rubocop/cop/migration/add_reference_spec.rb
@@ -25,38 +25,86 @@ describe RuboCop::Cop::Migration::AddReference do
allow(cop).to receive(:in_migration?).and_return(true)
end
- it 'registers an offense when using add_reference without index' do
- expect_offense(<<~RUBY)
- call do
- add_reference(:projects, :users)
- ^^^^^^^^^^^^^ `add_reference` requires `index: true` or `index: { options... }`
+ let(:offense) { '`add_reference` requires downtime for existing tables, use `add_concurrent_foreign_key` instead. When used for new tables, `index: true` or `index: { options... } is required.`' }
+
+ context 'when the table existed before' do
+ it 'registers an offense when using add_reference' do
+ expect_offense(<<~RUBY)
+ def up
+ add_reference(:projects, :users)
+ ^^^^^^^^^^^^^ #{offense}
+ end
+ RUBY
+ end
+
+ it 'registers an offense when using add_reference with index enabled' do
+ expect_offense(<<~RUBY)
+ def up
+ add_reference(:projects, :users, index: true)
+ ^^^^^^^^^^^^^ #{offense}
end
- RUBY
+ RUBY
+ end
+
+ it 'registers an offense if only a different table was created' do
+ expect_offense(<<~RUBY)
+ def up
+ create_table(:foo) do |t|
+ t.string :name
+ end
+ add_reference(:projects, :users, index: true)
+ ^^^^^^^^^^^^^ #{offense}
+ end
+ RUBY
+ end
end
- it 'registers an offense when using add_reference index disabled' do
- expect_offense(<<~RUBY)
+ context 'when creating the table at the same time' do
+ let(:create_table_statement) do
+ <<~RUBY
+ create_table(:projects) do |t|
+ t.string :name
+ end
+ RUBY
+ end
+
+ it 'registers an offense when using add_reference without index' do
+ expect_offense(<<~RUBY)
def up
+ #{create_table_statement}
+ add_reference(:projects, :users)
+ ^^^^^^^^^^^^^ #{offense}
+ end
+ RUBY
+ end
+
+ it 'registers an offense when using add_reference index disabled' do
+ expect_offense(<<~RUBY)
+ def up
+ #{create_table_statement}
add_reference(:projects, :users, index: false)
- ^^^^^^^^^^^^^ `add_reference` requires `index: true` or `index: { options... }`
+ ^^^^^^^^^^^^^ #{offense}
end
- RUBY
- end
+ RUBY
+ end
- it 'does not register an offense when using add_reference with index enabled' do
- expect_no_offenses(<<~RUBY)
+ it 'does not register an offense when using add_reference with index enabled' do
+ expect_no_offenses(<<~RUBY)
def up
+ #{create_table_statement}
add_reference(:projects, :users, index: true)
end
- RUBY
- end
+ RUBY
+ end
- it 'does not register an offense when the index is unique' do
- expect_no_offenses(<<~RUBY)
+ it 'does not register an offense when the index is unique' do
+ expect_no_offenses(<<~RUBY)
def up
+ #{create_table_statement}
add_reference(:projects, :users, index: { unique: true } )
end
- RUBY
+ RUBY
+ end
end
end
end
diff --git a/spec/rubocop/cop/qa/ambiguous_page_object_name_spec.rb b/spec/rubocop/cop/qa/ambiguous_page_object_name_spec.rb
new file mode 100644
index 00000000000..8ee720af9a5
--- /dev/null
+++ b/spec/rubocop/cop/qa/ambiguous_page_object_name_spec.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require 'rubocop'
+require 'rubocop/rspec/support'
+
+require_relative '../../../../rubocop/cop/qa/ambiguous_page_object_name'
+
+describe RuboCop::Cop::QA::AmbiguousPageObjectName do
+ include CopHelper
+
+ let(:source_file) { 'qa/page.rb' }
+
+ subject(:cop) { described_class.new }
+
+ context 'in a QA file' do
+ before do
+ allow(cop).to receive(:in_qa_file?).and_return(true)
+ end
+
+ it "registers an offense for pages named `page`" do
+ expect_offense(<<-RUBY)
+ Page::Layout::Bar.perform do |page|
+ ^^^^ Don't use 'page' as a name for a Page Object. Use `bar` instead.
+ expect(page).to have_performance_bar
+ expect(page).to have_detailed_metrics
+ end
+ RUBY
+ end
+
+ it "doesnt offend if the page object is named otherwise" do
+ expect_no_offenses(<<-RUBY)
+ Page::Object.perform do |obj|
+ obj.whatever
+ end
+ RUBY
+ end
+ end
+
+ context 'outside of a QA file' do
+ before do
+ allow(cop).to receive(:in_qa_file?).and_return(false)
+ end
+
+ it "does not register an offense" do
+ expect_no_offenses(<<-RUBY)
+ Page::Object.perform do |page|
+ page.do_something
+ end
+ RUBY
+ end
+ end
+end