Created
June 15, 2021 09:19
-
-
Save colindensem/71bfc521372a912c817d25f519cd3cec to your computer and use it in GitHub Desktop.
Example presenter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EstimatePresenter < SimpleDelegator | |
def self.from_estimate_list(*estimates) | |
estimates.flatten.map { |estimate| EstimatePresenter.new(estimate) } | |
end | |
def initialize(estimate) | |
super | |
end | |
def insurance? | |
type == "insurance" | |
end | |
def insurance_coverage | |
return unless insurance? | |
items.sum(&:insurance_rebate_value) | |
end | |
def gap_payment | |
return private_value unless insurance? | |
private_value - insurance_coverage | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe EstimatePresenter do | |
let(:estimate) { instance_double(Estimate, type: "insurance") } | |
let(:presenter) { EstimatePresenter.new(estimate) } | |
describe '.insurance?' do | |
it 'is an insurance type' do | |
allow(estimate).to receive(:type).and_return('insurance') | |
expect(presenter.insurance?).to be_true | |
end | |
it 'isnt an insurance type' do | |
allow(estimate).to receive(:type).and_return('ponzy') | |
expect(presenter.insurance?).to be_false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Of course 'insurance' is magic word ;)
Estimate::INSURANCE