citrusbyte-milton 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe Citrusbyte::Milton::IsImage do
4
- end
@@ -1,150 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe Citrusbyte::Milton::IsResizeable do
4
- describe "building the filename from options" do
5
- before :each do
6
- @image = Image.create :file => upload('milton.jpg')
7
- end
8
-
9
- describe "options as hash" do
10
- it "should coalesce size into filename" do
11
- File.basename(@image.path(:size => '40x40')).should eql('milton.size=40x40.jpg')
12
- end
13
-
14
- it "should raise unless a size is given" do
15
- lambda {
16
- File.basename(@image.path(:crop => true))
17
- }.should raise_error
18
- end
19
-
20
- it "should coalesce crop into filename" do
21
- File.basename(@image.path(:size => '40x40', :crop => true)).should eql('milton.crop=true_size=40x40.jpg')
22
- end
23
-
24
- it "should coalesce gravity into filename" do
25
- File.basename(@image.path(:size => '40x40', :gravity => 'north')).should eql('milton.gravity=north_size=40x40.jpg')
26
- end
27
-
28
- it "should coalese all options together" do
29
- File.basename(@image.path(:size => '40x40', :gravity => 'north', :crop => true)).should eql('milton.crop=true_gravity=north_size=40x40.jpg')
30
- end
31
- end
32
-
33
- describe "options as string" do
34
- it "should parse size" do
35
- File.basename(@image.path('size=40x40')).should eql('milton.size=40x40.jpg')
36
- end
37
-
38
- it "should parse crop" do
39
- File.basename(@image.path('size=40x40_crop=true')).should eql('milton.crop=true_size=40x40.jpg')
40
- end
41
-
42
- it "should parse gravity" do
43
- File.basename(@image.path('size=40x40_gravity=north')).should eql('milton.gravity=north_size=40x40.jpg')
44
- end
45
-
46
- it "should parse them all together" do
47
- File.basename(@image.path('size=40x40_crop=true_gravity=north')).should eql('milton.crop=true_gravity=north_size=40x40.jpg')
48
- end
49
- end
50
- end
51
-
52
- # milton.jpg is 320x300
53
- describe "resizing" do
54
- before :each do
55
- @image = Image.create :file => upload('milton.jpg')
56
- end
57
-
58
- describe "checking errors" do
59
- it "should raise a MissingFileError if source file does not exist" do
60
- FileUtils.rm(@image.path)
61
- lambda {
62
- @image.path(:size => '50x50')
63
- }.should raise_error(Citrusbyte::Milton::MissingFileError)
64
- end
65
- end
66
-
67
- describe "when cropped" do
68
- before :each do
69
- @info = Citrusbyte::Milton::IsResizeable::Image.from_path(@image.reload.path(:size => '50x50', :crop => true))
70
- end
71
-
72
- it "should have width of 50px" do
73
- @info.width.should eql(50)
74
- end
75
-
76
- it "should have height of 50px" do
77
- @info.height.should eql(50)
78
- end
79
- end
80
-
81
- # 300/320 = 0.9375
82
- # 50*0.9375 = 47
83
- describe "when not cropped" do
84
- before :each do
85
- @info = Citrusbyte::Milton::IsResizeable::Image.from_path(@image.reload.path(:size => '50x50'))
86
- end
87
-
88
- it "should have width of 47px" do
89
- @info.width.should eql(47)
90
- end
91
-
92
- it "should have height of 50px" do
93
- @info.height.should eql(50)
94
- end
95
- end
96
- end
97
-
98
- describe "smarter thumbnails" do
99
- before :each do
100
- @image = Image.create :file => upload('big-milton.jpg')
101
- end
102
-
103
- it "should generate 640px wide version when image is wider than 640px wide and generating an image smaller than 640px wide" do
104
- path = @image.path(:crop => true, :size => '40x40')
105
- File.exists?(path.gsub(/\.crop=true_size=40x40/, '.size=640x')).should be_true
106
- end
107
-
108
- it "should generate images smaller than 640px wide from the existing 640px one" do
109
- # TODO: how can i test this?
110
- @image.path(:crop => true, :size => '40x40')
111
- end
112
- end
113
-
114
- describe "fetching thumbnails" do
115
- before :each do
116
- @image = Image.create :file => upload('milton.jpg')
117
- end
118
-
119
- it "should use the partitioned path when grabbing the original file" do
120
- @image.path.should =~ /\/#{Citrusbyte::Milton::AttachableFile.partition(@image.id)}\/milton.jpg$/
121
- end
122
-
123
- it "should use the partitioned path when grabbing a thubmnail" do
124
- @image.path(:size => '10x10', :crop => true).should =~ /\/#{Citrusbyte::Milton::AttachableFile.partition(@image.id)}\/milton.crop=true_size=10x10.jpg$/
125
- end
126
- end
127
-
128
- describe "getting mime-type" do
129
- before :each do
130
- @image = Image.new :file => upload('milton.jpg')
131
- end
132
-
133
- describe "from freshly uploaded file" do
134
- it "should recognize it as an image/jpg" do
135
- @image.content_type.should eql('image/jpg')
136
- end
137
- end
138
-
139
- describe "from existing file" do
140
- before :each do
141
- @image.save
142
- @image.reload
143
- end
144
-
145
- it "should recognize it as an image/jpg" do
146
- @image.content_type.should eql('image/jpg')
147
- end
148
- end
149
- end
150
- end
@@ -1,110 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe Citrusbyte::Milton::IsUploadable do
4
- class NotUploadable < ActiveRecord::Base
5
- end
6
-
7
- class NoTable < ActiveRecord::Base
8
- end
9
-
10
- describe "filename column" do
11
- it 'should not raise an exception if there is a filename column' do
12
- lambda { Attachment.class_eval("is_uploadable") }.should_not raise_error
13
- end
14
-
15
- it "should raise an exception if there is no filename column" do
16
- lambda { NotUploadable.class_eval("is_uploadable") }.should raise_error
17
- end
18
-
19
- it 'should not raise an exception if the underlying table doesn\'t exist' do
20
- lambda { NoTable.class_eval('is_uploadable') }.should_not raise_error
21
- end
22
- end
23
-
24
- describe "setting :file_system_path" do
25
- it "should allow options to be accessed" do
26
- Attachment.milton_options.should be_kind_of(Hash)
27
- end
28
-
29
- it "should be able to overwrite file_system_path from is_uploadable call" do
30
- Attachment.class_eval("is_uploadable(:file_system_path => 'foo')")
31
- Attachment.milton_options[:file_system_path].should eql('foo')
32
- end
33
- end
34
-
35
- describe "class extensions" do
36
- describe "class methods" do
37
- it "should add before_file_saved callback" do
38
- Attachment.should respond_to(:before_file_saved)
39
- end
40
-
41
- it "should add after_file_saved callback" do
42
- Attachment.should respond_to(:after_file_saved)
43
- end
44
- end
45
- end
46
-
47
- describe "handling file upload" do
48
- describe "saving upload" do
49
- before :each do
50
- @attachment = Attachment.new :file => upload('milton.jpg')
51
- end
52
-
53
- it "should save the upload to the filesystem on save" do
54
- @attachment.save
55
- File.exists?(@attachment.path).should be_true
56
- end
57
-
58
- it "should have the same filesize as original file when large enough not to be a StringIO" do
59
- # FIXME: this doesn't actually upload as a StringIO, figure out how to
60
- # force that
61
- @attachment.save
62
- File.size(@attachment.path).should be_eql(File.size(File.join(File.dirname(__FILE__), '..', 'fixtures', 'milton.jpg')))
63
- end
64
-
65
- it "should have the same filesize as original file when small enough to be a StringIO" do
66
- File.size(Attachment.create(:file => upload('mini-milton.jpg')).path).should be_eql(File.size(File.join(File.dirname(__FILE__), '..', 'fixtures', 'mini-milton.jpg')))
67
- end
68
- end
69
-
70
- describe "stored full filename" do
71
- before :each do
72
- @attachment = Attachment.create! :file => upload('milton.jpg')
73
- end
74
-
75
- it "should use set file_system_path" do
76
- @attachment.path.should =~ /^#{@attachment.milton_options[:file_system_path]}.*$/
77
- end
78
-
79
- it "should use uploaded filename" do
80
- @attachment.path.should =~ /^.*#{@attachment.filename}$/
81
- end
82
- end
83
-
84
- describe "sanitizing filename" do
85
- before :each do
86
- @attachment = Attachment.create! :file => upload('unsanitary .milton.jpg')
87
- end
88
-
89
- it "should strip the space and . and replace them with -" do
90
- @attachment.path.should =~ /^.*\/unsanitary--milton.jpg$/
91
- end
92
-
93
- it "should exist with sanitized filename" do
94
- File.exists?(@attachment.path).should be_true
95
- end
96
- end
97
-
98
- describe "saving attachment after upload" do
99
- before :each do
100
- @attachment = Attachment.create! :file => upload('unsanitary .milton.jpg')
101
- end
102
-
103
- it "should save the file again" do
104
- lambda {
105
- Attachment.find(@attachment.id).save!
106
- }.should_not raise_error
107
- end
108
- end
109
- end
110
- end
@@ -1,4 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe Citrusbyte::Milton do
4
- end
@@ -1,13 +0,0 @@
1
- ActiveRecord::Schema.define :version => 0 do
2
- create_table :attachments, :force => true do |t|
3
- t.string :filename
4
- end
5
-
6
- create_table :images, :force => true do |t|
7
- t.string :filename
8
- t.string :content_type
9
- end
10
-
11
- create_table :not_uploadables, :force => true do |t|
12
- end
13
- end
@@ -1,7 +0,0 @@
1
- --colour
2
- --format
3
- specdoc
4
- --loadby
5
- mtime
6
- --reverse
7
- --backtrace
@@ -1,29 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
2
- require 'pathname'
3
-
4
- plugin_spec_dir = File.dirname(__FILE__)
5
- ActiveRecord::Base.logger = Logger.new(plugin_spec_dir + "/debug.log")
6
-
7
- load(File.dirname(__FILE__) + '/schema.rb')
8
-
9
- Spec::Runner.configure do |config|
10
- # have to set Test::Unit::TestCase.fixture_path until RSpec is fixed
11
- # (config.fixture_path seems to be ignored w/ Rails 2.2.2/Rspec 1.1.12)
12
- config.fixture_path = Test::Unit::TestCase.fixture_path = File.join(File.dirname(__FILE__), 'fixtures/')
13
-
14
- # remove files created from previous spec run, happens before instead of
15
- # after so you can view them after you run the specs
16
- FileUtils.rm_rf(File.join(File.dirname(__FILE__), 'output'))
17
- end
18
-
19
- def upload(file, type='image/jpg')
20
- fixture_file_upload file, type
21
- end
22
-
23
- class Attachment < ActiveRecord::Base
24
- is_uploadable :file_system_path => File.join(File.dirname(__FILE__), 'output')
25
- end
26
-
27
- class Image < ActiveRecord::Base
28
- is_image :file_system_path => File.join(File.dirname(__FILE__), 'output')
29
- end