Skip to content

Instantly share code, notes, and snippets.

@colindensem
Created June 15, 2021 09:19
Show Gist options
  • Save colindensem/71bfc521372a912c817d25f519cd3cec to your computer and use it in GitHub Desktop.
Save colindensem/71bfc521372a912c817d25f519cd3cec to your computer and use it in GitHub Desktop.
Example presenter
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
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
@colindensem
Copy link
Author

Of course 'insurance' is magic word ;)

Estimate::INSURANCE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment