Skip to content

Commit

Permalink
Fixed that overriding the validate method would cause images to stop …
Browse files Browse the repository at this point in the history
…being validated
  • Loading branch information
AlexJWayne authored and dummied committed Jan 21, 2009
1 parent 68d14cc commit baed6a8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions autotest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby -wKU
$stdout.sync = true
IO.popen('rstakeout "rake test" lib/fleximage/* lib/fleximage/**/* test/unit/*') do |f|
puts f.gets until f.eof?
end
5 changes: 4 additions & 1 deletion lib/fleximage/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def self.db_store?
end
end

# validation callback
validate :validate_image

# The filename of the temp image. Used for storing of good images when validation fails
# and the form needs to be redisplayed.
attr_reader :image_file_temp
Expand Down Expand Up @@ -359,7 +362,7 @@ def delete_image_file
end

# Execute image presence and validity validations.
def validate #:nodoc:
def validate_image #:nodoc:
field_name = (@image_file_url && @image_file_url.any?) ? :image_file_url : :image_file

if @invalid_image
Expand Down
14 changes: 14 additions & 0 deletions test/unit/require_image_option_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
require File.dirname(__FILE__) + '/../../test/test_helper'

class ValidatedPhoto < ActiveRecord::Base
set_table_name :photo_dbs
acts_as_fleximage

def validate
# overiding the validate method
end
end

class FleximageRequireImageOptionTest < Test::Unit::TestCase
def test_should_require_image_by_default
p = PhotoBare.new
Expand All @@ -13,4 +22,9 @@ def test_should_disable_image_requirement
ensure
PhotoBare.require_image = true
end

def test_should_require_image_when_validate_is_overriden
p = ValidatedPhoto.new
assert !p.save, 'Record expected to not be allowed to save'
end
end

0 comments on commit baed6a8

Please sign in to comment.