Skip to content

Commit

Permalink
Merge pull request #1503 from samvera/to_fs
Browse files Browse the repository at this point in the history
Use to_formatted_s(:db) instead of deprecated and removed to_s(:db)
  • Loading branch information
randalldfloyd authored Oct 22, 2024
2 parents 4640eab + 3ff9cf1 commit e532d65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/active_fedora/attribute_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def attribute_for_inspect(attr_name)
if value.is_a?(String) && value.length > 50
"#{value[0, 50]}...".inspect
elsif value.is_a?(Date) || value.is_a?(Time)
%("#{value.to_s(:db)}")
%("#{value.to_formatted_s(:db)}")
elsif value.is_a?(Array) && value.size > 10
inspected = value.first(10).inspect
%(#{inspected[0...-1]}, ...])
Expand Down
11 changes: 6 additions & 5 deletions spec/unit/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class BarHistory4 < ActiveFedora::Base
index.as :symbol
end
property :abstract, predicate: ::RDF::Vocab::DC.abstract, multiple: false
property :date, predicate: ::RDF::Vocab::DC.date, multiple: false
end
end

Expand All @@ -16,25 +17,25 @@ class BarHistory4 < ActiveFedora::Base
end

subject(:history) { obj }
let(:obj) { BarHistory4.new(title: ['test1'], id: 'test:123') }
let(:obj) { BarHistory4.new(title: ['test1'], id: 'test:123', date: Date.new(2024, 1, 1)) }

describe "#attribute_names" do
context "on an instance" do
it "lists the attributes" do
expect(history.attribute_names).to eq ["title", "abstract"]
expect(history.attribute_names).to eq ["title", "abstract", "date"]
end
end

context "on a class" do
it "lists the attributes" do
expect(BarHistory4.attribute_names).to eq ["title", "abstract"]
expect(BarHistory4.attribute_names).to eq ["title", "abstract", "date"]
end
end
end

describe "#inspect" do
it "shows the attributes" do
expect(history.inspect).to eq "#<BarHistory4 id: \"test:123\", title: [\"test1\"], abstract: nil>"
expect(history.inspect).to eq "#<BarHistory4 id: \"test:123\", title: [\"test1\"], abstract: nil, date: \"2024-01-01 00:00:00\">"
end

describe "with no attributes" do
Expand All @@ -60,7 +61,7 @@ class BarHistory2 < BarHistory4
end

it "shows the library_id" do
expect(history.inspect).to eq "#<BarHistory2 id: nil, title: [], abstract: nil, library_id: \"#{library.id}\">"
expect(history.inspect).to eq "#<BarHistory2 id: nil, title: [], abstract: nil, date: nil, library_id: \"#{library.id}\">"
end
end
end
Expand Down

0 comments on commit e532d65

Please sign in to comment.