From 80373b62eb6ccd3a5213cdacaff74484f3b17564 Mon Sep 17 00:00:00 2001 From: Yuri Rudman Date: Tue, 12 Feb 2019 13:30:39 -0500 Subject: [PATCH] adjusting rspec to accomodate below: if widget contents for specific Timezone not found than remove Timezone from search and try to find contents again without specifying timezone --- spec/models/miq_widget_spec.rb | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/spec/models/miq_widget_spec.rb b/spec/models/miq_widget_spec.rb index dbf6e3531f2..4209d7688a0 100644 --- a/spec/models/miq_widget_spec.rb +++ b/spec/models/miq_widget_spec.rb @@ -165,7 +165,7 @@ def add_dashboard_for_user(db_name, userid, group) end context "#contents_for_user" do - it "user owned" do + it "returns user owned widget contents in UTC timezone if user's timezone not specified" do content = FactoryBot.create(:miq_widget_content, :miq_widget => @widget_report_vendor_and_guest_os, :user_id => @user1.id, @@ -175,24 +175,26 @@ def add_dashboard_for_user(db_name, userid, group) expect(@widget_report_vendor_and_guest_os.contents_for_user(@user1)).to eq(content) end - it "owned by miq_group and in user's timezone" do + it "returns widget contents in user's timezone when content from different timezone also available" do @user1.settings.store_path(:display, :timezone, "Eastern Time (US & Canada)") - content = FactoryBot.create(:miq_widget_content, - :miq_widget => @widget_report_vendor_and_guest_os, - :miq_group_id => @group1.id, - :timezone => "Eastern Time (US & Canada)" - ) - expect(@widget_report_vendor_and_guest_os.contents_for_user(@user1)).to eq(content) + FactoryBot.create(:miq_widget_content, + :miq_widget => @widget_report_vendor_and_guest_os, + :miq_group_id => @group1.id, + :timezone => "UTC") + content_user_timezone = FactoryBot.create(:miq_widget_content, + :miq_widget => @widget_report_vendor_and_guest_os, + :miq_group_id => @group1.id, + :timezone => "Eastern Time (US & Canada)") + expect(@widget_report_vendor_and_guest_os.contents_for_user(@user1)).to eq(content_user_timezone) end - it "owned by miq_group and not in user's timezone" do + it "returns widget contents if only content available is not in user's timezone" do @user1.settings.store_path(:display, :timezone, "Eastern Time (US & Canada)") - FactoryBot.create(:miq_widget_content, - :miq_widget => @widget_report_vendor_and_guest_os, - :miq_group_id => @group1.id, - :timezone => "UTC" - ) - expect(@widget_report_vendor_and_guest_os.contents_for_user(@user1)).to be_nil + content_utc = FactoryBot.create(:miq_widget_content, + :miq_widget => @widget_report_vendor_and_guest_os, + :miq_group_id => @group1.id, + :timezone => "UTC") + expect(@widget_report_vendor_and_guest_os.contents_for_user(@user1)).to eq(content_utc) end it "both user and miq_group owned" do