Skip to content

Commit

Permalink
Fix time formatting in table builder
Browse files Browse the repository at this point in the history
  • Loading branch information
miks committed Mar 29, 2019
1 parent a9948ca commit 71ecc5d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions releaf-core/app/builders/releaf/builders/table_builder.rb
Expand Up @@ -174,6 +174,13 @@ def format_datetime_content(resource, column)
I18n.l(value, format: format) unless value.nil?
end


def format_time_content(resource, column)
value = column_value(resource, column)
format = Releaf::Builders::Utilities::DateFields.date_or_time_default_format(:time)
I18n.l(value, format: format) unless value.nil?
end

def format_association_content(resource, column)
format_string_content(resource, association_name(column))
end
Expand Down
13 changes: 13 additions & 0 deletions releaf-core/spec/builders/releaf/builders/table_builder_spec.rb
Expand Up @@ -457,6 +457,19 @@ def custom_title(resource); end
end
end

describe "#format_time_content" do
it "returns localized time value" do
value = Time.parse("2012.12.29 17:12:07")
allow(subject).to receive(:column_value).with(resource, :created_at)
.and_return(value)

allow(I18n).to receive(:l).with(value, format: "%H:%M")
.and_return("17:12")

expect(subject.format_time_content(resource, :created_at)).to eq("17:12")
end
end

describe "#association_name" do
it "normalizes given column name by removing '_id' postfix and returning new value as symbol" do
expect(subject.association_name(:author_id)).to eq(:author)
Expand Down

0 comments on commit 71ecc5d

Please sign in to comment.