Permalink
Browse files

Merge pull request #1339 from fernandomm/paperclip-presence

Fix for issue #1307: validates_attachment_presence doesn't change field-label
  • Loading branch information...
2 parents 97aa824 + 0db4fe2 commit 6a11609821b29682d7de45be25059f03161860cd @bbenezech bbenezech committed Nov 15, 2012
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,8 @@
+class CreateImages < ActiveRecord::Migration
+ def change
+ create_table :images do |t|
+ t.attachment :file
+ t.timestamps
+ end
+ end
+end
View
@@ -68,4 +68,8 @@
factory :hardball do
color('blue')
end
+
+ factory :image do
+ file File.open(Rails.root.join('public', 'robots.txt'))
+ end
end
@@ -70,5 +70,4 @@
expect(page).to have_css("select#team_player_ids option[selected='selected'][value='#{@player.id}']")
end
end
-
end
@@ -11,6 +11,12 @@
expect(RailsAdmin.config('Ball').fields.first.with(:object => Ball.new)).to be_required
expect(RailsAdmin.config('Ball').fields.first.with(:object => FactoryGirl.create(:ball))).not_to 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

0 comments on commit 6a11609

Please sign in to comment.