-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fixes user update #12
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
class Admin::UsersController < Admin::BaseController | ||
def index | ||
@users = User.unscoped.all | ||
|
||
end | ||
|
||
def show | ||
|
@@ -26,9 +27,23 @@ def update | |
|
||
def update_role | ||
@user = User.find(params[:user_id]) | ||
@user.update(user_role_params) | ||
flash[:success] = "The user role has been updated to #{@user.role}." | ||
redirect_to admin_dash_users_path | ||
@merchant = Merchant.where(name: params[:user][:merchant]).first | ||
if params[:user][:role] == "merchant_employee" && @merchant | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout/IndentationConsistency: Inconsistent indentation detected. |
||
@user.update(user_role_params) | ||
@user.merchant_id = @merchant.id | ||
@user.save | ||
elsif params[:user][:role] != "merchant_employee" && @user.merchant_id != nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
@user.update(user_role_params) | ||
@user.merchant_id = nil | ||
@user.save | ||
end | ||
if @user.update | ||
flash[:success] = "The user role has been updated to #{@user.role}." | ||
redirect_to admin_dash_users_path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/IdenticalConditionalBranches: Move redirect_to admin_dash_users_path out of the conditional. |
||
else | ||
flash[:error] = "Please try again. You may need to choose a merchant." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
redirect_to admin_dash_users_path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/IdenticalConditionalBranches: Move redirect_to admin_dash_users_path out of the conditional. |
||
end | ||
end | ||
|
||
def toggle_active | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
user = create(:random_user) | ||
user_2 = create(:random_user) | ||
user_3 = create(:random_user) | ||
|
||
merchant = create(:ray_merchant) | ||
allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(admin) | ||
|
||
visit admin_dash_users_path | ||
|
@@ -15,12 +15,58 @@ | |
|
||
within "#user-#{user.id}" do | ||
expect(page).to have_content('Role') | ||
select "merchant_admin", :from => "Role" | ||
select "merchant_employee", :from => "Role" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
select("Vintage Vampire", from: "Merchant").select_option | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
click_on "Update" | ||
end | ||
|
||
user.reload | ||
expect(user.role).to eq("merchant_employee") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
expect(user.merchant_id).to eq(merchant.id) | ||
expect(page).to have_content("The user role has been updated to #{user.role}.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [83/80] |
||
end | ||
|
||
it "won't update a merchant id if its not a merchant employee" do | ||
admin = create(:admin_user) | ||
user = create(:merchant_employee) | ||
merchant = create(:ray_merchant) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lint/UselessAssignment: Useless assignment to variable - merchant. |
||
allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(admin) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [92/80] |
||
|
||
visit admin_dash_users_path | ||
|
||
expect(user.role).to eq("merchant_employee") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
|
||
within "#user-#{user.id}" do | ||
select "user", :from => "Role" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
select("Vintage Vampire", from: "Merchant").select_option | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
click_on "Update" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
end | ||
|
||
user.reload | ||
expect(user.role).to eq("merchant_admin") | ||
expect(user.role).to eq("user") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
expect(user.merchant_id).to eq(nil) | ||
expect(page).to have_content("The user role has been updated to #{user.role}.") | ||
end | ||
|
||
it "won't update if no merchant is given for a merchant employee" do | ||
admin = create(:admin_user) | ||
user = create(:random_user) | ||
merchant = create(:ray_merchant) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lint/UselessAssignment: Useless assignment to variable - merchant. |
||
allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(admin) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [92/80] |
||
|
||
visit admin_dash_users_path | ||
|
||
expect(user.role).to eq("user") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
|
||
within "#user-#{user.id}" do | ||
select "merchant_employee", :from => "Role" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
click_on "Update" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
end | ||
|
||
user.reload | ||
expect(user.role).to eq("user") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
expect(user.merchant_id).to eq(nil) | ||
save_and_open_page | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout/IndentationConsistency: Inconsistent indentation detected. |
||
expect(page).to have_content("Please try again. You may need to choose a merchant.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. |
||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/EmptyLinesAroundMethodBody: Extra empty line detected at method body end.