Skip to content

Commit

Permalink
Rename delete_key to delete_value and keep_key to keep_value
Browse files Browse the repository at this point in the history
for consistentency with cache_value. Refs. fb093e0
  • Loading branch information
mshibuya committed Jul 15, 2019
1 parent 834c83d commit 8b8c3a4
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
%i.icon-white.icon-trash
= I18n.t('admin.actions.delete.menu').capitalize + " #{field.label.downcase} ##{i + 1}"
- if field.keep_method
= form.check_box(field.keep_method, {multiple:true, checked: true, style: 'display:none;'}, attachment.keep_key, nil)
= form.check_box(field.keep_method, {multiple:true, checked: true, style: 'display:none;'}, attachment.keep_value, nil)
- elsif field.delete_method
= form.check_box(field.delete_method, {multiple:true, style: 'display:none;'}, attachment.delete_key, nil)
= form.check_box(field.delete_method, {multiple:true, style: 'display:none;'}, attachment.delete_value, nil)

= form.file_field(field.name, field.html_attributes.reverse_merge({ data: { :"multiple-fileupload" => true }, multiple: true }))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ActiveStorageAttachment < RailsAdmin::Config::Fields::Types::MultipleFileU
{resize: '100x100>'}
end

register_instance_option :delete_key do
register_instance_option :delete_value do
value.id
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rails_admin/config/fields/types/multiple_carrierwave.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class CarrierwaveAttachment < RailsAdmin::Config::Fields::Types::MultipleFileUpl
@thumb_method ||= ((versions = value.versions.keys).detect { |k| k.in?([:thumb, :thumbnail, 'thumb', 'thumbnail']) } || versions.first.to_s)
end

register_instance_option :keep_key do
register_instance_option :keep_value do
value.cache_name || value.identifier
end

register_instance_option :delete_key do
register_instance_option :delete_value do
value.file.filename
end

Expand Down
6 changes: 4 additions & 2 deletions lib/rails_admin/config/fields/types/multiple_file_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ def initialize(value)
nil
end

register_instance_option :keep_key do
register_instance_option :keep_value do
nil
end

register_instance_option :delete_key do
register_instance_option :delete_value do
nil
end

register_deprecated_instance_option :delete_key, :delete_value

register_instance_option :pretty_value do
if value.presence
v = bindings[:view]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
end
end

describe '#delete_key', active_record: true do
describe '#delete_value', active_record: true do
before do
RailsAdmin.config FieldTest do
field :carrierwave_assets, :multiple_carrierwave
Expand All @@ -49,7 +49,7 @@

it 'does not use file.identifier, which is not available for Fog files' do
expect_any_instance_of(CarrierWave::SanitizedFile).not_to receive :identifier
expect(rails_admin_field.attachments.map(&:delete_key)).to eq ['dummy.gif']
expect(rails_admin_field.attachments.map(&:delete_value)).to eq ['dummy.gif']
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def resource_url(thumb = false)
RailsAdmin.config FieldTest do
field :string_field, :multiple_file_upload do
attachment do
delete_key 'something'
delete_value 'something'

def resource_url(_thumb = false)
"http://example.com/#{value}"
Expand All @@ -118,7 +118,7 @@ def value
end

it 'enables configuration' do
expect(rails_admin_field.attachments.map(&:delete_key)).to eq ['something']
expect(rails_admin_field.attachments.map(&:delete_value)).to eq ['something']
expect(rails_admin_field.attachments.map(&:resource_url)).to eq ['http://example.com/foo.jpg']
expect(rails_admin_field.pretty_value).to match(%r{src="http://example.com/foo.jpg"})
end
Expand Down

0 comments on commit 8b8c3a4

Please sign in to comment.