Fix for issue #1307: validates_attachment_presence doesn't change field-label #1339

Closed
wants to merge 3 commits into
from
View
2 lib/rails_admin/config/fields/base.rb
@@ -168,7 +168,7 @@ def virtual?
(@required ||= {})[context] ||= !!([name] + children_fields).uniq.find do |column_name|
!!abstract_model.model.validators_on(column_name).find do |v|
!v.options[:allow_nil] and
- [:presence, :numericality].include?(v.kind) and
+ [:presence, :numericality, :attachment_presence].include?(v.kind) and
(v.options[:on] == context or v.options[:on].blank?)
end
end
View
6 spec/dummy_app/app/active_record/image.rb
@@ -0,0 +1,6 @@
+class Image < ActiveRecord::Base
+ attr_accessible :file
+
+ has_attached_file :file, :styles => { :medium => "300x300>", :thumb => "100x100>" }
+ validates_attachment_presence :file
+end
View
9 spec/dummy_app/app/mongoid/image.rb
@@ -0,0 +1,9 @@
+class Image
+ include Mongoid::Document
+ include Mongoid::Paperclip
+
+ attr_accessible :file
+
+ has_mongoid_attached_file :file, :styles => { :medium => "300x300>", :thumb => "100x100>" }
+ validates_attachment_presence :file
+end
View
8 spec/dummy_app/db/migrate/20120928075608_create_images.rb
@@ -0,0 +1,8 @@
+class CreateImages < ActiveRecord::Migration
+ def change
+ create_table :images do |t|
+ t.attachment :file
+ t.timestamps
+ end
+ end
+end
View
4 spec/factories.rb
@@ -68,4 +68,8 @@
factory :hardball do
color('blue')
end
+
+ factory :image do
+ file File.open(Rails.root.join('public', 'robots.txt'))
+ end
end
View
1 spec/integration/basic/new/rails_admin_basic_new_spec.rb
@@ -70,5 +70,4 @@
page.should have_css("select#team_player_ids option[selected='selected'][value='#{@player.id}']")
end
end
-
end
View
6 spec/unit/config/fields/base_spec.rb
@@ -11,6 +11,12 @@
RailsAdmin.config('Ball').fields.first.with(:object => Ball.new).should be_required
RailsAdmin.config('Ball').fields.first.with(:object => FactoryGirl.create(:ball)).should_not be_required
end
+
+ context 'on a Paperclip installation' do
+ it "should detect required fields" do
+ RailsAdmin.config('Image').fields.find{ |f| f.name == :file }.with(:object => Image.new).should be_required
+ end
+ end
end
describe "#name" do