Skip to content

Commit

Permalink
Merge pull request #2455 from tvdeyen/fix-picture-file-filter
Browse files Browse the repository at this point in the history
Fix picture file format filter
  • Loading branch information
tvdeyen committed Apr 6, 2023
2 parents 2d173d3 + 21073e3 commit 3616f9f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/models/alchemy/picture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,15 @@ def url_class=(klass)
end

def alchemy_resource_filters
@_file_formats ||= distinct.pluck(:image_file_format).compact.presence || []
[
{
name: :by_file_format,
values: distinct.pluck(:image_file_format),
values: @_file_formats,
},
{
name: :misc,
values: %w(recent last_upload without_tag),
values: %w(recent last_upload without_tag deletable),
},
]
end
Expand Down
2 changes: 1 addition & 1 deletion config/locales/alchemy.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ en:
last_upload: Last upload only
recent: Recently uploaded only
without_tag: Without tag
deletable: Not linked by file content
attachment:
by_file_type:
name: File Type
Expand All @@ -136,7 +137,6 @@ en:
last_upload: Last upload only
recent: Recently uploaded only
without_tag: Without tag
deletable: Not linked by file content

# === Translations for ingredient validations
# Used when a user did not enter (correct) values to the ingredient field.
Expand Down
19 changes: 19 additions & 0 deletions spec/models/alchemy/picture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ module Alchemy
end
end

describe ".alchemy_resource_filters" do
context "with image file formats" do
let!(:picture) { create(:alchemy_picture, image_file_format: "png") }

it "returns a list of filters with image file formats" do
expect(Alchemy::Picture.alchemy_resource_filters).to eq([
{
name: :by_file_format,
values: ["png"],
},
{
name: :misc,
values: %w[recent last_upload without_tag deletable],
},
])
end
end
end

describe ".last_upload" do
it "should return all pictures that have the same upload-hash as the most recent picture" do
other_upload = Picture.create!(image_file: image_file, upload_hash: "456")
Expand Down

0 comments on commit 3616f9f

Please sign in to comment.