diff --git a/app/helpers/spree/base_helper.rb b/app/helpers/spree/base_helper.rb index 92e38aa8a1..f11c5532d9 100644 --- a/app/helpers/spree/base_helper.rb +++ b/app/helpers/spree/base_helper.rb @@ -39,5 +39,9 @@ module Spree [I18n.l(time.to_date, format: :long), time.strftime("%l:%M %p")].join(" ") end + + def pretty_date(date) + I18n.l(date.to_date, format: :long) + end end end diff --git a/app/views/spree/admin/invoices/_invoices_table.html.haml b/app/views/spree/admin/invoices/_invoices_table.html.haml index 6ac93077d3..aa0394eed5 100644 --- a/app/views/spree/admin/invoices/_invoices_table.html.haml +++ b/app/views/spree/admin/invoices/_invoices_table.html.haml @@ -12,7 +12,7 @@ - tr_id = spree_dom_id(invoice) %tr{:class => tr_class, "data-hook" => "invoice_row", :id => tr_id} %td.align-center.created_at - = invoice.presenter.invoice_date + = pretty_date(invoice.date) %td.align-center.label = invoice.number %td.align-center.label diff --git a/spec/helpers/spree/base_helper_spec.rb b/spec/helpers/spree/base_helper_spec.rb index 22f716a3e4..b0a3ac3428 100644 --- a/spec/helpers/spree/base_helper_spec.rb +++ b/spec/helpers/spree/base_helper_spec.rb @@ -55,4 +55,10 @@ describe Spree::BaseHelper do expect(pretty_time(DateTime.new(2012, 5, 6, 13, 33))).to eq "May 06, 2012 1:33 PM" end end + + context "pretty_date" do + it "prints in a format" do + expect(pretty_date(DateTime.new(2012, 5, 6, 13, 33))).to eq "May 06, 2012" + end + end end diff --git a/spec/system/admin/orders/invoices_spec.rb b/spec/system/admin/orders/invoices_spec.rb index e4a2c89f75..0ec2776045 100644 --- a/spec/system/admin/orders/invoices_spec.rb +++ b/spec/system/admin/orders/invoices_spec.rb @@ -4,7 +4,7 @@ require 'system_helper' describe ' As an administrator - I want to list/create an invoice for an order + I want to manage invoices for an order ' do include WebHelper include AuthenticationHelper @@ -93,7 +93,7 @@ describe ' expect(latest_invoice.reload.cancelled).to eq true expect(latest_invoice.presenter.sorted_line_items.first.quantity).to eq 1 - new_invoice = order.invoices.last + new_invoice = order.invoices.first # first invoice is the latest expect(new_invoice.cancelled).to eq false expect(new_invoice.number).to eq 2 expect(new_invoice.presenter.sorted_line_items.first.quantity).to eq 2 @@ -104,14 +104,11 @@ describe ' end describe 'listing invoices' do - before do - create(:invoice, order:, number: 1, cancelled: true) - create(:invoice, order:, number: 2, cancelled: false) - end + let(:date){ Time.current.to_date } let(:row1){ [ - Time.current.to_date.to_s, + I18n.l(date, format: :long), "2", order.total, "Active", @@ -121,7 +118,7 @@ describe ' let(:row2){ [ - Time.current.to_date.to_s, + I18n.l(date, format: :long), "1", order.total, "Cancelled", @@ -136,6 +133,11 @@ describe ' ].join(" ") } + before do + create(:invoice, order:, number: 1, cancelled: true, date:) + create(:invoice, order:, number: 2, cancelled: false, date:) + end + it 'should list the invoices on the reverse order of creation' do click_link 'Invoices' expect(page).to have_content table_content