Skip to content

Commit

Permalink
Add renewals column to boxi exemptions export (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulDoyle-DEFRA committed Aug 15, 2022
1 parent 94138b9 commit 68fc1e8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Reports
module Boxi
class RegistrationExemptionsSerializer < BaseSerializer
ATTRIBUTES = WasteExemptionsEngine::RegistrationExemption.column_names
ATTRIBUTES = WasteExemptionsEngine::RegistrationExemption.column_names + ["renewal"]

def file_name
"registration_exemptions.csv"
Expand Down
6 changes: 6 additions & 0 deletions app/models/waste_exemptions_engine/registration_exemption.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@ class RegistrationExemption < ::WasteExemptionsEngine::ApplicationRecord
.includes(registration: :addresses)
.order(:registered_on, :registration_id)
}

# This is called "renewal" rather than "renewal?" so that it can behave
# like an attribute in the Boxi export service without any mapping logic.
def renewal
registration&.renewal?
end
end
end
20 changes: 20 additions & 0 deletions spec/models/registration_exemption_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,24 @@
end
end
end

describe "#renewal" do
subject(:registration_exemption) { registration.registration_exemptions.first }

context "without a referring registration" do
let(:registration) { build(:registration) }

it "returns false" do
expect(subject.renewal).to be false
end
end

context "with a referring registration" do
let(:registration) { build(:registration, referring_registration: build(:registration)) }

it "returns true" do
expect(subject.renewal).to be true
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Boxi
result_lines = result.split("\n")

expect(result_lines.first.split(",")).to include(*WasteExemptionsEngine::RegistrationExemption.column_names)
expect(result_lines.first.split(",")).to include("renewal")
expect(result_lines.count).to eq(2)
end

Expand Down

0 comments on commit 68fc1e8

Please sign in to comment.