Browse files

Adding support for processing and integrity validations

  • Loading branch information...
1 parent f0fdf08 commit a15f2c69d8b42e46279ddd9ae06ebca283266fe4 @reu reu committed Jul 2, 2011
Showing with 40 additions and 0 deletions.
  1. +6 −0 lib/carrierwave/neo4j.rb
  2. +34 −0 spec/neo4j_spec.rb
View
6 lib/carrierwave/neo4j.rb
@@ -1,6 +1,7 @@
require "carrierwave/neo4j/version"
require "neo4j"
require "carrierwave"
+require "carrierwave/validations/active_model"
module CarrierWave
module Neo4j
@@ -17,6 +18,11 @@ def mount_uploader(column, uploader = nil, options = {}, &block)
alias_method :read_uploader, :read_attribute
alias_method :write_uploader, :write_attribute
+ include CarrierWave::Validations::ActiveModel
+
+ validates_integrity_of column if uploader_option(column.to_sym, :validate_integrity)
+ validates_processing_of column if uploader_option(column.to_sym, :validate_processing)
+
after_save :"store_#{column}!"
before_save :"write_#{column}_identifier"
after_destroy :"remove_#{column}!"
View
34 spec/neo4j_spec.rb
@@ -14,6 +14,20 @@ def reset_class(uploader = DefaultUploader)
class DefaultUploader < CarrierWave::Uploader::Base; end
+class PngUploader < CarrierWave::Uploader::Base
+ def extension_white_list
+ %w(png)
+ end
+end
+
+class ProcessingErrorUploader < CarrierWave::Uploader::Base
+ process :end_on_an_era
+
+ def end_on_an_era
+ raise CarrierWave::ProcessingError, "Bye Tarja"
+ end
+end
+
describe CarrierWave::Neo4j do
let(:user_class) { reset_class }
let(:user) { user_class.new }
@@ -71,6 +85,26 @@ class DefaultUploader < CarrierWave::Uploader::Base; end
its(:image) { should be_blank }
end
+
+ context "when validating integrity" do
+ subject do
+ user = reset_class(PngUploader).new
+ user.image = File.open(file_path("tarja.jpg"))
+ user
+ end
+
+ it { should_not be_valid }
+ end
+
+ context "when validating processing" do
+ subject do
+ user = reset_class(ProcessingErrorUploader).new
+ user.image = File.open(file_path("tarja.jpg"))
+ user
+ end
+
+ it { should_not be_valid }
+ end
end
describe "#destroy" do

0 comments on commit a15f2c6

Please sign in to comment.