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:
Diffstat (limited to 'spec/support_specs/helpers')
-rw-r--r--spec/support_specs/helpers/active_record/query_recorder_spec.rb10
-rw-r--r--spec/support_specs/helpers/graphql_helpers_spec.rb75
-rw-r--r--spec/support_specs/helpers/migrations_helpers_spec.rb74
-rw-r--r--spec/support_specs/helpers/stub_feature_flags_spec.rb12
4 files changed, 161 insertions, 10 deletions
diff --git a/spec/support_specs/helpers/active_record/query_recorder_spec.rb b/spec/support_specs/helpers/active_record/query_recorder_spec.rb
index f1af9ceffb9..d6c52b22449 100644
--- a/spec/support_specs/helpers/active_record/query_recorder_spec.rb
+++ b/spec/support_specs/helpers/active_record/query_recorder_spec.rb
@@ -78,12 +78,14 @@ RSpec.describe ActiveRecord::QueryRecorder do
end
describe 'detecting the right number of calls and their origin' do
- it 'detects two separate queries' do
- control = ActiveRecord::QueryRecorder.new query_recorder_debug: true do
+ let(:control) do
+ ActiveRecord::QueryRecorder.new query_recorder_debug: true do
2.times { TestQueries.count }
TestQueries.first
end
+ end
+ it 'detects two separate queries' do
# Check #find_query
expect(control.find_query(/.*/, 0).size)
.to eq(control.data.keys.size)
@@ -98,8 +100,8 @@ RSpec.describe ActiveRecord::QueryRecorder do
expect(control.log.size).to eq(3)
# Ensure memoization value match the raw value above
expect(control.count).to eq(control.log.size)
- # Ensure we have only two sources of queries
- expect(control.data.keys.size).to eq(1)
+ # Ensure we have two sources of queries
+ expect(control.data.keys.size).to eq(2)
end
end
end
diff --git a/spec/support_specs/helpers/graphql_helpers_spec.rb b/spec/support_specs/helpers/graphql_helpers_spec.rb
index fae29ec32f5..f567097af6f 100644
--- a/spec/support_specs/helpers/graphql_helpers_spec.rb
+++ b/spec/support_specs/helpers/graphql_helpers_spec.rb
@@ -10,6 +10,81 @@ RSpec.describe GraphqlHelpers do
query.tr("\n", ' ').gsub(/\s+/, ' ').strip
end
+ describe 'a_graphql_entity_for' do
+ context 'when no arguments are passed' do
+ it 'raises an error' do
+ expect { a_graphql_entity_for }.to raise_error(ArgumentError)
+ end
+ end
+
+ context 'when the model is nil, with no properties' do
+ it 'raises an error' do
+ expect { a_graphql_entity_for(nil) }.to raise_error(ArgumentError)
+ end
+ end
+
+ context 'when the model is nil, any fields are passed' do
+ it 'raises an error' do
+ expect { a_graphql_entity_for(nil, :username) }.to raise_error(ArgumentError)
+ end
+ end
+
+ context 'with no model' do
+ it 'behaves like hash-inclusion with camel-casing' do
+ response = { 'foo' => 1, 'bar' => 2, 'camelCased' => 3 }
+
+ expect(response).to match a_graphql_entity_for(foo: 1, camel_cased: 3)
+ expect(response).not_to match a_graphql_entity_for(missing: 5)
+ end
+ end
+
+ context 'with just a model' do
+ it 'only considers the ID' do
+ user = build_stubbed(:user)
+ response = { 'username' => 'foo', 'id' => global_id_of(user).to_s }
+
+ expect(response).to match a_graphql_entity_for(user)
+ end
+ end
+
+ context 'with a model and some method names' do
+ it 'also considers the method names' do
+ user = build_stubbed(:user)
+ response = { 'username' => user.username, 'id' => global_id_of(user).to_s }
+
+ expect(response).to match a_graphql_entity_for(user, :username)
+ expect(response).not_to match a_graphql_entity_for(user, :name)
+ end
+ end
+
+ context 'with a model and some other properties' do
+ it 'behaves like the superset' do
+ user = build_stubbed(:user)
+ response = { 'username' => 'foo', 'id' => global_id_of(user).to_s }
+
+ expect(response).to match a_graphql_entity_for(user, username: 'foo')
+ expect(response).not_to match a_graphql_entity_for(user, name: 'foo')
+ end
+ end
+
+ context 'with a model, method names, and some other properties' do
+ it 'behaves like the superset' do
+ user = build_stubbed(:user)
+ response = {
+ 'username' => user.username,
+ 'name' => user.name,
+ 'foo' => 'bar',
+ 'baz' => 'fop',
+ 'id' => global_id_of(user).to_s
+ }
+
+ expect(response).to match a_graphql_entity_for(user, :username, :name, foo: 'bar')
+ expect(response).to match a_graphql_entity_for(user, :name, foo: 'bar')
+ expect(response).not_to match a_graphql_entity_for(user, :name, bar: 'foo')
+ end
+ end
+ end
+
describe 'graphql_dig_at' do
it 'transforms symbol keys to graphql field names' do
data = { 'camelCased' => 'names' }
diff --git a/spec/support_specs/helpers/migrations_helpers_spec.rb b/spec/support_specs/helpers/migrations_helpers_spec.rb
new file mode 100644
index 00000000000..b82eddad9bc
--- /dev/null
+++ b/spec/support_specs/helpers/migrations_helpers_spec.rb
@@ -0,0 +1,74 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe MigrationsHelpers do
+ let(:helper_class) do
+ Class.new.tap do |klass|
+ klass.include described_class
+ allow(klass).to receive(:metadata).and_return(metadata)
+ end
+ end
+
+ let(:metadata) { {} }
+ let(:helper) { helper_class.new }
+
+ describe '#active_record_base' do
+ it 'returns the main base model' do
+ expect(helper.active_record_base).to eq(ActiveRecord::Base)
+ end
+
+ context 'ci database configured' do
+ before do
+ skip_if_multiple_databases_not_setup
+ end
+
+ it 'returns the CI base model' do
+ expect(helper.active_record_base(database: :ci)).to eq(Ci::ApplicationRecord)
+ end
+ end
+
+ context 'ci database not configured' do
+ before do
+ skip_if_multiple_databases_are_setup
+ end
+
+ it 'returns the main base model' do
+ expect(helper.active_record_base(database: :ci)).to eq(ActiveRecord::Base)
+ end
+ end
+
+ it 'raises ArgumentError for bad database argument' do
+ expect { helper.active_record_base(database: :non_existent) }.to raise_error(ArgumentError)
+ end
+ end
+
+ describe '#table' do
+ it 'creates a class based on main base model' do
+ klass = helper.table(:projects)
+ expect(klass.connection_specification_name).to eq('ActiveRecord::Base')
+ end
+
+ context 'ci database configured' do
+ before do
+ skip_if_multiple_databases_not_setup
+ end
+
+ it 'create a class based on the CI base model' do
+ klass = helper.table(:ci_builds, database: :ci)
+ expect(klass.connection_specification_name).to eq('Ci::ApplicationRecord')
+ end
+ end
+
+ context 'ci database not configured' do
+ before do
+ skip_if_multiple_databases_are_setup
+ end
+
+ it 'creates a class based on main base model' do
+ klass = helper.table(:ci_builds, database: :ci)
+ expect(klass.connection_specification_name).to eq('ActiveRecord::Base')
+ end
+ end
+ end
+end
diff --git a/spec/support_specs/helpers/stub_feature_flags_spec.rb b/spec/support_specs/helpers/stub_feature_flags_spec.rb
index 9b35fe35259..a59d8a20a40 100644
--- a/spec/support_specs/helpers/stub_feature_flags_spec.rb
+++ b/spec/support_specs/helpers/stub_feature_flags_spec.rb
@@ -47,13 +47,13 @@ RSpec.describe StubFeatureFlags do
it { expect(Feature.enabled?(feature_name)).to eq(expected_result) }
it { expect(Feature.disabled?(feature_name)).not_to eq(expected_result) }
- context 'default_enabled does not impact feature state' do
+ context 'default_enabled_if_undefined does not impact feature state' do
before do
allow(dummy_definition).to receive(:default_enabled).and_return(true)
end
- it { expect(Feature.enabled?(feature_name, default_enabled: true)).to eq(expected_result) }
- it { expect(Feature.disabled?(feature_name, default_enabled: true)).not_to eq(expected_result) }
+ it { expect(Feature.enabled?(feature_name, default_enabled_if_undefined: true)).to eq(expected_result) }
+ it { expect(Feature.disabled?(feature_name, default_enabled_if_undefined: true)).not_to eq(expected_result) }
end
end
end
@@ -83,13 +83,13 @@ RSpec.describe StubFeatureFlags do
it { expect(Feature.enabled?(feature_name, actor(tested_actor))).to eq(expected_result) }
it { expect(Feature.disabled?(feature_name, actor(tested_actor))).not_to eq(expected_result) }
- context 'default_enabled does not impact feature state' do
+ context 'default_enabled_if_undefined does not impact feature state' do
before do
allow(dummy_definition).to receive(:default_enabled).and_return(true)
end
- it { expect(Feature.enabled?(feature_name, actor(tested_actor), default_enabled: true)).to eq(expected_result) }
- it { expect(Feature.disabled?(feature_name, actor(tested_actor), default_enabled: true)).not_to eq(expected_result) }
+ it { expect(Feature.enabled?(feature_name, actor(tested_actor), default_enabled_if_undefined: true)).to eq(expected_result) }
+ it { expect(Feature.disabled?(feature_name, actor(tested_actor), default_enabled_if_undefined: true)).not_to eq(expected_result) }
end
end
end