Skip to content

Commit

Permalink
Added specs for change_current_group
Browse files Browse the repository at this point in the history
Move reset_current_group to :after_destroy
  • Loading branch information
lgalis committed Jan 17, 2018
1 parent aad0638 commit 2b3223f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,23 @@
end
end

describe "#change_current_group" do
let(:group1) { FactoryGirl.create(:miq_group) }
let(:group2) { FactoryGirl.create(:miq_group) }

it "changes the user to a group other than the current one" do
user = FactoryGirl.create(:user, :miq_groups => [group1, group2], :current_group => group1)
user.change_current_group
expect(user.current_group).to eq(group2)
end

it "raises an error if there is no group other than the current one to switch to" do
user = FactoryGirl.create(:user, :miq_groups => [group1], :current_group => group1)
expect { user.change_current_group }
.to raise_error(RuntimeError, /The user's current group cannot be changed because the user does not belong to any other group/)
end
end

context ".super_admin" do
it "has super_admin" do
FactoryGirl.create(:miq_group, :role => "super_administrator")
Expand Down

0 comments on commit 2b3223f

Please sign in to comment.