Skip to content

Commit

Permalink
Merge pull request #11999 from h-kataria/user_role_add_fix
Browse files Browse the repository at this point in the history
Fixed class name and key name in add/edit of user role code
  • Loading branch information
martinpovolny committed Oct 18, 2016
2 parents fc5dfda + cdc9419 commit 17bc43f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/ops_controller/ops_rbac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ def rbac_edit_save_or_add(what, rbac_suffix = what)
when :role then
rbac_role_validate?
rbac_role_set_record_vars(
record = @edit[:user_id] ? User.find_by_id(@edit[:user_id]) : User.new)
record = @edit[:role_id] ? MiqUserRole.find_by_id(@edit[:role_id]) : MiqUserRole.new)
end

if record.valid? && !flash_errors? && record.save
Expand Down
24 changes: 24 additions & 0 deletions spec/controllers/ops_controller/ops_rbac_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,28 @@
expect(edit[:current][:ldap_groups].find { |lg| lg.group_type == 'user' }).not_to be(nil)
end
end

context "rbac_role_edit" do
before do
MiqUserRole.seed
MiqGroup.seed
MiqRegion.seed
stub_user(:features => :all)
end

it "creates a new user role successfully" do
allow(controller).to receive(:replace_right_cell)
controller.instance_variable_set(:@_params, :button => "add")
new = {:features => ["everything"], :name => "foo"}
edit = {:key => "rbac_role_edit__new",
:new => new,
:current => new
}
session[:edit] = edit
controller.send(:rbac_role_edit)
flash_messages = assigns(:flash_array)
expect(flash_messages.first[:message]).to include("Role \"foo\" was saved")
expect(controller.send(:flash_errors?)).to be_falsey
end
end
end

0 comments on commit 17bc43f

Please sign in to comment.