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

Fix picture file format filter #2455

Merged
merged 1 commit into from
Apr 6, 2023
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
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