|
20 | 20 | end |
21 | 21 |
|
22 | 22 | describe "with link_to option" do |
23 | | - let(:field) { TinyAdmin::Field.new(name: "author_id", type: :integer, title: "Author", options: { link_to: "authors" }) } |
| 23 | + let(:field) { TinyAdmin::Field.new(name: "author_id", type: :integer, title: "Author", options: {link_to: "authors"}) } |
24 | 24 | let(:record) { double("record", id: 1) } # rubocop:disable RSpec/VerifiedDoubles |
25 | 25 |
|
26 | 26 | it "wraps the value in a link", :aggregate_failures do |
|
31 | 31 | end |
32 | 32 | end |
33 | 33 |
|
| 34 | + describe "with a RawHtml value" do |
| 35 | + let(:field) { TinyAdmin::Field.new(name: "items", type: :string, title: "Items", options: {method: "multiline"}) } |
| 36 | + let(:record) { double("record", id: 1) } # rubocop:disable RSpec/VerifiedDoubles |
| 37 | + |
| 38 | + before do |
| 39 | + allow(TinyAdmin.settings.helper_class).to receive(:multiline) |
| 40 | + .and_return(TinyAdmin::RawHtml.new("1<br/>2<br/>3")) |
| 41 | + end |
| 42 | + |
| 43 | + it "renders the value as raw HTML without escaping", :aggregate_failures do |
| 44 | + html = described_class.new(field, [1, 2, 3], record: record).call |
| 45 | + expect(html).to include("<span>") |
| 46 | + expect(html).to include("1<br/>2<br/>3") |
| 47 | + expect(html).not_to include("<br/>") |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + describe "with a RawHtml value inside a link" do |
| 52 | + let(:field) { TinyAdmin::Field.new(name: "items", type: :string, title: "Items", options: {method: "multiline", link_to: "posts"}) } |
| 53 | + let(:record) { double("record", id: 1) } # rubocop:disable RSpec/VerifiedDoubles |
| 54 | + |
| 55 | + before do |
| 56 | + allow(TinyAdmin.settings.helper_class).to receive(:multiline) |
| 57 | + .and_return(TinyAdmin::RawHtml.new("1<br/>2<br/>3")) |
| 58 | + end |
| 59 | + |
| 60 | + it "renders the value as raw HTML inside a link without escaping", :aggregate_failures do |
| 61 | + html = described_class.new(field, [1, 2, 3], record: record).call |
| 62 | + expect(html).to include("<a") |
| 63 | + expect(html).to include("1<br/>2<br/>3") |
| 64 | + expect(html).not_to include("<br/>") |
| 65 | + end |
| 66 | + end |
| 67 | + |
34 | 68 | describe "with value_class option" do |
35 | | - let(:field) { TinyAdmin::Field.new(name: "status", type: :string, title: "Status", options: { options: ["value_class"] }) } |
| 69 | + let(:field) { TinyAdmin::Field.new(name: "status", type: :string, title: "Status", options: {options: ["value_class"]}) } |
36 | 70 | let(:record) { double("record", id: 1) } # rubocop:disable RSpec/VerifiedDoubles |
37 | 71 |
|
38 | 72 | it "adds value-based CSS class to the span" do |
|
0 commit comments