...@@ -6,9 +6,9 @@ describe GitlabSchema.types['RootStorageStatistics'] do ...@@ -6,9 +6,9 @@ describe GitlabSchema.types['RootStorageStatistics'] do
it { expect(described_class.graphql_name).to eq('RootStorageStatistics') } it { expect(described_class.graphql_name).to eq('RootStorageStatistics') }
it 'has all the required fields' do it 'has all the required fields' do
is_expected.to have_graphql_fields(:storage_size, :repository_size, :lfs_objects_size, expect(described_class).to have_graphql_fields(:storage_size, :repository_size, :lfs_objects_size,
:build_artifacts_size, :packages_size, :wiki_size) :build_artifacts_size, :packages_size, :wiki_size)
end end
it { is_expected.to require_graphql_authorizations(:read_statistics) } it { expect(described_class).to require_graphql_authorizations(:read_statistics) }
end end
...@@ -10,7 +10,7 @@ describe GitlabSchema.types['Snippet'] do ...@@ -10,7 +10,7 @@ describe GitlabSchema.types['Snippet'] do
:web_url, :raw_url, :notes, :discussions, :web_url, :raw_url, :notes, :discussions,
:user_permissions, :description_html, :blob] :user_permissions, :description_html, :blob]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
describe 'authorizations' do describe 'authorizations' do
... ...
......
...@@ -8,6 +8,6 @@ describe GitlabSchema.types['SnippetBlob'] do ...@@ -8,6 +8,6 @@ describe GitlabSchema.types['SnippetBlob'] do
:raw_path, :size, :binary, :name, :path, :raw_path, :size, :binary, :name, :path,
:simple_viewer, :rich_viewer, :mode] :simple_viewer, :rich_viewer, :mode]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
end end
...@@ -7,6 +7,6 @@ describe GitlabSchema.types['SnippetBlobViewer'] do ...@@ -7,6 +7,6 @@ describe GitlabSchema.types['SnippetBlobViewer'] do
expected_fields = [:type, :load_async, :too_large, :collapsed, expected_fields = [:type, :load_async, :too_large, :collapsed,
:render_error, :file_type, :loading_partial_name] :render_error, :file_type, :loading_partial_name]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
end end
...@@ -6,7 +6,7 @@ describe GitlabSchema.types['Todo'] do ...@@ -6,7 +6,7 @@ describe GitlabSchema.types['Todo'] do
it 'has the correct fields' do it 'has the correct fields' do
expected_fields = [:id, :project, :group, :author, :action, :target_type, :body, :state, :created_at] expected_fields = [:id, :project, :group, :author, :action, :target_type, :body, :state, :created_at]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
it { expect(described_class).to require_graphql_authorizations(:read_todo) } it { expect(described_class).to require_graphql_authorizations(:read_todo) }
... ...
......
...@@ -12,7 +12,7 @@ describe GitlabSchema.types['User'] do ...@@ -12,7 +12,7 @@ describe GitlabSchema.types['User'] do
user_permissions snippets name username avatarUrl webUrl todos user_permissions snippets name username avatarUrl webUrl todos
] ]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
describe 'snippets field' do describe 'snippets field' do
... ...
......
...@@ -42,7 +42,7 @@ describe Feature do ...@@ -42,7 +42,7 @@ describe Feature do
.once .once
.and_call_original .and_call_original
expect(Gitlab::ThreadMemoryCache.cache_backend) expect(Gitlab::ProcessMemoryCache.cache_backend)
.to receive(:fetch) .to receive(:fetch)
.once .once
.with('flipper:persisted_names', expires_in: 1.minute) .with('flipper:persisted_names', expires_in: 1.minute)
... ...
......
...@@ -17,7 +17,7 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do ...@@ -17,7 +17,7 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do
allow(cop).to receive(:in_migration?).and_return(true) allow(cop).to receive(:in_migration?).and_return(true)
end end
described_class::SMALL_TABLES.each do |table| described_class::WHITELISTED_TABLES.each do |table|
context "for the #{table} table" do context "for the #{table} table" do
sources_and_offense = [ sources_and_offense = [
["add_column :#{table}, :column, :boolean, default: true", 'should disallow nulls'], ["add_column :#{table}, :column, :boolean, default: true", 'should disallow nulls'],
...@@ -62,14 +62,14 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do ...@@ -62,14 +62,14 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do
end end
end end
it 'registers no offense for tables not listed in SMALL_TABLES' do it 'registers no offense for tables not listed in WHITELISTED_TABLES' do
inspect_source("add_column :large_table, :column, :boolean") inspect_source("add_column :large_table, :column, :boolean")
expect(cop.offenses).to be_empty expect(cop.offenses).to be_empty
end end
it 'registers no offense for non-boolean columns' do it 'registers no offense for non-boolean columns' do
table = described_class::SMALL_TABLES.sample table = described_class::WHITELISTED_TABLES.sample
inspect_source("add_column :#{table}, :column, :string") inspect_source("add_column :#{table}, :column, :string")
expect(cop.offenses).to be_empty expect(cop.offenses).to be_empty
...@@ -78,7 +78,7 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do ...@@ -78,7 +78,7 @@ describe RuboCop::Cop::Migration::SaferBooleanColumn do
context 'outside of migration' do context 'outside of migration' do
it 'registers no offense' do it 'registers no offense' do
table = described_class::SMALL_TABLES.sample table = described_class::WHITELISTED_TABLES.sample
inspect_source("add_column :#{table}, :column, :boolean") inspect_source("add_column :#{table}, :column, :boolean")
expect(cop.offenses).to be_empty expect(cop.offenses).to be_empty
... ...
......
...@@ -18,7 +18,7 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do ...@@ -18,7 +18,7 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do
end end
shared_examples 'large tables' do |update_method| shared_examples 'large tables' do |update_method|
described_class::LARGE_TABLES.each do |table| described_class::BLACKLISTED_TABLES.each do |table|
it "registers an offense for the #{table} table" do it "registers an offense for the #{table} table" do
inspect_source("#{update_method} :#{table}, :column, default: true") inspect_source("#{update_method} :#{table}, :column, default: true")
...@@ -53,7 +53,7 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do ...@@ -53,7 +53,7 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do
end end
it 'registers no offense for non-blacklisted methods' do it 'registers no offense for non-blacklisted methods' do
table = described_class::LARGE_TABLES.sample table = described_class::BLACKLISTED_TABLES.sample
inspect_source("some_other_method :#{table}, :column, default: true") inspect_source("some_other_method :#{table}, :column, default: true")
...@@ -62,7 +62,7 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do ...@@ -62,7 +62,7 @@ describe RuboCop::Cop::Migration::UpdateLargeTable do
end end
context 'outside of migration' do context 'outside of migration' do
let(:table) { described_class::LARGE_TABLES.sample } let(:table) { described_class::BLACKLISTED_TABLES.sample }
it 'registers no offense for add_column_with_default' do it 'registers no offense for add_column_with_default' do
inspect_source("add_column_with_default :#{table}, :column, default: true") inspect_source("add_column_with_default :#{table}, :column, default: true")
... ...
......
...@@ -71,10 +71,10 @@ module GraphqlHelpers ...@@ -71,10 +71,10 @@ module GraphqlHelpers
mutation_name = GraphqlHelpers.fieldnamerize(name) mutation_name = GraphqlHelpers.fieldnamerize(name)
input_variable_name = "$#{input_variable_name_for_mutation(name)}" input_variable_name = "$#{input_variable_name_for_mutation(name)}"
mutation_field = GitlabSchema.mutation.fields[mutation_name] mutation_field = GitlabSchema.mutation.fields[mutation_name]
fields ||= all_graphql_fields_for(mutation_field.type) fields ||= all_graphql_fields_for(mutation_field.type.to_graphql)
query = <<~MUTATION query = <<~MUTATION
mutation(#{input_variable_name}: #{mutation_field.arguments['input'].type}) { mutation(#{input_variable_name}: #{mutation_field.arguments['input'].type.to_graphql}) {
#{mutation_name}(input: #{input_variable_name}) { #{mutation_name}(input: #{input_variable_name}) {
#{fields} #{fields}
} }
...@@ -118,15 +118,22 @@ module GraphqlHelpers ...@@ -118,15 +118,22 @@ module GraphqlHelpers
GraphqlHelpers.fieldnamerize(input_type) GraphqlHelpers.fieldnamerize(input_type)
end end
def query_graphql_field(name, attributes = {}, fields = nil) def field_with_params(name, attributes = {})
field_params = if attributes.present? namerized = GraphqlHelpers.fieldnamerize(name.to_s)
return "#{namerized}" if attributes.blank?
field_params = if attributes.is_a?(Hash)
"(#{attributes_to_graphql(attributes)})" "(#{attributes_to_graphql(attributes)})"
else else
'' "(#{attributes})"
end end
"#{namerized}#{field_params}"
end
def query_graphql_field(name, attributes = {}, fields = nil)
<<~QUERY <<~QUERY
#{GraphqlHelpers.fieldnamerize(name.to_s)}#{field_params} #{field_with_params(name, attributes)}
#{wrap_fields(fields || all_graphql_fields_for(name.to_s.classify))} #{wrap_fields(fields || all_graphql_fields_for(name.to_s.classify))}
QUERY QUERY
end end
...@@ -300,7 +307,7 @@ module GraphqlHelpers ...@@ -300,7 +307,7 @@ module GraphqlHelpers
end end
def field_type(field) def field_type(field)
field_type = field.type field_type = field.type.respond_to?(:to_graphql) ? field.type.to_graphql : field.type
# The type could be nested. For example `[GraphQL::STRING_TYPE]`: # The type could be nested. For example `[GraphQL::STRING_TYPE]`:
# - List # - List
... ...
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
RSpec::Matchers.define :require_graphql_authorizations do |*expected| RSpec::Matchers.define :require_graphql_authorizations do |*expected|
match do |field| match do |field|
expect(field.metadata[:authorize]).to eq(*expected) expect(field.to_graphql.metadata[:authorize]).to eq(*expected)
end end
end end
...@@ -87,13 +87,13 @@ end ...@@ -87,13 +87,13 @@ end
RSpec::Matchers.define :have_graphql_type do |expected| RSpec::Matchers.define :have_graphql_type do |expected|
match do |field| match do |field|
expect(field.type).to eq(expected.to_graphql) expect(field.type).to eq(expected)
end end
end end
RSpec::Matchers.define :have_non_null_graphql_type do |expected| RSpec::Matchers.define :have_non_null_graphql_type do |expected|
match do |field| match do |field|
expect(field.type).to eq(!expected.to_graphql) expect(field.type.to_graphql).to eq(!expected.to_graphql)
end end
end end
...@@ -101,16 +101,16 @@ RSpec::Matchers.define :have_graphql_resolver do |expected| ...@@ -101,16 +101,16 @@ RSpec::Matchers.define :have_graphql_resolver do |expected|
match do |field| match do |field|
case expected case expected
when Method when Method
expect(field.metadata[:type_class].resolve_proc).to eq(expected) expect(field.to_graphql.metadata[:type_class].resolve_proc).to eq(expected)
else else
expect(field.metadata[:type_class].resolver).to eq(expected) expect(field.to_graphql.metadata[:type_class].resolver).to eq(expected)
end end
end end
end end
RSpec::Matchers.define :have_graphql_extension do |expected| RSpec::Matchers.define :have_graphql_extension do |expected|
match do |field| match do |field|
expect(field.metadata[:type_class].extensions).to include(expected) expect(field.to_graphql.metadata[:type_class].extensions).to include(expected)
end end
end end
... ...
......
...@@ -15,7 +15,7 @@ RSpec.shared_context 'group and project boards query context' do ...@@ -15,7 +15,7 @@ RSpec.shared_context 'group and project boards query context' do
board_parent_type, board_parent_type,
{ 'fullPath' => board_parent.full_path }, { 'fullPath' => board_parent.full_path },
<<~BOARDS <<~BOARDS
boards(#{board_params}) { #{field_with_params('boards', board_params)} {
pageInfo { pageInfo {
startCursor startCursor
endCursor endCursor
...@@ -35,7 +35,7 @@ RSpec.shared_context 'group and project boards query context' do ...@@ -35,7 +35,7 @@ RSpec.shared_context 'group and project boards query context' do
board_parent_type, board_parent_type,
{ 'fullPath' => board_parent.full_path }, { 'fullPath' => board_parent.full_path },
<<~BOARD <<~BOARD
board(#{board_params}) { #{field_with_params('board', board_params)} {
#{all_graphql_fields_for('board'.classify)} #{all_graphql_fields_for('board'.classify)}
} }
BOARD BOARD
... ...
......