cloudfuji_paperclip 2.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/.gitignore +22 -0
  2. data/.travis.yml +13 -0
  3. data/Appraisals +14 -0
  4. data/CONTRIBUTING.md +38 -0
  5. data/Gemfile +5 -0
  6. data/Gemfile.lock +137 -0
  7. data/LICENSE +26 -0
  8. data/README.md +444 -0
  9. data/Rakefile +41 -0
  10. data/cucumber/paperclip_steps.rb +6 -0
  11. data/features/basic_integration.feature +46 -0
  12. data/features/rake_tasks.feature +63 -0
  13. data/features/step_definitions/attachment_steps.rb +65 -0
  14. data/features/step_definitions/html_steps.rb +15 -0
  15. data/features/step_definitions/rails_steps.rb +182 -0
  16. data/features/step_definitions/s3_steps.rb +14 -0
  17. data/features/step_definitions/web_steps.rb +209 -0
  18. data/features/support/env.rb +8 -0
  19. data/features/support/fakeweb.rb +3 -0
  20. data/features/support/fixtures/.boot_config.rb.swo +0 -0
  21. data/features/support/fixtures/boot_config.txt +15 -0
  22. data/features/support/fixtures/gemfile.txt +5 -0
  23. data/features/support/fixtures/preinitializer.txt +20 -0
  24. data/features/support/paths.rb +28 -0
  25. data/features/support/rails.rb +46 -0
  26. data/features/support/selectors.rb +19 -0
  27. data/gemfiles/rails2.gemfile +9 -0
  28. data/gemfiles/rails3.gemfile +9 -0
  29. data/gemfiles/rails3_1.gemfile +9 -0
  30. data/generators/paperclip/USAGE +5 -0
  31. data/generators/paperclip/paperclip_generator.rb +27 -0
  32. data/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  33. data/init.rb +4 -0
  34. data/lib/generators/paperclip/USAGE +8 -0
  35. data/lib/generators/paperclip/paperclip_generator.rb +33 -0
  36. data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  37. data/lib/paperclip/attachment.rb +468 -0
  38. data/lib/paperclip/callback_compatibility.rb +61 -0
  39. data/lib/paperclip/geometry.rb +120 -0
  40. data/lib/paperclip/interpolations.rb +174 -0
  41. data/lib/paperclip/iostream.rb +45 -0
  42. data/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
  43. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +81 -0
  44. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +54 -0
  45. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +95 -0
  46. data/lib/paperclip/matchers.rb +64 -0
  47. data/lib/paperclip/missing_attachment_styles.rb +87 -0
  48. data/lib/paperclip/processor.rb +58 -0
  49. data/lib/paperclip/railtie.rb +31 -0
  50. data/lib/paperclip/schema.rb +39 -0
  51. data/lib/paperclip/storage/filesystem.rb +81 -0
  52. data/lib/paperclip/storage/fog.rb +174 -0
  53. data/lib/paperclip/storage/s3.rb +333 -0
  54. data/lib/paperclip/storage.rb +3 -0
  55. data/lib/paperclip/style.rb +103 -0
  56. data/lib/paperclip/thumbnail.rb +105 -0
  57. data/lib/paperclip/upfile.rb +62 -0
  58. data/lib/paperclip/url_generator.rb +64 -0
  59. data/lib/paperclip/version.rb +3 -0
  60. data/lib/paperclip.rb +487 -0
  61. data/lib/tasks/paperclip.rake +101 -0
  62. data/paperclip.gemspec +41 -0
  63. data/rails/init.rb +2 -0
  64. data/shoulda_macros/paperclip.rb +124 -0
  65. data/test/.gitignore +1 -0
  66. data/test/attachment_test.rb +1116 -0
  67. data/test/database.yml +4 -0
  68. data/test/fixtures/12k.png +0 -0
  69. data/test/fixtures/50x50.png +0 -0
  70. data/test/fixtures/5k.png +0 -0
  71. data/test/fixtures/animated.gif +0 -0
  72. data/test/fixtures/bad.png +1 -0
  73. data/test/fixtures/fog.yml +8 -0
  74. data/test/fixtures/question?mark.png +0 -0
  75. data/test/fixtures/s3.yml +8 -0
  76. data/test/fixtures/spaced file.png +0 -0
  77. data/test/fixtures/text.txt +1 -0
  78. data/test/fixtures/twopage.pdf +0 -0
  79. data/test/fixtures/uppercase.PNG +0 -0
  80. data/test/geometry_test.rb +206 -0
  81. data/test/helper.rb +177 -0
  82. data/test/integration_test.rb +654 -0
  83. data/test/interpolations_test.rb +216 -0
  84. data/test/iostream_test.rb +71 -0
  85. data/test/matchers/have_attached_file_matcher_test.rb +24 -0
  86. data/test/matchers/validate_attachment_content_type_matcher_test.rb +87 -0
  87. data/test/matchers/validate_attachment_presence_matcher_test.rb +26 -0
  88. data/test/matchers/validate_attachment_size_matcher_test.rb +51 -0
  89. data/test/paperclip_missing_attachment_styles_test.rb +80 -0
  90. data/test/paperclip_test.rb +390 -0
  91. data/test/processor_test.rb +10 -0
  92. data/test/schema_test.rb +98 -0
  93. data/test/storage/filesystem_test.rb +56 -0
  94. data/test/storage/fog_test.rb +219 -0
  95. data/test/storage/s3_live_test.rb +138 -0
  96. data/test/storage/s3_test.rb +943 -0
  97. data/test/style_test.rb +209 -0
  98. data/test/support/mock_attachment.rb +22 -0
  99. data/test/support/mock_interpolator.rb +24 -0
  100. data/test/support/mock_model.rb +2 -0
  101. data/test/support/mock_url_generator_builder.rb +27 -0
  102. data/test/thumbnail_test.rb +383 -0
  103. data/test/upfile_test.rb +53 -0
  104. data/test/url_generator_test.rb +187 -0
  105. metadata +404 -0
data/test/database.yml ADDED
@@ -0,0 +1,4 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: ":memory:"
4
+
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1 @@
1
+ This is not an image.
@@ -0,0 +1,8 @@
1
+ development:
2
+ provider: AWS
3
+ aws_access_key_id: AWS_ID
4
+ aws_secret_access_key: AWS_SECRET
5
+ test:
6
+ provider: AWS
7
+ aws_access_key_id: AWS_ID
8
+ aws_secret_access_key: AWS_SECRET
Binary file
@@ -0,0 +1,8 @@
1
+ development:
2
+ key: 54321
3
+ production:
4
+ key: 12345
5
+ test:
6
+ bucket: <%= ENV['S3_BUCKET'] %>
7
+ access_key_id: <%= ENV['S3_KEY'] %>
8
+ secret_access_key: <%= ENV['S3_SECRET'] %>
Binary file
@@ -0,0 +1 @@
1
+ paperclip!
Binary file
Binary file
@@ -0,0 +1,206 @@
1
+ require './test/helper'
2
+
3
+ class GeometryTest < Test::Unit::TestCase
4
+ context "Paperclip::Geometry" do
5
+ should "correctly report its given dimensions" do
6
+ assert @geo = Paperclip::Geometry.new(1024, 768)
7
+ assert_equal 1024, @geo.width
8
+ assert_equal 768, @geo.height
9
+ end
10
+
11
+ should "set height to 0 if height dimension is missing" do
12
+ assert @geo = Paperclip::Geometry.new(1024)
13
+ assert_equal 1024, @geo.width
14
+ assert_equal 0, @geo.height
15
+ end
16
+
17
+ should "set width to 0 if width dimension is missing" do
18
+ assert @geo = Paperclip::Geometry.new(nil, 768)
19
+ assert_equal 0, @geo.width
20
+ assert_equal 768, @geo.height
21
+ end
22
+
23
+ should "be generated from a WxH-formatted string" do
24
+ assert @geo = Paperclip::Geometry.parse("800x600")
25
+ assert_equal 800, @geo.width
26
+ assert_equal 600, @geo.height
27
+ end
28
+
29
+ should "be generated from a xH-formatted string" do
30
+ assert @geo = Paperclip::Geometry.parse("x600")
31
+ assert_equal 0, @geo.width
32
+ assert_equal 600, @geo.height
33
+ end
34
+
35
+ should "be generated from a Wx-formatted string" do
36
+ assert @geo = Paperclip::Geometry.parse("800x")
37
+ assert_equal 800, @geo.width
38
+ assert_equal 0, @geo.height
39
+ end
40
+
41
+ should "be generated from a W-formatted string" do
42
+ assert @geo = Paperclip::Geometry.parse("800")
43
+ assert_equal 800, @geo.width
44
+ assert_equal 0, @geo.height
45
+ end
46
+
47
+ should "ensure the modifier is nil if not present" do
48
+ assert @geo = Paperclip::Geometry.parse("123x456")
49
+ assert_nil @geo.modifier
50
+ end
51
+
52
+ should "treat x and X the same in geometries" do
53
+ @lower = Paperclip::Geometry.parse("123x456")
54
+ @upper = Paperclip::Geometry.parse("123X456")
55
+ assert_equal 123, @lower.width
56
+ assert_equal 123, @upper.width
57
+ assert_equal 456, @lower.height
58
+ assert_equal 456, @upper.height
59
+ end
60
+
61
+ ['>', '<', '#', '@', '%', '^', '!', nil].each do |mod|
62
+ should "ensure the modifier #{mod.inspect} is preserved" do
63
+ assert @geo = Paperclip::Geometry.parse("123x456#{mod}")
64
+ assert_equal mod, @geo.modifier
65
+ assert_equal "123x456#{mod}", @geo.to_s
66
+ end
67
+ end
68
+
69
+ ['>', '<', '#', '@', '%', '^', '!', nil].each do |mod|
70
+ should "ensure the modifier #{mod.inspect} is preserved with no height" do
71
+ assert @geo = Paperclip::Geometry.parse("123x#{mod}")
72
+ assert_equal mod, @geo.modifier
73
+ assert_equal "123#{mod}", @geo.to_s
74
+ end
75
+ end
76
+
77
+ should "make sure the modifier gets passed during transformation_to" do
78
+ assert @src = Paperclip::Geometry.parse("123x456")
79
+ assert @dst = Paperclip::Geometry.parse("123x456>")
80
+ assert_equal ["123x456>", nil], @src.transformation_to(@dst)
81
+ end
82
+
83
+ should "generate correct ImageMagick formatting string for W-formatted string" do
84
+ assert @geo = Paperclip::Geometry.parse("800")
85
+ assert_equal "800", @geo.to_s
86
+ end
87
+
88
+ should "generate correct ImageMagick formatting string for Wx-formatted string" do
89
+ assert @geo = Paperclip::Geometry.parse("800x")
90
+ assert_equal "800", @geo.to_s
91
+ end
92
+
93
+ should "generate correct ImageMagick formatting string for xH-formatted string" do
94
+ assert @geo = Paperclip::Geometry.parse("x600")
95
+ assert_equal "x600", @geo.to_s
96
+ end
97
+
98
+ should "generate correct ImageMagick formatting string for WxH-formatted string" do
99
+ assert @geo = Paperclip::Geometry.parse("800x600")
100
+ assert_equal "800x600", @geo.to_s
101
+ end
102
+
103
+ should "be generated from a file" do
104
+ file = File.join(File.dirname(__FILE__), "fixtures", "5k.png")
105
+ file = File.new(file, 'rb')
106
+ assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
107
+ assert @geo.height > 0
108
+ assert @geo.width > 0
109
+ end
110
+
111
+ should "be generated from a file path" do
112
+ file = File.join(File.dirname(__FILE__), "fixtures", "5k.png")
113
+ assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
114
+ assert @geo.height > 0
115
+ assert @geo.width > 0
116
+ end
117
+
118
+ should "not generate from a bad file" do
119
+ file = "/home/This File Does Not Exist.omg"
120
+ assert_raise(Paperclip::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) }
121
+ end
122
+
123
+ should "not generate from a blank filename" do
124
+ file = ""
125
+ assert_raise(Paperclip::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) }
126
+ end
127
+
128
+ should "not generate from a nil file" do
129
+ file = nil
130
+ assert_raise(Paperclip::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) }
131
+ end
132
+
133
+ should "not generate from a file with no path" do
134
+ file = mock("file", :path => "")
135
+ file.stubs(:respond_to?).with(:path).returns(true)
136
+ assert_raise(Paperclip::NotIdentifiedByImageMagickError){ @geo = Paperclip::Geometry.from_file(file) }
137
+ end
138
+
139
+ should "let us know when a command isn't found versus a processing error" do
140
+ old_path = ENV['PATH']
141
+ begin
142
+ ENV['PATH'] = ''
143
+ assert_raises(Paperclip::CommandNotFoundError) do
144
+ file = File.join(File.dirname(__FILE__), "fixtures", "5k.png")
145
+ @geo = Paperclip::Geometry.from_file(file)
146
+ end
147
+ ensure
148
+ ENV['PATH'] = old_path
149
+ end
150
+ end
151
+
152
+ [['vertical', 900, 1440, true, false, false, 1440, 900, 0.625],
153
+ ['horizontal', 1024, 768, false, true, false, 1024, 768, 1.3333],
154
+ ['square', 100, 100, false, false, true, 100, 100, 1]].each do |args|
155
+ context "performing calculations on a #{args[0]} viewport" do
156
+ setup do
157
+ @geo = Paperclip::Geometry.new(args[1], args[2])
158
+ end
159
+
160
+ should "#{args[3] ? "" : "not"} be vertical" do
161
+ assert_equal args[3], @geo.vertical?
162
+ end
163
+
164
+ should "#{args[4] ? "" : "not"} be horizontal" do
165
+ assert_equal args[4], @geo.horizontal?
166
+ end
167
+
168
+ should "#{args[5] ? "" : "not"} be square" do
169
+ assert_equal args[5], @geo.square?
170
+ end
171
+
172
+ should "report that #{args[6]} is the larger dimension" do
173
+ assert_equal args[6], @geo.larger
174
+ end
175
+
176
+ should "report that #{args[7]} is the smaller dimension" do
177
+ assert_equal args[7], @geo.smaller
178
+ end
179
+
180
+ should "have an aspect ratio of #{args[8]}" do
181
+ assert_in_delta args[8], @geo.aspect, 0.0001
182
+ end
183
+ end
184
+ end
185
+
186
+ [[ [1000, 100], [64, 64], "x64", "64x64+288+0" ],
187
+ [ [100, 1000], [50, 950], "x950", "50x950+22+0" ],
188
+ [ [100, 1000], [50, 25], "50x", "50x25+0+237" ]]. each do |args|
189
+ context "of #{args[0].inspect} and given a Geometry #{args[1].inspect} and sent transform_to" do
190
+ setup do
191
+ @geo = Paperclip::Geometry.new(*args[0])
192
+ @dst = Paperclip::Geometry.new(*args[1])
193
+ @scale, @crop = @geo.transformation_to @dst, true
194
+ end
195
+
196
+ should "be able to return the correct scaling transformation geometry #{args[2]}" do
197
+ assert_equal args[2], @scale
198
+ end
199
+
200
+ should "be able to return the correct crop transformation geometry #{args[3]}" do
201
+ assert_equal args[3], @crop
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,177 @@
1
+ require 'rubygems'
2
+ require 'tempfile'
3
+ require 'pathname'
4
+ require 'test/unit'
5
+
6
+ require 'shoulda'
7
+ require 'mocha'
8
+
9
+ require 'active_record'
10
+ require 'active_record/version'
11
+ require 'active_support'
12
+ require 'mime/types'
13
+ require 'pathname'
14
+
15
+ require 'pathname'
16
+
17
+ puts "Testing against version #{ActiveRecord::VERSION::STRING}"
18
+
19
+ `ruby -e 'exit 0'` # Prime $? with a value.
20
+
21
+ begin
22
+ require 'ruby-debug'
23
+ rescue LoadError => e
24
+ puts "debugger disabled"
25
+ end
26
+
27
+ ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..')))
28
+
29
+ def silence_warnings
30
+ old_verbose, $VERBOSE = $VERBOSE, nil
31
+ yield
32
+ ensure
33
+ $VERBOSE = old_verbose
34
+ end
35
+
36
+ class Test::Unit::TestCase
37
+ def setup
38
+ silence_warnings do
39
+ Object.const_set(:Rails, stub('Rails', :root => ROOT, :env => 'test'))
40
+ end
41
+ end
42
+ end
43
+
44
+ $LOAD_PATH << File.join(ROOT, 'lib')
45
+ $LOAD_PATH << File.join(ROOT, 'lib', 'paperclip')
46
+
47
+ require File.join(ROOT, 'lib', 'paperclip.rb')
48
+
49
+ require './shoulda_macros/paperclip'
50
+
51
+ FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
52
+ config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
53
+ ActiveRecord::Base.logger = ActiveSupport::BufferedLogger.new(File.dirname(__FILE__) + "/debug.log")
54
+ ActiveRecord::Base.establish_connection(config['test'])
55
+ Paperclip.options[:logger] = ActiveRecord::Base.logger
56
+
57
+ Dir[File.join(File.dirname(__FILE__), 'support','*')].each do |f|
58
+ require f
59
+ end
60
+
61
+ def reset_class class_name
62
+ ActiveRecord::Base.send(:include, Paperclip::Glue)
63
+ Object.send(:remove_const, class_name) rescue nil
64
+ klass = Object.const_set(class_name, Class.new(ActiveRecord::Base))
65
+ klass.class_eval{ include Paperclip::Glue }
66
+ klass
67
+ end
68
+
69
+ def reset_table table_name, &block
70
+ block ||= lambda { |table| true }
71
+ ActiveRecord::Base.connection.create_table :dummies, {:force => true}, &block
72
+ end
73
+
74
+ def modify_table table_name, &block
75
+ ActiveRecord::Base.connection.change_table :dummies, &block
76
+ end
77
+
78
+ def rebuild_model options = {}
79
+ ActiveRecord::Base.connection.create_table :dummies, :force => true do |table|
80
+ table.column :title, :string
81
+ table.column :other, :string
82
+ table.column :avatar_file_name, :string
83
+ table.column :avatar_content_type, :string
84
+ table.column :avatar_file_size, :integer
85
+ table.column :avatar_updated_at, :datetime
86
+ table.column :avatar_fingerprint, :string
87
+ end
88
+ rebuild_class options
89
+ end
90
+
91
+ def rebuild_class options = {}
92
+ ActiveRecord::Base.send(:include, Paperclip::Glue)
93
+ Object.send(:remove_const, "Dummy") rescue nil
94
+ Object.const_set("Dummy", Class.new(ActiveRecord::Base))
95
+ Paperclip.reset_duplicate_clash_check!
96
+ Dummy.class_eval do
97
+ include Paperclip::Glue
98
+ has_attached_file :avatar, options
99
+ end
100
+ Dummy.reset_column_information
101
+ end
102
+
103
+ class FakeModel
104
+ attr_accessor :avatar_file_name,
105
+ :avatar_file_size,
106
+ :avatar_updated_at,
107
+ :avatar_content_type,
108
+ :avatar_fingerprint,
109
+ :id
110
+
111
+ def errors
112
+ @errors ||= []
113
+ end
114
+
115
+ def run_paperclip_callbacks name, *args
116
+ end
117
+
118
+ end
119
+
120
+ def attachment options
121
+ Paperclip::Attachment.new(:avatar, FakeModel.new, options)
122
+ end
123
+
124
+ def silence_warnings
125
+ old_verbose, $VERBOSE = $VERBOSE, nil
126
+ yield
127
+ ensure
128
+ $VERBOSE = old_verbose
129
+ end
130
+
131
+ def should_accept_dummy_class
132
+ should "accept the class" do
133
+ assert_accepts @matcher, @dummy_class
134
+ end
135
+
136
+ should "accept an instance of that class" do
137
+ assert_accepts @matcher, @dummy_class.new
138
+ end
139
+ end
140
+
141
+ def should_reject_dummy_class
142
+ should "reject the class" do
143
+ assert_rejects @matcher, @dummy_class
144
+ end
145
+
146
+ should "reject an instance of that class" do
147
+ assert_rejects @matcher, @dummy_class.new
148
+ end
149
+ end
150
+
151
+ def with_exitstatus_returning(code)
152
+ saved_exitstatus = $?.nil? ? 0 : $?.exitstatus
153
+ begin
154
+ `ruby -e 'exit #{code.to_i}'`
155
+ yield
156
+ ensure
157
+ `ruby -e 'exit #{saved_exitstatus.to_i}'`
158
+ end
159
+ end
160
+
161
+ def fixture_file(filename)
162
+ File.join(File.dirname(__FILE__), 'fixtures', filename)
163
+ end
164
+
165
+ def assert_success_response(url)
166
+ Net::HTTP.get_response(URI.parse(url)) do |response|
167
+ assert_equal "200", response.code,
168
+ "Expected HTTP response code 200, got #{response.code}"
169
+ end
170
+ end
171
+
172
+ def assert_not_found_response(url)
173
+ Net::HTTP.get_response(URI.parse(url)) do |response|
174
+ assert_equal "404", response.code,
175
+ "Expected HTTP response code 404, got #{response.code}"
176
+ end
177
+ end