diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/finders/projects_finder_spec.rb | 18 | ||||
-rw-r--r-- | spec/requests/api/api_spec.rb | 8 | ||||
-rw-r--r-- | spec/rubocop/cop/migration/datetime_spec.rb | 138 |
3 files changed, 135 insertions, 29 deletions
diff --git a/spec/finders/projects_finder_spec.rb b/spec/finders/projects_finder_spec.rb index 626517f8fa0..379cbe83a08 100644 --- a/spec/finders/projects_finder_spec.rb +++ b/spec/finders/projects_finder_spec.rb @@ -85,6 +85,24 @@ describe ProjectsFinder, :do_not_mock_admin_mode do end end + describe 'regression: Combination of id_before/id_after and joins requires fully qualified column names' do + context 'only returns projects with a project id less than given and matching search' do + subject { finder.execute.joins(:route) } + + let(:params) { { id_before: public_project.id }} + + it { is_expected.to eq([internal_project]) } + end + + context 'only returns projects with a project id greater than given and matching search' do + subject { finder.execute.joins(:route) } + + let(:params) { { id_after: internal_project.id }} + + it { is_expected.to eq([public_project]) } + end + end + describe 'filter by visibility_level' do before do private_project.add_maintainer(user) diff --git a/spec/requests/api/api_spec.rb b/spec/requests/api/api_spec.rb index c794db4cb0b..baebbbce631 100644 --- a/spec/requests/api/api_spec.rb +++ b/spec/requests/api/api_spec.rb @@ -13,13 +13,5 @@ describe API::API do it 'updates the users last_activity_on date' do expect { get api('/groups', user) }.to change { user.reload.last_activity_on }.to(Date.today) end - - context 'when the the api_activity_logging feature is disabled' do - it 'does not touch last_activity_on' do - stub_feature_flags(api_activity_logging: false) - - expect { get api('/groups', user) }.not_to change { user.reload.last_activity_on } - end - end end end diff --git a/spec/rubocop/cop/migration/datetime_spec.rb b/spec/rubocop/cop/migration/datetime_spec.rb index 0a771003100..e3023406dce 100644 --- a/spec/rubocop/cop/migration/datetime_spec.rb +++ b/spec/rubocop/cop/migration/datetime_spec.rb @@ -12,9 +12,69 @@ describe RuboCop::Cop::Migration::Datetime do subject(:cop) { described_class.new } - let(:migration_with_datetime) do + let(:create_table_migration_with_datetime) do %q( - class Users < ActiveRecord::Migration[4.2] + class Users < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + create_table :users do |t| + t.string :username, null: false + t.datetime :last_sign_in + end + end + end + ) + end + + let(:create_table_migration_with_timestamp) do + %q( + class Users < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + create_table :users do |t| + t.string :username, null: false + t.timestamp :last_sign_in + end + end + end + ) + end + + let(:create_table_migration_without_datetime) do + %q( + class Users < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + create_table :users do |t| + t.string :username, null: false + t.string :password + end + end + end + ) + end + + let(:create_table_migration_with_datetime_with_timezone) do + %q( + class Users < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def change + create_table :users do |t| + t.string :username, null: false + t.datetime_with_timezone :last_sign_in + end + end + end + ) + end + + let(:add_column_migration_with_datetime) do + %q( + class Users < ActiveRecord::Migration[6.0] DOWNTIME = false def change @@ -25,9 +85,9 @@ describe RuboCop::Cop::Migration::Datetime do ) end - let(:migration_with_timestamp) do + let(:add_column_migration_with_timestamp) do %q( - class Users < ActiveRecord::Migration[4.2] + class Users < ActiveRecord::Migration[6.0] DOWNTIME = false def change @@ -38,9 +98,9 @@ describe RuboCop::Cop::Migration::Datetime do ) end - let(:migration_without_datetime) do + let(:add_column_migration_without_datetime) do %q( - class Users < ActiveRecord::Migration[4.2] + class Users < ActiveRecord::Migration[6.0] DOWNTIME = false def change @@ -50,9 +110,9 @@ describe RuboCop::Cop::Migration::Datetime do ) end - let(:migration_with_datetime_with_timezone) do + let(:add_column_migration_with_datetime_with_timezone) do %q( - class Users < ActiveRecord::Migration[4.2] + class Users < ActiveRecord::Migration[6.0] DOWNTIME = false def change @@ -68,18 +128,54 @@ describe RuboCop::Cop::Migration::Datetime do allow(cop).to receive(:in_migration?).and_return(true) end - it 'registers an offense when the ":datetime" data type is used' do - inspect_source(migration_with_datetime) + it 'registers an offense when the ":datetime" data type is used on create_table' do + inspect_source(create_table_migration_with_datetime) + + aggregate_failures do + expect(cop.offenses.size).to eq(1) + expect(cop.offenses.map(&:line)).to eq([8]) + expect(cop.offenses.first.message).to include('`datetime`') + end + end + + it 'registers an offense when the ":timestamp" data type is used on create_table' do + inspect_source(create_table_migration_with_timestamp) + + aggregate_failures do + expect(cop.offenses.size).to eq(1) + expect(cop.offenses.map(&:line)).to eq([8]) + expect(cop.offenses.first.message).to include('timestamp') + end + end + + it 'does not register an offense when the ":datetime" data type is not used on create_table' do + inspect_source(create_table_migration_without_datetime) + + aggregate_failures do + expect(cop.offenses.size).to eq(0) + end + end + + it 'does not register an offense when the ":datetime_with_timezone" data type is used on create_table' do + inspect_source(create_table_migration_with_datetime_with_timezone) + + aggregate_failures do + expect(cop.offenses.size).to eq(0) + end + end + + it 'registers an offense when the ":datetime" data type is used on add_column' do + inspect_source(add_column_migration_with_datetime) aggregate_failures do expect(cop.offenses.size).to eq(1) expect(cop.offenses.map(&:line)).to eq([7]) - expect(cop.offenses.first.message).to include('datetime') + expect(cop.offenses.first.message).to include('`datetime`') end end - it 'registers an offense when the ":timestamp" data type is used' do - inspect_source(migration_with_timestamp) + it 'registers an offense when the ":timestamp" data type is used on add_column' do + inspect_source(add_column_migration_with_timestamp) aggregate_failures do expect(cop.offenses.size).to eq(1) @@ -88,16 +184,16 @@ describe RuboCop::Cop::Migration::Datetime do end end - it 'does not register an offense when the ":datetime" data type is not used' do - inspect_source(migration_without_datetime) + it 'does not register an offense when the ":datetime" data type is not used on add_column' do + inspect_source(add_column_migration_without_datetime) aggregate_failures do expect(cop.offenses.size).to eq(0) end end - it 'does not register an offense when the ":datetime_with_timezone" data type is used' do - inspect_source(migration_with_datetime_with_timezone) + it 'does not register an offense when the ":datetime_with_timezone" data type is used on add_column' do + inspect_source(add_column_migration_with_datetime_with_timezone) aggregate_failures do expect(cop.offenses.size).to eq(0) @@ -107,10 +203,10 @@ describe RuboCop::Cop::Migration::Datetime do context 'outside of migration' do it 'registers no offense' do - inspect_source(migration_with_datetime) - inspect_source(migration_with_timestamp) - inspect_source(migration_without_datetime) - inspect_source(migration_with_datetime_with_timezone) + inspect_source(add_column_migration_with_datetime) + inspect_source(add_column_migration_with_timestamp) + inspect_source(add_column_migration_without_datetime) + inspect_source(add_column_migration_with_datetime_with_timezone) expect(cop.offenses.size).to eq(0) end |