Skip to content

Commit

Permalink
chore: Add new fields to Reports::Nomination model and Reports::Nomin…
Browse files Browse the repository at this point in the history
…ationsReport class

Signed-off-by: Louis Kirkham <[email protected]>
  • Loading branch information
TheDancingClown committed Aug 7, 2024
1 parent 5c6d3ee commit 2d7e690
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/models/reports/nomination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,26 @@ def secondary_activity
obj.secondary_activity.presence && NomineeActivityHelper.lookup_label_for_activity(obj.secondary_activity.to_sym)
end

def nominee_established_date
doc["nominee_established_date"]
end

def group_activities
doc["group_activities"]
end

def beneficiaries
doc["beneficiaries"]
end

def benefits
doc["benefits"]
end

def volunteers
doc["volunteers"]
end

def ceremonial_county
obj.ceremonial_county.try(:name)
end
Expand Down
22 changes: 21 additions & 1 deletion app/models/reports/nominations_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,27 @@ class Reports::NominationsReport < Reports::QavsBase
{
label: "Assigned Sub-Group",
method: :sub_group,
}
},
{
label: "Year founded",
method: :nominee_established_date,
},
{
label: "Please summarise the activities of the group",
method: :group_activities,
},
{
label: "Who are the beneficiaries (the people it helps) and where do they live?",
method: :beneficiaries,
},
{
label: "What are the benefits of the group's work?",
method: :benefits,
},
{
label: "This Award is specifically for groups that rely on significant and committed work by volunteers. Please explain what the volunteers do and what makes this particular group of volunteers so impressive?",
method: :volunteers,
},
]

private
Expand Down
31 changes: 31 additions & 0 deletions spec/models/reports/nominations_report_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'rails_helper'
require 'csv'

RSpec.describe Reports::NominationsReport, type: :model do
let!(:form_answer) { create(:form_answer) }
let(:report) { Reports::NominationsReport.new(FormAnswer.all).build }
let(:csv_content) { CSV.parse(report, headers: true) }

context 'renders the report with data' do
it "renders rows" do
expect(csv_content.length).to eq(1)
end

it "renders the correct columns" do
columns = Reports::NominationsReport::MAPPING
expect(csv_content.headers.length).to eq(columns.length)

columns.each do |column|
expect(csv_content.headers).to include(column[:label])
end
end

it 'renders the correct data' do
columns = Reports::NominationsReport::MAPPING
nomination = Reports::Nomination.new(form_answer)
columns.each do |column|
expect(csv_content[0][column[:label]]).to eq(nomination.call_method(column[:method]).to_s)
end
end
end
end

0 comments on commit 2d7e690

Please sign in to comment.