-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix specs related to widget set factories #7594
Changes from 6 commits
135c397
6ad6f0f
b9379a8
be25fda
ceb4ba5
c9db235
ec55b7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,27 +208,33 @@ | |
end | ||
|
||
context "Create Dashboard" do | ||
let(:widget) { FactoryBot.create(:miq_widget) } | ||
|
||
before do | ||
EvmSpecHelper.local_miq_server | ||
@group = FactoryBot.create(:miq_group, :miq_user_role => FactoryBot.create(:miq_user_role, :features => %w[everything])) | ||
@user = FactoryBot.create(:user, :miq_groups => [@group]) | ||
# create dashboard for a group | ||
@ws = FactoryBot.create(:miq_widget_set, | ||
:name => "group_default", | ||
:set_data => {:last_group_db_updated => Time.now.utc, | ||
:col1 => [], :col2 => [], :col3 => []}, | ||
:set_data => {:col1 => [widget.id], :col2 => [], :col3 => [], :last_group_db_updated => Time.now.utc}, | ||
# :userid => @user.userid, | ||
:group_id => @group.id) | ||
:owner => @group) | ||
@group.update(:settings => {:dashboard_order => [@ws.id]}) | ||
end | ||
|
||
it "dashboard show" do | ||
EvmSpecHelper.local_miq_server | ||
controller.instance_variable_set(:@sb, :active_db => @ws.name) | ||
controller.instance_variable_set(:@tabs, []) | ||
login_as @user | ||
# create a user's dashboard using group dashboard name. | ||
FactoryBot.create(:miq_widget_set, | ||
:name => "#{@user.userid}|#{@group.id}|#{@ws.name}", | ||
:set_data => {:last_group_db_updated => Time.now.utc, :col1 => [1], :col2 => [], :col3 => []}) | ||
:name => @user.userid.to_s, | ||
:owner => @user, | ||
:group_id => @user.current_group_id, | ||
:set_data => {:col1 => [widget.id], :col2 => [], :col3 => [], :last_group_db_updated => Time.now.utc}) | ||
|
||
controller.show | ||
expect(controller.send(:flash_errors?)).not_to be_truthy | ||
end | ||
|
@@ -259,7 +265,8 @@ | |
controller.show | ||
|
||
# change original dashboard and set reset_upon_login flag to true | ||
@ws.update(:set_data => {:last_group_db_updated => Time.now.utc, :reset_upon_login => true, :col1 => [], :col2 => [], :col3 => []}) | ||
@ws.set_data.merge(:last_group_db_updated => Time.now.utc, :reset_upon_login => true) | ||
@ws.save! | ||
|
||
# get user's copy of dashboard and add widgets | ||
user_dashboard = MiqWidgetSet.find_by(:name => @ws.name, :userid => @user.userid) | ||
|
@@ -329,27 +336,29 @@ | |
|
||
let(:user) { FactoryBot.create(:user, :miq_groups => [group]) } | ||
|
||
let(:widget) { FactoryBot.create(:miq_widget) } | ||
let(:wset) do | ||
FactoryBot.create( | ||
:miq_widget_set, | ||
:name => "Widgets", | ||
:userid => user.userid, | ||
:group_id => group.id, | ||
:owner => group, | ||
:set_data => { | ||
:last_group_db_updated => Time.now.utc, | ||
:col1 => [1], :col2 => [], :col3 => [] | ||
:col1 => [widget.id], :col2 => [], :col3 => [] | ||
} | ||
) | ||
end | ||
|
||
before do | ||
EvmSpecHelper.local_miq_server | ||
login_as user | ||
|
||
controller.params = {:tab => wset.id} | ||
controller.instance_variable_set( | ||
:@sb, | ||
:active_db => wset.name, :active_db_id => wset.id, | ||
:dashboards => { wset.name => {:col1 => [1], :col2 => [], :col3 => []} } | ||
:dashboards => {wset.name => {:col1 => [widget.id], :col2 => [], :col3 => []}} | ||
) | ||
|
||
controller.show | ||
|
@@ -461,20 +470,24 @@ | |
context 'changing tabs' do | ||
let(:group) { FactoryBot.create(:miq_group, :features => %w[everything]) } | ||
let(:user) { FactoryBot.create(:user_admin, :current_group => group, :miq_groups => [group]) } | ||
let(:widget) { FactoryBot.create(:miq_widget) } | ||
let(:ws1) do | ||
FactoryBot.create(:miq_widget_set, | ||
:name => 'A', | ||
:owner_id => group.id, | ||
:set_data => {:col1 => [], :col2 => [], :col3 => []}) | ||
:set_data => {:col1 => [widget.id], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that a lot of these sets were incomplete which made me uncomfortable. That is where the smarter factory with encapsulation came into play. An alternative would be to put the setter into the actual model and treat these like fields (which is probably the correct schema/interface) |
||
:col2 => [], | ||
:col3 => []}, | ||
:owner => group) | ||
end | ||
let(:ws2) do | ||
FactoryBot.create(:miq_widget_set, | ||
:name => 'B', | ||
:owner_id => group.id, | ||
:set_data => {:col1 => [], :col2 => [], :col3 => []}) | ||
:set_data => {:col1 => [widget.id], :col2 => [], :col3 => []}, | ||
:owner => group) | ||
end | ||
|
||
before do | ||
EvmSpecHelper.local_miq_server | ||
login_as user | ||
controller.params = {'uib-tab' => ws2.id.to_s} | ||
controller.instance_variable_set(:@sb, {}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
describe ReportController do | ||
context "::Dashboards" do | ||
let(:miq_widget_set) { FactoryBot.create(:miq_widget_set, :owner => user.current_group, :set_data => {:col1 => [], :col2 => [], :col3 => []}) } | ||
let(:miq_widget) { FactoryBot.create(:miq_widget) } | ||
let(:miq_widget_set) { FactoryBot.create(:miq_widget_set, :owner => user.current_group, :set_data => {:col1 => [miq_widget.id], :col2 => [], :col3 => []}) } | ||
let(:user) { FactoryBot.create(:user, :features => "db_edit") } | ||
|
||
before do | ||
|
@@ -102,9 +103,9 @@ | |
allow(controller).to receive(:db_fields_validation) | ||
allow(controller).to receive(:replace_right_cell) | ||
owner = miq_widget_set.owner | ||
new_hash = {:name => "New Name", :description => "New Description", :col1 => [1], :col2 => [], :col3 => []} | ||
current = {:name => "New Name", :description => "New Description", :col1 => [], :col2 => [], :col3 => []} | ||
controller.instance_variable_set(:@edit, :new => new_hash, :db_id => miq_widget_set.id, :current => current) | ||
new_widget = FactoryBot.create(:miq_widget) | ||
new_hash = {:name => "New Name", :description => "New Description", :col1 => [new_widget.id], :col2 => [], :col3 => []} | ||
controller.instance_variable_set(:@edit, :new => new_hash, :db_id => miq_widget_set.id, :current => miq_widget_set.set_data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wasn't sure if this needed a deep clone. One thing is for certain, setting this to an invalid hash (with no widgets at all) was not productive |
||
controller.params = {:id => miq_widget_set.id, :button => "save"} | ||
controller.db_edit | ||
expect(miq_widget_set.owner.id).to eq(owner.id) | ||
|
@@ -115,7 +116,7 @@ | |
|
||
describe "#db_save_members" do | ||
let(:set_data) do | ||
Array.new(3) { |n| ["col#{(n + 1)}".to_sym, Array.new(2, FactoryBot.create(:miq_widget))] }.to_h | ||
Array.new(3) { |n| ["col#{(n + 1)}".to_sym, Array.new(2, FactoryBot.create(:miq_widget).id)] }.to_h | ||
end | ||
|
||
before do | ||
|
@@ -132,7 +133,7 @@ | |
controller.send(:db_save_members) | ||
|
||
miq_widget_set.reload | ||
expect(miq_widget_set.members.uniq).to match_array((set_data[:col1] + set_data[:col2] + set_data[:col3]).uniq) | ||
expect(miq_widget_set.members.uniq.map(&:id)).to match_array((set_data[:col1] + set_data[:col2] + set_data[:col3]).uniq) | ||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,8 @@ | |
end | ||
|
||
it 'renders list of Dashboards in Dashboards tree' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not thrilled about these but had trouble seeding a widget set without valid data. I guess manually creating the default would have worked as well |
||
MiqReport.seed | ||
MiqWidget.seed | ||
MiqWidgetSet.seed | ||
post :tree_select, :params => { :id => 'root', :format => :js, :accord => 'db' } | ||
expect(response).to render_template('report/_db_list') | ||
|
@@ -107,11 +109,13 @@ | |
expect(response.body).not_to include(other_group.name) | ||
end | ||
|
||
let(:miq_widget) { FactoryBot.create(:miq_widget) } | ||
|
||
it 'renders show of Dashboards in Dashboards tree' do | ||
ApplicationController.handle_exceptions = true | ||
|
||
MiqWidgetSet.seed | ||
widget_set = FactoryBot.create(:miq_widget_set, :group_id => user.current_group.id) | ||
widget_set = FactoryBot.create(:miq_widget_set, :set_data => {:col1 => [miq_widget.id]}, :owner_id => user.current_group.id, :group_id => user.current_group.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there are a bunch of places where the |
||
post :tree_select, :params => { :id => "xx-g_g-#{user.current_group.id}_ws-#{widget_set.id}", :format => :js, :accord => 'db' } | ||
expect(response).to render_template('report/_db_show') | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean we should fix the before validation in the model to work with users?
Thinking having a
user_with_group
may be what we want