Skip to content

Commit

Permalink
130 - fix rubocop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gamesover committed Dec 18, 2024
1 parent 8360520 commit 020e6f5
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 26 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Metrics/ModuleLength:
Metrics/BlockLength:
Exclude:
- 'spec/**/*'
- 'config/routes.rb'

# Allow both single-quoted and double-quoted string literals.
Style/StringLiterals:
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/my/emails_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def create
def set_primary
email = Email.find(params[:id])
ActiveRecord::Base.transaction do
current_user.emails.where(primary: true).update_all(primary: false)
current_user.emails.where(primary: true).find_each { |email| email.update!(primary: false) }
email.update!(primary: true)
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/email.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Email < ActiveRecord::Base
class Email < ApplicationRecord
belongs_to :user

validates :email, presence: true, uniqueness: true
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class User < ApplicationRecord
)
}
scope :committee, -> { where(committee: true) }
scope :without_emails, -> {
scope :without_emails, lambda {
left_outer_joins(:emails)
.where(emails: { id: nil })
.where.not(email: nil)
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
email { Faker::Internet.email }

trait :confirmed do
confirmed_at { Time.now }
confirmed_at { Time.current }
end
end
end
2 changes: 1 addition & 1 deletion spec/models/email_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

context 'uniqueness' do
it 'requires a unique email address regardless of case' do
existing_email = create(:email, email: '[email protected]')
create(:email, email: '[email protected]')
new_email = build(:email, email: '[email protected]')

expect(new_email).not_to be_valid
Expand Down
16 changes: 8 additions & 8 deletions spec/requests/imported_members_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

context "with valid parameters" do
it "creates new imported members" do
expect {
expect do
post admin_imported_members_path, params: { source: source, file: file }
}.to change(ImportedMember, :count).by(2)
end.to change(ImportedMember, :count).by(2)

expect(response).to redirect_to(admin_imported_members_path)
follow_redirect!
Expand Down Expand Up @@ -45,9 +45,9 @@
it "updates the existing imported member" do
existing_member = create(:imported_member, email: '[email protected]', full_name: 'Old Name', data: { sources: ['old_source'] })

expect {
expect do
post admin_imported_members_path, params: { source: source, file: file }
}.to change(ImportedMember, :count).by(1)
end.to change(ImportedMember, :count).by(1)

existing_member.reload
expect(existing_member.full_name).to eq('Old Name')
Expand All @@ -59,9 +59,9 @@
it "skips the row" do
create(:email, email: '[email protected]')

expect {
expect do
post admin_imported_members_path, params: { source: source, file: file }
}.to change(ImportedMember, :count).by(1)
end.to change(ImportedMember, :count).by(1)

expect(ImportedMember.find_by(email: '[email protected]')).to be_nil
end
Expand All @@ -71,9 +71,9 @@
let(:file) { fixture_file_upload('imported_members_blank_email.csv', 'text/csv') }

it "skips the row" do
expect {
expect do
post admin_imported_members_path, params: { source: source, file: file }
}.to change(ImportedMember, :count).by(1)
end.to change(ImportedMember, :count).by(1)

expect(ImportedMember.find_by(email: '')).to be_nil
end
Expand Down
3 changes: 1 addition & 2 deletions spec/requests/invitations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

post "/invitations/#{imported_member.token}", params: { user: user_params }


expect(response).to redirect_to(root_path)
expect(flash[:notice]).to eq("Your membership to Ruby Australia has been confirmed.")
user = User.last
Expand All @@ -32,7 +31,7 @@
end

context "with invalid user params" do
let(:user_params) { { full_name: "", email: imported_member.email, password: "password", password_confirmation: "wrong_password" } }
let(:user_params) { { full_name: "", email: imported_member.email, password: "password", password_confirmation: "wrong_password" } }

it "renders the new template" do
post "/invitations/#{imported_member.token}", params: { user: user_params }
Expand Down
6 changes: 3 additions & 3 deletions spec/requests/mailing_lists_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"Type" => "Subscribe",
"EmailAddress" => user.email,
"ListId" => list.api_id,
},
}
],
}.to_json
end
Expand All @@ -36,7 +36,7 @@
"Type" => "Deactivate",
"EmailAddress" => user.email,
"ListId" => list.api_id,
},
}
],
}.to_json
end
Expand Down Expand Up @@ -72,7 +72,7 @@
"Type" => "Subscribe",
"EmailAddress" => "[email protected]",
"ListId" => list.api_id,
},
}
],
}.to_json
end
Expand Down
12 changes: 6 additions & 6 deletions spec/requests/my/emails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
describe "POST /create" do
context "with valid parameters" do
it "creates a new email and redirects to my_details_path" do
expect {
expect do
post my_emails_path, params: { email: { email: "[email protected]" } }
}.to change(Email, :count).by(1)
end.to change(Email, :count).by(1)
expect(response).to redirect_to(my_details_path)
end
end

context "with invalid parameters" do
it "re-renders the new template" do
expect {
expect do
post my_emails_path, params: { email: { email: "" } }
}.not_to change(Email, :count)
end.not_to change(Email, :count)
expect(response).to render_template(:new)
end
end
Expand All @@ -51,9 +51,9 @@
let!(:email) { create(:email, user: user) }

it "deletes the specified email and redirects to my_details_path" do
expect {
expect do
delete my_email_path(email)
}.to change(Email, :count).by(-1)
end.to change(Email, :count).by(-1)
expect(response).to redirect_to(my_details_path)
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/reactivations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
end

it "does not create a new membership" do
expect {
expect do
post "/reactivations", params: { user: { email: user.email, password: "wrong_password" } }
}.not_to change(Membership, :count)
end.not_to change(Membership, :count)
end

it "does not sign in the user" do
Expand Down

0 comments on commit 020e6f5

Please sign in to comment.