diff --git a/app/services/report_actions/report_content.rb b/app/services/report_actions/report_content.rb index 7aa215315..9a97ed355 100644 --- a/app/services/report_actions/report_content.rb +++ b/app/services/report_actions/report_content.rb @@ -29,9 +29,11 @@ module ReportActions # Delete existing template values @report.report_template_values.destroy_all - formatted_template_values = @template_values.as_json.map { |k, v| v['name'] = k; v } - # Save new template values - @report.report_template_values.create!(formatted_template_values) + if @template_values.present? + formatted_template_values = @template_values.as_json.map { |k, v| v['name'] = k; v } + # Save new template values + @report.report_template_values.create!(formatted_template_values) + end end @report diff --git a/spec/controllers/reports_controller_spec.rb b/spec/controllers/reports_controller_spec.rb index 2e8a9ce27..282871c7f 100644 --- a/spec/controllers/reports_controller_spec.rb +++ b/spec/controllers/reports_controller_spec.rb @@ -9,9 +9,10 @@ describe ReportsController, type: :controller do let!(:team) { create :team, created_by: user } let!(:user_team) { create :user_team, team: team, user: user } let(:user_project) { create :user_project, :owner, user: user } - let(:project) do - create :project, team: team, user_projects: [user_project] - end + let(:project) { create :project, team: team, user_projects: [user_project] } + let(:experiment) { create :experiment, project: project } + let(:my_module1) { create :my_module, experiment: experiment } + let(:my_module2) { create :my_module, experiment: experiment } let(:report) do create :report, user: user, project: project, team: team, name: 'test repot A1', description: 'test description A1' @@ -23,9 +24,10 @@ describe ReportsController, type: :controller do let(:params) do { project_id: project.id, report: { name: 'test report created', - description: 'test description created' }, - report_contents: '[{"type_of":"project_header","id":{"project_id":' + - project.id.to_s + '},"sort_order":null,"children":[]}]' } + description: 'test description created', + settings: Report::DEFAULT_SETTINGS }, + project_content: { experiments: { experiment.id => [my_module1.id] } }, + template_values: [] } end it 'calls create activity service' do @@ -49,8 +51,8 @@ describe ReportsController, type: :controller do id: report.id, report: { name: 'test report update', description: 'test description update' }, - report_contents: '[{"type_of":"project_header","id":{"project_id":' + - project.id.to_s + '},"sort_order":null,"children":[]}]' } + project_content: { experiments: { experiment.id => [my_module2.id] } }, + template_values: [] } end it 'calls create activity service' do expect(Activities::CreateActivityService).to receive(:call)