has_image 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/storage_test.rb CHANGED
@@ -1,15 +1,15 @@
1
1
  require 'test_helper.rb'
2
2
 
3
3
  class StorageTest < Test::Unit::TestCase
4
-
4
+
5
5
  def setup
6
6
  end
7
-
7
+
8
8
  def teardown
9
9
  FileUtils.rm_rf(File.dirname(__FILE__) + '/../tmp')
10
10
  @temp_file.close! if @temp_file && !@temp_file.closed?
11
11
  end
12
-
12
+
13
13
  def default_options
14
14
  mock_class = "test"
15
15
  mock_class.stubs(:table_name).returns('tests')
@@ -17,19 +17,19 @@ class StorageTest < Test::Unit::TestCase
17
17
  :base_path => File.join(File.dirname(__FILE__), '..', 'tmp')
18
18
  )
19
19
  end
20
-
20
+
21
21
  def test_partitioned_path
22
22
  assert_equal(["0001", "2345"], HasImage::Storage.partitioned_path("12345"))
23
23
  end
24
-
24
+
25
25
  def test_partitioned_path_doesnt_collide_with_high_ids
26
26
  assert_not_equal HasImage::Storage.partitioned_path(867792732),
27
27
  HasImage::Storage.partitioned_path(867792731)
28
28
  # FIXME: collisions when IDs have more than 8 digits
29
29
  # assert_not_equal HasImage::Storage.partitioned_path(967792731),
30
- # HasImage::Storage.partitioned_path(967792731)
30
+ # HasImage::Storage.partitioned_path(967792731)
31
31
  end
32
-
32
+
33
33
  def test_id_from_partitioned_path
34
34
  assert_equal 123, HasImage::Storage.id_from_partitioned_path(HasImage::Storage.partitioned_path(123))
35
35
  assert_equal 56, HasImage::Storage.id_from_partitioned_path(HasImage::Storage.partitioned_path(56))
@@ -37,44 +37,44 @@ class StorageTest < Test::Unit::TestCase
37
37
  # FIXME: for IDs with more than 8 digits partitioned path is destructive
38
38
  # assert_equal 867792731, HasImage::Storage.id_from_partitioned_path(HasImage::Storage.partitioned_path(867792731))
39
39
  end
40
-
40
+
41
41
  def test_id_from_path_accepts_array
42
42
  assert_equal 123, HasImage::Storage.id_from_path(['0000','0123','image_something.jpg'])
43
43
  end
44
-
44
+
45
45
  def test_id_from_path_accepts_path
46
46
  assert_equal 12345, HasImage::Storage.id_from_path('0001/2345/0123/image_something.jpg')
47
47
  end
48
-
48
+
49
49
  def test_generated_file_name
50
50
  assert_equal("1", HasImage::Storage.generated_file_name(stub(:to_param => 1)))
51
51
  end
52
-
52
+
53
53
  def test_path_for
54
54
  @storage = HasImage::Storage.new(default_options)
55
55
  assert_match(/\/tmp\/tests\/0000\/0001/, @storage.send(:path_for, 1))
56
56
  end
57
-
57
+
58
58
  def test_public_path_for
59
59
  @storage = HasImage::Storage.new(default_options.merge(:base_path => '/public'))
60
60
  pic = stub(:has_image_file => "mypic", :has_image_id => 1)
61
61
  assert_equal "/tests/0000/0001/mypic_square.jpg", @storage.public_path_for(pic, :square)
62
62
  end
63
-
63
+
64
64
  def test_public_path_for_image_with_html_special_symbols_in_name
65
65
  @storage = HasImage::Storage.new(default_options.merge(:base_path => '/public'))
66
66
  pic = stub(:has_image_file => "my+pic", :has_image_id => 1)
67
67
  assert_equal "/tests/0000/0001/my%2Bpic_square.jpg", @storage.public_path_for(pic, :square)
68
68
  end
69
-
69
+
70
70
  def test_name_generation_takes_into_account_thumbnail_separator_constant
71
71
  old_separator = HasImage::Storage.thumbnail_separator
72
-
72
+
73
73
  @storage = HasImage::Storage.new(default_options.merge(:thumbnails => {:schick => '22x22'}, :base_path => '/public'))
74
74
  HasImage::Storage.thumbnail_separator = '.'
75
75
  pic = stub(:has_image_file => "pic", :has_image_id => 1)
76
76
  assert_equal "/tests/0000/0001/pic.schick.jpg", @storage.public_path_for(pic, :schick)
77
-
77
+
78
78
  HasImage::Storage.thumbnail_separator = old_separator
79
79
  end
80
80
 
@@ -89,7 +89,7 @@ class StorageTest < Test::Unit::TestCase
89
89
  real = @storage.escape_file_name_for_http("/tests/00+00/0001/mypic+square?something.jpg")
90
90
  assert_equal "/tests/00+00/0001/mypic%2Bsquare%3Fsomething.jpg", real
91
91
  end
92
-
92
+
93
93
  def test_filename_for
94
94
  @storage = HasImage::Storage.new(default_options)
95
95
  assert_equal "test.jpg", @storage.send(:file_name_for, "test")
@@ -97,19 +97,19 @@ class StorageTest < Test::Unit::TestCase
97
97
 
98
98
  def test_set_data_from_file
99
99
  @storage = HasImage::Storage.new(default_options)
100
- @file = File.new(File.dirname(__FILE__) + "/../test_rails/fixtures/image.jpg", "r")
100
+ @file = File.new(File.expand_path("../fixtures/image.jpg", __FILE__), "r")
101
101
  @storage.image_data = @file
102
102
  assert @storage.temp_file.size > 0
103
103
  assert_equal Zlib.crc32(@file.read), Zlib.crc32(@storage.temp_file.read)
104
104
  end
105
-
105
+
106
106
  def test_set_data_from_tempfile
107
107
  @storage = HasImage::Storage.new(default_options)
108
108
  @storage.image_data = temp_file("image.jpg")
109
109
  assert @storage.temp_file.size > 0
110
110
  assert_equal Zlib.crc32(@storage.temp_file.read), Zlib.crc32(@temp_file.read)
111
111
  end
112
-
112
+
113
113
  def test_install_and_remove_images
114
114
  @storage = HasImage::Storage.new(default_options.merge(:thumbnails => {
115
115
  :one => "100x100", :two => "200x200"}))
@@ -117,7 +117,7 @@ class StorageTest < Test::Unit::TestCase
117
117
  @name = @storage.install_images(stub(:has_image_id => 1))
118
118
  assert @storage.remove_images(stub(:has_image_id => 1), @name)
119
119
  end
120
-
120
+
121
121
  def test_install_images_doesnt_automatically_generate_thumbnails_if_that_option_is_set
122
122
  @storage = HasImage::Storage.new(default_options.merge(
123
123
  :thumbnails => {:two => "200x200"},
@@ -133,32 +133,31 @@ class StorageTest < Test::Unit::TestCase
133
133
  @storage.image_data = temp_file("image.jpg")
134
134
  assert !@storage.image_too_small?
135
135
  end
136
-
136
+
137
137
  def test_image_too_small
138
138
  @storage = HasImage::Storage.new(default_options.merge(:min_size => 1.gigabyte))
139
139
  @storage.image_data = temp_file("image.jpg")
140
140
  assert @storage.image_too_small?
141
141
  end
142
-
142
+
143
143
  def test_image_too_big
144
144
  @storage = HasImage::Storage.new(default_options.merge(:max_size => 1.kilobyte))
145
- @storage.image_data = temp_file("image.jpg")
145
+ @storage.image_data = temp_file("image.jpg")
146
146
  assert @storage.image_too_big?
147
147
  end
148
148
 
149
149
  def test_image_not_too_big
150
150
  @storage = HasImage::Storage.new(default_options.merge(:max_size => 1.gigabyte))
151
- @storage.image_data = temp_file("image.jpg")
151
+ @storage.image_data = temp_file("image.jpg")
152
152
  assert !@storage.image_too_big?
153
153
  end
154
-
154
+
155
155
  private
156
-
156
+
157
157
  def temp_file(fixture)
158
- file = File.new(File.dirname(__FILE__) + "/../test_rails/fixtures/#{fixture}", "r")
158
+ file = File.new(File.expand_path("../fixtures/#{fixture}", __FILE__), "r")
159
159
  @temp_file = Tempfile.new("test")
160
160
  @temp_file.write(file.read)
161
161
  return @temp_file
162
162
  end
163
-
164
163
  end
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require "active_support/core_ext/kernel/reporting"
4
+ require "active_support/core_ext/class/attribute_accessors"
5
+ require 'test/unit'
6
+ require 'mocha'
7
+ require "active_record"
8
+ require "logger"
9
+ require "rack/test"
10
+
11
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
12
+ require "has_image"
13
+
14
+ RAILS_ROOT = File.join(File.dirname(__FILE__), '..', 'tmp')
15
+
16
+ ActiveRecord::Base.logger = Logger.new($stdout) if ENV["LOG"]
17
+ ActiveRecord::Migration.verbose = false
18
+
19
+ # Change the connection args as you see fit to test against different adapters.
20
+ ActiveRecord::Base.establish_connection(
21
+ :adapter => "sqlite3",
22
+ :database => ":memory:"
23
+ )
24
+
25
+ module ActionView
26
+ class Base
27
+ end
28
+ end
29
+
30
+ ActiveRecord::Migration.create_table :pics do |t|
31
+ t.string :has_image_file
32
+ t.timestamps
33
+ end
34
+
35
+ ActiveRecord::Migration.create_table :complex_pics do |t|
36
+ t.string :filename
37
+ t.integer :width, :height
38
+ t.string :image_size
39
+ t.timestamps
40
+ end
41
+
42
+ HasImage.enable
43
+
44
+ def fixture_file_upload(path, mime_type)
45
+ path = File.expand_path("../fixtures/#{path}", __FILE__)
46
+ Rack::Test::UploadedFile.new(path, mime_type)
47
+ end
metadata CHANGED
@@ -1,29 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_image
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Norman Clarke
13
+ - "Adri\xC3\xA1n Mugnolo"
8
14
  autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2008-10-22 00:00:00 -02:00
18
+ date: 2010-09-29 00:00:00 -03:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: mini_magick
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 2
31
+ - 1
32
+ version: "2.1"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: activesupport
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 2
45
+ - 1
46
+ version: "2.1"
17
47
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: activerecord
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
20
54
  requirements:
21
55
  - - ">="
22
56
  - !ruby/object:Gem::Version
23
- version: 1.2.3
24
- version:
25
- description: HasImage is a Ruby on Rails gem/plugin that allows you to attach images to ActiveRecord models.
26
- email: norman@randomba.org
57
+ segments:
58
+ - 2
59
+ - 1
60
+ version: "2.1"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: mocha
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ - 9
74
+ version: "0.9"
75
+ type: :development
76
+ version_requirements: *id004
77
+ description: Has_image is a Ruby on Rails gem/plugin that allows you to attach images to Active Record models.
78
+ email:
79
+ - norman@njclarke.com
80
+ - adrian@mugnolo.com
27
81
  executables: []
28
82
 
29
83
  extensions: []
@@ -31,52 +85,55 @@ extensions: []
31
85
  extra_rdoc_files: []
32
86
 
33
87
  files:
34
- - CHANGELOG
35
- - FAQ
36
- - MIT-LICENSE
37
- - README.textile
38
- - init.rb
39
- - lib/has_image.rb
40
88
  - lib/has_image/processor.rb
89
+ - lib/has_image/railtie.rb
41
90
  - lib/has_image/storage.rb
91
+ - lib/has_image/version.rb
42
92
  - lib/has_image/view_helpers.rb
93
+ - lib/has_image.rb
94
+ - Changelog.md
95
+ - README.md
96
+ - MIT-LICENSE
43
97
  - Rakefile
98
+ - test/complex_pic_test.rb
99
+ - test/fixtures/bad_image.jpg
100
+ - test/fixtures/image.jpg
101
+ - test/fixtures/image.png
102
+ - test/pic_test.rb
103
+ - test/processor_test.rb
104
+ - test/storage_test.rb
105
+ - test/test_helper.rb
44
106
  has_rdoc: true
45
- homepage: http://randomba.org
107
+ homepage: http://github.com/norman/has_image
108
+ licenses: []
109
+
46
110
  post_install_message:
47
- rdoc_options:
48
- - --main
49
- - --inline-source
50
- - --line-numbers
111
+ rdoc_options: []
112
+
51
113
  require_paths:
52
114
  - lib
53
115
  required_ruby_version: !ruby/object:Gem::Requirement
116
+ none: false
54
117
  requirements:
55
118
  - - ">="
56
119
  - !ruby/object:Gem::Version
120
+ segments:
121
+ - 0
57
122
  version: "0"
58
- version:
59
123
  required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
60
125
  requirements:
61
126
  - - ">="
62
127
  - !ruby/object:Gem::Version
128
+ segments:
129
+ - 0
63
130
  version: "0"
64
- version:
65
131
  requirements: []
66
132
 
67
133
  rubyforge_project: has-image
68
- rubygems_version: 1.2.0
134
+ rubygems_version: 1.3.7
69
135
  signing_key:
70
- specification_version: 2
71
- summary: Lets you attach images with thumbnails to active record models.
72
- test_files:
73
- - test_rails/database.yml
74
- - test_rails/fixtures/bad_image.jpg
75
- - test_rails/fixtures/image.jpg
76
- - test_rails/fixtures/image.png
77
- - test_rails/pic_test.rb
78
- - test_rails/complex_pic_test.rb
79
- - test_rails/schema.rb
80
- - test_rails/test_helper.rb
81
- - test/processor_test.rb
82
- - test/storage_test.rb
136
+ specification_version: 3
137
+ summary: Lets you attach images with thumbnails to Active Record models.
138
+ test_files: []
139
+
data/CHANGELOG DELETED
@@ -1,72 +0,0 @@
1
- 2008-10-22 Gerrit Keiser and Tricycle Developments
2
- * Added option to not delete images on destroy
3
- * Made thumbnail name separator configurable
4
- * Added height/width methods to storage
5
- * Allowed regenerating only one thumbnail size
6
- * Made has_image column configurable
7
- * Added some compatibility with attachment_fu
8
- * General refactorings and overall code improvement
9
-
10
- 2008-10-22 Norman Clarke <norman@randomba.org>
11
- * Documentation improvements and minor code cleanups.
12
-
13
- 2008-10-09 Dima Sabanin <sdmitry@gmail.com>
14
- * Fixed display of images with special symbols in the name,
15
- like '2777-nipple-+-apple-napple.jpg'. + is reserved by HTTP.
16
- Now escaping filenames before giving them back in #public_path()
17
-
18
- 2008-09-10 Norman Clarke <norman@randomba.org>
19
- * Fixed images not being converted to target format.
20
-
21
- 2008-08-29 Norman Clarke <norman@randomba.org>
22
- * Fixed bad call to has_image_file
23
-
24
- 2008-08-28 Norman Clarke <norman@randomba.org>
25
- * Added ability to regenerate a model's thumbnails.
26
- * Changed a few methods in storage to accept the model rather than the id.
27
- This makes storage more hackable as regards generating paths and file names.
28
- * Added "has_image_id" method to model instance methods to facilitate
29
- grouping the images under a directory structure based on a related model's
30
- ids.
31
- * Made the generated file name simply by the image object's id - this
32
- is better adherance to the principle of least surprise.
33
-
34
- 2008-08-25 Norman Clarke <norman@randomba.org>
35
- * Fixed bad call to resize_to in view helper.
36
-
37
- 2008-08-19 Norman Clarke <norman@randomba.org>
38
- * Made storage work more correctly with tempfiles.
39
-
40
- 2008-08-18 Norman Clarke <norman@randomba.org>
41
- * Fixed ability to set the path for storing image files.
42
-
43
- 2008-08-1 Adrian Mugnolo <adrian@randomba.org>
44
- * Improved partitioned path handling to avoid collisions when the id is
45
- very high, which can happen if you use db:fixtures:load.
46
-
47
- 2008-08-1 Norman Clarke <norman@randomba.org>
48
- * Fixed a bug where overwriting a previous image triggered callbacks more
49
- than once, causing errors.
50
-
51
- 2008-07-29 Norman Clarke <norman@randomba.org>
52
-
53
- * Downcased generated file names to avoid potential issues on
54
- case-insensitive filesystems.
55
- * Added "absolute path" method to model instances.
56
- * Made image deletion nullify the "has_image_file" field.
57
- * Added "has_image?" method to model instances.
58
- * Fixed ENONENT error with record update when there are no images yet.
59
- * Reverted thumbnail sorting feature - it's fast but makes terrible quality
60
- thumbnails. It's just not worth it.
61
-
62
- 2008-07-28 Norman Clarke <norman@randomba.org>
63
-
64
- * Added sorted thumbnail processing. This improves thumbnail generation
65
- speed by about 25% for 4.5 meg jpegs with 5 thumbnails.
66
- * Fixed broken resize for non-fixed-width thumbnails.
67
- * Added check for bad geometry strings.
68
- * Added dependencies and Rubyforge project to gemspec, updated docs.
69
-
70
- 2008-07-25 Norman Clarke <norman@randomba.org>
71
-
72
- * First public release.