Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to rspec for non-sample app specs #128

Merged
merged 7 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: bundle install --gemfile=gemfiles/${{ matrix.gemfile }}

- name: Test
run: BUNDLE_GEMFILE=gemfiles/${{ matrix.gemfile }} bundle exec rake
run: BUNDLE_GEMFILE=gemfiles/${{ matrix.gemfile }} bundle exec rspec

rubocop:
runs-on: ubuntu-latest
Expand Down
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ doc
docs.zip
Gemfile.lock
sample_app/Gemfile.lock
test/dummy/db/migrate
test/dummy/log/
test/dummy/tmp/
gemfiles/*.gemfile.lock
spec/dummy/db/migrate
spec/dummy/log/
spec/dummy/tmp/
vendor
.idea/
15 changes: 9 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ inherit_from: .rubocop_todo.yml

AllCops:
NewCops: enable
TargetRubyVersion: 2.5
TargetRubyVersion: 2.7
Exclude:
- 'tasks/release/**/*'
- 'sample_app/**/*'
- 'test/dummy/**/*'
- 'test/fixtures/**/*'
- 'test/fixtures/**/*'
- 'spec/dummy/**/*'
- 'spec/fixtures/**/*'
- 'spec/fixtures/**/*'

Gemspec/DevelopmentDependencies:
Enabled: false
Expand All @@ -28,8 +28,11 @@ Style/GlobalVars:

Metrics/BlockLength:
Exclude:
- 'test/**/*.rb'
- 'spec/**/*.rb'

Metrics/ModuleLength:
Exclude:
- 'test/**/*.rb'
- 'spec/**/*.rb'

Style/HashSyntax:
EnforcedShorthandSyntax: never
32 changes: 5 additions & 27 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-09-28 18:54:02 UTC using RuboCop version 1.56.3.
# on 2024-06-24 17:56:34 UTC using RuboCop version 1.64.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
Lint/ConstantDefinitionInBlock:
Exclude:
- 'test/aws/rails/notifications_test.rb'
- 'test/generators/aws_record/generated_attribute_test.rb'

# Offense count: 1
Lint/DuplicateMethods:
Exclude:
Expand All @@ -31,7 +23,7 @@ Lint/ShadowingOuterLocalVariable:

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
# Configuration parameters: AutoCorrect, AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
Lint/UnusedMethodArgument:
Exclude:
- 'lib/aws/rails/sqs_active_job/lambda_handler.rb'
Expand All @@ -51,10 +43,10 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 11

# Offense count: 19
# Offense count: 18
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 35
Max: 25

# Offense count: 3
# Configuration parameters: AllowedMethods, AllowedPatterns.
Expand All @@ -66,13 +58,6 @@ Naming/AccessorMethodName:
Exclude:
- 'lib/aws/rails/sqs_active_job/configuration.rb'

# Offense count: 2
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
Naming/MethodParameterName:
Exclude:
- 'test/aws/rails/sqs_active_job/test_job.rb'

# Offense count: 1
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
# NamePrefix: is_, has_, have_
Expand Down Expand Up @@ -108,14 +93,7 @@ Style/IfUnlessModifier:
- 'lib/generators/aws_record/base.rb'
- 'lib/generators/aws_record/secondary_index.rb'

# Offense count: 1
# Configuration parameters: AllowedMethods.
# AllowedMethods: respond_to_missing?
Style/OptionalBooleanParameter:
Exclude:
- 'test/aws/rails/middleware/ebs_sqs_active_job_middleware_test.rb'

# Offense count: 22
# Offense count: 23
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ GitHub provides additional document on [forking a
repository](https://help.github.com/articles/fork-a-repo/) and [creating a pull
request](https://help.github.com/articles/creating-a-pull-request/).

### Setup

To setup the repository:

1. `bundle install`

All tests should pass when running:

`bundle exec rspec`

## Finding contributions to work on

Looking at the existing issues is a great way to find something to contribute
Expand Down
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ end

group :test do
gem 'bcrypt'
gem 'rspec-expectations'
gem 'rspec-mocks'
end

group :docs do
Expand Down
3 changes: 2 additions & 1 deletion aws-sdk-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
spec.add_dependency('concurrent-ruby', '>= 1.3.1') # Utilities for concurrent processing
spec.add_dependency('railties', '>= 5.2.0') # encrypted credentials
spec.add_development_dependency('rails')
spec.add_development_dependency('rspec-rails', '~> 6.1')

spec.required_ruby_version = '>= 2.5'
spec.required_ruby_version = '>= 2.7'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @mullermp

end
6 changes: 2 additions & 4 deletions lib/aws/rails/sqs_active_job/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,11 @@ def load_yaml(file_path)

# Avoid incompatible changes with Psych 4.0.0
# https://bugs.ruby-lang.org/issues/17866
# rubocop:disable Security/YAMLLoad
begin
YAML.load(source, aliases: true) || {}
YAML.safe_load(source, aliases: true) || {}
rescue ArgumentError
YAML.load(source) || {}
YAML.safe_load(source) || {}
end
# rubocop:enable Security/YAMLLoad
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/aws_record/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ def parse_table_config!

@primary_read_units, @primary_write_units = parse_rw_units('primary')

@gsi_rw_units = @gsis.map do |idx|
@gsi_rw_units = @gsis.to_h do |idx|
[idx.name, parse_rw_units(idx.name)]
end.to_h
end

options['table_config'].each_key do |config|
next if config == 'primary'
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/aws_record/generated_attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def validate_opt_combs(name, type, opts)

def parse_type_and_options(name, type, opts)
opts ||= []
[parse_type(name, type), opts.map { |opt| parse_option(name, opt) }.to_h]
[parse_type(name, type), opts.to_h { |opt| parse_option(name, opt) }]
end

def parse_option(name, opt)
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/aws_record/secondary_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def parse(key_definition)

def parse_raw_options(raw_opts)
raw_opts ||= []
raw_opts.map { |opt| get_option_value(opt) }.to_h
raw_opts.to_h { |opt| get_option_value(opt) }
end

def get_option_value(raw_option)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module Rails
end

it 'successfully invokes periodic task when passed through custom header' do
mock_rack_env = create_mock_env('127.0.0.1', 'aws-sqsd/1.1', true)
mock_rack_env = create_mock_env('127.0.0.1', 'aws-sqsd/1.1', is_periodic_task: true)
test_middleware = EbsSqsActiveJobMiddleware.new(mock_rack_app)

expect_any_instance_of(ElasticBeanstalkPeriodicTask).to receive(:perform_now)
Expand All @@ -69,7 +69,7 @@ module Rails
end

it 'returns internal server error if periodic task cannot be resolved' do
mock_rack_env = create_mock_env('127.0.0.1', 'aws-sqsd/1.1', true)
mock_rack_env = create_mock_env('127.0.0.1', 'aws-sqsd/1.1', is_periodic_task: true)
mock_rack_env['HTTP_X_AWS_SQSD_TASKNAME'] = 'NonExistentTask'

test_middleware = EbsSqsActiveJobMiddleware.new(mock_rack_app)
Expand All @@ -79,7 +79,7 @@ module Rails
end

it 'successfully invokes job when docker default gateway ip is changed' do
mock_rack_env = create_mock_env('192.168.176.1', 'aws-sqsd/1.1', false)
mock_rack_env = create_mock_env('192.168.176.1', 'aws-sqsd/1.1', is_periodic_task: false)
test_middleware = EbsSqsActiveJobMiddleware.new(mock_rack_app)

proc_net_route = <<~CONTENT
Expand All @@ -103,7 +103,7 @@ module Rails
end

it 'successfully invokes job when /proc/net/route does not exist' do
mock_rack_env = create_mock_env('172.17.0.1', 'aws-sqsd/1.1', false)
mock_rack_env = create_mock_env('172.17.0.1', 'aws-sqsd/1.1', is_periodic_task: false)
test_middleware = EbsSqsActiveJobMiddleware.new(mock_rack_app)

allow(File).to receive(:exist?).and_call_original
Expand All @@ -119,7 +119,7 @@ module Rails
end

it 'successfully invokes job in docker container with cgroup1' do
mock_rack_env = create_mock_env('172.17.0.1', 'aws-sqsd/1.1', false)
mock_rack_env = create_mock_env('172.17.0.1', 'aws-sqsd/1.1', is_periodic_task: false)
test_middleware = EbsSqsActiveJobMiddleware.new(mock_rack_app)

proc_1_cgroup = <<~CONTENT
Expand All @@ -144,7 +144,7 @@ module Rails
end

it 'successfully invokes job in docker container with cgroup2' do
mock_rack_env = create_mock_env('172.17.0.1', 'aws-sqsd/1.1', false)
mock_rack_env = create_mock_env('172.17.0.1', 'aws-sqsd/1.1', is_periodic_task: false)
test_middleware = EbsSqsActiveJobMiddleware.new(mock_rack_app)

proc_1_cgroup = <<~CONTENT
Expand Down Expand Up @@ -177,7 +177,7 @@ module Rails
end

# Create a minimal mock Rack environment hash to test just what we need
def create_mock_env(source_ip, user_agent, is_periodic_task = false)
def create_mock_env(source_ip, user_agent, is_periodic_task: false)
mock_env = {
'REMOTE_ADDR' => source_ip,
'HTTP_USER_AGENT' => user_agent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Aws
module Rails
describe Notifications do
let(:client) do
Client = Aws::SES::Client
Client = Aws::SES::Client # rubocop:disable Lint/ConstantDefinitionInBlock
Client.add_plugin(Aws::Rails::Notifications)
Client.new(stub_responses: true, logger: nil)
end
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class TestJob < ActiveJob::Base
self.queue_adapter = :amazon_sqs
queue_as :default

def perform(a1, a2); end
def perform(arg1, arg2); end
end

class TestJobWithMessageGroupID < TestJob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class TestModelComplex
string_attr :post_title
string_attr :post_body
string_set_attr :tags, default_value: Set.new
datetime_attr :created_at, database_attribute_name: "PostCreatedAtTime"
datetime_attr :created_at, database_attribute_name: 'PostCreatedAtTime'
boolean_attr :moderation, default_value: false
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TestModelGsiBasic
:SecondaryIndex,
hash_key: :gsi_hkey,
projection: {
projection_type: "ALL"
projection_type: 'ALL'
}
)
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TestModelGsiKeys
hash_key: :gsi_hkey,
range_key: :gsi_rkey,
projection: {
projection_type: "ALL"
projection_type: 'ALL'
}
)
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class TestModelGsiMult
:SecondaryIndex,
hash_key: :gsi_hkey,
projection: {
projection_type: "ALL"
projection_type: 'ALL'
}
)

global_secondary_index(
:SecondaryIndex2,
hash_key: :gsi2_hkey,
projection: {
projection_type: "ALL"
projection_type: 'ALL'
}
)
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ class TestModelSetTableName
include Aws::Record

string_attr :uuid, hash_key: true
set_table_name "CustomTableName"
set_table_name 'CustomTableName'
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class TestTableConfigGsiMult
:SecondaryIndex,
hash_key: :gsi_hkey,
projection: {
projection_type: "ALL"
projection_type: 'ALL'
}
)

global_secondary_index(
:SecondaryIndex2,
hash_key: :gsi2_hkey,
projection: {
projection_type: "ALL"
projection_type: 'ALL'
}
)
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TestTableConfigGsiProvided
:SecondaryIndex,
hash_key: :gsi_hkey,
projection: {
projection_type: "ALL"
projection_type: 'ALL'
}
)
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class TestModelComplex
string_attr :post_title
string_attr :post_body
string_set_attr :tags, default_value: Set.new
datetime_attr :created_at, database_attribute_name: "PostCreatedAtTime"
datetime_attr :created_at, database_attribute_name: 'PostCreatedAtTime'
boolean_attr :moderation, default_value: false
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TestModelGsiBasic
:SecondaryIndex,
hash_key: :gsi_hkey,
projection: {
projection_type: "ALL"
projection_type: 'ALL'
}
)
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TestModelGsiKeys
hash_key: :gsi_hkey,
range_key: :gsi_rkey,
projection: {
projection_type: "ALL"
projection_type: 'ALL'
}
)
end
Loading
Loading