Skip to content

Commit cd28e66

Browse files
committed
rubocop -A for spec dir
1 parent a9ae75d commit cd28e66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+571
-422
lines changed

.rubocop.yml

+9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Lint/ConstantDefinitionInBlock:
4444
Lint/EmptyBlock:
4545
Exclude:
4646
- "spec/**/*.rb"
47+
- "tmp/**/*.rb"
4748

4849
Lint/EmptyClass:
4950
Exclude:
@@ -88,6 +89,10 @@ Naming/MethodName:
8889
Naming/MethodParameterName:
8990
Enabled: false
9091

92+
Style/MutableConstant:
93+
Exclude:
94+
- "spec/**/*.rb"
95+
9196
Naming/PredicateName:
9297
Enabled: false
9398

@@ -163,6 +168,10 @@ Style/MultipleComparison:
163168
Style/NumberedParametersLimit:
164169
Max: 2
165170

171+
Style/OpenStructUse:
172+
Exclude:
173+
- "spec/**/*.rb"
174+
166175
Style/ParallelAssignment:
167176
Enabled: false
168177

spec/integration/associations/many_to_many/custom_fks_spec.rb

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# frozen_string_literal: true
2+
13
RSpec.describe ROM::SQL::Associations::ManyToMany, '#call' do
24
include_context 'users'
35

46
before do
5-
inferrable_relations.concat %i(puzzles puzzle_solvers)
7+
inferrable_relations.push(:puzzles, :puzzle_solvers)
68
end
79

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

62-
expect(relation.schema.map(&:to_sql_name)).
63-
to eql([Sequel.qualify(:puzzles, :id),
64-
Sequel.qualify(:puzzles, :text),
65-
Sequel.qualify(:puzzle_solvers, :solver_id)])
64+
expect(relation.schema.map(&:to_sql_name)).to eql([
65+
Sequel.qualify(:puzzles, :id),
66+
Sequel.qualify(:puzzles, :text),
67+
Sequel.qualify(:puzzle_solvers, :solver_id)
68+
])
6669

67-
expect(relation.to_a).
68-
to eql([
69-
{ id: 1, solver_id: 2, text: 'P1' },
70-
{ id: 2, solver_id: 1, text: 'P2' },
71-
{ id: 2, solver_id: 2, text: 'P2' },
72-
{ id: 3, solver_id: 1, text: 'P3' }
73-
])
70+
expect(relation.to_a).to eql([
71+
{ id: 1, solver_id: 2, text: 'P1' },
72+
{ id: 2, solver_id: 1, text: 'P2' },
73+
{ id: 2, solver_id: 2, text: 'P2' },
74+
{ id: 3, solver_id: 1, text: 'P3' }
75+
])
7476
end
7577
end
7678
end

spec/integration/associations/many_to_many/from_view_spec.rb

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# frozen_string_literal: true
2+
13
RSpec.describe ROM::SQL::Associations::ManyToMany, '#call' do
24
include_context 'users'
35

46
before do
5-
inferrable_relations.concat %i(puzzles puzzle_solvers)
7+
inferrable_relations.push(:puzzles, :puzzle_solvers)
68
end
79

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

75-
expect(relation.schema.map(&:to_sql_name)).
76-
to eql([Sequel.qualify(:puzzles, :id),
77-
Sequel.qualify(:puzzles, :text),
78-
Sequel.qualify(:puzzles, :solved),
79-
Sequel.qualify(:puzzle_solvers, :user_id)])
80-
81-
expect(relation.to_a).
82-
to eql([
83-
{ id: 2, user_id: 1, solved: db_true, text: 'P2' },
84-
{ id: 2, user_id: 2, solved: db_true, text: 'P2' }
85-
])
77+
expect(relation.schema.map(&:to_sql_name)).to eql([
78+
Sequel.qualify(:puzzles, :id),
79+
Sequel.qualify(:puzzles, :text),
80+
Sequel.qualify(:puzzles, :solved),
81+
Sequel.qualify(:puzzle_solvers, :user_id)
82+
])
83+
84+
expect(relation.to_a).to eql([
85+
{ id: 2, user_id: 1, solved: db_true, text: 'P2' },
86+
{ id: 2, user_id: 2, solved: db_true, text: 'P2' }
87+
])
8688
end
8789
end
8890
end

spec/integration/associations/many_to_many/self_ref_spec.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
RSpec.describe ROM::SQL::Associations::ManyToMany, '#call' do
24
include_context 'database setup'
35

@@ -50,12 +52,12 @@
5052
end
5153

5254
it 'preloads self-referenced tuples' do
53-
jane = employees.insert(name: "Jane")
54-
fred = employees.insert(name: "Fred")
55+
jane = employees.insert(name: 'Jane')
56+
fred = employees.insert(name: 'Fred')
5557

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

58-
expect(assoc.().to_a).to eql([{ id: 1, name: 'Jane', participant_id: 2}])
60+
expect(assoc.().to_a).to eql([{ id: 1, name: 'Jane', participant_id: 2 }])
5961
end
6062
end
6163
end

spec/integration/associations/many_to_many_spec.rb

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
RSpec.describe ROM::SQL::Associations::ManyToMany, helpers: true do
24
include_context 'users and tasks'
35

@@ -41,10 +43,11 @@
4143
it 'prepares joined relations' do
4244
relation = assoc.()
4345

44-
expect(relation.schema.map(&:to_sql_name)).
45-
to eql([Sequel.qualify(:tags, :id),
46-
Sequel.qualify(:tags, :name),
47-
Sequel.qualify(:task_tags, :task_id)])
46+
expect(relation.schema.map(&:to_sql_name)).to eql([
47+
Sequel.qualify(:tags, :id),
48+
Sequel.qualify(:tags, :name),
49+
Sequel.qualify(:task_tags, :task_id)
50+
])
4851
expect(relation.to_a).to eql([id: 1, name: 'important', task_id: 1])
4952
end
5053
end
@@ -57,10 +60,11 @@
5760
it 'prepares joined relations through other association' do
5861
relation = assoc.()
5962

60-
expect(relation.schema.map(&:to_sql_name)).
61-
to eql([Sequel.qualify(:tags, :id),
62-
Sequel.qualify(:tags, :name),
63-
Sequel.qualify(:tasks, :user_id)])
63+
expect(relation.schema.map(&:to_sql_name)).to eql([
64+
Sequel.qualify(:tags, :id),
65+
Sequel.qualify(:tags, :name),
66+
Sequel.qualify(:tasks, :user_id)
67+
])
6468
expect(relation.to_a).to eql([id: 1, name: 'important', user_id: 2])
6569
end
6670
end
@@ -73,9 +77,9 @@
7377
end
7478

7579
it 'maintains original relation' do
76-
relation = tags.
77-
select_append(tags[:name].as(:tag)).
78-
eager_load(assoc).call(tasks.call)
80+
relation = tags
81+
.select_append(tags[:name].as(:tag))
82+
.eager_load(assoc).call(tasks.call)
7983

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

87-
relation = tags.
88-
order(tags[:name].qualified).
89-
eager_load(assoc).call(tasks.call)
91+
relation = tags
92+
.order(tags[:name].qualified)
93+
.eager_load(assoc).call(tasks.call)
9094

91-
expect(relation.to_a).
92-
to eql([
93-
{ id: 2, name: 'boring', task_id: 1 },
94-
{ id: 1, name: 'important', task_id: 1 }
95-
])
95+
expect(relation.to_a).to eql([
96+
{ id: 2, name: 'boring', task_id: 1 },
97+
{ id: 1, name: 'important', task_id: 1 }
98+
])
9699
end
97100
end
98101
end
99102

100103
context 'with two associations pointing to the same target relation' do
101104
before do
102-
inferrable_relations.concat %i(users_tasks)
105+
inferrable_relations.push(:users_tasks)
103106
end
104107

105108
before do

spec/integration/associations/many_to_one/custom_fks_spec.rb

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
# frozen_string_literal: true
2+
13
require 'spec_helper'
24

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

68
before do
7-
inferrable_relations.concat %i(destinations flights)
9+
inferrable_relations.push(:destinations, :flights)
810
end
911

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

47-
expect(relation.schema.map(&:to_sql_name)).
48-
to eql([Sequel.qualify(:destinations, :id),
49-
Sequel.qualify(:destinations, :name),
50-
Sequel.qualify(:flights, :id).as(:flight_id)])
49+
expect(relation.schema.map(&:to_sql_name)).to eql([
50+
Sequel.qualify(:destinations, :id),
51+
Sequel.qualify(:destinations, :name),
52+
Sequel.qualify(:flights, :id).as(:flight_id)
53+
])
5154

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

5457
relation = assoc_to.()
5558

56-
expect(relation.schema.map(&:to_sql_name)).
57-
to eql([Sequel.qualify(:destinations, :id),
58-
Sequel.qualify(:destinations, :name),
59-
Sequel.qualify(:flights, :id).as(:flight_id)])
59+
expect(relation.schema.map(&:to_sql_name)).to eql([
60+
Sequel.qualify(:destinations, :id),
61+
Sequel.qualify(:destinations, :name),
62+
Sequel.qualify(:flights, :id).as(:flight_id)
63+
])
6064

6165
expect(relation.first).to eql(id: 2, name: 'TO', flight_id: 1)
6266
end

spec/integration/associations/many_to_one/from_view_spec.rb

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
# frozen_string_literal: true
2+
13
require 'spec_helper'
24

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

68
before do
7-
inferrable_relations.concat %i(destinations flights)
9+
inferrable_relations.push(:destinations, :flights)
810
end
911

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

63-
expect(relation.schema.map(&:to_sql_name)).
64-
to eql([Sequel.qualify(:destinations, :id),
65-
Sequel.qualify(:destinations, :name),
66-
Sequel.qualify(:destinations, :intermediate),
67-
Sequel.qualify(:flights, :id).as(:flight_id)])
65+
expect(relation.schema.map(&:to_sql_name)).to eql([
66+
Sequel.qualify(:destinations, :id),
67+
Sequel.qualify(:destinations, :name),
68+
Sequel.qualify(:destinations, :intermediate),
69+
Sequel.qualify(:flights, :id).as(:flight_id)
70+
])
6871

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

7275
relation = assoc_final.()
7376

74-
expect(relation.schema.map(&:to_sql_name)).
75-
to eql([Sequel.qualify(:destinations, :id),
76-
Sequel.qualify(:destinations, :name),
77-
Sequel.qualify(:destinations, :intermediate),
78-
Sequel.qualify(:flights, :id).as(:flight_id)])
77+
expect(relation.schema.map(&:to_sql_name)).to eql([
78+
Sequel.qualify(:destinations, :id),
79+
Sequel.qualify(:destinations, :name),
80+
Sequel.qualify(:destinations, :intermediate),
81+
Sequel.qualify(:flights, :id).as(:flight_id)
82+
])
7983

8084
expect(relation.first).to eql(id: 1, intermediate: db_false, name: 'Final', flight_id: 2)
8185
expect(relation.count).to be(1)

spec/integration/associations/many_to_one/self_ref_spec.rb

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'spec_helper'
24

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

40-
expect(relation.schema.map(&:to_sql_name)).
41-
to eql([Sequel.qualify(:categories, :id),
42-
Sequel.qualify(:categories, :parent_id),
43-
Sequel.qualify(:categories, :name)])
44-
45-
expect(relation.to_a).
46-
to eql([
47-
{ id: 1, parent_id: nil, name: 'P1' },
48-
{ id: 1, parent_id: nil, name: 'P1' },
49-
{ id: 2, parent_id: nil, name: 'P2' }
50-
])
42+
expect(relation.schema.map(&:to_sql_name)).to eql([
43+
Sequel.qualify(:categories, :id),
44+
Sequel.qualify(:categories, :parent_id),
45+
Sequel.qualify(:categories, :name)
46+
])
47+
48+
expect(relation.to_a).to eql([
49+
{ id: 1, parent_id: nil, name: 'P1' },
50+
{ id: 1, parent_id: nil, name: 'P1' },
51+
{ id: 2, parent_id: nil, name: 'P2' }
52+
])
5153
end
5254
end
5355
end

0 commit comments

Comments
 (0)