diff --git a/app/controllers/ops_controller/ops_rbac.rb b/app/controllers/ops_controller/ops_rbac.rb index b0d3fe012bf..8be09a14886 100644 --- a/app/controllers/ops_controller/ops_rbac.rb +++ b/app/controllers/ops_controller/ops_rbac.rb @@ -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 diff --git a/spec/controllers/ops_controller/ops_rbac_spec.rb b/spec/controllers/ops_controller/ops_rbac_spec.rb index a96ea72dde8..79a69b257af 100644 --- a/spec/controllers/ops_controller/ops_rbac_spec.rb +++ b/spec/controllers/ops_controller/ops_rbac_spec.rb @@ -444,4 +444,28 @@ expect(controller.instance_variable_get(:@users_count)).to eq(5) 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