Skip to content

Commit

Permalink
chore: fixed incorrect refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
brwali committed Oct 27, 2024
1 parent a1ae6dc commit 8cd6a61
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
16 changes: 8 additions & 8 deletions app/controllers/account_request_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create_approved_user
if requested_user.status.nil?
flash[:error] = 'Please Approve or Reject before submitting'
elsif requested_user.update_attributes(requested_user_params)
flash[:success] = "The user \"#{requested_user.username}\" has been successfully updated."
flash[:success] = "The user \"#{requested_user.name}\" has been successfully updated."
end
# If the users request is approved, they are stored as a user in the database
if requested_user.status == 'Approved'
Expand All @@ -47,7 +47,7 @@ def create_approved_user
elsif requested_user.status == 'Rejected'
# If the user request has been rejected, a flash message is shown and redirected to review page
if requested_user.update_columns(status: is_approved)
flash[:success] = "The user \"#{requested_user.username}\" has been Rejected."
flash[:success] = "The user \"#{requested_user.name}\" has been Rejected."
# redirect_to action: 'list_pending_requested'
# return
else
Expand All @@ -61,7 +61,7 @@ def create_approved_user
# Creates a new user if their request is approved
def user_new(requested_user)
new_user = User.new
new_user.username = requested_user.username
new_user.username = requested_user.name
new_user.role_id = requested_user.role_id
new_user.institution_id = requested_user.institution_id
new_user.fullname = requested_user.fullname
Expand All @@ -75,7 +75,7 @@ def user_new(requested_user)
prepared_mail = MailerHelper.send_mail_to_user(new_user, 'Your Expertiza account and password have been created.', 'user_welcome', password)
prepared_mail.deliver_now
flash[:success] = "A new password has been sent to new user's e-mail address."
undo_link("The user \"#{requested_user.username}\" has been successfully created. ")
undo_link("The user \"#{requested_user.name}\" has been successfully created. ")
else
foreign
end
Expand Down Expand Up @@ -108,7 +108,7 @@ def list_pending_requested
def create_requested_user_record
requested_user = AccountRequest.new(requested_user_params)
# An object is created with respect to AccountRequest model inorder to populate the users information when account is requested
(user_exists = User.find_by(username: requested_user.username)) || User.find_by(username: requested_user.email)
(user_exists = User.find_by(username: requested_user.name)) || User.find_by(username: requested_user.email)
requested_user_saved = save_requested_user(requested_user, params)
# Stores a boolean value with respect to whether the user data is saved or not
if !user_exists && requested_user_saved
Expand All @@ -122,7 +122,7 @@ def create_requested_user_record
flash[:error] = requested_user.errors.full_messages.to_sentence
# If saving in the AccountRequests model has failed
end
ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.username, flash[:error], request)
ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)
redirect_to controller: 'account_request', action: 'new', role: 'Student'
# if the first if clause fails, redirect back to the account requests page!
end
Expand Down Expand Up @@ -152,8 +152,8 @@ def notify_supers_new_request(requested_user)
prepared_mail.deliver
end
# Notifying an email to the administrator regarding the new user request!
ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.username, 'The account you are requesting has been created successfully.', request)
flash[:success] = "User signup for \"#{requested_user.username}\" has been successfully requested."
ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)
flash[:success] = "User signup for \"#{requested_user.name}\" has been successfully requested."
# Print out the acknowledgement message to the user and redirect to /instructors/home page when successful
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/participants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def change_handle
# Deletes participants from an assignment
def delete
contributor = AssignmentParticipant.find(params[:id])
username = contributor.username
username = contributor.name
assignment_id = contributor.assignment
begin
contributor.destroy
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/conference_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
user: { username: 'lily',
assignment: '2' }
}
allow(User).to receive(:find_by).with(name: 'lily').and_return(student1)
allow(User).to receive(:find_by).with(username: 'lily').and_return(student1)
allow(Assignment).to receive(:find_by_id).with('2').and_return(assignment1)
allow(Assignment).to receive(:find).with('2').and_return(assignment1)
allow(AssignmentParticipant).to receive(:create).with(any_args).and_return(participant)
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/invitations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
allow(AssignmentParticipant).to receive(:find).with('1').and_return(participant)
allow(Assignment).to receive(:find).with(1).and_return(assignment)
request_params = {
user: { username: '[email protected]', email: '[email protected]' },
user: { name: '[email protected]', email: '[email protected]' },
student_id: 1
}
user_session = { user: student }
Expand Down Expand Up @@ -103,7 +103,7 @@
allow(Team).to receive(:find).with('1').and_return(team)
user_session = { user: student1 }
expect { post :create, params: request_params, session: user_session }.to change(Invitation, :count).by(0).and change(User, :count).by(0)
expect(flash[:error]).to eq 'The user "[email protected]" does not exist. Please make sure the name entered is correct.'
expect(flash[:error]).to eq 'The user "[email protected]" does not exist. Please make sure the username entered is correct.'
end
end
describe '#create' do
Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/lti_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'other_param' => 'value'
}
end
let(:user) { User.create(name: 'testuser', email: '[email protected]') }
let(:user) { User.create(username: 'testuser', email: '[email protected]') }
let(:shared_secret) { 'shared_secret' }

before do
Expand Down Expand Up @@ -140,10 +140,10 @@

describe '#authenticate_and_login_user' do
context 'when user exists' do
let(:user) { User.create(name: 'testuser', email: '[email protected]') }
let(:user) { User.create(username: 'testuser', email: '[email protected]') }

before do
allow(User).to receive(:find_by).with(name: 'testuser').and_return(user)
allow(User).to receive(:find_by).with(username: 'testuser').and_return(user)
allow(controller).to receive(:redirect_to)
allow(controller).to receive(:session).and_return({})
allow(AuthController).to receive(:set_current_role)
Expand All @@ -159,7 +159,7 @@

context 'when user does not exist' do
before do
allow(User).to receive(:find_by).with(name: 'testuser').and_return(nil)
allow(User).to receive(:find_by).with(username: 'testuser').and_return(nil)
allow(controller).to receive(:redirect_to)
end

Expand All @@ -171,7 +171,7 @@

context 'when an error occurs' do
before do
allow(User).to receive(:find_by).with(name: 'testuser').and_raise(StandardError.new('Test error'))
allow(User).to receive(:find_by).with(username: 'testuser').and_raise(StandardError.new('Test error'))
allow(controller).to receive(:redirect_to)
allow(Rails.logger).to receive(:error)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/password_retrieval_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@user = User.new
@user.email = '[email protected]'
@user.fullname = 'John Bumgardner'
@user.username = 'ex'
@user.username = 'exe'
@user.save!
request_params = { user: { email: '[email protected]' } }
post :send_password, params: request_params
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/popup_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
describe '#reviewer_details_popup' do
it 'render reviewer_details_popup page successfully' do
participant = double(:participant, user_id: 1)
user = double(:user, fullname: 'Test User', name: 'Test', email: '[email protected]', handle: 1)
user = double(:user, fullname: 'Test User', username: 'Test', email: '[email protected]', handle: 1)
allow(Participant).to receive(:find).with('1').and_return(participant)
allow(User).to receive(:find).with(participant.user_id).and_return(user)
request_params = { id: 1, assignment_id: 1 }
Expand Down
14 changes: 7 additions & 7 deletions spec/controllers/submitted_content_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
allow(AssignmentParticipant).to receive(:find).and_return(participant)
stub_current_user(student1, student1.role.name, student1.role)
allow(participant).to receive(:team).and_return(team)
allow(participant).to receive(:username).and_return('Name')
allow(participant).to receive(:name).and_return('Name')
end
it 'flashes error if a duplicate hyperlink is submitted' do
allow(team).to receive(:hyperlinks).and_return(['google.com'])
Expand Down Expand Up @@ -286,7 +286,7 @@
it 'student#view it' do
allow(AssignmentParticipant).to receive(:find).and_return(participant)
stub_current_user(student1, student1.role.name, student1.role)
allow(participant).to receive(:username).and_return('Name')
allow(participant).to receive(:name).and_return('Name')
params = { id: 21 }
response = get :view, params: params
expect(response).to redirect_to(action: :edit, view: true, id: 21)
Expand All @@ -300,7 +300,7 @@
it 'instructor#view it' do
allow(AssignmentParticipant).to receive(:find).and_return(participant)
stub_current_user(instructor1, instructor1.role.name, instructor1.role)
allow(participant).to receive(:username).and_return('Name')
allow(participant).to receive(:name).and_return('Name')
params = { id: 21 }
response = get :view, params: params
expect(response).to redirect_to(action: :edit, view: true, id: 21)
Expand All @@ -314,7 +314,7 @@
it 'superadmin#view it' do
allow(AssignmentParticipant).to receive(:find).and_return(participant)
stub_current_user(superadmin1, superadmin1.role.name, superadmin1.role)
allow(participant).to receive(:username).and_return('Name')
allow(participant).to receive(:name).and_return('Name')
params = { id: 21 }
response = get :view, params: params
expect(response).to redirect_to(action: :edit, view: true, id: 21)
Expand All @@ -330,7 +330,7 @@
allow(Participant).to receive(:find_by).and_return(participant)
allow(User).to receive(:find).and_return(participant)
stub_current_user(student1, student1.role.name, student1.role)
allow(participant).to receive(:username).and_return('Name')
allow(participant).to receive(:name).and_return('Name')
params = { id: 21 }
response = get :edit, params: params
expect(response).to render_template(:edit)
Expand All @@ -346,7 +346,7 @@
allow(Participant).to receive(:find_by).and_return(participant)
allow(User).to receive(:find).and_return(participant)
stub_current_user(instructor1, instructor1.role.name, instructor1.role)
allow(participant).to receive(:username).and_return('Name')
allow(participant).to receive(:name).and_return('Name')
params = { id: 21 }
response = get :edit, params: params
expect(response).to render_template(:edit)
Expand All @@ -362,7 +362,7 @@
allow(Participant).to receive(:find_by).and_return(participant)
allow(User).to receive(:find).and_return(participant)
stub_current_user(superadmin1, superadmin1.role.name, superadmin1.role)
allow(participant).to receive(:username).and_return('Name')
allow(participant).to receive(:name).and_return('Name')
params = { id: 21 }
response = get :edit, params: params
expect(response).to render_template(:edit)
Expand Down

0 comments on commit 8cd6a61

Please sign in to comment.