Skip to content

Commit

Permalink
does not exist unless ed. Closes #1674
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya committed Oct 4, 2015
1 parent 0a36dc0 commit aad913c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rails_admin/config/fields/factories/paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
extensions = [:file_name, :content_type, :file_size, :updated_at, :fingerprint]
model = parent.abstract_model.model
if (properties.name.to_s =~ /^(.+)_file_name$/) && defined?(::Paperclip) && model.attachment_definitions && model.attachment_definitions.key?(attachment_name = Regexp.last_match[1].to_sym)
if (properties.name.to_s =~ /^(.+)_file_name$/) && defined?(::Paperclip) && model.try(:attachment_definitions) && model.attachment_definitions.key?(attachment_name = Regexp.last_match[1].to_sym)
field = RailsAdmin::Config::Fields::Types.load(:paperclip).new(parent, attachment_name, properties)
children_fields = []
extensions.each do |ext|
Expand Down
13 changes: 13 additions & 0 deletions spec/rails_admin/config/fields/types/paperclip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@

describe RailsAdmin::Config::Fields::Types::Paperclip do
it_behaves_like 'a generic field type', :string_field, :paperclip

context 'when a *_file_name field exists but not decleared as has_attached_file' do
before do
class PaperclipTest < Tableless
column :some_file_name, :varchar
end
RailsAdmin.config.included_models = [PaperclipTest]
end

it 'does not break' do
expect{ RailsAdmin.config(PaperclipTest).fields }.not_to raise_error
end
end
end

0 comments on commit aad913c

Please sign in to comment.