From dc2495f65382ed16d75d683c3985c6b4463f1e19 Mon Sep 17 00:00:00 2001 From: Yuri Rudman Date: Fri, 5 Oct 2018 15:29:24 -0400 Subject: [PATCH 1/6] Script to copy/reset available reports (for group and role): - duplicate report structure from one group to another group - duplicate report structure from group to role, which means to each group having that role - remove cutomized report sructure from group - remove customized report structure from role, which means from each group having that role EXAMPLE: bundle exec ruby ./tools/copy_reports_structure -s EvmGroup -r SomeRole bundle exec ruby ./tools/copy_reports_structure -p SomeRole Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1634673 --- tools/copy_reports_structure.rb | 92 +++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 tools/copy_reports_structure.rb diff --git a/tools/copy_reports_structure.rb b/tools/copy_reports_structure.rb new file mode 100755 index 00000000000..0e8040aab4d --- /dev/null +++ b/tools/copy_reports_structure.rb @@ -0,0 +1,92 @@ +#!/usr/bin/env ruby +require File.expand_path('../config/environment', __dir__) +require 'bundler/setup' +require 'trollop' + +def find_group(group_name) + group = MiqGroup.where(:description => group_name).first + abort("MiqGroup '#{group_name}' not found") if group.nil? + group +end + +def find_role(role_name) + role = MiqUserRole.where(:name => role_name).first + abort("MiqUserRole '#{role_name}' not found") if role.nil? + role +end + +def duplicate_for_group(source_group_name, destination_group_name) + destination_group = find_group(destination_group_name) + destination_group.settings = find_group(source_group_name).settings + destination_group.save! + puts "Reports structure was succesfully cloned from '#{source_group_name}' to '#{destination_group_name}'" +rescue StandardError => e + $stderr.puts e.message +end + +def duplicate_for_role(source_group_name, destination_role_name) + puts "Copying report structure from group '#{source_group_name}' to role ' #{destination_role_name}' ..." + source_group = find_group(source_group_name) + find_role(destination_role_name).miq_groups.each do |destination_group| + begin + destination_group.settings = source_group.settings + destination_group.save! + puts " Reports structure was succesfully copied from '#{source_group_name}' to '#{destination_group.description}'" + rescue StandardError => e + $stderr.puts e.message + end + end +end + +def reset_for_group(group_name) + group = find_group(group_name) + group.settings = nil + group.save! + puts "Succsefully removed custom report structure for group '#{group_name}'" +rescue StandardError => e + $stderr.puts e.message +end + +def reset_for_role(role_name) + puts "Removing custom report structure for role '#{role_name}'..." + find_role(role_name).miq_groups.each do |group| + begin + group.settings = nil + group.save! + puts "Succsefully removed custom report structure for group '#{group.description}'" + rescue StandardError => e + $stderr.puts e.message + end + end +end + +opts = Trollop.options(ARGV) do + banner "Utility to: \n" \ + " - make report structure configured for a group available to another group\n" \ + " - make report structure configured for a group available to role\n" \ + " - reset report access to default for group or role\n" \ + "Example (Duplicate for Group): bundle exec ruby #{__FILE__} -s EvmGroup -g SomeGroup\n" \ + "Example (Duplicate for Role): bundle exec ruby #{__FILE__} -s EvmGroup -r SomeRole\n" \ + "Example (Reset to Default for Group): bundle exec ruby #{__FILE__} -d SomeGroup\n" \ + "Example (Reset to Default for Role): bundle exec ruby #{__FILE__} -p SomeRole\n" + opt :source_group, "Source group to take report structure from", :short => "s", :type => :string + opt :group, "Destination group", :short => "g", :type => :string + opt :role, "Destination role", :short => "r", :type => :string + opt :delete_group, "Group to reset reports structure to default", :short => "d", :type => :string + opt :delete_role, "Role to reset reports structure to default", :short => "p", :type => :string +end + +if opts[:source_group_given] + msg = ":source_group argument can not be used with :delete_group" if opts[:delete_group_given] + msg ||= ":source_group argument can not be used with :delete_role" if opts[:delete_role_given] + msg ||= "either :group or :role arguments requiered" unless opts[:group_given] || opts[:role_given] + abort(msg) unless msg.nil? + duplicate_for_group(opts[:source_group], opts[:group]) if opts[:group_given] + duplicate_for_role(opts[:source_group], opts[:role]) if opts[:role_given] +else + unless opts[:delete_group_given] || opts[:delete_role_given] + abort("use either :delete_group or :delete_role parameter for resetting report structure to default") + end + reset_for_group(opts[:delete_group]) if opts[:delete_group_given] + reset_for_role(opts[:delete_role]) if opts[:delete_role_given] +end \ No newline at end of file From 25b0e8299e03568977e51eb65d6185978c12d129 Mon Sep 17 00:00:00 2001 From: Yuri Rudman Date: Wed, 10 Oct 2018 11:51:45 -0400 Subject: [PATCH 2/6] do not use short options and make long options more descriptive --- tools/copy_reports_structure.rb | 36 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tools/copy_reports_structure.rb b/tools/copy_reports_structure.rb index 0e8040aab4d..b9b6387806f 100755 --- a/tools/copy_reports_structure.rb +++ b/tools/copy_reports_structure.rb @@ -65,28 +65,28 @@ def reset_for_role(role_name) " - make report structure configured for a group available to another group\n" \ " - make report structure configured for a group available to role\n" \ " - reset report access to default for group or role\n" \ - "Example (Duplicate for Group): bundle exec ruby #{__FILE__} -s EvmGroup -g SomeGroup\n" \ - "Example (Duplicate for Role): bundle exec ruby #{__FILE__} -s EvmGroup -r SomeRole\n" \ - "Example (Reset to Default for Group): bundle exec ruby #{__FILE__} -d SomeGroup\n" \ - "Example (Reset to Default for Role): bundle exec ruby #{__FILE__} -p SomeRole\n" - opt :source_group, "Source group to take report structure from", :short => "s", :type => :string - opt :group, "Destination group", :short => "g", :type => :string - opt :role, "Destination role", :short => "r", :type => :string - opt :delete_group, "Group to reset reports structure to default", :short => "d", :type => :string - opt :delete_role, "Role to reset reports structure to default", :short => "p", :type => :string + "Example (Duplicate for Group): bundle exec ruby #{__FILE__} --source-group=EvmGroup --target-group=SomeGroup\n" \ + "Example (Duplicate for Role): bundle exec ruby #{__FILE__} --source-group=EvmGroup --target-role=SomeRole\n" \ + "Example (Reset to Default for Group): bundle exec ruby #{__FILE__} --reset-group=SomeGroup\n" \ + "Example (Reset to Default for Role): bundle exec ruby #{__FILE__} --reset-role=SomeRole\n" + opt :source_group, "Source group to take report structure from", :short => :none, :type => :string + opt :target_group, "Target group to get report menue from source group", :short => :none, :type => :string + opt :target_role, "Target role to get report menue from source group", :short => :none, :type => :string + opt :reset_group, "Group to reset reports structure to default", :short => :none, :type => :string + opt :reset_role, "Role to reset reports structure to default", :short => :none, :type => :string end if opts[:source_group_given] - msg = ":source_group argument can not be used with :delete_group" if opts[:delete_group_given] - msg ||= ":source_group argument can not be used with :delete_role" if opts[:delete_role_given] - msg ||= "either :group or :role arguments requiered" unless opts[:group_given] || opts[:role_given] + msg = ":source-group argument can not be used with :reset-group" if opts[:reset_group_given] + msg ||= ":source-group argument can not be used with :reset-role" if opts[:reset_role_given] + msg ||= "either :target-group or :target-role arguments requiered" unless opts[:target_group_given] || opts[:target_role_given] abort(msg) unless msg.nil? - duplicate_for_group(opts[:source_group], opts[:group]) if opts[:group_given] - duplicate_for_role(opts[:source_group], opts[:role]) if opts[:role_given] + duplicate_for_group(opts[:source_group], opts[:target_group]) if opts[:target_group_given] + duplicate_for_role(opts[:source_group], opts[:target_role]) if opts[:target_role_given] else - unless opts[:delete_group_given] || opts[:delete_role_given] - abort("use either :delete_group or :delete_role parameter for resetting report structure to default") + unless opts[:reset_group_given] || opts[:reset_role_given] + abort("use either :reset_group or :reset_role parameter for resetting report structure to default") end - reset_for_group(opts[:delete_group]) if opts[:delete_group_given] - reset_for_role(opts[:delete_role]) if opts[:delete_role_given] + reset_for_group(opts[:reset_group]) if opts[:reset_group_given] + reset_for_role(opts[:reset_role]) if opts[:reset_role_given] end \ No newline at end of file From f2dc86af08517309404764ac79f11eb1ca385a11 Mon Sep 17 00:00:00 2001 From: Yuri Rudman Date: Wed, 10 Oct 2018 14:55:48 -0400 Subject: [PATCH 3/6] added dry-run --- tools/copy_reports_structure.rb | 57 +++++++++++++++++---------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/tools/copy_reports_structure.rb b/tools/copy_reports_structure.rb index b9b6387806f..fe58057ee0e 100755 --- a/tools/copy_reports_structure.rb +++ b/tools/copy_reports_structure.rb @@ -15,47 +15,47 @@ def find_role(role_name) role end -def duplicate_for_group(source_group_name, destination_group_name) +def duplicate_for_group(source_group_name, destination_group_name, dry_run) + puts "Copying report structure from group '#{source_group_name}' to group ' #{destination_group_name}' ..." destination_group = find_group(destination_group_name) - destination_group.settings = find_group(source_group_name).settings - destination_group.save! - puts "Reports structure was succesfully cloned from '#{source_group_name}' to '#{destination_group_name}'" + destination_group.update!(:settings => find_group(source_group_name).settings) unless dry_run + puts "Reports structure was successfully copied from '#{source_group_name}' to '#{destination_group_name}'" rescue StandardError => e - $stderr.puts e.message + $stderr.puts "Copying failed: #{e.message}" end -def duplicate_for_role(source_group_name, destination_role_name) +def duplicate_for_role(source_group_name, destination_role_name, dry_run) puts "Copying report structure from group '#{source_group_name}' to role ' #{destination_role_name}' ..." source_group = find_group(source_group_name) find_role(destination_role_name).miq_groups.each do |destination_group| begin - destination_group.settings = source_group.settings - destination_group.save! - puts " Reports structure was succesfully copied from '#{source_group_name}' to '#{destination_group.description}'" + destination_group.update!(:settings => source_group.settings) unless dry_run + puts " Reports structure was successfully copied from '#{source_group_name}' to '#{destination_group.description}'" rescue StandardError => e - $stderr.puts e.message + $stderr.puts "Copying failed: #{e.message}" end end end -def reset_for_group(group_name) +def reset_for_group(group_name, dry_run) + puts "Removing custom report structure for group '#{group_name}'..." group = find_group(group_name) - group.settings = nil - group.save! - puts "Succsefully removed custom report structure for group '#{group_name}'" -rescue StandardError => e - $stderr.puts e.message + begin + group.update!(:settings => nil) unless dry_run + puts "Successfully removed custom report structure for group '#{group_name}'" + rescue StandardError => e + $stderr.puts "Removing failed: #{e.message}" + end end -def reset_for_role(role_name) +def reset_for_role(role_name, dry_run) puts "Removing custom report structure for role '#{role_name}'..." find_role(role_name).miq_groups.each do |group| begin - group.settings = nil - group.save! - puts "Succsefully removed custom report structure for group '#{group.description}'" - rescue StandardError => e - $stderr.puts e.message + group.update!(:settings => nil) unless dry_run + puts "Successfully removed custom report structure for group '#{group.description}'" + rescue StandardError => e + $stderr.puts "Removing failed: #{e.message}" end end end @@ -69,6 +69,7 @@ def reset_for_role(role_name) "Example (Duplicate for Role): bundle exec ruby #{__FILE__} --source-group=EvmGroup --target-role=SomeRole\n" \ "Example (Reset to Default for Group): bundle exec ruby #{__FILE__} --reset-group=SomeGroup\n" \ "Example (Reset to Default for Role): bundle exec ruby #{__FILE__} --reset-role=SomeRole\n" + opt :dry_run, "Dry Run", :short => "d" opt :source_group, "Source group to take report structure from", :short => :none, :type => :string opt :target_group, "Target group to get report menue from source group", :short => :none, :type => :string opt :target_role, "Target role to get report menue from source group", :short => :none, :type => :string @@ -81,12 +82,14 @@ def reset_for_role(role_name) msg ||= ":source-group argument can not be used with :reset-role" if opts[:reset_role_given] msg ||= "either :target-group or :target-role arguments requiered" unless opts[:target_group_given] || opts[:target_role_given] abort(msg) unless msg.nil? - duplicate_for_group(opts[:source_group], opts[:target_group]) if opts[:target_group_given] - duplicate_for_role(opts[:source_group], opts[:target_role]) if opts[:target_role_given] + duplicate_for_group(opts[:source_group], opts[:target_group], opts[:dry_run]) if opts[:target_group_given] + duplicate_for_role(opts[:source_group], opts[:target_role], opts[:dry_run]) if opts[:target_role_given] else unless opts[:reset_group_given] || opts[:reset_role_given] abort("use either :reset_group or :reset_role parameter for resetting report structure to default") end - reset_for_group(opts[:reset_group]) if opts[:reset_group_given] - reset_for_role(opts[:reset_role]) if opts[:reset_role_given] -end \ No newline at end of file + reset_for_group(opts[:reset_group], opts[:dry_run]) if opts[:reset_group_given] + reset_for_role(opts[:reset_role], opts[:dry_run]) if opts[:reset_role_given] +end + +puts "**** Dry run, no updates have been made" if opts[:dry_run] \ No newline at end of file From e22ff2b2c1182d9a7ec3da2af4b4d9d08b366d70 Mon Sep 17 00:00:00 2001 From: Yuri Rudman Date: Thu, 11 Oct 2018 14:32:08 -0400 Subject: [PATCH 4/6] refactored to separate Trollop parsing from class with logic, it would help to write rspec --- tools/copy_reports_structure.rb | 68 +++---------------- .../report_structure.rb | 60 ++++++++++++++++ 2 files changed, 68 insertions(+), 60 deletions(-) mode change 100755 => 100644 tools/copy_reports_structure.rb create mode 100755 tools/copy_reports_structure/report_structure.rb diff --git a/tools/copy_reports_structure.rb b/tools/copy_reports_structure.rb old mode 100755 new mode 100644 index fe58057ee0e..c139c78faf5 --- a/tools/copy_reports_structure.rb +++ b/tools/copy_reports_structure.rb @@ -1,64 +1,12 @@ #!/usr/bin/env ruby require File.expand_path('../config/environment', __dir__) -require 'bundler/setup' -require 'trollop' - -def find_group(group_name) - group = MiqGroup.where(:description => group_name).first - abort("MiqGroup '#{group_name}' not found") if group.nil? - group -end - -def find_role(role_name) - role = MiqUserRole.where(:name => role_name).first - abort("MiqUserRole '#{role_name}' not found") if role.nil? - role -end - -def duplicate_for_group(source_group_name, destination_group_name, dry_run) - puts "Copying report structure from group '#{source_group_name}' to group ' #{destination_group_name}' ..." - destination_group = find_group(destination_group_name) - destination_group.update!(:settings => find_group(source_group_name).settings) unless dry_run - puts "Reports structure was successfully copied from '#{source_group_name}' to '#{destination_group_name}'" -rescue StandardError => e - $stderr.puts "Copying failed: #{e.message}" -end -def duplicate_for_role(source_group_name, destination_role_name, dry_run) - puts "Copying report structure from group '#{source_group_name}' to role ' #{destination_role_name}' ..." - source_group = find_group(source_group_name) - find_role(destination_role_name).miq_groups.each do |destination_group| - begin - destination_group.update!(:settings => source_group.settings) unless dry_run - puts " Reports structure was successfully copied from '#{source_group_name}' to '#{destination_group.description}'" - rescue StandardError => e - $stderr.puts "Copying failed: #{e.message}" - end - end -end - -def reset_for_group(group_name, dry_run) - puts "Removing custom report structure for group '#{group_name}'..." - group = find_group(group_name) - begin - group.update!(:settings => nil) unless dry_run - puts "Successfully removed custom report structure for group '#{group_name}'" - rescue StandardError => e - $stderr.puts "Removing failed: #{e.message}" - end +if __FILE__ == $PROGRAM_NAME + $LOAD_PATH.push(File.expand_path(__dir__)) end -def reset_for_role(role_name, dry_run) - puts "Removing custom report structure for role '#{role_name}'..." - find_role(role_name).miq_groups.each do |group| - begin - group.update!(:settings => nil) unless dry_run - puts "Successfully removed custom report structure for group '#{group.description}'" - rescue StandardError => e - $stderr.puts "Removing failed: #{e.message}" - end - end -end +require 'trollop' +require 'copy_reports_structure/report_structure' opts = Trollop.options(ARGV) do banner "Utility to: \n" \ @@ -82,14 +30,14 @@ def reset_for_role(role_name, dry_run) msg ||= ":source-group argument can not be used with :reset-role" if opts[:reset_role_given] msg ||= "either :target-group or :target-role arguments requiered" unless opts[:target_group_given] || opts[:target_role_given] abort(msg) unless msg.nil? - duplicate_for_group(opts[:source_group], opts[:target_group], opts[:dry_run]) if opts[:target_group_given] - duplicate_for_role(opts[:source_group], opts[:target_role], opts[:dry_run]) if opts[:target_role_given] + ReportStructure.duplicate_for_group(opts[:source_group], opts[:target_group], opts[:dry_run]) if opts[:target_group_given] + ReportStructure.duplicate_for_role(opts[:source_group], opts[:target_role], opts[:dry_run]) if opts[:target_role_given] else unless opts[:reset_group_given] || opts[:reset_role_given] abort("use either :reset_group or :reset_role parameter for resetting report structure to default") end - reset_for_group(opts[:reset_group], opts[:dry_run]) if opts[:reset_group_given] - reset_for_role(opts[:reset_role], opts[:dry_run]) if opts[:reset_role_given] + ReportStructure.reset_for_group(opts[:reset_group], opts[:dry_run]) if opts[:reset_group_given] + ReportStructure.reset_for_role(opts[:reset_role], opts[:dry_run]) if opts[:reset_role_given] end puts "**** Dry run, no updates have been made" if opts[:dry_run] \ No newline at end of file diff --git a/tools/copy_reports_structure/report_structure.rb b/tools/copy_reports_structure/report_structure.rb new file mode 100755 index 00000000000..44746fda03d --- /dev/null +++ b/tools/copy_reports_structure/report_structure.rb @@ -0,0 +1,60 @@ +class ReportStructure + + def self.duplicate_for_group(source_group_name, destination_group_name, dry_run = false) + puts "Copying report structure from group '#{source_group_name}' to group ' #{destination_group_name}' ..." + destination_group = find_group(destination_group_name) + destination_group.update!(:settings => find_group(source_group_name).settings) unless dry_run + puts "Reports structure was successfully copied from '#{source_group_name}' to '#{destination_group_name}'" + rescue StandardError => e + $stderr.puts "Copying failed: #{e.message}" + end + + def self.duplicate_for_role(source_group_name, destination_role_name, dry_run = false) + puts "Copying report structure from group '#{source_group_name}' to role ' #{destination_role_name}' ..." + source_group = find_group(source_group_name) + find_role(destination_role_name).miq_groups.each do |destination_group| + begin + destination_group.update!(:settings => source_group.settings) unless dry_run + puts " Reports structure was successfully copied from '#{source_group_name}' to '#{destination_group.description}'" + rescue StandardError => e + $stderr.puts "Copying failed: #{e.message}" + end + end + end + + def self.reset_for_group(group_name, dry_run = false) + puts "Removing custom report structure for group '#{group_name}'..." + group = find_group(group_name) + begin + group.update!(:settings => nil) unless dry_run + puts "Successfully removed custom report structure for group '#{group_name}'" + rescue StandardError => e + $stderr.puts "Removing failed: #{e.message}" + end + end + + def self.reset_for_role(role_name, dry_run = false) + puts "Removing custom report structure for role '#{role_name}'..." + find_role(role_name).miq_groups.each do |group| + begin + group.update!(:settings => nil) unless dry_run + puts "Successfully removed custom report structure for group '#{group.description}'" + rescue StandardError => e + $stderr.puts "Removing failed: #{e.message}" + end + end + end + + def self.find_group(group_name) + group = MiqGroup.where(:description => group_name).first + abort("MiqGroup '#{group_name}' not found") if group.nil? + group + end + + def self.find_role(role_name) + role = MiqUserRole.where(:name => role_name).first + abort("MiqUserRole '#{role_name}' not found") if role.nil? + role + end +end + From 6ce89e3b77482f5a311f6dda767b44b78c30728e Mon Sep 17 00:00:00 2001 From: Yuri Rudman Date: Thu, 11 Oct 2018 14:33:46 -0400 Subject: [PATCH 5/6] addded rspec covering copying reports structure --- spec/tools/copy_reports_structure_spec.rb | 64 +++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 spec/tools/copy_reports_structure_spec.rb diff --git a/spec/tools/copy_reports_structure_spec.rb b/spec/tools/copy_reports_structure_spec.rb new file mode 100644 index 00000000000..5a187bdf0d4 --- /dev/null +++ b/spec/tools/copy_reports_structure_spec.rb @@ -0,0 +1,64 @@ +$LOAD_PATH << Rails.root.join("tools").to_s + +require 'copy_reports_structure/report_structure' + +describe ReportStructure do + let(:group_name) { "SourceGroup" } + let(:settings) { {"reports_menus" => [["Configuration Management", ["Virtual Machines", ["Vendor and Type"]]]]} } + let(:role) { FactoryGirl.create(:miq_user_role) } + let(:source_group) { FactoryGirl.create(:miq_group, :settings => settings) } + let(:destination_group) { FactoryGirl.create(:miq_group, :miq_user_role => role) } + + context "copy reports structure" do + describe ".duplicate_for_group" do + it "copies reports structure from one group to another" do + ReportStructure.duplicate_for_group(source_group.description, destination_group.description) + destination_group.reload + expect(destination_group.settings).to eq(settings) + end + + it "does not copy reports structure if dry_run is set to true" do + ReportStructure.duplicate_for_group(source_group.description, destination_group.description, true) + destination_group.reload + expect(destination_group.settings).to be nil + end + + it "does not change reports structure on destination group is source group not found" do + expect(ReportStructure).to receive(:abort) + ReportStructure.duplicate_for_group("Some_Not_existed_Group", source_group.description) + source_group.reload + expect(source_group.settings).to eq(settings) + end + end + + describe ".duplicate_for_role" do + before do + @destination_group2 = FactoryGirl.create(:miq_group, :miq_user_role => destination_group.miq_user_role) + end + + it "copies reports structure from one group to role (to all groups having that role)" do + ReportStructure.duplicate_for_role(source_group.description, role.name) + destination_group.reload + expect(destination_group.settings).to eq(settings) + @destination_group2.reload + expect(@destination_group2.settings).to eq(settings) + end + + it "does not copy reports structure if dry_run is set to true" do + ReportStructure.duplicate_for_role(source_group.description, role.name, true) + destination_group.reload + expect(destination_group.settings).to be nil + @destination_group2.reload + expect(@destination_group2.settings).to be nil + end + + it "does not change reports structure on group with destination role is source group not found" do + destination_group.update(:settings => settings) + expect(ReportStructure).to receive(:abort) + ReportStructure.duplicate_for_role("Some_Not_existed_Group", role.name) + destination_group.reload + expect(destination_group.settings).to eq(settings) + end + end + end +end \ No newline at end of file From c675c6aa13f37a88986e68f55eeb0e21230d68c9 Mon Sep 17 00:00:00 2001 From: Yuri Rudman Date: Thu, 11 Oct 2018 15:10:32 -0400 Subject: [PATCH 6/6] aded rspec covering resetting reports structure --- spec/tools/copy_reports_structure_spec.rb | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/spec/tools/copy_reports_structure_spec.rb b/spec/tools/copy_reports_structure_spec.rb index 5a187bdf0d4..9a38c993ce9 100644 --- a/spec/tools/copy_reports_structure_spec.rb +++ b/spec/tools/copy_reports_structure_spec.rb @@ -61,4 +61,37 @@ end end end + + context "reset reports structure" do + describe ".reset_for_group" do + it "reset report structure to default for group" do + ReportStructure.reset_for_group(source_group.description) + source_group.reload + expect(source_group.settings).to be nil + end + end + + describe ".reset_for_role" do + before do + source_group.update(:miq_user_role => role) + destination_group.update(:settings => settings) + end + + it "reset reports structure to default for role" do + ReportStructure.reset_for_role(role.name) + source_group.reload + destination_group.reload + expect(source_group.settings).to be nil + expect(destination_group.settings).to be nil + end + + it "does not reset reports if dry_run is set to true" do + ReportStructure.reset_for_role(role.name, true) + source_group.reload + destination_group.reload + expect(source_group.settings).to eq(settings) + expect(destination_group.settings).to eq(settings) + end + end + end end \ No newline at end of file