Skip to content

Commit

Permalink
rubocop -A on unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 2, 2025
1 parent 3379d52 commit a9ae75d
Show file tree
Hide file tree
Showing 63 changed files with 691 additions and 464 deletions.
6 changes: 5 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Layout/SpaceInLambdaLiteral:

Layout/SpaceInsideHashLiteralBraces:
Enabled: true
EnforcedStyle: no_space
EnforcedStyle: space
EnforcedStyleForEmptyBraces: no_space

Lint/BooleanSymbol:
Expand Down Expand Up @@ -111,6 +111,10 @@ Style/ClassAndModuleChildren:
Exclude:
- "spec/**/*_spec.rb"

Style/ColonMethodCall:
Exclude:
- "spec/**/*_spec.rb"

Style/ConditionalAssignment:
Enabled: false

Expand Down
18 changes: 10 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
Expand All @@ -9,10 +11,10 @@ if ENV['DRY_TYPES_FROM_MASTER'].eql?('true')
end

git 'https://github.com/rom-rb/rom.git', branch: 'release-5.4' do
gem 'rom-core'
gem 'rom'
gem 'rom-changeset'
gem 'rom-core'
gem 'rom-repository'
gem 'rom'
end

if ENV['SEQUEL_FROM_MASTER'].eql?('true')
Expand All @@ -30,18 +32,18 @@ group :test do
end

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.4')
gem 'ostruct'
gem 'mutex_m'
gem 'ostruct'
end

gem 'activesupport', '~> 5.0'
gem 'pg', '~> 1.2', platforms: :ruby
gem 'mysql2', '~> 0.5', platforms: :ruby
gem 'jdbc-postgres', '>= 9.4.1212', platforms: :jruby
gem 'dotenv', require: false
gem 'jdbc-mysql', platforms: :jruby
gem 'sqlite3', '~> 1.4', platforms: :ruby
gem 'jdbc-postgres', '>= 9.4.1212', platforms: :jruby
gem 'jdbc-sqlite3', platforms: :jruby
gem 'mysql2', '~> 0.5', platforms: :ruby
gem 'pg', '~> 1.2', platforms: :ruby
gem 'ruby-oci8', platforms: :ruby if ENV['ROM_USE_ORACLE']
gem 'dotenv', require: false
gem 'sequel_pg', require: false, platforms: :ruby
gem 'sqlite3', '~> 1.4', platforms: :ruby
end
10 changes: 5 additions & 5 deletions Gemfile.devtools
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

group :test do
gem "simplecov", require: false, platforms: :ruby
gem "simplecov-cobertura", require: false, platforms: :ruby
gem "rexml", require: false
gem 'simplecov', require: false, platforms: :ruby
gem 'simplecov-cobertura', require: false, platforms: :ruby
gem 'rexml', require: false

gem "warning"
gem 'warning'
end

group :tools do
# this is the same version that we use on codacy
gem "rubocop", "1.69.2"
gem 'rubocop', '1.69.2'
end
39 changes: 23 additions & 16 deletions spec/unit/attribute_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::Attribute, :postgres do
Expand All @@ -12,7 +14,7 @@
end

it 'returns a boolean equality expression for attribute' do
expect((users[:id].is(1)).sql_literal(ds)).to eql('("users"."id" = 1)')
expect(users[:id].is(1).sql_literal(ds)).to eql('("users"."id" = 1)')
end
end

Expand All @@ -22,7 +24,7 @@
end

it 'returns an IS NULL expression for attribute' do
expect((users[:id].is(nil)).sql_literal(ds)).to eql('("users"."id" IS NULL)')
expect(users[:id].is(nil).sql_literal(ds)).to eql('("users"."id" IS NULL)')
end
end

Expand All @@ -32,21 +34,21 @@
end

it 'returns an IS TRUE expression for attribute' do
expect((users[:id].is(true)).sql_literal(ds)).to eql('("users"."id" IS TRUE)')
expect(users[:id].is(true).sql_literal(ds)).to eql('("users"."id" IS TRUE)')
end
end

context 'with a boolean false' do
it 'returns an IS FALSE expression' do
expect((users[:id].is(false)).sql_literal(ds)).to eql('("users"."id" IS FALSE)')
expect(users[:id].is(false).sql_literal(ds)).to eql('("users"."id" IS FALSE)')
end
end
end

describe '#not' do
context 'with a standard value' do
it 'returns a negated boolean equality expression' do
expect((users[:id].not(1)).sql_literal(ds)).to eql('("users"."id" != 1)')
expect(users[:id].not(1).sql_literal(ds)).to eql('("users"."id" != 1)')
end
end

Expand All @@ -58,7 +60,7 @@

context 'with a boolean true' do
it 'returns an IS NOT TRUE expression' do
expect((users[:id].not(true)).sql_literal(ds)).to eql('("users"."id" IS NOT TRUE)')
expect(users[:id].not(true).sql_literal(ds)).to eql('("users"."id" IS NOT TRUE)')
end
end

Expand All @@ -77,8 +79,8 @@

describe '#concat' do
it 'returns a concat function attribute' do
expect(users[:id].concat(users[:name]).as(:uid).sql_literal(ds)).
to eql(%(CONCAT("users"."id", ' ', "users"."name") AS "uid"))
expect(users[:id].concat(users[:name]).as(:uid).sql_literal(ds))
.to eql(%(CONCAT("users"."id", ' ', "users"."name") AS "uid"))
end
end

Expand All @@ -89,15 +91,19 @@
1 => string_type.value('first'),
else: string_type.value('second')
}
expect(users[:id].case(mapping).as(:mapped_id).sql_literal(ds)).
to eql(%[(CASE "users"."id" WHEN 1 THEN 'first' ELSE 'second' END) AS "mapped_id"])
expect(
users[:id].case(mapping).as(:mapped_id).sql_literal(ds)
).to eql(
%[(CASE "users"."id" WHEN 1 THEN 'first' ELSE 'second' END) AS "mapped_id"]
)
end
end

describe '#aliased' do
it 'can alias a previously aliased attribute' do
expect(users[:id].as(:uid).as(:uuid).sql_literal(ds)).
to eql(%("users"."id" AS "uuid"))
expect(
users[:id].as(:uid).as(:uuid).sql_literal(ds)
).to eql(%("users"."id" AS "uuid"))
end
end

Expand All @@ -107,8 +113,8 @@

ROM::SQL::TypeExtensions.register(type) do
def custom(_type, _expr, value)
ROM::SQL::Attribute[ROM::SQL::Types::Bool].
meta(sql_expr: Sequel::SQL::BooleanExpression.new(:'=', 1, value))
ROM::SQL::Attribute[ROM::SQL::Types::Bool]
.meta(sql_expr: Sequel::SQL::BooleanExpression.new(:'=', 1, value))
end
end
end
Expand All @@ -117,8 +123,9 @@ def custom(_type, _expr, value)

shared_context 'type methods' do
it 'successfully invokes type-specific methods' do
expect(attribute.custom(2)).
to eql(ROM::SQL::Attribute[ROM::SQL::Types::Bool].meta(sql_expr: equality_expr))
expect(attribute.custom(2)).to eql(
ROM::SQL::Attribute[ROM::SQL::Types::Bool].meta(sql_expr: equality_expr)
)
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/unit/commands/create_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rom/sql/commands/create'

RSpec.describe ROM::SQL::Commands::Create do
Expand Down
Loading

0 comments on commit a9ae75d

Please sign in to comment.