From 27c1fd0d3035daec4db72c88a0b59575047ff276 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Thu, 25 May 2023 09:04:54 +0100 Subject: [PATCH] test invoice model --- app/models/invoice.rb | 4 +++- spec/models/invoice_spec.rb | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 65b20091a3..33a128a3e0 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -10,6 +10,8 @@ class Invoice < ApplicationRecord end def serialize_order - self.data ||= Invoice::OrderSerializer.new(order).serializable_hash + return data unless data.empty? + + self.data = Invoice::OrderSerializer.new(order).serializable_hash end end diff --git a/spec/models/invoice_spec.rb b/spec/models/invoice_spec.rb index c432c97b87..6bd6257c1e 100644 --- a/spec/models/invoice_spec.rb +++ b/spec/models/invoice_spec.rb @@ -3,5 +3,19 @@ require 'spec_helper' RSpec.describe Invoice, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + describe 'presenter' do + it 'should return an instance of Invoice::DataPresenter' do + invoice = create(:invoice) + expect(invoice.presenter).to be_a(Invoice::DataPresenter) + end + end + + describe 'serialize_order' do + let!(:distributor) { create(:distributor_enterprise) } + let!(:order) { create(:order, :with_line_item, :completed, distributor: distributor) } + it 'serializes the order' do + invoice = create(:invoice, order: order) + expect(invoice.data).to eq(Invoice::OrderSerializer.new(order).serializable_hash) + end + end end