fix date formatting

implement a new helper `pretty_date`
This commit is contained in:
Mohamed ABDELLANI
2023-07-14 10:35:04 +01:00
parent 1a8c0f18b7
commit d044959cec
4 changed files with 21 additions and 9 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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