roachclip 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -0,0 +1,13 @@
1
+ module Roachclip
2
+ module Validations
3
+ class ValidatesPresenceOf < Validatable::ValidationBase
4
+ def valid?(instance)
5
+ instance.send("#{attribute}?")
6
+ end
7
+
8
+ def message(instance)
9
+ super || 'is required'
10
+ end
11
+ end
12
+ end
13
+ end
data/lib/roachclip.rb CHANGED
@@ -2,6 +2,7 @@ require 'set'
2
2
  require 'tempfile'
3
3
  require 'paperclip'
4
4
  require 'joint'
5
+ require 'roachclip/validations'
5
6
 
6
7
  module Paperclip
7
8
  class << self
@@ -34,6 +35,10 @@ module Roachclip
34
35
  before_save :process_roaches
35
36
  before_save :destroy_nil_roaches
36
37
  end
38
+
39
+ def validates_roachclip(*args)
40
+ add_validations(args, Roachclip::Validations::ValidatesPresenceOf)
41
+ end
37
42
  end
38
43
 
39
44
  module InstanceMethods
data/roachclip.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{roachclip}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ryan Angilly"]
12
- s.date = %q{2010-06-24}
12
+ s.date = %q{2010-08-10}
13
13
  s.description = %q{Let you upload images and have use paperclip's hotness to post process them}
14
14
  s.email = %q{ryan@angilly.com}
15
15
  s.extra_rdoc_files = [
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  "Rakefile",
23
23
  "VERSION",
24
24
  "lib/roachclip.rb",
25
+ "lib/roachclip/validations.rb",
25
26
  "lib/roachclip/version.rb",
26
27
  "roachclip.gemspec",
27
28
  "script/runner.rb",
data/test/test_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'rubygems'
1
2
  require 'test/unit'
2
3
  require 'ruby-debug'
3
4
  require 'shoulda'
@@ -43,6 +43,26 @@ class RoachclipTest < Test::Unit::TestCase
43
43
  Doc.roachclip :image, @opts
44
44
  end
45
45
 
46
+ context "with validations" do
47
+ setup do
48
+ Doc.validates_roachclip :image
49
+ end
50
+
51
+ context "on a new instance" do
52
+ setup do
53
+ @doc = Doc.new
54
+ end
55
+
56
+ should "validate presence of images" do
57
+ assert !@doc.valid?
58
+ assert @doc.errors.on(:image)
59
+
60
+ @doc.image = File.open(test_file_path)
61
+ assert @doc.valid?
62
+ end
63
+ end
64
+ end
65
+
46
66
  should "add attachments for each option style" do
47
67
  d = Doc.new
48
68
 
@@ -54,10 +74,8 @@ class RoachclipTest < Test::Unit::TestCase
54
74
 
55
75
  context "with a saved document w/ image" do
56
76
  setup do
57
- @fname = 'fonz.jpg'
58
- @test_file_path = File.join(File.dirname(__FILE__), '..', 'data', @fname)
59
77
  @doc = Doc.new
60
- @doc.image = File.open(@test_file_path)
78
+ @doc.image = File.open(test_file_path)
61
79
 
62
80
  assert @doc.save
63
81
  end
@@ -65,14 +83,14 @@ class RoachclipTest < Test::Unit::TestCase
65
83
  should "still save documents w/ images" do
66
84
  d = Doc.find @doc.id
67
85
 
68
- assert_equal @fname, d.image_name
69
- assert_equal File.size(@test_file_path), d.image_size
86
+ assert_equal fname, d.image_name
87
+ assert_equal File.size(test_file_path), d.image_size
70
88
  end
71
89
 
72
90
  should "destroy thumbs when image set to nil" do
73
91
  @doc.image = nil
74
92
  @doc.save!
75
-
93
+
76
94
  d = Doc.find(@doc.id)
77
95
  # until joint supports clearing IDs
78
96
  assert_raises(Mongo::GridFileNotFound) { d.image_thumb.read }
@@ -89,4 +107,12 @@ class RoachclipTest < Test::Unit::TestCase
89
107
  end
90
108
  end
91
109
  end
110
+
111
+ def fname
112
+ 'fonz.jpg'
113
+ end
114
+
115
+ def test_file_path
116
+ @test_file_path = File.join(File.dirname(__FILE__), '..', 'data', fname)
117
+ end
92
118
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ryan Angilly
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-24 00:00:00 -04:00
17
+ date: 2010-08-10 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -102,6 +102,7 @@ files:
102
102
  - Rakefile
103
103
  - VERSION
104
104
  - lib/roachclip.rb
105
+ - lib/roachclip/validations.rb
105
106
  - lib/roachclip/version.rb
106
107
  - roachclip.gemspec
107
108
  - script/runner.rb