Skip to content

Commit

Permalink
Remove unnecessary variable and validation before clicking on Add/Save
Browse files Browse the repository at this point in the history
Remove unneccessary code related to adding/editing a Group
  • Loading branch information
Hilda Stastna committed Sep 18, 2019
1 parent 8d2ea04 commit f93d713
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
13 changes: 1 addition & 12 deletions app/controllers/ops_controller/ops_rbac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -756,17 +756,7 @@ def rbac_field_changed(rec_type)

@edit[:new][:group] = rbac_user_get_group_ids.map(&:to_i) if rec_type == "user"

bad = case rec_type
when 'group'
@edit[:new].values_at(:role, :group_tenant, :description).any?(&:blank?)
when 'role'
@edit[:new][:name].blank?
else
false
end

# We need to consider also bad variable, for proper response of Add button
session[:changed] = changed = @edit[:new] != @edit[:current] && !bad
session[:changed] = changed = @edit[:new] != @edit[:current]

render :update do |page|
page << javascript_prologue
Expand All @@ -775,7 +765,6 @@ def rbac_field_changed(rec_type)
page.replace("flash_msg_div", :partial => "layouts/flash_msg") if @refresh_div == "column_lists"
page.replace(@refresh_div, :partial => @refresh_partial)
end
bad = false
else
# only do following for user (adding/editing a user)
if x_node.split("-").first == "u" || x_node == "xx-u"
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/ops_controller/ops_rbac_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -727,13 +727,13 @@
let(:params) { {:id => "new", :group_tenant => tenant.id.to_s} }
let(:edit) { {:new => {:role => 1}} }

it 'sets session[:changed] to false while filling in role and tenant' do
it 'sets session[:changed] to true while filling in role and tenant' do
controller.send(:rbac_field_changed, rec_type)
expect(controller.session[:changed]).to be(false)
expect(controller.session[:changed]).to be(true)
end

context 'filling in all the required info' do
let(:edit) { {:new => {:role => 1, :description => 'new_group'}} }
context 'filling in description' do
let(:edit) { {:new => {:description => 'new_group'}} }

it 'sets session[:changed] to true' do
controller.send(:rbac_field_changed, rec_type)
Expand Down

0 comments on commit f93d713

Please sign in to comment.