From 2670de603dd77bf03c942bdd60cb96f11089daf9 Mon Sep 17 00:00:00 2001 From: lgalis Date: Wed, 17 Jan 2018 04:38:55 -0500 Subject: [PATCH] Added specs for change_current_group Move reset_current_group to :after_destroy --- spec/models/user_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 29184a35474d..06f6bc9d05e4 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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")