Skip to content

Commit

Permalink
added application's annotations to pdf, added more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lennart L committed Dec 13, 2016
1 parent 9974ea4 commit 83c72e8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
8 changes: 8 additions & 0 deletions lib/pdf_generation/applications_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ def create_application_page_content(application_letter)
end
pad_top(10) { text "<u>#{ApplicationLetter.human_attribute_name(:motivation)}</u>", inline_format: true}
pad_top(5) { text application_letter.motivation }
unless application_letter.application_notes.count == 0
pad_top(15) {
text "<u>#{ApplicationNote.model_name.human(count: application_letter.application_notes.count)}</u>", inline_format: true
application_letter.application_notes.each do |note|
pad_top(5) { text note.note }
end
}
end
end

def applicants_detail_data(application_letter)
Expand Down
34 changes: 30 additions & 4 deletions spec/controllers/events_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,21 +252,47 @@
@event.date_ranges.each { |d| expect(text).to include(d.to_s) }
end

it "shows an overview of every application" do
FactoryGirl.create(:application_letter, event: @event,)
it "shows an overview of all and details of every application" do
al = FactoryGirl.create(:application_letter, event: @event,)
FactoryGirl.create(:application_note, application_letter_id: al.id)
User.find_each { |u| FactoryGirl.create(:profile, user: u) }
get :print_applications, id: @event.to_param, session: valid_session
analysis = PDF::Inspector::Text.analyze response.body
text = analysis.strings.join
text = analysis.strings.join(' ')
@event.application_letters.each do |a|
expect(text).to include(
a.user.profile.name,
a.user.profile.age.to_s,
a.user.profile.gender,
a.user.accepted_applications_count(@event).to_s,
a.user.rejected_applications_count(@event).to_s,
a.status)
I18n.t("application_status.#{a.status}"),
a.user.profile.address,
a.motivation
)
a.application_notes.each do |note|
expect(text).to include(
note.note
)
end
end
end

it "includes at last one page per application" do
FactoryGirl.create(:application_letter, event: @event,)
FactoryGirl.create(:application_letter2, event: @event,)
User.find_each { |u| FactoryGirl.create(:profile, user: u) }
get :print_applications, id: @event.to_param, session: valid_session
page_analysis = PDF::Inspector::Page.analyze(response.body)
expect(page_analysis.pages.size).to be >= 3
end

it "extends long applications over several pages" do
FactoryGirl.create(:application_letter_long, event: @event,)
User.find_each { |u| FactoryGirl.create(:profile, user: u) }
get :print_applications, id: @event.to_param, session: valid_session
page_analysis = PDF::Inspector::Page.analyze(response.body)
expect(page_analysis.pages.size).to be >= 3
end
end
end
11 changes: 11 additions & 0 deletions spec/factories/application_letters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
event
end

factory :application_letter2, parent: :application_letter do
grade 11
experience "A lot"
motivation "Ich bin sehr motiviert, glaubt mir."
emergency_number "110"
vegeterian true
end

factory :application_letter_long, parent: :application_letter do
motivation "Ich bin sehr motiviert, glaubt mir." * 200
end

factory :application_letter_deadline_over, parent: :application_letter do
association :event, factory: :event, application_deadline: Date.yesterday
Expand Down

0 comments on commit 83c72e8

Please sign in to comment.