Skip to content

Commit

Permalink
Merge pull request #42 from code0-tech/aggregate-failures-as-derived-…
Browse files Browse the repository at this point in the history
…metadata

Define aggregate_failures as derived metadata
  • Loading branch information
Taucher2003 authored Jan 9, 2024
2 parents f70cd06 + a0639c5 commit fb73b80
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 53 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ RSpec/ExpectChange:
RSpec/ImplicitSubject:
EnforcedStyle: require_implicit

# aggregate_failures is defined with derived metadata for every spec
RSpec/MultipleExpectations:
Enabled: false

RSpec/MultipleMemoizedHelpers:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion spec/graphql/types/user_session_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

before { post_graphql query, headers: { authorization: "Session #{session.token}" } }

it 'does not expose token', :aggregate_failures do
it 'does not expose token' do
expect(graphql_data_at(:current_authorization, :__typename)).to eq('UserSession')
expect(graphql_data_at(:current_authorization, :id)).to eq(session.to_global_id.to_s)
expect(graphql_data_at(:current_authorization, :token)).to be_nil
Expand Down
16 changes: 8 additions & 8 deletions spec/lib/sagittarius/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe Sagittarius::Context do
describe '.with_context' do
it 'builds a context with values from the previous one', :aggregate_failures do
it 'builds a context with values from the previous one' do
inner = nil
outer = nil

Expand All @@ -19,7 +19,7 @@
expect(data_from(inner)).to eq(log_hash(described_class::CORRELATION_ID_KEY => 'hello', 'user' => 'username'))
end

it 'builds a context with overwritten key/values in the newer context', :aggregate_failures do
it 'builds a context with overwritten key/values in the newer context' do
inner = nil
outer = nil

Expand All @@ -46,7 +46,7 @@
end
end

it 'pops the context from the stack when the block fails', :aggregate_failures do
it 'pops the context from the stack when the block fails' do
expect { described_class.with_context { |_| raise('broken') } }.to raise_error('broken')

expect(contexts).to be_empty
Expand Down Expand Up @@ -104,7 +104,7 @@
described_class.pop(root_context)
end

it 'returns the last context', :aggregate_failures do
it 'returns the last context' do
expect(described_class.current).to eq(root_context)

new_context = described_class.push
Expand Down Expand Up @@ -194,7 +194,7 @@
end

describe '#merge' do
it 'returns a new context with duplicated data', :aggregate_failures do
it 'returns a new context with duplicated data' do
context = described_class.new(user: 'user')

new_context = context.merge({})
Expand All @@ -211,7 +211,7 @@
expect(data_from(new_context)).to include(log_hash('root_namespace' => 'namespace', 'user' => 'u'))
end

it 'removes empty values', :aggregate_failures do
it 'removes empty values' do
context = described_class.new(project: 'p', root_namespace: 'n', user: 'u')

new_context = context.merge(project: '', user: nil)
Expand All @@ -221,7 +221,7 @@
described_class.log_key('user'))
end

it 'keeps false values', :aggregate_failures do
it 'keeps false values' do
context = described_class.new(project: 'p', root_namespace: 'n', flag: false)

new_context = context.merge(project: '', false: nil) # rubocop:disable Lint/BooleanSymbol -- intended for this spec
Expand All @@ -238,7 +238,7 @@
expect(new_context.correlation_id).to eq('hello')
end

it 'generates a new correlation id if a blank one was passed', :aggregate_failures do
it 'generates a new correlation id if a blank one was passed' do
context = described_class.new
old_correlation_id = context.correlation_id

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def original_dump_schema_information; end

let(:instance) { instance_class.new }

it 'calls SchemaMigrations touch_all and skips original implementation', :aggregate_failures do
it 'calls SchemaMigrations touch_all and skips original implementation' do
allow(Sagittarius::Database::SchemaMigrations).to receive(:touch_all)
allow(instance).to receive(:original_dump_schema_information)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def connection; end

let(:instance) { instance_class.new }

it 'calls SchemaMigrations load_all', :aggregate_failures do
it 'calls SchemaMigrations load_all' do
connection = double('connection') # rubocop:disable RSpec/VerifiedDoubles -- we don't need an actual connection here
allow(instance).to receive(:connection).and_return(connection)
allow(instance).to receive(:original_structure_load)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

let(:relative_schema_directory) { 'db/schema_migrations' }

it 'creates a file containing a checksum for each version with a matching migration', :aggregate_failures do
it 'creates a file containing a checksum for each version with a matching migration' do
Dir.mktmpdir do |tmpdir|
schema_directory = Pathname.new(tmpdir).join(relative_schema_directory)
FileUtils.mkdir_p(schema_directory)
Expand Down Expand Up @@ -65,7 +65,7 @@
context 'when there are no version files' do
let(:filenames) { [] }

it 'does nothing', :aggregate_failures do
it 'does nothing' do
allow(connection).to receive(:quote_string)
allow(connection).to receive(:execute)

Expand All @@ -76,7 +76,7 @@
end
end

context 'when there are version files', :aggregate_failures do
context 'when there are version files' do
let(:filenames) { %w[123 456 789] }

it 'inserts the missing versions into schema_migrations' do
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/sagittarius/database/transactional_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
expect(described_class.transactional { 1 }).to eq(1)
end

it 'can return and rollback', :aggregate_failures do
it 'can return and rollback' do
user = nil
expect(described_class.transactional do |helper|
user = create(:user)
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/sagittarius/middleware/rack/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
expect(app).to have_received(:call).with(env)
end

it 'injects meta headers', :aggregate_failures do
it 'injects meta headers' do
Sagittarius::Context.push(metadata)

allow(app).to receive(:call).with(env).and_return([nil, {}, nil])
Expand Down
10 changes: 5 additions & 5 deletions spec/lib/sagittarius/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

RSpec.describe Sagittarius::Utils do
describe '.to_boolean' do
it 'accepts booleans', :aggregate_failures do
it 'accepts booleans' do
expect(described_class.to_boolean(true)).to be(true)
expect(described_class.to_boolean(false)).to be(false)
end

it 'converts a valid value to a boolean', :aggregate_failures do
it 'converts a valid value to a boolean' do
expect(described_class.to_boolean(true)).to be(true)
expect(described_class.to_boolean('true')).to be(true)
expect(described_class.to_boolean('YeS')).to be(true)
Expand All @@ -28,14 +28,14 @@
expect(described_class.to_boolean('oFF')).to be(false)
end

it 'converts an invalid value to nil', :aggregate_failures do
it 'converts an invalid value to nil' do
expect(described_class.to_boolean('fals')).to be_nil
expect(described_class.to_boolean('yeah')).to be_nil
expect(described_class.to_boolean('')).to be_nil
expect(described_class.to_boolean(nil)).to be_nil
end

it 'accepts a default value, and does not return it when a valid value is given', :aggregate_failures do
it 'accepts a default value, and does not return it when a valid value is given' do
expect(described_class.to_boolean(true, default: false)).to be(true)
expect(described_class.to_boolean('true', default: false)).to be(true)
expect(described_class.to_boolean('YeS', default: false)).to be(true)
Expand All @@ -51,7 +51,7 @@
expect(described_class.to_boolean('oFF', default: 42)).to be(false)
end

it 'accepts a default value, and returns it when an invalid value is given', :aggregate_failures do
it 'accepts a default value, and returns it when an invalid value is given' do
expect(described_class.to_boolean('fals', default: true)).to be(true)
expect(described_class.to_boolean('yeah', default: false)).to be(false)
expect(described_class.to_boolean('', default: 'any value')).to eq('any value')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

before { post_graphql mutation, variables: variables, current_user: current_user }

it 'updates application settings', :aggregate_failures do
it 'updates application settings' do
expect(graphql_data_at(:application_settings_update, :application_settings)).to be_present
expect(graphql_data_at(:application_settings_update, :application_settings, :user_registration_enabled)).to be false

Expand All @@ -42,7 +42,7 @@
context 'when user is not an admin' do
let(:current_user) { create(:user) }

it 'returns an error', :aggregate_failures do
it 'returns an error' do
expect(graphql_data_at(:application_settings_update, :application_settings)).to be_nil
expect(graphql_data_at(:application_settings_update, :errors)).to include('message' => 'permission_missing')
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
create(:team_member, team: team, user: current_user)
end

it 'creates team role', :aggregate_failures do
it 'creates team role' do
mutate!

expect(graphql_data_at(:team_roles_create, :team_role, :id)).to be_present
Expand All @@ -67,7 +67,7 @@
let(:team_role) { create(:team_role, team: team) }
let(:input) { { teamId: team.to_global_id.to_s, name: team_role.name } }

it 'returns an error', :aggregate_failures do
it 'returns an error' do
mutate!

expect(graphql_data_at(:team_roles_create, :team_role)).to be_nil
Expand All @@ -78,7 +78,7 @@
context 'when team role name is taken in another team' do
let(:other_team) { create(:team).tap { |t| create(:team_role, team: t, name: input[:name]) } }

it 'creates team role', :aggregate_failures do
it 'creates team role' do
mutate!

expect(graphql_data_at(:team_roles_create, :team_role, :id)).to be_present
Expand All @@ -102,7 +102,7 @@
end

context 'when user is not a member of the team' do
it 'returns an error', :aggregate_failures do
it 'returns an error' do
mutate!

expect(graphql_data_at(:team_roles_create, :team_role)).to be_nil
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/graphql/mutation/teams/create_mutation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

before { post_graphql mutation, variables: variables, current_user: current_user }

it 'creates team', :aggregate_failures do
it 'creates team' do
expect(graphql_data_at(:teams_create, :team, :id)).to be_present

team = SagittariusSchema.object_from_id(graphql_data_at(:teams_create, :team, :id))
Expand All @@ -54,7 +54,7 @@
let(:team) { create(:team) }
let(:input) { { name: team.name } }

it 'returns an error', :aggregate_failures do
it 'returns an error' do
expect(graphql_data_at(:teams_create, :team)).to be_nil
expect(graphql_data_at(:teams_create, :errors)).to include({ 'attribute' => 'name', 'type' => 'taken' })
end
Expand Down
12 changes: 6 additions & 6 deletions spec/requests/graphql/mutation/users/login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
}
end

it 'creates the user session', :aggregate_failures do
it 'creates the user session' do
expect(graphql_data_at(:users_login, :user_session, :id)).to be_present
expect(graphql_data_at(:users_login, :user_session, :token)).to be_present

Expand All @@ -64,7 +64,7 @@
}
end

it 'creates the user session', :aggregate_failures do
it 'creates the user session' do
expect(graphql_data_at(:users_login, :user_session, :id)).to be_present
expect(graphql_data_at(:users_login, :user_session, :token)).to be_present

Expand Down Expand Up @@ -94,7 +94,7 @@
}
end

it 'returns errors', :aggregate_failures do
it 'returns errors' do
expect(graphql_data_at(:users_login, :user_session)).not_to be_present

expect(graphql_errors).to include(
Expand All @@ -111,7 +111,7 @@
}
end

it 'returns errors', :aggregate_failures do
it 'returns errors' do
expect(graphql_data_at(:users_login, :user_session)).not_to be_present

expect(graphql_data_at(:users_login, :errors, :message)).to include('invalid_login_data')
Expand All @@ -126,7 +126,7 @@
}
end

it 'returns errors', :aggregate_failures do
it 'returns errors' do
expect(graphql_data_at(:users_login, :user_session)).not_to be_present

expect(graphql_data_at(:users_login, :errors, :message)).to include('invalid_login_data')
Expand All @@ -141,7 +141,7 @@
}
end

it 'returns errors', :aggregate_failures do
it 'returns errors' do
expect(graphql_data_at(:users_login, :user_session)).not_to be_present

expect(graphql_data_at(:users_login, :errors, :message)).to include('invalid_login_data')
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/graphql/mutation/users/logout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
context 'when logging out a session of the same user' do
let(:current_user) { user_session.user }

it 'logs out the session', :aggregate_failures do
it 'logs out the session' do
expect(graphql_data_at(:users_logout, :user_session, :id)).to eq(user_session_id)
expect(graphql_data_at(:users_logout, :user_session, :active)).to be(false)
end
Expand All @@ -41,7 +41,7 @@
context 'when logging out a session of another user' do
let(:current_user) { create(:user) }

it 'does not log out the session', :aggregate_failures do
it 'does not log out the session' do
expect(graphql_data_at(:users_logout, :errors, :message)).to include('missing_permission')
expect(graphql_data_at(:users_logout, :user_session)).to be_nil
end
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/graphql/mutation/users/register_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

before { post_graphql mutation, variables: variables }

it 'creates the user', :aggregate_failures do
it 'creates the user' do
expect(graphql_data_at(:users_register, :user, :id)).to be_present

user = SagittariusSchema.object_from_id(graphql_data_at(:users_register, :user, :id))
Expand All @@ -56,7 +56,7 @@
}
end

it 'returns errors', :aggregate_failures do
it 'returns errors' do
expect(graphql_data_at(:users_register, :user)).not_to be_present

expect(graphql_data_at(:users_register, :errors)).to include(
Expand Down
Loading

0 comments on commit fb73b80

Please sign in to comment.