-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1572 from yeti-switch/1569-interval-report-except…
…ion-on-empty-group-by #1569, fix when Render data of "Report Interval Cdr" with empty group_by
- Loading branch information
Showing
11 changed files
with
70 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
db/cdr_migrate/20241006113650_change_default_for_cdr_interval_report.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class ChangeDefaultForCdrIntervalReport < ActiveRecord::Migration[7.0] | ||
def change | ||
change_column_default 'reports.cdr_interval_report', :group_by, from: nil, to: [] | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
db/cdr_migrate/20241006123022_update_reports_cdr_interval_report_to_change_null_group_by.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class UpdateReportsCdrIntervalReportToChangeNullGroupBy < ActiveRecord::Migration[7.0] | ||
def up | ||
execute "UPDATE reports.cdr_interval_report SET group_by = '{}' WHERE group_by IS NULL;" | ||
change_column_null 'reports.cdr_interval_report', 'group_by', false | ||
end | ||
|
||
def down | ||
change_column_null 'reports.cdr_interval_report', 'group_by', true | ||
execute "UPDATE reports.cdr_interval_report SET group_by = NULL WHERE group_by = '{}';" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Report::IntervalCdrForm do | ||
subject { form.save } | ||
|
||
let(:form) { described_class.new(form_attributes) } | ||
let(:form_attributes) do | ||
{ | ||
date_start: Time.current.to_fs(:db), | ||
date_end: Time.current.to_fs(:db), | ||
interval_length: 5, | ||
aggregate_by: Report::IntervalCdr::CDR_AGG_COLUMNS.sample, | ||
aggregator_id: Report::IntervalAggregator.take!.id | ||
} | ||
end | ||
|
||
context 'when group_by is not filled' do | ||
let(:form_attributes) { super().merge group_by: [''] } | ||
|
||
it 'should create record with empty group_by' do | ||
expect { subject }.to change(Report::IntervalCdr, :count).by(1) | ||
expect(Report::IntervalCdr.take!).to have_attributes(group_by: []) | ||
end | ||
end | ||
|
||
context 'when group_by is filled' do | ||
let(:form_attributes) { super().merge group_by: Report::IntervalCdr::CDR_COLUMNS.first(2) } | ||
|
||
it 'should create record with NOT empty group_by' do | ||
expect { subject }.to change(Report::IntervalCdr, :count).by(1) | ||
expect(Report::IntervalCdr.take!).to have_attributes group_by: Report::IntervalCdr::CDR_COLUMNS.first(2).map(&:to_s) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters