Skip to content

Commit fff0e70

Browse files
committed
fix(views): apply call option on field values without link_to
1 parent 6accf55 commit fff0e70

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

lib/tiny_admin/views/components/field_value.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ def initialize(field, value, record:)
1414

1515
def view_template
1616
translated_value = field.translate_value(value)
17+
display_value = field.apply_call_option(record) || translated_value
1718
value_class = field.options[:options]&.include?("value_class") ? "value-#{value}" : nil
1819
if field.options[:link_to]
1920
a(href: TinyAdmin.route_for(field.options[:link_to], reference: translated_value)) {
2021
span(class: value_class) {
21-
render_value(field.apply_call_option(record) || translated_value)
22+
render_value(display_value)
2223
}
2324
}
2425
else
2526
span(class: value_class) {
26-
render_value(translated_value)
27+
render_value(display_value)
2728
}
2829
end
2930
end

spec/lib/tiny_admin/views/components/field_value_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@
6464
end
6565
end
6666

67+
describe "with call option (no link_to)" do
68+
let(:field) { TinyAdmin::Field.new(name: "author_id", type: :integer, title: "Author", options: { call: "author, name" }) }
69+
let(:author) { double("author", name: "John") } # rubocop:disable RSpec/VerifiedDoubles
70+
let(:record) { double("record", id: 1, author: author) } # rubocop:disable RSpec/VerifiedDoubles
71+
72+
it "renders the call result instead of the raw value", :aggregate_failures do
73+
html = described_class.new(field, 42, record: record).call
74+
expect(html).to include("John")
75+
expect(html).not_to include("42")
76+
end
77+
end
78+
6779
describe "with value_class option" do
6880
let(:field) { TinyAdmin::Field.new(name: "status", type: :string, title: "Status", options: { options: ["value_class"] }) }
6981
let(:record) { double("record", id: 1) } # rubocop:disable RSpec/VerifiedDoubles

0 commit comments

Comments
 (0)