Skip to content

Commit

Permalink
rubocop -A for spec dir
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 3, 2025
1 parent a9ae75d commit cd28e66
Show file tree
Hide file tree
Showing 62 changed files with 571 additions and 422 deletions.
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Lint/ConstantDefinitionInBlock:
Lint/EmptyBlock:
Exclude:
- "spec/**/*.rb"
- "tmp/**/*.rb"

Lint/EmptyClass:
Exclude:
Expand Down Expand Up @@ -88,6 +89,10 @@ Naming/MethodName:
Naming/MethodParameterName:
Enabled: false

Style/MutableConstant:
Exclude:
- "spec/**/*.rb"

Naming/PredicateName:
Enabled: false

Expand Down Expand Up @@ -163,6 +168,10 @@ Style/MultipleComparison:
Style/NumberedParametersLimit:
Max: 2

Style/OpenStructUse:
Exclude:
- "spec/**/*.rb"

Style/ParallelAssignment:
Enabled: false

Expand Down
26 changes: 14 additions & 12 deletions spec/integration/associations/many_to_many/custom_fks_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

RSpec.describe ROM::SQL::Associations::ManyToMany, '#call' do
include_context 'users'

before do
inferrable_relations.concat %i(puzzles puzzle_solvers)
inferrable_relations.push(:puzzles, :puzzle_solvers)
end

subject(:assoc) do
Expand Down Expand Up @@ -59,18 +61,18 @@
it 'prepares joined relations using custom FK' do
relation = assoc.().order(puzzles[:text].qualified, puzzle_solvers[:solver_id].qualified)

expect(relation.schema.map(&:to_sql_name)).
to eql([Sequel.qualify(:puzzles, :id),
Sequel.qualify(:puzzles, :text),
Sequel.qualify(:puzzle_solvers, :solver_id)])
expect(relation.schema.map(&:to_sql_name)).to eql([
Sequel.qualify(:puzzles, :id),
Sequel.qualify(:puzzles, :text),
Sequel.qualify(:puzzle_solvers, :solver_id)
])

expect(relation.to_a).
to eql([
{ id: 1, solver_id: 2, text: 'P1' },
{ id: 2, solver_id: 1, text: 'P2' },
{ id: 2, solver_id: 2, text: 'P2' },
{ id: 3, solver_id: 1, text: 'P3' }
])
expect(relation.to_a).to eql([
{ id: 1, solver_id: 2, text: 'P1' },
{ id: 2, solver_id: 1, text: 'P2' },
{ id: 2, solver_id: 2, text: 'P2' },
{ id: 3, solver_id: 1, text: 'P3' }
])
end
end
end
26 changes: 14 additions & 12 deletions spec/integration/associations/many_to_many/from_view_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

RSpec.describe ROM::SQL::Associations::ManyToMany, '#call' do
include_context 'users'

before do
inferrable_relations.concat %i(puzzles puzzle_solvers)
inferrable_relations.push(:puzzles, :puzzle_solvers)
end

subject(:assoc) do
Expand Down Expand Up @@ -72,17 +74,17 @@
it 'prepares joined relations using custom FK' do
relation = assoc.().order(puzzles[:text].qualified, puzzle_solvers[:user_id].qualified)

expect(relation.schema.map(&:to_sql_name)).
to eql([Sequel.qualify(:puzzles, :id),
Sequel.qualify(:puzzles, :text),
Sequel.qualify(:puzzles, :solved),
Sequel.qualify(:puzzle_solvers, :user_id)])

expect(relation.to_a).
to eql([
{ id: 2, user_id: 1, solved: db_true, text: 'P2' },
{ id: 2, user_id: 2, solved: db_true, text: 'P2' }
])
expect(relation.schema.map(&:to_sql_name)).to eql([
Sequel.qualify(:puzzles, :id),
Sequel.qualify(:puzzles, :text),
Sequel.qualify(:puzzles, :solved),
Sequel.qualify(:puzzle_solvers, :user_id)
])

expect(relation.to_a).to eql([
{ id: 2, user_id: 1, solved: db_true, text: 'P2' },
{ id: 2, user_id: 2, solved: db_true, text: 'P2' }
])
end
end
end
8 changes: 5 additions & 3 deletions spec/integration/associations/many_to_many/self_ref_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

RSpec.describe ROM::SQL::Associations::ManyToMany, '#call' do
include_context 'database setup'

Expand Down Expand Up @@ -50,12 +52,12 @@
end

it 'preloads self-referenced tuples' do
jane = employees.insert(name: "Jane")
fred = employees.insert(name: "Fred")
jane = employees.insert(name: 'Jane')
fred = employees.insert(name: 'Fred')

positions.insert(manager_id: jane, participant_id: fred)

expect(assoc.().to_a).to eql([{ id: 1, name: 'Jane', participant_id: 2}])
expect(assoc.().to_a).to eql([{ id: 1, name: 'Jane', participant_id: 2 }])
end
end
end
43 changes: 23 additions & 20 deletions spec/integration/associations/many_to_many_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

RSpec.describe ROM::SQL::Associations::ManyToMany, helpers: true do
include_context 'users and tasks'

Expand Down Expand Up @@ -41,10 +43,11 @@
it 'prepares joined relations' do
relation = assoc.()

expect(relation.schema.map(&:to_sql_name)).
to eql([Sequel.qualify(:tags, :id),
Sequel.qualify(:tags, :name),
Sequel.qualify(:task_tags, :task_id)])
expect(relation.schema.map(&:to_sql_name)).to eql([
Sequel.qualify(:tags, :id),
Sequel.qualify(:tags, :name),
Sequel.qualify(:task_tags, :task_id)
])
expect(relation.to_a).to eql([id: 1, name: 'important', task_id: 1])
end
end
Expand All @@ -57,10 +60,11 @@
it 'prepares joined relations through other association' do
relation = assoc.()

expect(relation.schema.map(&:to_sql_name)).
to eql([Sequel.qualify(:tags, :id),
Sequel.qualify(:tags, :name),
Sequel.qualify(:tasks, :user_id)])
expect(relation.schema.map(&:to_sql_name)).to eql([
Sequel.qualify(:tags, :id),
Sequel.qualify(:tags, :name),
Sequel.qualify(:tasks, :user_id)
])
expect(relation.to_a).to eql([id: 1, name: 'important', user_id: 2])
end
end
Expand All @@ -73,9 +77,9 @@
end

it 'maintains original relation' do
relation = tags.
select_append(tags[:name].as(:tag)).
eager_load(assoc).call(tasks.call)
relation = tags
.select_append(tags[:name].as(:tag))
.eager_load(assoc).call(tasks.call)

expect(relation.to_a).to eql([id: 1, tag: 'important', name: 'important', task_id: 1])
end
Expand All @@ -84,22 +88,21 @@
conn[:tags].insert id: 2, name: 'boring'
conn[:task_tags].insert(tag_id: 2, task_id: 1)

relation = tags.
order(tags[:name].qualified).
eager_load(assoc).call(tasks.call)
relation = tags
.order(tags[:name].qualified)
.eager_load(assoc).call(tasks.call)

expect(relation.to_a).
to eql([
{ id: 2, name: 'boring', task_id: 1 },
{ id: 1, name: 'important', task_id: 1 }
])
expect(relation.to_a).to eql([
{ id: 2, name: 'boring', task_id: 1 },
{ id: 1, name: 'important', task_id: 1 }
])
end
end
end

context 'with two associations pointing to the same target relation' do
before do
inferrable_relations.concat %i(users_tasks)
inferrable_relations.push(:users_tasks)
end

before do
Expand Down
22 changes: 13 additions & 9 deletions spec/integration/associations/many_to_one/custom_fks_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ROM::SQL::Associations::ManyToOne, '#call' do
include_context 'database setup'

before do
inferrable_relations.concat %i(destinations flights)
inferrable_relations.push(:destinations, :flights)
end

let(:assoc_from) { relations[:flights].associations[:from] }
Expand Down Expand Up @@ -44,19 +46,21 @@
it 'prepares joined relations using correct FKs based on association aliases' do
relation = assoc_from.()

expect(relation.schema.map(&:to_sql_name)).
to eql([Sequel.qualify(:destinations, :id),
Sequel.qualify(:destinations, :name),
Sequel.qualify(:flights, :id).as(:flight_id)])
expect(relation.schema.map(&:to_sql_name)).to eql([
Sequel.qualify(:destinations, :id),
Sequel.qualify(:destinations, :name),
Sequel.qualify(:flights, :id).as(:flight_id)
])

expect(relation.first).to eql(id: 1, name: 'FROM', flight_id: 1)

relation = assoc_to.()

expect(relation.schema.map(&:to_sql_name)).
to eql([Sequel.qualify(:destinations, :id),
Sequel.qualify(:destinations, :name),
Sequel.qualify(:flights, :id).as(:flight_id)])
expect(relation.schema.map(&:to_sql_name)).to eql([
Sequel.qualify(:destinations, :id),
Sequel.qualify(:destinations, :name),
Sequel.qualify(:flights, :id).as(:flight_id)
])

expect(relation.first).to eql(id: 2, name: 'TO', flight_id: 1)
end
Expand Down
26 changes: 15 additions & 11 deletions spec/integration/associations/many_to_one/from_view_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ROM::SQL::Associations::ManyToOne, '#call' do
include_context 'database setup'

before do
inferrable_relations.concat %i(destinations flights)
inferrable_relations.push(:destinations, :flights)
end

let(:assoc_inter) { relations[:flights].associations[:inter_destination] }
Expand Down Expand Up @@ -60,22 +62,24 @@
it 'prepares joined relations using custom view in target relation' do
relation = assoc_inter.()

expect(relation.schema.map(&:to_sql_name)).
to eql([Sequel.qualify(:destinations, :id),
Sequel.qualify(:destinations, :name),
Sequel.qualify(:destinations, :intermediate),
Sequel.qualify(:flights, :id).as(:flight_id)])
expect(relation.schema.map(&:to_sql_name)).to eql([
Sequel.qualify(:destinations, :id),
Sequel.qualify(:destinations, :name),
Sequel.qualify(:destinations, :intermediate),
Sequel.qualify(:flights, :id).as(:flight_id)
])

expect(relation.first).to eql(id: 2, intermediate: db_true, name: 'Intermediate', flight_id: 1)
expect(relation.count).to be(1)

relation = assoc_final.()

expect(relation.schema.map(&:to_sql_name)).
to eql([Sequel.qualify(:destinations, :id),
Sequel.qualify(:destinations, :name),
Sequel.qualify(:destinations, :intermediate),
Sequel.qualify(:flights, :id).as(:flight_id)])
expect(relation.schema.map(&:to_sql_name)).to eql([
Sequel.qualify(:destinations, :id),
Sequel.qualify(:destinations, :name),
Sequel.qualify(:destinations, :intermediate),
Sequel.qualify(:flights, :id).as(:flight_id)
])

expect(relation.first).to eql(id: 1, intermediate: db_false, name: 'Final', flight_id: 2)
expect(relation.count).to be(1)
Expand Down
24 changes: 13 additions & 11 deletions spec/integration/associations/many_to_one/self_ref_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ROM::SQL::Associations::ManyToOne, '#call' do
Expand Down Expand Up @@ -37,17 +39,17 @@
it 'prepares joined relations using custom FK for a self-ref association' do
relation = assoc.()

expect(relation.schema.map(&:to_sql_name)).
to eql([Sequel.qualify(:categories, :id),
Sequel.qualify(:categories, :parent_id),
Sequel.qualify(:categories, :name)])

expect(relation.to_a).
to eql([
{ id: 1, parent_id: nil, name: 'P1' },
{ id: 1, parent_id: nil, name: 'P1' },
{ id: 2, parent_id: nil, name: 'P2' }
])
expect(relation.schema.map(&:to_sql_name)).to eql([
Sequel.qualify(:categories, :id),
Sequel.qualify(:categories, :parent_id),
Sequel.qualify(:categories, :name)
])

expect(relation.to_a).to eql([
{ id: 1, parent_id: nil, name: 'P1' },
{ id: 1, parent_id: nil, name: 'P1' },
{ id: 2, parent_id: nil, name: 'P2' }
])
end
end
end
Loading

0 comments on commit cd28e66

Please sign in to comment.