Skip to content

Commit

Permalink
Merge pull request #706 from bitzesty/nomination-csv
Browse files Browse the repository at this point in the history
Adds additional columns to NominationsReport
  • Loading branch information
dreamfall authored Aug 9, 2024
2 parents 5c6d3ee + 1d19517 commit 3f9d314
Show file tree
Hide file tree
Showing 3 changed files with 87 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
30 changes: 29 additions & 1 deletion app/models/reports/nominations_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,40 @@ 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

def mapping
MAPPING
end

def sanitize_string(string)
if string.present?
ActionView::Base.full_sanitizer.sanitize(string.to_s.strip)
else
""
end
end
end
38 changes: 38 additions & 0 deletions spec/models/reports/nominations_report_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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

it 'renders new lines' do
test_answer = "Line one\nLine two\nLine three"
form_answer.document[:group_activities] = test_answer
form_answer.save
expect(csv_content[0]["Please summarise the activities of the group"]).to eq(test_answer)
end
end
end

0 comments on commit 3f9d314

Please sign in to comment.