Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Picture view fixes #2798

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/alchemy/ingredients/picture_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def call
def caption
return unless show_caption?

@_caption ||= content_tag(:figcaption, ingredient.caption)
@_caption ||= content_tag(:figcaption, ingredient.caption.html_safe)
end

def src
Expand Down
2 changes: 1 addition & 1 deletion app/models/alchemy/picture_variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def initialize(picture, options = {})

@picture = picture
@options = options
@render_format = options[:format] || picture.default_render_format
@render_format = (options[:format] || picture.default_render_format).to_s
end

# Process a variant of picture
Expand Down
16 changes: 16 additions & 0 deletions spec/components/alchemy/ingredients/picture_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@
expect(page).to have_content("This is a cute cat")
end

context "having html tags" do
let(:ingredient) do
stub_model Alchemy::Ingredients::Picture,
role: "image",
picture: picture,
data: {
caption: "This is a<br />cute cat"
}
end

it "should show the caption" do
render_view
expect(page).to have_content("This is acute cat")
end
end

it "does not pass default options to picture url" do
expect(ingredient).to receive(:picture_url).with({}) { picture_url }
render_view
Expand Down
12 changes: 12 additions & 0 deletions spec/models/alchemy/picture_variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,18 @@
end
end
end

context "passed as symbol" do
let(:options) do
{format: :gif}
end

it "converts the format" do
step = subject.steps[0]
expect(step.name).to eq(:encode)
expect(step.arguments).to include("gif")
end
end
end

context "requesting a not allowed format" do
Expand Down