dm-paperclip 2.1.2.1 → 2.1.4

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.
File without changes
data/test/helper.rb CHANGED
@@ -4,7 +4,7 @@ require 'shoulda'
4
4
  require 'mocha'
5
5
  require 'tempfile'
6
6
 
7
- require 'data_mapper'
7
+ require 'dm-core'
8
8
  require 'dm-validations'
9
9
  require 'dm-migrations'
10
10
  begin
@@ -15,6 +15,7 @@ end
15
15
 
16
16
  ROOT = File.join(File.dirname(__FILE__), '..')
17
17
  RAILS_ROOT = ROOT
18
+ RAILS_ENV = ENV['RAILS_ENV']
18
19
 
19
20
  Object.const_set("Merb", Class.new())
20
21
  Merb.class_eval do
@@ -42,23 +43,6 @@ unless defined?(Mash)
42
43
  end
43
44
 
44
45
  def rebuild_model options = {}
45
- DataMapper::Migration.new( 1, :drop_dummies_table ) do
46
- up do
47
- create_table :dummies do
48
- column :id, "integer", true
49
- column :other, "varchar(255)"
50
- column :avatar_file_name, "varchar(255)"
51
- column :avatar_content_type, "varchar(255)"
52
- column :avatar_file_size, "integer"
53
- end
54
- end
55
- down do
56
- drop_table :dummies
57
- end
58
- perform_down
59
- perform_up
60
- end
61
-
62
46
  Object.send(:remove_const, "Dummy") rescue nil
63
47
  Object.const_set("Dummy", Class.new())
64
48
  Dummy.class_eval do
@@ -69,4 +53,12 @@ def rebuild_model options = {}
69
53
  property :other, String
70
54
  has_attached_file :avatar, options
71
55
  end
56
+ Dummy.auto_migrate!
72
57
  end
58
+
59
+ def temporary_env(new_env)
60
+ old_env = defined?(RAILS_ENV) ? RAILS_ENV : nil
61
+ Object.const_set("RAILS_ENV", new_env)
62
+ yield
63
+ Object.const_set("RAILS_ENV", old_env)
64
+ end
@@ -39,7 +39,7 @@ class IntegrationTest < Test::Unit::TestCase
39
39
  Dummy.class_eval do
40
40
  has_attached_file :avatar, :styles => { :thumb => "150x25#" }
41
41
  end
42
- @d2 = Dummy[@dummy.id]
42
+ @d2 = Dummy.get(@dummy.id)
43
43
  @d2.avatar.reprocess!
44
44
  @d2.save
45
45
  end
@@ -92,6 +92,38 @@ class IntegrationTest < Test::Unit::TestCase
92
92
  end
93
93
  end
94
94
 
95
+ context "A model with no thumbnail_convert_options setting" do
96
+ setup do
97
+ rebuild_model :styles => { :large => "300x300>",
98
+ :medium => "100x100",
99
+ :thumb => ["32x32#", :gif] },
100
+ :default_style => :medium,
101
+ :url => "/:attachment/:class/:style/:id/:basename.:extension",
102
+ :path => ":merb_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
103
+ @dummy = Dummy.new
104
+ end
105
+
106
+ should "have its definition return nil when asked about convert_options" do
107
+ assert ! Dummy.attachment_definitions[:avatar][:thumbnail_convert_options]
108
+ end
109
+
110
+ context "redefined to have convert_options setting" do
111
+ setup do
112
+ rebuild_model :styles => { :large => "300x300>",
113
+ :medium => "100x100",
114
+ :thumb => ["32x32#", :gif] },
115
+ :thumbnail_convert_options => "-strip -depth 8",
116
+ :default_style => :medium,
117
+ :url => "/:attachment/:class/:style/:id/:basename.:extension",
118
+ :path => ":merb_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
119
+ end
120
+
121
+ should "have its definition return convert_options value when asked about convert_options" do
122
+ assert_equal "-strip -depth 8", Dummy.attachment_definitions[:avatar][:thumbnail_convert_options]
123
+ end
124
+ end
125
+ end
126
+
95
127
  context "A model with a filesystem attachment" do
96
128
  setup do
97
129
  rebuild_model :styles => { :large => "300x300>",
@@ -122,7 +154,7 @@ class IntegrationTest < Test::Unit::TestCase
122
154
 
123
155
  saved_paths = [:thumb, :medium, :large, :original].collect{|s| @dummy.avatar.to_file(s).path }
124
156
 
125
- @d2 = Dummy[@dummy.id]
157
+ @d2 = Dummy.get(@dummy.id)
126
158
  assert_equal "100x15", `identify -format "%wx%h" #{@d2.avatar.to_file.path}`.chomp
127
159
  assert_equal "434x66", `identify -format "%wx%h" #{@d2.avatar.to_file(:original).path}`.chomp
128
160
  assert_equal "300x46", `identify -format "%wx%h" #{@d2.avatar.to_file(:large).path}`.chomp
@@ -148,12 +180,12 @@ class IntegrationTest < Test::Unit::TestCase
148
180
  assert ! File.exists?(p)
149
181
  end
150
182
 
151
- @d2 = Dummy[@dummy.id]
183
+ @d2 = Dummy.get(@dummy.id)
152
184
  assert_nil @d2.avatar_file_name
153
185
  end
154
186
 
155
187
  should "work exactly the same when new as when reloaded" do
156
- @d2 = Dummy[@dummy.id]
188
+ @d2 = Dummy.get(@dummy.id)
157
189
 
158
190
  assert_equal @dummy.avatar_file_name, @d2.avatar_file_name
159
191
  [:thumb, :medium, :large, :original].each do |style|
@@ -184,7 +216,7 @@ class IntegrationTest < Test::Unit::TestCase
184
216
 
185
217
  should "know the difference between good files, bad files, not files, and nil when validating" do
186
218
  Dummy.validates_attachment_presence :avatar
187
- @d2 = Dummy[@dummy.id]
219
+ @d2 = Dummy.get(@dummy.id)
188
220
  @d2.avatar = @file
189
221
  assert @d2.valid?
190
222
  @d2.avatar = @bad_file
@@ -195,12 +227,42 @@ class IntegrationTest < Test::Unit::TestCase
195
227
 
196
228
  should "be able to reload without saving an not have the file disappear" do
197
229
  @dummy.avatar = @file
198
- assert @dummy.save
230
+ @dummy.save
199
231
  @dummy.avatar = nil
200
232
  assert_nil @dummy.avatar_file_name
201
233
  @dummy.reload
202
234
  assert_equal "5k.png", @dummy.avatar_file_name
203
235
  end
236
+
237
+ context "that is assigned its file from another Paperclip attachment" do
238
+ setup do
239
+ @dummy2 = Dummy.new
240
+ @file2 = File.new(File.join(FIXTURES_DIR, "12k.png"))
241
+ assert @dummy2.avatar = @file2
242
+ @dummy2.save
243
+ end
244
+
245
+ should "work when assigned a file" do
246
+ assert_not_equal `identify -format "%wx%h" #{@dummy.avatar.to_file(:original).path}`,
247
+ `identify -format "%wx%h" #{@dummy2.avatar.to_file(:original).path}`
248
+
249
+ assert @dummy.avatar = @dummy2.avatar
250
+ @dummy.save
251
+ assert_equal `identify -format "%wx%h" #{@dummy.avatar.to_file(:original).path}`,
252
+ `identify -format "%wx%h" #{@dummy2.avatar.to_file(:original).path}`
253
+ end
254
+
255
+ should "work when assigned a nil file" do
256
+ @dummy2.avatar = nil
257
+ @dummy2.save
258
+
259
+ @dummy.avatar = @dummy2.avatar
260
+ @dummy.save
261
+
262
+ assert !@dummy.avatar?
263
+ end
264
+ end
265
+
204
266
  end
205
267
 
206
268
  if ENV['S3_TEST_BUCKET']
@@ -247,7 +309,7 @@ class IntegrationTest < Test::Unit::TestCase
247
309
  assert_equal geo, `#{cmd}`.chomp, cmd
248
310
  end
249
311
 
250
- @d2 = Dummy[@dummy.id]
312
+ @d2 = Dummy.get(@dummy.id)
251
313
  @d2_files = s3_files_for @d2.avatar
252
314
  [["434x66", :original],
253
315
  ["300x46", :large],
@@ -277,12 +339,12 @@ class IntegrationTest < Test::Unit::TestCase
277
339
  assert ! key.exists?
278
340
  end
279
341
 
280
- @d2 = Dummy[@dummy.id]
342
+ @d2 = Dummy.get(@dummy.id)
281
343
  assert_nil @d2.avatar_file_name
282
344
  end
283
345
 
284
346
  should "work exactly the same when new as when reloaded" do
285
- @d2 = Dummy[@dummy.id]
347
+ @d2 = Dummy.get(@dummy.id)
286
348
 
287
349
  assert_equal @dummy.avatar_file_name, @d2.avatar_file_name
288
350
  [:thumb, :medium, :large, :original].each do |style|
@@ -311,7 +373,7 @@ class IntegrationTest < Test::Unit::TestCase
311
373
  assert @dummy.valid?
312
374
 
313
375
  Dummy.validates_attachment_presence :avatar
314
- @d2 = Dummy[@dummy.id]
376
+ @d2 = Dummy.get(@dummy.id)
315
377
  @d2.avatar = @file
316
378
  assert @d2.valid?
317
379
  @d2.avatar = @bad_file
@@ -320,7 +382,7 @@ class IntegrationTest < Test::Unit::TestCase
320
382
  assert ! @d2.valid?
321
383
  end
322
384
 
323
- should "be able to reload without saving an not have the file disappear" do
385
+ should "be able to reload without saving and not have the file disappear" do
324
386
  @dummy.avatar = @file
325
387
  assert @dummy.save
326
388
  @dummy.avatar = nil
File without changes
@@ -1,12 +1,39 @@
1
1
  require 'test/helper.rb'
2
2
 
3
3
  class PaperclipTest < Test::Unit::TestCase
4
- context "An ActiveRecord model with an 'avatar' attachment" do
4
+ context "A DataMapper model with an 'avatar' attachment" do
5
5
  setup do
6
6
  rebuild_model :path => "tmp/:class/omg/:style.:extension"
7
7
  @file = File.new(File.join(FIXTURES_DIR, "5k.png"))
8
8
  end
9
9
 
10
+ should "not error when trying to also create a 'blah' attachment" do
11
+ assert_nothing_raised do
12
+ Dummy.class_eval do
13
+ has_attached_file :blah
14
+ end
15
+ end
16
+ end
17
+
18
+ should "handle multiple classes using attachments" do
19
+ Object.const_set("DummyTwo", Class.new())
20
+ DummyTwo.class_eval do
21
+ include DataMapper::Resource
22
+ include DataMapper::Validate
23
+ include Paperclip::Resource
24
+ property :id, Integer, :serial => true
25
+ property :other, String
26
+ has_attached_file :file
27
+ end
28
+
29
+ assert_equal [:file], DummyTwo.attachment_definitions.keys
30
+ assert_equal [:avatar], Dummy.attachment_definitions.keys
31
+
32
+ Object.send(:remove_const, "DummyTwo") rescue nil
33
+
34
+ assert_equal [:avatar], Dummy.attachment_definitions.keys
35
+ end
36
+
10
37
  context "that is write protected" do
11
38
  setup do
12
39
  Dummy.class_eval do
@@ -60,6 +87,38 @@ class PaperclipTest < Test::Unit::TestCase
60
87
  assert Dummy.new.respond_to?(:avatar=)
61
88
  end
62
89
 
90
+ context "that is valid" do
91
+ setup do
92
+ @dummy = Dummy.new
93
+ @dummy.avatar = @file
94
+ end
95
+
96
+ should "be valid" do
97
+ assert @dummy.valid?
98
+ end
99
+
100
+ context "then has a validation added that makes it invalid" do
101
+ setup do
102
+ assert @dummy.save
103
+ Dummy.class_eval do
104
+ validates_attachment_content_type :avatar, :content_type => ["text/plain"]
105
+ end
106
+ @dummy2 = Dummy.get(@dummy.id)
107
+ end
108
+
109
+ should "be invalid when reloaded" do
110
+ assert ! @dummy2.valid?, @dummy2.errors.inspect
111
+ end
112
+
113
+ should "be able to call #valid? twice without having duplicate errors" do
114
+ @dummy2.avatar.valid?
115
+ first_errors = @dummy2.avatar.errors
116
+ @dummy2.avatar.valid?
117
+ assert_equal first_errors, @dummy2.avatar.errors
118
+ end
119
+ end
120
+ end
121
+
63
122
  [[:presence, nil, "5k.png", nil],
64
123
  [:size, {:in => 1..10240}, "5k.png", "12k.png"],
65
124
  [:size2, {:in => 1..10240}, nil, "12k.png"],
@@ -98,21 +157,6 @@ class PaperclipTest < Test::Unit::TestCase
98
157
  assert_equal 1, @dummy.errors.length
99
158
  end
100
159
  end
101
-
102
- # context "and an invalid file with :message" do
103
- # setup do
104
- # @file = args[3] && File.new(File.join(FIXTURES_DIR, args[3]))
105
- # end
106
- #
107
- # should "have errors" do
108
- # if args[1] && args[1][:message] && args[4]
109
- # @dummy.avatar = @file
110
- # assert ! @dummy.valid?
111
- # assert_equal 1, @dummy.errors.length
112
- # assert_equal args[4], @dummy.errors[0]
113
- # end
114
- # end
115
- # end
116
160
  end
117
161
  end
118
162
  end
@@ -42,6 +42,25 @@ class StorageTest < Test::Unit::TestCase
42
42
  end
43
43
  end
44
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
+
45
64
  context "An attachment with S3 storage" do
46
65
  setup do
47
66
  rebuild_model :storage => :s3,
@@ -71,7 +90,7 @@ class StorageTest < Test::Unit::TestCase
71
90
  should "not get a bucket to get a URL" do
72
91
  @dummy.avatar.expects(:s3).never
73
92
  @dummy.avatar.expects(:s3_bucket).never
74
- assert_equal "https://s3.amazonaws.com/testing/avatars/original/5k.png", @dummy.avatar.url
93
+ assert_match %r{^http://s3\.amazonaws\.com/testing/avatars/original/5k\.png}, @dummy.avatar.url
75
94
  end
76
95
 
77
96
  context "and saved" do
@@ -84,6 +103,7 @@ class StorageTest < Test::Unit::TestCase
84
103
  @bucket_mock.expects(:key).returns(@key_mock)
85
104
  @key_mock.expects(:data=)
86
105
  @key_mock.expects(:put)
106
+ @dummy.id = 1
87
107
  @dummy.save
88
108
  end
89
109
 
@@ -91,6 +111,23 @@ class StorageTest < Test::Unit::TestCase
91
111
  assert true
92
112
  end
93
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
94
131
  end
95
132
  end
96
133
 
@@ -90,10 +90,36 @@ class ThumbnailTest < Test::Unit::TestCase
90
90
  should "have whiny_thumbnails turned on by default" do
91
91
  assert @thumb.whiny_thumbnails
92
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
+ @thumb.expects(:system).with do |arg|
100
+ arg.match %r{convert\s+"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-resize\s+\"x50\"\s+-crop\s+\"100x50\+114\+0\"\s+\+repage\s+".*?"}
101
+ end
102
+ @thumb.make
103
+ end
104
+
105
+ should "create the thumbnail when sent #make" do
106
+ dst = @thumb.make
107
+ assert_match /100x50/, `identify #{dst.path}`
108
+ end
109
+ end
110
+
111
+ context "being thumbnailed with convert options set" do
112
+ setup do
113
+ @thumb = Paperclip::Thumbnail.new(@file, "100x50#", format=nil, convert_options="-strip -depth 8", whiny_thumbnails=true)
114
+ end
115
+
116
+ should "have convert_options value set" do
117
+ assert_equal "-strip -depth 8", @thumb.convert_options
118
+ end
93
119
 
94
120
  should "send the right command to convert when sent #make" do
95
121
  @thumb.expects(:system).with do |arg|
96
- arg.match %r{convert\s+"#{File.expand_path(@thumb.file.path)}"\s+-scale\s+\"x50\"\s+-crop\s+\"100x50\+114\+0\"\s+\+repage\s+".*?"}
122
+ arg.match %r{convert\s+"#{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+".*?"}
97
123
  end
98
124
  @thumb.make
99
125
  end
@@ -102,6 +128,18 @@ class ThumbnailTest < Test::Unit::TestCase
102
128
  dst = @thumb.make
103
129
  assert_match /100x50/, `identify #{dst.path}`
104
130
  end
131
+
132
+ context "redefined to have bad convert_options setting" do
133
+ setup do
134
+ @thumb = Paperclip::Thumbnail.new(@file, "100x50#", format=nil, convert_options="-this-aint-no-option", whiny_thumbnails=true)
135
+ end
136
+
137
+ should "error when trying to create the thumbnail" do
138
+ assert_raises(Paperclip::PaperclipError) do
139
+ @thumb.make
140
+ end
141
+ end
142
+ end
105
143
  end
106
144
  end
107
145
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2.1
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Robertson
@@ -9,20 +9,20 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-15 00:00:00 -07:00
12
+ date: 2008-11-29 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
16
  description:
17
- email: ken@invalidlogic.com jyurek@thoughtbot.com
17
+ email: ken@invalidlogic.com
18
18
  executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
- - README.textile
23
+ - README.rdoc
24
24
  files:
25
- - README.textile
25
+ - README.rdoc
26
26
  - LICENSE
27
27
  - Rakefile
28
28
  - init.rb
@@ -36,20 +36,20 @@ files:
36
36
  - lib/dm-paperclip/validations.rb
37
37
  - lib/dm-paperclip.rb
38
38
  - tasks/paperclip_tasks.rake
39
+ - test/attachment_test.rb
39
40
  - test/fixtures
40
41
  - test/fixtures/12k.png
41
42
  - test/fixtures/50x50.png
42
43
  - test/fixtures/5k.png
43
44
  - test/fixtures/bad.png
44
45
  - test/fixtures/text.txt
46
+ - test/geometry_test.rb
45
47
  - test/helper.rb
46
- - test/test_attachment.rb
47
- - test/test_geometry.rb
48
- - test/test_integration.rb
49
- - test/test_iostream.rb
50
- - test/test_paperclip.rb
51
- - test/test_storage.rb
52
- - test/test_thumbnail.rb
48
+ - test/integration_test.rb
49
+ - test/iostream_test.rb
50
+ - test/paperclip_test.rb
51
+ - test/storage_test.rb
52
+ - test/thumbnail_test.rb
53
53
  has_rdoc: true
54
54
  homepage: http://invalidlogic.com/dm-paperclip/
55
55
  post_install_message:
@@ -74,15 +74,9 @@ requirements:
74
74
  - ImageMagick
75
75
  - data_mapper
76
76
  rubyforge_project: dm-paperclip
77
- rubygems_version: 1.1.1
77
+ rubygems_version: 1.3.1
78
78
  signing_key:
79
79
  specification_version: 2
80
80
  summary: File attachments as attributes for DataMapper, based on the original Paperclip by Jon Yurek at Thoughtbot
81
- test_files:
82
- - test/test_attachment.rb
83
- - test/test_geometry.rb
84
- - test/test_integration.rb
85
- - test/test_iostream.rb
86
- - test/test_paperclip.rb
87
- - test/test_storage.rb
88
- - test/test_thumbnail.rb
81
+ test_files: []
82
+