Skip to content

Commit 373a1a7

Browse files
committed
rubocop-rspec fixes
1 parent fdb8824 commit 373a1a7

File tree

9 files changed

+107
-183
lines changed

9 files changed

+107
-183
lines changed

app-rails/.rubocop.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
require:
1+
plugins:
22
- rubocop-rspec
33
inherit_gem:
44
pundit: config/rubocop-rspec.yml
55
rubocop-rails-omakase: rubocop.yml
6+
7+
RSpec/ExampleLength:
8+
Enabled: false
9+
RSpec/MultipleExpectations:
10+
Enabled: false
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Be sure to restart your server when you modify this file.
2+
#
3+
# This file eases your Rails 7.2 framework defaults upgrade.
4+
#
5+
# Uncomment each configuration one by one to switch to the new default.
6+
# Once your application is ready to run with all new defaults, you can remove
7+
# this file and set the `config.load_defaults` to `7.2`.
8+
#
9+
# Read the Guide for Upgrading Ruby on Rails for more info on each option.
10+
# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html
11+
12+
###
13+
# Controls whether Active Job's `#perform_later` and similar methods automatically defer
14+
# the job queuing to after the current Active Record transaction is committed.
15+
#
16+
# Example:
17+
# Topic.transaction do
18+
# topic = Topic.create(...)
19+
# NewTopicNotificationJob.perform_later(topic)
20+
# end
21+
#
22+
# In this example, if the configuration is set to `:never`, the job will
23+
# be enqueued immediately, even though the `Topic` hasn't been committed yet.
24+
# Because of this, if the job is picked up almost immediately, or if the
25+
# transaction doesn't succeed for some reason, the job will fail to find this
26+
# topic in the database.
27+
#
28+
# If `enqueue_after_transaction_commit` is set to `:default`, the queue adapter
29+
# will define the behaviour.
30+
#
31+
# Note: Active Job backends can disable this feature. This is generally done by
32+
# backends that use the same database as Active Record as a queue, hence they
33+
# don't need this feature.
34+
#++
35+
# Rails.application.config.active_job.enqueue_after_transaction_commit = :default
36+
37+
###
38+
# Adds image/webp to the list of content types Active Storage considers as an image
39+
# Prevents automatic conversion to a fallback PNG, and assumes clients support WebP, as they support gif, jpeg, and png.
40+
# This is possible due to broad browser support for WebP, but older browsers and email clients may still not support
41+
# WebP. Requires imagemagick/libvips built with WebP support.
42+
#++
43+
# Rails.application.config.active_storage.web_image_content_types = %w[image/png image/jpeg image/gif image/webp]
44+
45+
###
46+
# Enable validation of migration timestamps. When set, an ActiveRecord::InvalidMigrationTimestampError
47+
# will be raised if the timestamp prefix for a migration is more than a day ahead of the timestamp
48+
# associated with the current time. This is done to prevent forward-dating of migration files, which can
49+
# impact migration generation and other migration commands.
50+
#
51+
# Applications with existing timestamped migrations that do not adhere to the
52+
# expected format can disable validation by setting this config to `false`.
53+
#++
54+
# Rails.application.config.active_record.validate_migration_timestamps = true
55+
56+
###
57+
# Controls whether the PostgresqlAdapter should decode dates automatically with manual queries.
58+
#
59+
# Example:
60+
# ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.select_value("select '2024-01-01'::date") #=> Date
61+
#
62+
# This query used to return a `String`.
63+
#++
64+
# Rails.application.config.active_record.postgresql_adapter_decode_dates = true
65+
66+
###
67+
# Enables YJIT as of Ruby 3.3, to bring sizeable performance improvements. If you are
68+
# deploying to a memory constrained environment you may want to set this to `false`.
69+
#++
70+
# Rails.application.config.yjit = true

app-rails/spec/adapters/cognito_adapter_spec.rb

Lines changed: 0 additions & 153 deletions
This file was deleted.

app-rails/spec/controllers/users/sessions_controller_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
let (:uid_generator) { -> { uid } }
99

1010
before do
11+
# rubocop:disable RSpec/InstanceVariable
1112
@request.env["devise.mapping"] = Devise.mappings[:user]
13+
# rubocop:enable RSpec/InstanceVariable
1214

1315
allow(controller).to receive(:auth_service).and_return(
1416
AuthService.new(Auth::MockAdapter.new(uid_generator: uid_generator))

app-rails/spec/forms/users/new_session_form_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
RSpec.describe Users::NewSessionForm do
44
it "passes validation with valid email and password" do
5-
form = Users::NewSessionForm.new(
5+
form = described_class.new(
66
email: "test@example.com",
77
password: "password"
88
)
@@ -11,33 +11,33 @@
1111
end
1212

1313
it "requires email and password" do
14-
form = Users::NewSessionForm.new({
14+
form = described_class.new({
1515
email: "",
1616
password: ""
1717
})
1818

1919
expect(form).not_to be_valid
20-
expect(form.errors.of_kind?(:email, :blank)).to be_truthy
21-
expect(form.errors.of_kind?(:password, :blank)).to be_truthy
20+
expect(form.errors).to be_of_kind(:email, :blank)
21+
expect(form.errors).to be_of_kind(:password, :blank)
2222
end
2323

2424
it "requires a valid email" do
25-
form = Users::NewSessionForm.new(
25+
form = described_class.new(
2626
email: "not_an_email"
2727
)
2828

2929
expect(form).not_to be_valid
30-
expect(form.errors.of_kind?(:email, :invalid)).to be_truthy
30+
expect(form.errors).to be_of_kind(:email, :invalid)
3131
end
3232

3333
it "requires the honeypot field to be empty" do
34-
form = Users::NewSessionForm.new(
34+
form = described_class.new(
3535
email: "test@example.com",
3636
password: "password",
3737
spam_trap: "I am a bot"
3838
)
3939

4040
expect(form).not_to be_valid
41-
expect(form.errors.of_kind?(:spam_trap, :present)).to be_truthy
41+
expect(form.errors).to be_of_kind(:spam_trap, :present)
4242
end
4343
end

app-rails/spec/forms/users/registration_form_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
valid_password = "password1234"
44

55
RSpec.describe Users::RegistrationForm do
6-
let (:form) { Users::RegistrationForm.new() }
6+
let (:form) { described_class.new() }
77

88
it "passes validation with valid email and password" do
99
form.email = "test@example.com"
@@ -18,23 +18,23 @@
1818
form.password = ""
1919

2020
expect(form).not_to be_valid
21-
expect(form.errors.of_kind?(:email, :blank)).to be_truthy
22-
expect(form.errors.of_kind?(:password, :blank)).to be_truthy
21+
expect(form.errors).to be_of_kind(:email, :blank)
22+
expect(form.errors).to be_of_kind(:password, :blank)
2323
end
2424

2525
it "confirms the password matches" do
2626
form.password = valid_password
2727
form.password_confirmation = "not_the_same"
2828

2929
expect(form).not_to be_valid
30-
expect(form.errors.of_kind?(:password_confirmation, :confirmation)).to be_truthy
30+
expect(form.errors).to be_of_kind(:password_confirmation, :confirmation)
3131
end
3232

3333
it "requires a valid email" do
3434
form.email = "not_an_email"
3535

3636
expect(form).not_to be_valid
37-
expect(form.errors.of_kind?(:email, :invalid)).to be_truthy
37+
expect(form.errors).to be_of_kind(:email, :invalid)
3838
end
3939

4040
it "requires the honeypot field is empty" do
@@ -43,6 +43,6 @@
4343
form.spam_trap = "I am a bot"
4444

4545
expect(form).not_to be_valid
46-
expect(form.errors.of_kind?(:spam_trap, :present)).to be_truthy
46+
expect(form.errors).to be_of_kind(:spam_trap, :present)
4747
end
4848
end

app-rails/spec/forms/users/verify_account_form_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22

33
RSpec.describe Users::VerifyAccountForm do
44
it "passes validation with valid email and code" do
5-
form = Users::VerifyAccountForm.new(email: "test@example.com", code: "123456")
5+
form = described_class.new(email: "test@example.com", code: "123456")
66

77
expect(form).to be_valid
88
end
99

1010
it "requires email and code" do
11-
form = Users::VerifyAccountForm.new(email: nil, code: nil)
11+
form = described_class.new(email: nil, code: nil)
1212

1313
expect(form).to be_invalid
14-
expect(form.errors.of_kind?(:email, :blank)).to be_truthy
15-
expect(form.errors.of_kind?(:code, :blank)).to be_truthy
14+
expect(form.errors).to be_of_kind(:email, :blank)
15+
expect(form.errors).to be_of_kind(:code, :blank)
1616
end
1717

1818
it "requires email to be a valid email" do
19-
form = Users::VerifyAccountForm.new(email: "invalid-email", code: "123456")
19+
form = described_class.new(email: "invalid-email", code: "123456")
2020

2121
expect(form).to be_invalid
22-
expect(form.errors.of_kind?(:email, :invalid)).to be_truthy
22+
expect(form.errors).to be_of_kind(:email, :invalid)
2323
end
2424

2525
it "requires code to be 6 characters" do
26-
form = Users::VerifyAccountForm.new(email: "test@example.com", code: "12345")
26+
form = described_class.new(email: "test@example.com", code: "12345")
2727

2828
expect(form).to be_invalid
29-
expect(form.errors.of_kind?(:code, :wrong_length)).to be_truthy
29+
expect(form.errors).to be_of_kind(:code, :wrong_length)
3030
end
3131
end

app-rails/spec/models/user_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
}
1818

1919
it "returns true if the access token expires within the designated minutes" do
20-
expect(user.access_token_expires_within_minutes?(access_token, 5)).to eq(true)
20+
expect(user.access_token_expires_within_minutes?(access_token, 5)).to be(true)
2121
end
2222

2323
it "returns false if the access token is not expiring within the designated minutes" do
24-
expect(user.access_token_expires_within_minutes?(access_token, 1)).to eq(false)
24+
expect(user.access_token_expires_within_minutes?(access_token, 1)).to be(false)
2525
end
2626
end
2727
end

0 commit comments

Comments
 (0)