diff --git a/app/models/project.rb b/app/models/project.rb index a44e6cd..f1193be 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -38,7 +38,7 @@ class Project < ApplicationRecord has_many :issues, dependent: :destroy has_many :statement_of_works, dependent: :destroy has_many :dynamic_datasets, dependent: :destroy - has_one :project_report + has_one :project_report, dependent: :destroy validates :name, presence: true, uniqueness: { case_sensitive: false } validates :billable, inclusion: { in: [true, false] } diff --git a/app/views/projects/_project.json.jbuilder b/app/views/projects/_project.json.jbuilder index 71f468f..c8b1451 100644 --- a/app/views/projects/_project.json.jbuilder +++ b/app/views/projects/_project.json.jbuilder @@ -11,3 +11,5 @@ end json.extract! project, :id, :name, :billable, :slack_channel, :metadata, :slug, :logo_url, :sync_source_control, :sync_ticket_tracking_system, :logo_background_color, :display_code_metrics, :display_tasks_metrics + +json.report_key project.project_report&.key diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index f97e9f5..7fdf3fe 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -46,6 +46,14 @@ expect(response.parsed_body['customer']['id']).to eq(project.customer.id) end + + it 'returns a report key if it has a project_report' do + project = Project.create! valid_attributes + project.project_report = ProjectReport.create!(project:, key: '123') + + get :show, params: { id: project.to_param }, format: :json + expect(response.parsed_body['report_key']).to eq('123') + end end describe 'POST #create' do