ripta-dm-paperclip 2.2.9.2

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.
@@ -0,0 +1,173 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'right_aws'
5
+
6
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'dm-paperclip', 'geometry.rb')
7
+
8
+ class StorageTest < Test::Unit::TestCase
9
+ context "Parsing S3 credentials" do
10
+ setup do
11
+ rebuild_model :storage => :s3,
12
+ :bucket => "testing",
13
+ :s3_credentials => {:not => :important}
14
+
15
+ @dummy = Dummy.new
16
+ @avatar = @dummy.avatar
17
+
18
+ @current_env = ENV['RAILS_ENV']
19
+ end
20
+
21
+ teardown do
22
+ ENV['RAILS_ENV'] = @current_env
23
+ end
24
+
25
+ should "get the correct credentials when RAILS_ENV is production" do
26
+ ENV['RAILS_ENV'] = 'production'
27
+ assert_equal({'key' => "12345"},
28
+ @avatar.parse_credentials('production' => {:key => '12345'},
29
+ :development => {:key => "54321"}))
30
+ end
31
+
32
+ should "get the correct credentials when RAILS_ENV is development" do
33
+ ENV['RAILS_ENV'] = 'development'
34
+ assert_equal({'key' => "54321"},
35
+ @avatar.parse_credentials('production' => {:key => '12345'},
36
+ :development => {:key => "54321"}))
37
+ end
38
+
39
+ should "return the argument if the key does not exist" do
40
+ ENV['RAILS_ENV'] = "not really an env"
41
+ assert_equal({'test' => "12345"}, @avatar.parse_credentials(:test => "12345"))
42
+ end
43
+ end
44
+
45
+ context "Parsing S3 credentials with a bucket in them" do
46
+ setup do
47
+ rebuild_model :storage => :s3,
48
+ :s3_credentials => {
49
+ :production => { :bucket => "prod_bucket" },
50
+ :development => { :bucket => "dev_bucket" }
51
+ }
52
+ @dummy = Dummy.new
53
+ end
54
+
55
+ should "get the right bucket in production", :before => lambda{ ENV.expects(:[]).returns('production') } do
56
+ assert_equal "prod_bucket", @dummy.avatar.bucket_name
57
+ end
58
+
59
+ should "get the right bucket in development", :before => lambda{ ENV.expects(:[]).returns('development') } do
60
+ assert_equal "dev_bucket", @dummy.avatar.bucket_name
61
+ end
62
+ end
63
+
64
+ context "An attachment with S3 storage" do
65
+ setup do
66
+ rebuild_model :storage => :s3,
67
+ :bucket => "testing",
68
+ :path => ":attachment/:style/:basename.:extension",
69
+ :s3_credentials => {
70
+ 'access_key_id' => "12345",
71
+ 'secret_access_key' => "54321"
72
+ }
73
+ end
74
+
75
+ should "be extended by the S3 module" do
76
+ assert Dummy.new.avatar.is_a?(Paperclip::Storage::S3)
77
+ end
78
+
79
+ should "not be extended by the Filesystem module" do
80
+ assert ! Dummy.new.avatar.is_a?(Paperclip::Storage::Filesystem)
81
+ end
82
+
83
+ context "when assigned" do
84
+ setup do
85
+ @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'))
86
+ @dummy = Dummy.new
87
+ @dummy.avatar = @file
88
+ end
89
+
90
+ should "not get a bucket to get a URL" do
91
+ @dummy.avatar.expects(:s3).never
92
+ @dummy.avatar.expects(:s3_bucket).never
93
+ assert_match %r{^http://s3\.amazonaws\.com/testing/avatars/original/5k\.png}, @dummy.avatar.url
94
+ end
95
+
96
+ context "and saved" do
97
+ setup do
98
+ @s3_mock = stub
99
+ @bucket_mock = stub
100
+ RightAws::S3.expects(:new).with("12345", "54321", {}).returns(@s3_mock)
101
+ @s3_mock.expects(:bucket).with("testing", true, "public-read").returns(@bucket_mock)
102
+ @key_mock = stub
103
+ @bucket_mock.expects(:key).returns(@key_mock)
104
+ @key_mock.expects(:data=)
105
+ @key_mock.expects(:put)
106
+ @dummy.id = 1
107
+ @dummy.save
108
+ end
109
+
110
+ should "succeed" do
111
+ assert true
112
+ end
113
+ end
114
+
115
+ context "and remove" do
116
+ setup do
117
+ @s3_mock = stub
118
+ @bucket_mock = stub
119
+ RightAws::S3.expects(:new).with("12345", "54321", {}).returns(@s3_mock)
120
+ @s3_mock.expects(:bucket).with("testing", true, "public-read").returns(@bucket_mock)
121
+ @key_mock = stub
122
+ @bucket_mock.expects(:key).at_least(2).returns(@key_mock)
123
+ @key_mock.expects(:delete)
124
+ @dummy.destroy_attached_files
125
+ end
126
+
127
+ should "succeed" do
128
+ assert true
129
+ end
130
+ end
131
+ end
132
+ end
133
+
134
+ unless ENV["S3_TEST_BUCKET"].blank?
135
+ context "Using S3 for real, an attachment with S3 storage" do
136
+ setup do
137
+ rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
138
+ :storage => :s3,
139
+ :bucket => ENV["S3_TEST_BUCKET"],
140
+ :path => ":class/:attachment/:id/:style.:extension",
141
+ :s3_credentials => File.new(File.join(File.dirname(__FILE__), "s3.yml"))
142
+
143
+ Dummy.delete_all
144
+ @dummy = Dummy.new
145
+ end
146
+
147
+ should "be extended by the S3 module" do
148
+ assert Dummy.new.avatar.is_a?(Paperclip::Storage::S3)
149
+ end
150
+
151
+ context "when assigned" do
152
+ setup do
153
+ @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'))
154
+ @dummy.avatar = @file
155
+ end
156
+
157
+ should "still return a Tempfile when sent #to_io" do
158
+ assert_equal Tempfile, @dummy.avatar.to_io.class
159
+ end
160
+
161
+ context "and saved" do
162
+ setup do
163
+ @dummy.save
164
+ end
165
+
166
+ should "be on S3" do
167
+ assert true
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,147 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'mocha'
5
+ require 'tempfile'
6
+
7
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'dm-paperclip', 'geometry.rb')
8
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'dm-paperclip', 'thumbnail.rb')
9
+
10
+ class ThumbnailTest < Test::Unit::TestCase
11
+
12
+ context "A Paperclip Tempfile" do
13
+ setup do
14
+ @tempfile = Paperclip::Tempfile.new("file.jpg")
15
+ end
16
+
17
+ should "have its path contain a real extension" do
18
+ assert_equal ".jpg", File.extname(@tempfile.path)
19
+ end
20
+
21
+ should "be a real Tempfile" do
22
+ assert @tempfile.is_a?(::Tempfile)
23
+ end
24
+ end
25
+
26
+ context "Another Paperclip Tempfile" do
27
+ setup do
28
+ @tempfile = Paperclip::Tempfile.new("file")
29
+ end
30
+
31
+ should "not have an extension if not given one" do
32
+ assert_equal "", File.extname(@tempfile.path)
33
+ end
34
+
35
+ should "still be a real Tempfile" do
36
+ assert @tempfile.is_a?(::Tempfile)
37
+ end
38
+ end
39
+
40
+ context "An image" do
41
+ setup do
42
+ @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"))
43
+ end
44
+
45
+ [["600x600>", "434x66"],
46
+ ["400x400>", "400x61"],
47
+ ["32x32<", "434x66"]
48
+ ].each do |args|
49
+ context "being thumbnailed with a geometry of #{args[0]}" do
50
+ setup do
51
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => args[0])
52
+ end
53
+
54
+ should "start with dimensions of 434x66" do
55
+ cmd = %Q[identify -format "%wx%h" #{@file.path}]
56
+ assert_equal "434x66", `#{cmd}`.chomp
57
+ end
58
+
59
+ should "report the correct target geometry" do
60
+ assert_equal args[0], @thumb.target_geometry.to_s
61
+ end
62
+
63
+ context "when made" do
64
+ setup do
65
+ @thumb_result = @thumb.make
66
+ end
67
+
68
+ should "be the size we expect it to be" do
69
+ cmd = %Q[identify -format "%wx%h" #{@thumb_result.path}]
70
+ assert_equal args[1], `#{cmd}`.chomp
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ context "being thumbnailed at 100x50 with cropping" do
77
+ setup do
78
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#")
79
+ end
80
+
81
+ should "report its correct current and target geometries" do
82
+ assert_equal "100x50#", @thumb.target_geometry.to_s
83
+ assert_equal "434x66", @thumb.current_geometry.to_s
84
+ end
85
+
86
+ should "report its correct format" do
87
+ assert_nil @thumb.format
88
+ end
89
+
90
+ should "have whiny_thumbnails turned on by default" do
91
+ assert @thumb.whiny
92
+ end
93
+
94
+ should "have convert_options set to nil by default" do
95
+ assert_equal nil, @thumb.convert_options
96
+ end
97
+
98
+ should "send the right command to convert when sent #make" do
99
+ Paperclip.expects(:run).with do |cmd, arg|
100
+ cmd.match 'convert'
101
+ arg.match %r{"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-resize\s+\"x50\"\s+-crop\s+\"100x50\+114\+0\"\s+\+repage\s+".*?"}
102
+ end
103
+ @thumb.make
104
+ end
105
+
106
+ should "create the thumbnail when sent #make" do
107
+ dst = @thumb.make
108
+ assert_match /100x50/, `identify #{dst.path}`
109
+ end
110
+ end
111
+
112
+ context "being thumbnailed with convert options set" do
113
+ setup do
114
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#", :format => (format = nil), :convert_options => (convert_options="-strip -depth 8"), :whiny => (whiny_thumbnails=true))
115
+ end
116
+
117
+ should "have convert_options value set" do
118
+ assert_equal "-strip -depth 8", @thumb.convert_options
119
+ end
120
+
121
+ should "send the right command to convert when sent #make" do
122
+ Paperclip.expects(:run).with do |cmd, arg|
123
+ cmd.match 'convert'
124
+ arg.match %r{"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-resize\s+"x50"\s+-crop\s+"100x50\+114\+0"\s+\+repage\s+-strip\s+-depth\s+8\s+".*?"}
125
+ end
126
+ @thumb.make
127
+ end
128
+
129
+ should "create the thumbnail when sent #make" do
130
+ dst = @thumb.make
131
+ assert_match /100x50/, `identify #{dst.path}`
132
+ end
133
+
134
+ context "redefined to have bad convert_options setting" do
135
+ setup do
136
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#", :format => nil, :convert_options => "-this-aint-no-option", :whiny => true)
137
+ end
138
+
139
+ should "error when trying to create the thumbnail" do
140
+ assert_raises(Paperclip::PaperclipError) do
141
+ @thumb.make
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ripta-dm-paperclip
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.2.9.2
5
+ platform: ruby
6
+ authors:
7
+ - Ken Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-23 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: ken@invalidlogic.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - README.rdoc
26
+ - LICENSE
27
+ - Rakefile
28
+ - init.rb
29
+ - lib/dm-paperclip/attachment.rb
30
+ - lib/dm-paperclip/callback_compatability.rb
31
+ - lib/dm-paperclip/geometry.rb
32
+ - lib/dm-paperclip/interpolations.rb
33
+ - lib/dm-paperclip/iostream.rb
34
+ - lib/dm-paperclip/processor.rb
35
+ - lib/dm-paperclip/storage.rb
36
+ - lib/dm-paperclip/thumbnail.rb
37
+ - lib/dm-paperclip/upfile.rb
38
+ - lib/dm-paperclip/validations.rb
39
+ - lib/dm-paperclip.rb
40
+ - tasks/paperclip_tasks.rake
41
+ - test/attachment_test.rb
42
+ - test/fixtures/12k.png
43
+ - test/fixtures/50x50.png
44
+ - test/fixtures/5k.png
45
+ - test/fixtures/bad.png
46
+ - test/fixtures/text.txt
47
+ - test/geometry_test.rb
48
+ - test/helper.rb
49
+ - test/integration_test.rb
50
+ - test/iostream_test.rb
51
+ - test/paperclip_test.rb
52
+ - test/storage_test.rb
53
+ - test/thumbnail_test.rb
54
+ has_rdoc: true
55
+ homepage: http://invalidlogic.com/dm-paperclip/
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --line-numbers
61
+ - --inline-source
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ requirements:
77
+ - ImageMagick
78
+ - data_mapper
79
+ rubyforge_project: dm-paperclip
80
+ rubygems_version: 1.3.5
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: File attachments as attributes for DataMapper, based on the original Paperclip by Jon Yurek at Thoughtbot
84
+ test_files: []
85
+