jnicklas-carrierwave 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/spec_helper.rb CHANGED
@@ -30,91 +30,55 @@ end
30
30
  CarrierWave.config[:public] = public_path
31
31
  CarrierWave.config[:root] = File.expand_path(File.dirname(__FILE__))
32
32
 
33
- module SanitizedFileSpecHelper
34
- def stub_merb_tempfile(filename)
35
- raise "#{path} file does not exist" unless File.exist?(file_path(filename))
36
-
37
- t = Tempfile.new(filename)
38
- FileUtils.copy_file(file_path(filename), t.path)
33
+ module CarrierWave
34
+ module Test
35
+ module MockFiles
36
+ def stub_merb_tempfile(filename)
37
+ raise "#{path} file does not exist" unless File.exist?(file_path(filename))
38
+
39
+ t = Tempfile.new(filename)
40
+ FileUtils.copy_file(file_path(filename), t.path)
39
41
 
40
- return t
41
- end
42
+ return t
43
+ end
42
44
 
43
- def stub_tempfile(filename, mime_type=nil, fake_name=nil)
44
- raise "#{path} file does not exist" unless File.exist?(file_path(filename))
45
+ def stub_tempfile(filename, mime_type=nil, fake_name=nil)
46
+ raise "#{path} file does not exist" unless File.exist?(file_path(filename))
45
47
 
46
- t = Tempfile.new(filename)
47
- FileUtils.copy_file(file_path(filename), t.path)
48
+ t = Tempfile.new(filename)
49
+ FileUtils.copy_file(file_path(filename), t.path)
48
50
 
49
- # This is stupid, but for some reason rspec won't play nice...
50
- eval <<-EOF
51
- def t.original_filename; '#{fake_name || filename}'; end
52
- def t.content_type; '#{mime_type}'; end
53
- def t.local_path; path; end
54
- EOF
55
-
56
- return t
57
- end
58
-
59
- def stub_stringio(filename, mime_type=nil, fake_name=nil)
60
- if filename
61
- t = StringIO.new( IO.read( file_path( filename ) ) )
62
- else
63
- t = StringIO.new
64
- end
65
- t.stub!(:local_path).and_return("")
66
- t.stub!(:original_filename).and_return(filename || fake_name)
67
- t.stub!(:content_type).and_return(mime_type)
68
- return t
69
- end
70
-
71
- def stub_file(filename, mime_type=nil, fake_name=nil)
72
- f = File.open(file_path(filename))
73
- return f
74
- end
75
-
76
- class BeIdenticalTo
77
- def initialize(expected)
78
- @expected = expected
79
- end
80
- def matches?(actual)
81
- @actual = actual
82
- FileUtils.identical?(@actual, @expected)
83
- end
84
- def failure_message
85
- "expected #{@actual.inspect} to be identical to #{@expected.inspect}"
86
- end
87
- def negative_failure_message
88
- "expected #{@actual.inspect} to not be identical to #{@expected.inspect}"
89
- end
90
- end
91
-
92
- def be_identical_to(expected)
93
- BeIdenticalTo.new(expected)
94
- end
95
-
96
- class HavePermissions
97
- def initialize(expected)
98
- @expected = expected
99
- end
100
-
101
- def matches?(actual)
102
- @actual = actual
103
- # Satisfy expectation here. Return false or raise an error if it's not met.
104
- (File.stat(@actual.path).mode & 0777) == @expected
105
- end
106
-
107
- def failure_message
108
- "expected #{@actual.inspect} to have permissions #{@expected.to_s(8)}, but they were #{(File.stat(@actual.path).mode & 0777).to_s(8)}"
109
- end
110
-
111
- def negative_failure_message
112
- "expected #{@actual.inspect} not to have permissions #{@expected.to_s(8)}, but it did"
51
+ # This is stupid, but for some reason rspec won't play nice...
52
+ eval <<-EOF
53
+ def t.original_filename; '#{fake_name || filename}'; end
54
+ def t.content_type; '#{mime_type}'; end
55
+ def t.local_path; path; end
56
+ EOF
57
+
58
+ return t
59
+ end
60
+
61
+ def stub_stringio(filename, mime_type=nil, fake_name=nil)
62
+ if filename
63
+ t = StringIO.new( IO.read( file_path( filename ) ) )
64
+ else
65
+ t = StringIO.new
66
+ end
67
+ t.stub!(:local_path).and_return("")
68
+ t.stub!(:original_filename).and_return(filename || fake_name)
69
+ t.stub!(:content_type).and_return(mime_type)
70
+ return t
71
+ end
72
+
73
+ def stub_file(filename, mime_type=nil, fake_name=nil)
74
+ f = File.open(file_path(filename))
75
+ return f
76
+ end
113
77
  end
114
78
  end
79
+ end
115
80
 
116
- def have_permissions(expected)
117
- HavePermissions.new(expected)
118
- end
119
-
81
+ Spec::Runner.configure do |config|
82
+ config.include CarrierWave::Test::Matchers
83
+ config.include CarrierWave::Test::MockFiles
120
84
  end
@@ -1,9 +1,11 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe CarrierWave::Uploader do
4
-
4
+
5
5
  before do
6
- @uploader_class = Class.new(CarrierWave::Uploader)
6
+ @uploader_class = Class.new do
7
+ include CarrierWave::Uploader
8
+ end
7
9
  @uploader = @uploader_class.new
8
10
  end
9
11
 
@@ -34,10 +36,10 @@ describe CarrierWave::Uploader do
34
36
  @uploader.thumb.version_name.should == :thumb
35
37
  end
36
38
 
37
- it "should set the version name on the class" do
39
+ it "should set the version names on the class" do
38
40
  @uploader_class.version :thumb
39
- @uploader.class.version_name.should == nil
40
- @uploader.thumb.class.version_name.should == :thumb
41
+ @uploader.class.version_names.should == []
42
+ @uploader.thumb.class.version_names.should == [:thumb]
41
43
  end
42
44
 
43
45
  it "should remember mount options" do
@@ -58,6 +60,45 @@ describe CarrierWave::Uploader do
58
60
  @uploader.store_dir.should == 'uploads'
59
61
  @uploader.thumb.store_dir.should == public_path('monkey/apache')
60
62
  end
63
+
64
+ it "should reopen the same class when called multiple times" do
65
+ @uploader_class.version :thumb do
66
+ def self.monkey
67
+ "monkey"
68
+ end
69
+ end
70
+ @uploader_class.version :thumb do
71
+ def self.llama
72
+ "llama"
73
+ end
74
+ end
75
+ @uploader_class.version(:thumb).monkey.should == "monkey"
76
+ @uploader_class.version(:thumb).llama.should == "llama"
77
+ end
78
+
79
+ describe 'with nested versions' do
80
+ before do
81
+ @uploader_class.version :thumb do
82
+ version :mini
83
+ version :micro
84
+ end
85
+ end
86
+
87
+ it "should add an array of version names" do
88
+ @uploader.class.version_names.should == []
89
+ @uploader.thumb.class.version_names.should == [:thumb]
90
+ @uploader.thumb.mini.class.version_names.should == [:thumb, :mini]
91
+ @uploader.thumb.micro.class.version_names.should == [:thumb, :micro]
92
+ end
93
+
94
+ it "should set the version name for the instances" do
95
+ @uploader.version_name.should be_nil
96
+ @uploader.thumb.version_name.should == :thumb
97
+ @uploader.thumb.mini.version_name.should == :thumb_mini
98
+ @uploader.thumb.micro.version_name.should == :thumb_micro
99
+ end
100
+
101
+ end
61
102
 
62
103
  end
63
104
 
@@ -133,7 +174,7 @@ describe CarrierWave::Uploader do
133
174
  end
134
175
  end
135
176
 
136
- describe '#blank' do
177
+ describe '#blank?' do
137
178
  it "should be true when nothing has been done" do
138
179
  @uploader.should be_blank
139
180
  end
@@ -149,6 +190,17 @@ describe CarrierWave::Uploader do
149
190
  end
150
191
  end
151
192
 
193
+ describe '#read' do
194
+ it "should be nil by default" do
195
+ @uploader.read.should be_nil
196
+ end
197
+
198
+ it "should read the contents of a cached file" do
199
+ @uploader.cache!(File.open(file_path('test.jpg')))
200
+ @uploader.read.should == "this is stuff"
201
+ end
202
+ end
203
+
152
204
  describe '#store_dir' do
153
205
  it "should default to the config option" do
154
206
  @uploader.store_dir.should == 'uploads'
@@ -291,6 +343,16 @@ describe CarrierWave::Uploader do
291
343
  @uploader.cache!(nil)
292
344
  end
293
345
 
346
+ it "should set permissions if options are given" do
347
+ old_permissions = CarrierWave.config[:permissions]
348
+ CarrierWave.config[:permissions] = 0777
349
+
350
+ @uploader.cache!(File.open(file_path('test.jpg')))
351
+ @uploader.should have_permissions(0777)
352
+
353
+ CarrierWave.config[:permissions] = old_permissions
354
+ end
355
+
294
356
  it "should not raise an integiry error if there is no white list" do
295
357
  @uploader.stub!(:extension_white_list).and_return(nil)
296
358
  running {
@@ -500,6 +562,7 @@ describe CarrierWave::Uploader do
500
562
  @stored_file.stub!(:path).and_return('/path/to/somewhere')
501
563
  @stored_file.stub!(:url).and_return('http://www.example.com')
502
564
  @stored_file.stub!(:identifier).and_return('this-is-me')
565
+ @stored_file.stub!(:read).and_return('here be content')
503
566
 
504
567
  @uploader_class.storage.stub!(:retrieve!).and_return(@stored_file)
505
568
  end
@@ -518,6 +581,11 @@ describe CarrierWave::Uploader do
518
581
  @uploader.retrieve_from_store('monkey.txt')
519
582
  @uploader.identifier.should == 'this-is-me'
520
583
  end
584
+
585
+ it "should read out the contents" do
586
+ @uploader.retrieve_from_store('monkey.txt')
587
+ @uploader.read.should == 'here be content'
588
+ end
521
589
 
522
590
  it "should instruct the storage engine to retrieve the file and store the result" do
523
591
  @uploader_class.storage.should_receive(:retrieve!).with(@uploader, 'monkey.txt').and_return(@stored_file)
@@ -543,10 +611,11 @@ describe CarrierWave::Uploader do
543
611
  CarrierWave::Uploader.stub!(:generate_cache_id).and_return('20071201-1234-345-2255')
544
612
  end
545
613
 
546
- it "should suffix the version's store_dir" do
614
+ it "should set store_path with versions" do
547
615
  @uploader.cache!(File.open(file_path('test.jpg')))
548
- @uploader.store_dir.should == 'uploads'
549
- @uploader.thumb.store_dir.should == 'uploads/thumb'
616
+ @uploader.store_path.should == 'uploads/test.jpg'
617
+ @uploader.thumb.store_path.should == 'uploads/thumb_test.jpg'
618
+ @uploader.thumb.store_path('kebab.png').should == 'uploads/thumb_kebab.png'
550
619
  end
551
620
 
552
621
  it "should move it to the tmp dir with the filename prefixed" do
@@ -565,10 +634,11 @@ describe CarrierWave::Uploader do
565
634
  @uploader.thumb.current_path.should == public_path('uploads/tmp/20071201-1234-345-2255/thumb_test.jpg')
566
635
  end
567
636
 
568
- it "should suffix the version's store_dir" do
637
+ it "should set store_path with versions" do
569
638
  @uploader.retrieve_from_cache!('20071201-1234-345-2255/test.jpg')
570
- @uploader.store_dir.should == 'uploads'
571
- @uploader.thumb.store_dir.should == 'uploads/thumb'
639
+ @uploader.store_path.should == 'uploads/test.jpg'
640
+ @uploader.thumb.store_path.should == 'uploads/thumb_test.jpg'
641
+ @uploader.thumb.store_path('kebab.png').should == 'uploads/thumb_kebab.png'
572
642
  end
573
643
  end
574
644
 
@@ -600,17 +670,11 @@ describe CarrierWave::Uploader do
600
670
  @uploader.url.should == 'http://www.example.com'
601
671
  end
602
672
 
603
- it "should, if a file is given as argument, suffix the version's store_dir" do
604
- @uploader.store!(@file)
605
- @uploader.store_dir.should == 'uploads'
606
- @uploader.thumb.store_dir.should == 'uploads/thumb'
607
- end
608
-
609
- it "should, if a files is given as an argument and use_cache is false, suffix the version's store_dir" do
610
- CarrierWave.config[:use_cache] = false
673
+ it "should, if a file is given as argument, set the store_path" do
611
674
  @uploader.store!(@file)
612
- @uploader.store_dir.should == 'uploads'
613
- @uploader.thumb.store_dir.should == 'uploads/thumb'
675
+ @uploader.store_path.should == 'uploads/test.jpg'
676
+ @uploader.thumb.store_path.should == 'uploads/thumb_test.jpg'
677
+ @uploader.thumb.store_path('kebab.png').should == 'uploads/thumb_kebab.png'
614
678
  end
615
679
 
616
680
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jnicklas-carrierwave
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-13 00:00:00 -07:00
12
+ date: 2009-04-15 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -20,13 +20,13 @@ executables: []
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
- - README.md
23
+ - README.rdoc
24
24
  - LICENSE
25
25
  - TODO
26
26
  files:
27
27
  - LICENSE
28
28
  - Generators
29
- - README.md
29
+ - README.rdoc
30
30
  - Rakefile
31
31
  - TODO
32
32
  - lib/carrierwave
@@ -34,6 +34,7 @@ files:
34
34
  - lib/carrierwave/orm
35
35
  - lib/carrierwave/orm/activerecord.rb
36
36
  - lib/carrierwave/orm/datamapper.rb
37
+ - lib/carrierwave/orm/sequel.rb
37
38
  - lib/carrierwave/processing
38
39
  - lib/carrierwave/processing/image_science.rb
39
40
  - lib/carrierwave/processing/rmagick.rb
@@ -42,6 +43,8 @@ files:
42
43
  - lib/carrierwave/storage/abstract.rb
43
44
  - lib/carrierwave/storage/file.rb
44
45
  - lib/carrierwave/storage/s3.rb
46
+ - lib/carrierwave/test
47
+ - lib/carrierwave/test/matchers.rb
45
48
  - lib/carrierwave/uploader.rb
46
49
  - lib/carrierwave.rb
47
50
  - lib/generators
@@ -54,6 +57,7 @@ files:
54
57
  - spec/orm
55
58
  - spec/orm/activerecord_spec.rb
56
59
  - spec/orm/datamapper_spec.rb
60
+ - spec/orm/sequel_spec.rb
57
61
  - spec/sanitized_file_spec.rb
58
62
  - spec/spec_helper.rb
59
63
  - spec/uploader_spec.rb