paperclip-time-stamped 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/paperclip-time-stamped.rb +2 -1
- data/paperclip-time-stamped.gemspec +1 -1
- data/spec/paperclip-time-stamped_spec.rb +26 -3
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.5
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'active_record'
|
3
|
+
require 'paperclip'
|
3
4
|
|
4
5
|
ActiveRecord::Base.class_eval do
|
5
6
|
|
@@ -22,7 +23,7 @@ ActiveRecord::Base.class_eval do
|
|
22
23
|
end
|
23
24
|
|
24
25
|
define_method("#{name}?") do |*style|
|
25
|
-
|
26
|
+
send(name).exists? && (style.empty? || File.file?(send("#{name}_path", style.first)))
|
26
27
|
end
|
27
28
|
|
28
29
|
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
require 'active_record_connectionless'
|
3
3
|
|
4
|
+
Paperclip::Attachment::RAILS_ROOT = '/'
|
5
|
+
|
4
6
|
class PaperclipTimeStamped < ActiveRecord::Base
|
5
7
|
|
8
|
+
has_attached_file :name, :styles => {:thumbnail=> "80x80>", :small => "180x180>"}, :path => '/'
|
6
9
|
has_timestamped_paperclip_attachment :name
|
7
10
|
|
8
11
|
end
|
@@ -28,17 +31,33 @@ describe "PaperclipTimeStamped" do
|
|
28
31
|
end
|
29
32
|
|
30
33
|
describe 'name?' do
|
31
|
-
it 'should be
|
32
|
-
@name.should_receive(:exists?).and_return(true)
|
34
|
+
it 'should be true when name.exists? is true and no style given' do
|
33
35
|
@paperclip_time_stamped.should_receive(:name).and_return(@name)
|
36
|
+
@name.should_receive(:exists?).and_return(true)
|
34
37
|
@paperclip_time_stamped.name?.should be_true
|
35
38
|
end
|
36
39
|
|
37
|
-
it 'should
|
40
|
+
it 'should be true when name.exists? is true and File.file? on given file with style is true' do
|
41
|
+
@paperclip_time_stamped.should_receive(:name).and_return(@name)
|
42
|
+
@name.should_receive(:exists?).and_return(true)
|
38
43
|
File.should_receive(:file?).with('path').and_return(true)
|
39
44
|
@paperclip_time_stamped.should_receive(:name_path).with(:small).and_return('path')
|
40
45
|
@paperclip_time_stamped.name?(:small).should be_true
|
41
46
|
end
|
47
|
+
|
48
|
+
it 'should be false when name.exists? is false' do
|
49
|
+
@paperclip_time_stamped.should_receive(:name).and_return(@name)
|
50
|
+
@name.should_receive(:exists?).and_return(false)
|
51
|
+
@paperclip_time_stamped.name?(:small).should be_false
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should be false when name.exists? is true but File.file? on given file with style is false' do
|
55
|
+
@name.should_receive(:exists?).and_return(true)
|
56
|
+
@paperclip_time_stamped.should_receive(:name).and_return(@name)
|
57
|
+
File.should_receive(:file?).with('path').and_return(false)
|
58
|
+
@paperclip_time_stamped.should_receive(:name_path).with(:small).and_return('path')
|
59
|
+
@paperclip_time_stamped.name?(:small).should be_false
|
60
|
+
end
|
42
61
|
end
|
43
62
|
|
44
63
|
describe 'name_timestamp' do
|
@@ -61,4 +80,8 @@ describe "PaperclipTimeStamped" do
|
|
61
80
|
@paperclip_time_stamped.timestamped_name_url(:small).should == 'name_url?1000000000'
|
62
81
|
end
|
63
82
|
|
83
|
+
it 'should work in normal environment' do
|
84
|
+
@paperclip_time_stamped.timestamped_name_url(:thumbnail)
|
85
|
+
end
|
86
|
+
|
64
87
|
end
|