Skip to content

Commit

Permalink
Add spec to check setting proper string with unavailable fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilda Stastna committed Apr 3, 2019
1 parent e84311c commit 55d06fa
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
46 changes: 42 additions & 4 deletions spec/controllers/miq_report_controller/reports/editor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
end
end

context "::Reports::Editor" do
context "#set_form_vars" do
describe "::Reports::Editor" do
describe "#set_form_vars" do
let(:user) { stub_user(:features => :all) }

let(:chargeback_report) do
Expand Down Expand Up @@ -109,14 +109,15 @@

describe '#reportable_models' do
subject { controller.send(:reportable_models) }

it 'does not contain duplicate items' do
duplicates = subject.group_by(&:first).select { |_, v| v.size > 1 }.map(&:first)
expect(duplicates).to be_empty
end
end
end

context "#miq_report_edit" do
describe "#miq_report_edit" do
it "should build tabs with correct tab id after reset button is pressed to prevent error when changing tabs" do
user = stub_user(:features => :all)
user.save!
Expand Down Expand Up @@ -200,7 +201,7 @@
end
end

describe "set_form_vars" do
describe "#set_form_vars" do
let(:admin_user) { FactoryBot.create(:user, :role => "super_administrator") }
let(:chargeback_report) do
FactoryBot.create(:miq_report, :db => "ChargebackVm", :col_order => ["name"], :headers => ["Name"])
Expand Down Expand Up @@ -282,6 +283,43 @@ def empty_category(attrs = {})
expect(controller.send(:entries_hash, "no_such_name")).to eq({})
end
end

describe '#form_field_changed' do
before do
allow(controller).to receive(:build_edit_screen)
allow(controller).to receive(:get_form_vars)
allow(controller).to receive(:load_edit).and_return(true)
allow(controller).to receive(:render)
controller.instance_variable_set(:@edit, :new => {:model => model})
end

context 'configuring Report Columns and Chargeback for VMs' do
let(:model) { 'ChargebackVm' }

it 'sets string with unavailable fields while adding/editing report' do
controller.send(:form_field_changed)
expect(controller.instance_variable_get(:@unav_fields)).to eq('CPU Cores Allocated Metric, CPU Cores Used Metric, Fixed Compute Metric, Fixed Storage Metric')
end
end

context 'configuring Report Columns and Chargeback for Images' do
let(:model) { 'ChargebackContainerImage' }

it 'sets string with unavailable fields while adding/editing report' do
controller.send(:form_field_changed)
expect(controller.instance_variable_get(:@unav_fields)).to eq('CPU Allocated Metric, CPU Used Metric, Disk I/O Used Metric, Fixed Compute Metric, Fixed Storage Metric, Storage Allocated Metric, Storage Used Metric')
end
end

context 'configuring Report Columns and Chargeback for Projects' do
let(:model) { 'ChargebackContainerProject' }

it 'sets string with unavailable fields while adding/editing report' do
controller.send(:form_field_changed)
expect(controller.instance_variable_get(:@unav_fields)).to eq('CPU Allocated Metric, CPU Used Metric, CPU Cores Allocated Metric, Disk I/O Used Metric, Fixed Compute Metric, Memory Allocated Metric, Fixed Storage Metric, Storage Allocated Metric, Storage Used Metric')
end
end
end
end

describe '#verify is_valid? flash messages' do
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/report_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create_and_generate_report_for_user(report_name, user_id)
end

describe ReportHelper do
context '#chart_fields_options' do
describe '#chart_fields_options' do
it 'should return fields with models and aggregate functions from summary when "Show Sort Breaks" is not "No"' do
@edit = {
:new => {
Expand Down

0 comments on commit 55d06fa

Please sign in to comment.