Skip to content
Browse files

Fixes issue #1307 by adding attachment_presence to the validators in

required? function.
  • Loading branch information...
1 parent 3a0b832 commit 1844d562550dfd599d0c071ae07d0abedbda35b6 @fernandomm committed Sep 28, 2012
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
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
9 spec/integration/basic/edit/rails_admin_basic_edit_spec.rb
@@ -106,4 +106,13 @@
page.current_url.should == 'http://www.example.com/admin/ball?sort=color'
end
end
+
+ describe "image edit" do
+ it "should show required for paperclip attached file with validates_attachment_presence" do
+ @image = FactoryGirl.create :image
+ visit edit_path(:model_name => "image", :id => @image.id)
+
+ should have_selector("div", :text => /Required./)
+ end
+ end
end
View
7 spec/integration/basic/new/rails_admin_basic_new_spec.rb
@@ -71,4 +71,11 @@
end
end
+ describe "GET /admin/image/new" do
+ it "should show required for paperclip attached file with validates_attachment_presence" do
+ visit new_path(:model_name => "image")
+
+ should have_selector("div", :text => /File\s*Required/)
+ end
+ end
end

0 comments on commit 1844d56

Please sign in to comment.
Something went wrong with that request. Please try again.