dougmcbride-fleximage 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. data/.gitignore +27 -0
  2. data/CHANGELOG.rdoc +14 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +257 -0
  5. data/Rakefile +49 -0
  6. data/VERSION +1 -0
  7. data/autotest.rb +5 -0
  8. data/fleximage.gemspec +236 -0
  9. data/init.rb +1 -0
  10. data/lib/dsl_accessor.rb +52 -0
  11. data/lib/fleximage.rb +59 -0
  12. data/lib/fleximage/aviary_controller.rb +75 -0
  13. data/lib/fleximage/blank.rb +70 -0
  14. data/lib/fleximage/helper.rb +41 -0
  15. data/lib/fleximage/image_proxy.rb +69 -0
  16. data/lib/fleximage/legacy_view.rb +63 -0
  17. data/lib/fleximage/model.rb +726 -0
  18. data/lib/fleximage/operator/background.rb +62 -0
  19. data/lib/fleximage/operator/base.rb +189 -0
  20. data/lib/fleximage/operator/border.rb +50 -0
  21. data/lib/fleximage/operator/crop.rb +58 -0
  22. data/lib/fleximage/operator/image_overlay.rb +85 -0
  23. data/lib/fleximage/operator/resize.rb +92 -0
  24. data/lib/fleximage/operator/shadow.rb +87 -0
  25. data/lib/fleximage/operator/text.rb +104 -0
  26. data/lib/fleximage/operator/trim.rb +14 -0
  27. data/lib/fleximage/operator/unsharp_mask.rb +36 -0
  28. data/lib/fleximage/rmagick_image_patch.rb +5 -0
  29. data/lib/fleximage/string_patch.rb +5 -0
  30. data/lib/fleximage/view.rb +58 -0
  31. data/tasks/fleximage_tasks.rake +154 -0
  32. data/test/fixtures/100x1.jpg +0 -0
  33. data/test/fixtures/100x100.jpg +0 -0
  34. data/test/fixtures/1x1.jpg +0 -0
  35. data/test/fixtures/1x100.jpg +0 -0
  36. data/test/fixtures/cmyk.jpg +0 -0
  37. data/test/fixtures/not_a_photo.xml +1 -0
  38. data/test/fixtures/photo.jpg +0 -0
  39. data/test/mock_file.rb +21 -0
  40. data/test/rails_root/app/controllers/application.rb +10 -0
  41. data/test/rails_root/app/controllers/avatars_controller.rb +85 -0
  42. data/test/rails_root/app/controllers/photo_bares_controller.rb +85 -0
  43. data/test/rails_root/app/controllers/photo_dbs_controller.rb +85 -0
  44. data/test/rails_root/app/controllers/photo_files_controller.rb +85 -0
  45. data/test/rails_root/app/helpers/application_helper.rb +3 -0
  46. data/test/rails_root/app/helpers/avatars_helper.rb +2 -0
  47. data/test/rails_root/app/helpers/photo_bares_helper.rb +2 -0
  48. data/test/rails_root/app/helpers/photo_dbs_helper.rb +2 -0
  49. data/test/rails_root/app/helpers/photo_files_helper.rb +2 -0
  50. data/test/rails_root/app/locales/de.yml +7 -0
  51. data/test/rails_root/app/locales/en.yml +8 -0
  52. data/test/rails_root/app/models/abstract.rb +8 -0
  53. data/test/rails_root/app/models/avatar.rb +4 -0
  54. data/test/rails_root/app/models/photo_bare.rb +7 -0
  55. data/test/rails_root/app/models/photo_custom_error.rb +10 -0
  56. data/test/rails_root/app/models/photo_db.rb +3 -0
  57. data/test/rails_root/app/models/photo_file.rb +3 -0
  58. data/test/rails_root/app/views/avatars/edit.html.erb +17 -0
  59. data/test/rails_root/app/views/avatars/index.html.erb +20 -0
  60. data/test/rails_root/app/views/avatars/new.html.erb +16 -0
  61. data/test/rails_root/app/views/avatars/show.html.erb +8 -0
  62. data/test/rails_root/app/views/layouts/avatars.html.erb +17 -0
  63. data/test/rails_root/app/views/layouts/photo_bares.html.erb +17 -0
  64. data/test/rails_root/app/views/layouts/photo_dbs.html.erb +17 -0
  65. data/test/rails_root/app/views/layouts/photo_files.html.erb +17 -0
  66. data/test/rails_root/app/views/photo_bares/edit.html.erb +12 -0
  67. data/test/rails_root/app/views/photo_bares/index.html.erb +18 -0
  68. data/test/rails_root/app/views/photo_bares/new.html.erb +11 -0
  69. data/test/rails_root/app/views/photo_bares/show.html.erb +3 -0
  70. data/test/rails_root/app/views/photo_dbs/edit.html.erb +32 -0
  71. data/test/rails_root/app/views/photo_dbs/index.html.erb +26 -0
  72. data/test/rails_root/app/views/photo_dbs/new.html.erb +31 -0
  73. data/test/rails_root/app/views/photo_dbs/show.html.erb +23 -0
  74. data/test/rails_root/app/views/photo_files/edit.html.erb +27 -0
  75. data/test/rails_root/app/views/photo_files/index.html.erb +24 -0
  76. data/test/rails_root/app/views/photo_files/new.html.erb +26 -0
  77. data/test/rails_root/app/views/photo_files/show.html.erb +18 -0
  78. data/test/rails_root/config/boot.rb +109 -0
  79. data/test/rails_root/config/database.yml +7 -0
  80. data/test/rails_root/config/environment.rb +66 -0
  81. data/test/rails_root/config/environments/development.rb +18 -0
  82. data/test/rails_root/config/environments/production.rb +19 -0
  83. data/test/rails_root/config/environments/sqlite3.rb +0 -0
  84. data/test/rails_root/config/environments/test.rb +22 -0
  85. data/test/rails_root/config/initializers/inflections.rb +10 -0
  86. data/test/rails_root/config/initializers/load_translations.rb +4 -0
  87. data/test/rails_root/config/initializers/mime_types.rb +5 -0
  88. data/test/rails_root/config/routes.rb +43 -0
  89. data/test/rails_root/db/migrate/001_create_photo_files.rb +16 -0
  90. data/test/rails_root/db/migrate/002_create_photo_dbs.rb +16 -0
  91. data/test/rails_root/db/migrate/003_create_photo_bares.rb +12 -0
  92. data/test/rails_root/db/migrate/004_create_avatars.rb +13 -0
  93. data/test/rails_root/public/.htaccess +40 -0
  94. data/test/rails_root/public/404.html +30 -0
  95. data/test/rails_root/public/422.html +30 -0
  96. data/test/rails_root/public/500.html +30 -0
  97. data/test/rails_root/public/dispatch.cgi +10 -0
  98. data/test/rails_root/public/dispatch.fcgi +24 -0
  99. data/test/rails_root/public/dispatch.rb +10 -0
  100. data/test/rails_root/public/favicon.ico +0 -0
  101. data/test/rails_root/public/images/rails.png +0 -0
  102. data/test/rails_root/public/index.html +277 -0
  103. data/test/rails_root/public/javascripts/application.js +2 -0
  104. data/test/rails_root/public/javascripts/controls.js +963 -0
  105. data/test/rails_root/public/javascripts/dragdrop.js +972 -0
  106. data/test/rails_root/public/javascripts/effects.js +1120 -0
  107. data/test/rails_root/public/javascripts/prototype.js +4225 -0
  108. data/test/rails_root/public/robots.txt +5 -0
  109. data/test/rails_root/public/stylesheets/scaffold.css +74 -0
  110. data/test/rails_root/vendor/plugins/fleximage/init.rb +2 -0
  111. data/test/test_helper.rb +81 -0
  112. data/test/unit/abstract_test.rb +20 -0
  113. data/test/unit/basic_model_test.rb +36 -0
  114. data/test/unit/blank_test.rb +23 -0
  115. data/test/unit/default_image_path_option_test.rb +16 -0
  116. data/test/unit/dsl_accessor_test.rb +120 -0
  117. data/test/unit/file_upload_from_local_test.rb +31 -0
  118. data/test/unit/file_upload_from_strings_test.rb +23 -0
  119. data/test/unit/file_upload_from_url_test.rb +35 -0
  120. data/test/unit/file_upload_to_db_test.rb +41 -0
  121. data/test/unit/i18n_messages_test.rb +49 -0
  122. data/test/unit/image_directory_option_test.rb +20 -0
  123. data/test/unit/image_proxy_test.rb +17 -0
  124. data/test/unit/image_storage_format_option_test.rb +31 -0
  125. data/test/unit/magic_columns_test.rb +34 -0
  126. data/test/unit/minimum_image_size_test.rb +56 -0
  127. data/test/unit/operator_base_test.rb +124 -0
  128. data/test/unit/operator_resize_test.rb +18 -0
  129. data/test/unit/preprocess_image_option_test.rb +21 -0
  130. data/test/unit/require_image_option_test.rb +30 -0
  131. data/test/unit/temp_image_test.rb +23 -0
  132. data/test/unit/use_creation_date_based_directories_option_test.rb +16 -0
  133. metadata +284 -0
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,74 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ .fieldWithErrors {
20
+ padding: 2px;
21
+ background-color: red;
22
+ display: table;
23
+ }
24
+
25
+ #errorExplanation {
26
+ width: 400px;
27
+ border: 2px solid red;
28
+ padding: 7px;
29
+ padding-bottom: 12px;
30
+ margin-bottom: 20px;
31
+ background-color: #f0f0f0;
32
+ }
33
+
34
+ #errorExplanation h2 {
35
+ text-align: left;
36
+ font-weight: bold;
37
+ padding: 5px 5px 5px 15px;
38
+ font-size: 12px;
39
+ margin: -7px;
40
+ background-color: #c00;
41
+ color: #fff;
42
+ }
43
+
44
+ #errorExplanation p {
45
+ color: #333;
46
+ margin-bottom: 0;
47
+ padding: 5px;
48
+ }
49
+
50
+ #errorExplanation ul li {
51
+ font-size: 12px;
52
+ list-style: square;
53
+ }
54
+
55
+ div.uploadStatus {
56
+ margin: 5px;
57
+ }
58
+
59
+ div.progressBar {
60
+ margin: 5px;
61
+ }
62
+
63
+ div.progressBar div.border {
64
+ background-color: #fff;
65
+ border: 1px solid gray;
66
+ width: 100%;
67
+ }
68
+
69
+ div.progressBar div.background {
70
+ background-color: #333;
71
+ height: 18px;
72
+ width: 0%;
73
+ }
74
+
@@ -0,0 +1,2 @@
1
+ init_path = "#{RAILS_ROOT}/../../init.rb"
2
+ silence_warnings { eval(IO.read(init_path), binding, init_path) }
@@ -0,0 +1,81 @@
1
+ # Load the environment
2
+ ENV['RAILS_ENV'] ||= 'test'
3
+ require File.dirname(__FILE__) + '/rails_root/config/environment.rb'
4
+
5
+ # Load the testing framework
6
+ require 'test_help'
7
+ silence_warnings { RAILS_ENV = ENV['RAILS_ENV'] }
8
+
9
+ # Run the migrations
10
+ ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")
11
+
12
+ # Setup the fixtures path
13
+ Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
14
+ $LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
15
+
16
+ require File.dirname(__FILE__) + '/mock_file'
17
+ require 'open-uri'
18
+
19
+ unless Magick::QuantumDepth == 16
20
+ puts "**** WARNING ****"
21
+ puts "* Tests expect a ImageMagick bit depth of 16, you have Magick::QuantumDepth == #{Magick::QuantumDepth}"
22
+ puts "* Color checking tests will likely fail"
23
+ end
24
+
25
+ class Test::Unit::TestCase #:nodoc:
26
+ def create_fixtures(*table_names)
27
+ if block_given?
28
+ Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
29
+ else
30
+ Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
31
+ end
32
+ end
33
+
34
+ self.use_transactional_fixtures = true
35
+ self.use_instantiated_fixtures = false
36
+
37
+ def files(name)
38
+ case name
39
+ when :photo
40
+ MockFile.new("#{RAILS_ROOT}/../fixtures/photo.jpg")
41
+
42
+ when :not_a_photo
43
+ MockFile.new("#{RAILS_ROOT}/../fixtures/not_a_photo.xml")
44
+
45
+ when :web_photo
46
+ 'http://www.google.com/intl/en_ALL/images/logo.gif'
47
+
48
+ when :cmyk
49
+ MockFile.new("#{RAILS_ROOT}/../fixtures/cmyk.jpg")
50
+
51
+ when :i100x100
52
+ MockFile.new("#{RAILS_ROOT}/../fixtures/100x100.jpg")
53
+
54
+ when :i1x100
55
+ MockFile.new("#{RAILS_ROOT}/../fixtures/1x100.jpg")
56
+
57
+ when :i100x1
58
+ MockFile.new("#{RAILS_ROOT}/../fixtures/100x1.jpg")
59
+
60
+ when :i1x1
61
+ MockFile.new("#{RAILS_ROOT}/../fixtures/1x1.jpg")
62
+
63
+ end
64
+ end
65
+
66
+ def color_at(image, coords)
67
+ image.load_image.pixel_color(*coords)
68
+ end
69
+
70
+ def to_color(rgb)
71
+ Magick::Pixel.new(*rgb)
72
+ end
73
+
74
+ def assert_color(expected, coords, image)
75
+ coords = coords.split('x').collect(&:to_i)
76
+ expected = to_color(expected)
77
+ actual = color_at(image, coords)
78
+
79
+ assert_equal(expected, actual, "Wrong color at (#{coords.join(',')}). Expected #{expected}, Got #{actual}")
80
+ end
81
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+ class FleximageAbstractTest < Test::Unit::TestCase
4
+
5
+ def test_should_generate_a_default_image
6
+ p = Abstract.new
7
+ assert p.save
8
+
9
+ assert_equal 320, p.load_image.columns
10
+ assert_equal 240, p.load_image.rows
11
+ assert_color [65535, 0, 0], '160x120', p
12
+ end
13
+
14
+ def test_should_delete_an_abstract_model
15
+ p = Abstract.new
16
+ assert p.save
17
+ assert_nothing_raised { p.destroy }
18
+ end
19
+
20
+ end
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+ class FleximageBasicModelTest < Test::Unit::TestCase
4
+ def test_should_have_correct_file_path_with_creation_date_based_storage
5
+ p = PhotoBare.create(:image_file => files(:photo))
6
+ assert_equal "#{RAILS_ROOT}/public/uploads/#{Time.now.year}/#{Time.now.month}/#{Time.now.day}/#{p.id}.png", p.file_path
7
+ end
8
+
9
+ def test_should_have_correct_directory_path_with_creation_date_based_storage
10
+ p = PhotoBare.create(:image_file => files(:photo))
11
+ assert_equal "#{RAILS_ROOT}/public/uploads/#{Time.now.year}/#{Time.now.month}/#{Time.now.day}", p.directory_path
12
+ end
13
+
14
+ def test_should_have_correct_file_path_without_creation_date_based_storage
15
+ PhotoBare.use_creation_date_based_directories = false
16
+ p = PhotoBare.create(:image_file => files(:photo))
17
+ assert_equal "#{RAILS_ROOT}/public/uploads/#{p.id}.png", p.file_path
18
+ ensure
19
+ PhotoBare.use_creation_date_based_directories = true
20
+ end
21
+
22
+ def test_should_have_correct_directory_path_without_creation_date_based_storage
23
+ PhotoBare.use_creation_date_based_directories = false
24
+ p = PhotoBare.create(:image_file => files(:photo))
25
+ assert_equal "#{RAILS_ROOT}/public/uploads", p.directory_path
26
+ ensure
27
+ PhotoBare.use_creation_date_based_directories = true
28
+ end
29
+
30
+ def test_should_not_prepend_rails_root_to_absolute_path
31
+ PhotoBare.image_directory = '/tmp'
32
+ PhotoBare.use_creation_date_based_directories = false
33
+ p = PhotoBare.create(:image_file => files(:photo))
34
+ assert_equal '/tmp', p.directory_path
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+ class FleximageBlankTest < Test::Unit::TestCase
4
+
5
+ def test_should_create_blank_image_of_proper_dimensions
6
+ p = Fleximage::Blank.new('320x480')
7
+ p.operate do |image|
8
+ assert_equal(320, image.width)
9
+ assert_equal(480, image.height)
10
+ end
11
+ end
12
+
13
+ def test_should_be_transparent_by_default
14
+ p = Fleximage::Blank.new('320x480')
15
+ assert_color([0, 0, 0, 65535], '50x50', p)
16
+ end
17
+
18
+ def test_should_color_image
19
+ p = Fleximage::Blank.new('320x480', :color => 'red')
20
+ assert_color([65535, 0, 0, 0], '50x50', p)
21
+ end
22
+
23
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+ class FleximageDefaultImagePathOptionTest < Test::Unit::TestCase
4
+ def test_should_use_a_default_image
5
+ PhotoBare.require_image = false
6
+ PhotoBare.default_image_path = "../fixtures/photo.jpg"
7
+
8
+ p = PhotoBare.new
9
+ assert p.save
10
+ assert_equal 1024, p.load_image.rows
11
+ assert_equal 768, p.load_image.columns
12
+ ensure
13
+ PhotoBare.require_image = true
14
+ PhotoBare.default_image_path = nil
15
+ end
16
+ end
@@ -0,0 +1,120 @@
1
+ require File.dirname(__FILE__) + '/../test_helper.rb'
2
+
3
+ class DslAccessorTest < Test::Unit::TestCase
4
+ class CoolActiveRecord
5
+ dsl_accessor :primary_key
6
+ dsl_accessor :table_name
7
+ end
8
+
9
+ class Item < CoolActiveRecord
10
+ end
11
+
12
+ class LegacyItem < CoolActiveRecord
13
+ primary_key :itcd
14
+ table_name :item
15
+ end
16
+
17
+
18
+ def test_accessor_without_initialization
19
+ assert_equal nil, Item.primary_key
20
+ assert_equal nil, Item.table_name
21
+
22
+ Item.primary_key :itcd
23
+ Item.table_name :item
24
+
25
+ assert_equal :itcd, Item.primary_key
26
+ assert_equal :item, Item.table_name
27
+ end
28
+
29
+ def test_accessor_with_initialization
30
+ assert_equal :itcd, LegacyItem.primary_key
31
+ assert_equal :item, LegacyItem.table_name
32
+
33
+ LegacyItem.primary_key :item_id
34
+ LegacyItem.table_name :item_table
35
+
36
+ assert_equal :item_id, LegacyItem.primary_key
37
+ assert_equal :item_table, LegacyItem.table_name
38
+ end
39
+ end
40
+
41
+
42
+ class DslDefaultAccessorTest < Test::Unit::TestCase
43
+
44
+ class CoolActiveRecord
45
+ dsl_accessor :primary_key, :default=>"id"
46
+ dsl_accessor :table_name, :default=>proc{|klass| klass.name.demodulize.underscore.pluralize}
47
+ end
48
+
49
+ class Item < CoolActiveRecord
50
+ end
51
+
52
+ class User < CoolActiveRecord
53
+ end
54
+
55
+ class Folder
56
+ dsl_accessor :array_folder, :default=>[]
57
+ dsl_accessor :hash_folder, :default=>{}
58
+ end
59
+
60
+ class SubFolder < Folder
61
+ end
62
+
63
+ def test_default_accessor_with_string
64
+ assert_equal "id", Item.primary_key
65
+ assert_equal "id", User.primary_key
66
+ end
67
+
68
+ def test_default_accessor_with_proc
69
+ assert_equal "items", Item.table_name
70
+ assert_equal "users", User.table_name
71
+ end
72
+
73
+ def test_default_accessor_should_duplicate_empty_array_or_hash
74
+ Folder.array_folder << 1
75
+ Folder.hash_folder[:name] = "maiha"
76
+
77
+ assert_equal([1], Folder.array_folder)
78
+ assert_equal({:name=>"maiha"}, Folder.hash_folder)
79
+
80
+ assert_equal([], SubFolder.array_folder)
81
+ assert_equal({}, SubFolder.hash_folder)
82
+ end
83
+ end
84
+
85
+
86
+ class DslOverwritenDefaultAccessorTest < Test::Unit::TestCase
87
+ class CoolActiveRecord
88
+ dsl_accessor :primary_key, :default=>"id"
89
+ dsl_accessor :table_name, :default=>proc{|klass| klass.name.demodulize.underscore.pluralize}
90
+ end
91
+
92
+ class Item < CoolActiveRecord
93
+ primary_key :item_id
94
+ table_name :item_table
95
+ end
96
+
97
+ def test_overwrite_default_accessor
98
+ assert_equal :item_id, Item.primary_key
99
+ assert_equal :item_table, Item.table_name
100
+ end
101
+ end
102
+
103
+
104
+ class DslWriterAccessorTest < Test::Unit::TestCase
105
+ class Item
106
+ dsl_accessor :primary_key, :writer=>proc{|value| value.to_s}
107
+ end
108
+
109
+ def test_string_writer
110
+ assert_equal "", Item.primary_key
111
+
112
+ Item.primary_key :id
113
+ assert_equal "id", Item.primary_key
114
+
115
+ Item.primary_key "id"
116
+ assert_equal "id", Item.primary_key
117
+ end
118
+ end
119
+
120
+
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+ class FleximageFileUploadFromLocalTest < Test::Unit::TestCase
4
+ def test_should_be_valid_with_image
5
+ p = PhotoBare.new(:image_file => files(:photo))
6
+ assert p.save, 'Record expected to be allowed to save'
7
+ end
8
+
9
+ def test_should_require_an_image
10
+ p = PhotoBare.new
11
+ assert !p.save, 'Record expected to not be allowed to save'
12
+ assert_equal 1, p.errors.size
13
+ assert_equal 'is required', p.errors.on(:image_file)
14
+ end
15
+
16
+ def test_should_require_an_valid_image
17
+ p = PhotoBare.new(:image_file => files(:not_a_photo))
18
+ assert !p.save, 'Record expected to not be allowed to save'
19
+ assert_equal 1, p.errors.size
20
+ assert_equal 'was not a readable image', p.errors.on(:image_file)
21
+ end
22
+
23
+ def test_should_correct_colorspace_and_dpi
24
+ p = PhotoBare.new(:image_file => files(:cmyk))
25
+ image = p.load_image
26
+ assert_equal Magick::RGBColorspace, image.colorspace
27
+ assert_equal '72x72', image.density
28
+ assert_equal 300, image.columns
29
+ assert_equal 300, image.rows
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+ class FleximageFileUploadFromStringsTest < Test::Unit::TestCase
4
+ def test_should_accept_file_as_string
5
+ data = files(:photo).read
6
+
7
+ p = PhotoBare.new
8
+ p.image_file_string = data
9
+ p.save
10
+ assert p.save, 'Record expected to be allowed to save'
11
+ assert p.has_image?
12
+ end
13
+
14
+ def test_should_accept_file_as_base64
15
+ data = Base64.encode64(files(:photo).read)
16
+
17
+ p = PhotoBare.new
18
+ p.image_file_base64 = data
19
+ p.save
20
+ assert p.save, 'Record expected to be allowed to save'
21
+ assert p.has_image?
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/../../test/test_helper'
2
+
3
+ class FleximageFileUploadFromUrlTest < Test::Unit::TestCase
4
+ def test_should_be_valid_with_image_from_url
5
+ p = PhotoBare.new(:image_file_url => files(:web_photo))
6
+ assert p.save, 'Record expected to be valid after upload via URL'
7
+ rescue SocketError
8
+ print '!'
9
+ end
10
+
11
+ def test_should_be_invalid_with_nonimage_from_url
12
+ p = PhotoBare.new(:image_file_url => 'http://www.google.com/')
13
+ assert !p.save, 'Record expected to be invalid after upload via URL'
14
+ assert_equal 1, p.errors.size
15
+ assert_equal 'was not a readable image', p.errors.on(:image_file_url)
16
+ rescue SocketError
17
+ print '!'
18
+ end
19
+
20
+ def test_should_be_invalid_with_invalid_url
21
+ p = PhotoBare.new(:image_file_url => 'foo')
22
+ assert !p.save, 'Record expected to be invalid after upload via URL'
23
+ assert_equal 1, p.errors.size
24
+ assert_equal 'was not a readable image', p.errors.on(:image_file_url)
25
+ rescue SocketError
26
+ print '!'
27
+ end
28
+
29
+ def test_should_have_an_original_filename
30
+ p = PhotoFile.new(:image_file_url => files(:web_photo))
31
+ assert_equal p.image_filename, files(:web_photo)
32
+ rescue SocketError
33
+ print '!'
34
+ end
35
+ end