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
(cherry picked from commit 17bc43f)

https://bugzilla.redhat.com/show_bug.cgi?id=1390969
  • Loading branch information
Martin Povolny authored and chessbyte committed Nov 7, 2016
1 parent 301fa15 commit 02b4259
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
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
Expand Up @@ -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

0 comments on commit 02b4259

Please sign in to comment.