Skip to content

Commit 483e756

Browse files
authored
Merge pull request #2274 from yahonda/introduce_rubocop_rspec
Introduce RuboCop RSpec
2 parents 3cb5480 + 7a5df41 commit 483e756

File tree

8 files changed

+45
-3
lines changed

8 files changed

+45
-3
lines changed

.rubocop.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require:
22
- rubocop-performance
33
- rubocop-rails
4+
- rubocop-rspec
45

56
AllCops:
67
TargetRubyVersion: 2.7
@@ -280,3 +281,16 @@ Performance/DeleteSuffix:
280281

281282
Performance/OpenStruct:
282283
Enabled: true
284+
285+
# RuboCop RSpec cops
286+
RSpec/EmptyLineAfterExampleGroup:
287+
Enabled: true
288+
289+
RSpec/EmptyLineAfterHook:
290+
Enabled: true
291+
292+
RSpec/EmptyLineAfterSubject:
293+
Enabled: true
294+
295+
RSpec/ExcessiveDocstringSpacing:
296+
Enabled: true

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ group :development do
1111
gem "rubocop", require: false
1212
gem "rubocop-performance", require: false
1313
gem "rubocop-rails", require: false
14+
gem "rubocop-rspec", require: false
1415

1516
gem "activerecord", github: "rails/rails", branch: "main"
1617
gem "ruby-plsql", github: "rsim/ruby-plsql", branch: "master"

spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def lookup(path)
392392
@conn.exec "DROP TABLE test_employees" rescue nil
393393
end
394394

395-
it "should execute prepared statement with decimal bind parameter " do
395+
it "should execute prepared statement with decimal bind parameter" do
396396
cursor = @conn.prepare("INSERT INTO test_employees VALUES(:1)")
397397
type_metadata = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: "NUMBER", type: :decimal, limit: 10, precision: nil, scale: 2)
398398
column = ActiveRecord::ConnectionAdapters::OracleEnhanced::Column.new("age", nil, type_metadata, false, comment: nil)

spec/active_record/connection_adapters/oracle_enhanced/database_tasks_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
ActiveRecord::Tasks::DatabaseTasks.create(new_user_config)
1717
end
1818
end
19+
1920
it "creates user" do
2021
query = "SELECT COUNT(*) FROM dba_users WHERE UPPER(username) = '#{new_user_config[:username].upcase}'"
2122
expect(ActiveRecord::Base.connection.select_value(query)).to eq(1)
@@ -62,13 +63,15 @@ def fake_terminal(input)
6263

6364
describe "drop" do
6465
before { ActiveRecord::Tasks::DatabaseTasks.drop(config) }
66+
6567
it "drops all tables" do
6668
expect(ActiveRecord::Base.connection.table_exists?(:test_posts)).to be_falsey
6769
end
6870
end
6971

7072
describe "purge" do
7173
before { ActiveRecord::Tasks::DatabaseTasks.purge(config) }
74+
7275
it "drops all tables" do
7376
expect(ActiveRecord::Base.connection.table_exists?(:test_posts)).to be_falsey
7477
expect(ActiveRecord::Base.connection.select_value("SELECT COUNT(*) FROM RECYCLEBIN")).to eq(0)
@@ -84,6 +87,7 @@ def fake_terminal(input)
8487

8588
describe "structure_dump" do
8689
before { ActiveRecord::Tasks::DatabaseTasks.structure_dump(config, temp_file) }
90+
8791
it "dumps the database structure to a file without the schema information" do
8892
contents = File.read(temp_file)
8993
expect(contents).to include('CREATE TABLE "TEST_POSTS"')
@@ -97,6 +101,7 @@ def fake_terminal(input)
97101
ActiveRecord::Tasks::DatabaseTasks.drop(config)
98102
ActiveRecord::Tasks::DatabaseTasks.structure_load(config, temp_file)
99103
end
104+
100105
it "loads the database structure from a file" do
101106
expect(ActiveRecord::Base.connection.table_exists?(:test_posts)).to be_truthy
102107
end

spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def drop_test_posts_table
127127
remove_foreign_key :test_comments, name: "comments_posts_baz_fooz_fk" rescue nil
128128
end
129129
end
130+
130131
after(:all) do
131132
schema_define do
132133
drop_table :test_comments, if_exists: true
@@ -383,13 +384,15 @@ class ::TestName < ActiveRecord::Base
383384
end
384385
end
385386
end
387+
386388
after(:all) do
387389
if @oracle11g_or_higher
388390
schema_define do
389391
remove_index "test_names", name: "index_on_virtual_col"
390392
end
391393
end
392394
end
395+
393396
it "should dump correctly" do
394397
output = dump_table_schema "test_names"
395398
expect(output).not_to match(/t\.index .+FIRST_NAME.+$/)

spec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ class ::TestComment < ActiveRecord::Base
550550
class ::TestPost < ActiveRecord::Base
551551
end
552552
end
553+
553554
it "should use default tablespace for clobs" do
554555
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] = DATABASE_NON_DEFAULT_TABLESPACE
555556
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:nclob] = nil
@@ -1157,6 +1158,7 @@ class << @conn
11571158
@conn.drop_table :tablespace_tests, if_exists: true
11581159
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces.delete(:table)
11591160
end
1161+
11601162
it "should use correct tablespace" do
11611163
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:table] = DATABASE_NON_DEFAULT_TABLESPACE
11621164
@conn.create_table :tablespace_tests do |t|
@@ -1171,6 +1173,7 @@ class << @conn
11711173
@conn.drop_table :tablespace_tests, if_exists: true
11721174
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces.delete(:table)
11731175
end
1176+
11741177
it "should use correct tablespace" do
11751178
@conn.create_table :tablespace_tests, id: false, organization: "INDEX INITRANS 4 COMPRESS 1", tablespace: "bogus" do |t|
11761179
t.integer :id

spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@oracle11g_or_higher = !! @conn.select_value(
1010
"select * from product_component_version where product like 'Oracle%' and to_number(substr(version,1,2)) >= 11")
1111
end
12+
1213
describe "structure dump" do
1314
before(:each) do
1415
@conn.create_table :test_posts, force: true do |t|
@@ -243,10 +244,12 @@ class ::TestPost < ActiveRecord::Base
243244
expect(dump).to match(/#{comment_sql}/)
244245
end
245246
end
247+
246248
describe "temporary tables" do
247249
after(:all) do
248250
@conn.drop_table :test_comments, if_exists: true
249251
end
252+
250253
it "should dump correctly" do
251254
@conn.create_table :test_comments, temporary: true, id: false do |t|
252255
t.integer :post_id
@@ -261,26 +264,32 @@ class ::TestPost < ActiveRecord::Base
261264
before(:each) do
262265
@conn.execute sql
263266
end
267+
264268
after(:each) do
265269
@conn.execute "drop SEQUENCE \"#{sequence_name}\""
266270
end
271+
267272
subject do
268273
ActiveRecord::Base.connection.structure_dump
269274
end
275+
270276
context "default sequence" do
271277
let(:sql) { "CREATE SEQUENCE \"#{sequence_name}\"" }
272278
it { is_expected.to_not match(%r{CREATE SEQUENCE "#{sequence_name}" MAXVALUE \d+ MINVALUE \d+ NOORDER NOCYCLE}) }
273279
end
280+
274281
context "noorder" do
275282
let(:sql) { "CREATE SEQUENCE \"#{sequence_name}\" NOORDER" }
276283
it { is_expected.to include("NOORDER") }
277284
it { is_expected.to_not include(" ORDER") }
278285
end
286+
279287
context "order" do
280288
let(:sql) { "CREATE SEQUENCE \"#{sequence_name}\" ORDER" }
281289
it { is_expected.to include(" ORDER") }
282290
it { is_expected.to_not include("NOORDER") }
283291
end
292+
284293
context "min max values" do
285294
let(:sql) { "CREATE SEQUENCE \"#{sequence_name}\" MINVALUE 7 MAXVALUE 444" }
286295
it { is_expected.to include("MINVALUE 7") }
@@ -317,6 +326,7 @@ class ::TestPost < ActiveRecord::Base
317326
t.string :foo
318327
end
319328
end
329+
320330
it "should dump drop sql for just temp tables" do
321331
dump = @conn.temp_table_drop
322332
expect(dump).to match(/DROP TABLE "TEMP_TBL"/)
@@ -444,6 +454,7 @@ class ::TestPost < ActiveRecord::Base
444454
create or replace type full_drop_test_type as table of number
445455
SQL
446456
end
457+
447458
after(:each) do
448459
@conn.drop_table :full_drop_test
449460
@conn.drop_table :full_drop_test_temp
@@ -455,6 +466,7 @@ class ::TestPost < ActiveRecord::Base
455466
@conn.execute "DROP PROCEDURE FULL_DROP_TEST_PROCEDURE" rescue nil
456467
@conn.execute "DROP TYPE FULL_DROP_TEST_TYPE" rescue nil
457468
end
469+
458470
it "should contain correct sql" do
459471
drop = @conn.full_drop
460472
expect(drop).to match(/DROP TABLE "FULL_DROP_TEST" CASCADE CONSTRAINTS/)

spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,15 @@ class ::TestEmployee2 < ActiveRecord::Base
129129
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] = "UNUSED"
130130
@conn = ActiveRecord::Base.connection
131131
end
132+
132133
after(:all) do
133134
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces = {}
134135
end
135136

136137
after(:each) do
137138
@conn.drop_table :foos, if_exists: true
138139
end
140+
139141
it "should create ok" do
140142
@conn.create_table :foos, temporary: true, id: false do |t|
141143
t.integer :id
@@ -648,7 +650,7 @@ class Group < ActiveRecord::Base
648650
expect(@logger.logged(:debug).last).to match(/\["table_name", "TEST_POSTS"\]/)
649651
end
650652

651-
it "should not raise missing IN/OUT parameter like issue 1678 " do
653+
it "should not raise missing IN/OUT parameter like issue 1678" do
652654
# "to_sql" enforces unprepared_statement including dictionary access SQLs
653655
expect { User.joins(:group).to_sql }.not_to raise_exception
654656
end
@@ -721,12 +723,14 @@ class ::TestPost < ActiveRecord::Base
721723
end
722724
end
723725
end
726+
724727
after(:all) do
725728
schema_define do
726729
drop_table :table_with_name_thats_just_ok,
727730
sequence_name: "suitably_short_seq" rescue nil
728731
end
729732
end
733+
730734
it "should create table with custom sequence name" do
731735
expect(@conn.select_value("select suitably_short_seq.nextval from dual")).to eq(1)
732736
end
@@ -767,7 +771,7 @@ class ::TestPost < ActiveRecord::Base
767771
expect(post.explain).to include("| TABLE ACCESS FULL| TEST_POSTS |")
768772
end
769773

770-
it "should explain considers hints with /*+ */ " do
774+
it "should explain considers hints with /*+ */" do
771775
post = TestPost.optimizer_hints("/*+ FULL (\"TEST_POSTS\") */")
772776
post = post.where(id: 1)
773777
expect(post.explain).to include("| TABLE ACCESS FULL| TEST_POSTS |")

0 commit comments

Comments
 (0)