Commit c82d3272c1ef371a91ca6bfac0b66a49986cf3f4
1 parent
3baef002
Exists in
master
and in
27 other branches
rails3: fix image test
Showing
1 changed file
with
14 additions
and
14 deletions
Show diff stats
test/unit/image_test.rb
@@ -15,14 +15,14 @@ class ImageTest < ActiveSupport::TestCase | @@ -15,14 +15,14 @@ class ImageTest < ActiveSupport::TestCase | ||
15 | end | 15 | end |
16 | 16 | ||
17 | should 'match max_size in validates message of size field' do | 17 | should 'match max_size in validates message of size field' do |
18 | - image = Image.new(:filename => 'fake_filename.png') | 18 | + image = build(Image, :filename => 'fake_filename.png') |
19 | image.valid? | 19 | image.valid? |
20 | 20 | ||
21 | - assert_match /#{Image.max_size.to_humanreadable}/, image.errors[:size] | 21 | + assert_match /#{Image.max_size.to_humanreadable}/, image.errors[:size].first |
22 | end | 22 | end |
23 | 23 | ||
24 | should 'create thumbnails after processing jobs' do | 24 | should 'create thumbnails after processing jobs' do |
25 | - file = Image.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | 25 | + file = create(Image, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) |
26 | profile.update_attribute(:image_id, file.id) | 26 | profile.update_attribute(:image_id, file.id) |
27 | 27 | ||
28 | process_delayed_job_queue | 28 | process_delayed_job_queue |
@@ -33,7 +33,7 @@ class ImageTest < ActiveSupport::TestCase | @@ -33,7 +33,7 @@ class ImageTest < ActiveSupport::TestCase | ||
33 | end | 33 | end |
34 | 34 | ||
35 | should 'set thumbnails_processed to true after creating thumbnails' do | 35 | should 'set thumbnails_processed to true after creating thumbnails' do |
36 | - file = Image.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | 36 | + file = create(Image, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) |
37 | profile.update_attribute(:image_id, file.id) | 37 | profile.update_attribute(:image_id, file.id) |
38 | 38 | ||
39 | process_delayed_job_queue | 39 | process_delayed_job_queue |
@@ -64,7 +64,7 @@ class ImageTest < ActiveSupport::TestCase | @@ -64,7 +64,7 @@ class ImageTest < ActiveSupport::TestCase | ||
64 | end | 64 | end |
65 | 65 | ||
66 | should 'return image thumbnail if thumbnails were processed' do | 66 | should 'return image thumbnail if thumbnails were processed' do |
67 | - file = Image.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | 67 | + file = create(Image, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) |
68 | profile.update_attribute(:image_id, file.id) | 68 | profile.update_attribute(:image_id, file.id) |
69 | process_delayed_job_queue | 69 | process_delayed_job_queue |
70 | 70 | ||
@@ -74,7 +74,7 @@ class ImageTest < ActiveSupport::TestCase | @@ -74,7 +74,7 @@ class ImageTest < ActiveSupport::TestCase | ||
74 | end | 74 | end |
75 | 75 | ||
76 | should 'store width and height after processing' do | 76 | should 'store width and height after processing' do |
77 | - file = Image.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | 77 | + file = create(Image, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) |
78 | profile.update_attribute(:image_id, file.id) | 78 | profile.update_attribute(:image_id, file.id) |
79 | file.create_thumbnails | 79 | file.create_thumbnails |
80 | 80 | ||
@@ -84,24 +84,24 @@ class ImageTest < ActiveSupport::TestCase | @@ -84,24 +84,24 @@ class ImageTest < ActiveSupport::TestCase | ||
84 | 84 | ||
85 | should 'have a loading image to each size of thumbnails' do | 85 | should 'have a loading image to each size of thumbnails' do |
86 | Image.attachment_options[:thumbnails].each do |suffix, size| | 86 | Image.attachment_options[:thumbnails].each do |suffix, size| |
87 | - image = Rails.root + '/public/images/icons-app/image-loading-%s.png' % suffix | ||
88 | - assert File.exists?(image) | 87 | + image = File.join(Rails.root, "public/images/icons-app/image-loading-#{suffix}.png") |
88 | + assert File.exists?(image), "#{image} should exist." | ||
89 | end | 89 | end |
90 | end | 90 | end |
91 | 91 | ||
92 | - should 'not create a background job for an image that is already a thumbnail' do | 92 | + should 'not create a background job for an image that is not thumbnailable' do |
93 | # this test verifies whether it created background jobs also for the | 93 | # this test verifies whether it created background jobs also for the |
94 | # thumbnails! | 94 | # thumbnails! |
95 | assert_no_difference Delayed::Job, :count do | 95 | assert_no_difference Delayed::Job, :count do |
96 | - image = Image.new(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
97 | - image.stubs(:is_thumbnail?).returns(true) | 96 | + image = build(Image, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) |
97 | + image.stubs(:thumbnailable?).returns(false) | ||
98 | image.save! | 98 | image.save! |
99 | end | 99 | end |
100 | end | 100 | end |
101 | 101 | ||
102 | should 'upload to a folder with same name as the schema if database is postgresql' do | 102 | should 'upload to a folder with same name as the schema if database is postgresql' do |
103 | uses_postgresql | 103 | uses_postgresql |
104 | - file = Image.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | 104 | + file = create(Image, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) |
105 | profile.update_attribute(:image_id, file.id) | 105 | profile.update_attribute(:image_id, file.id) |
106 | process_delayed_job_queue | 106 | process_delayed_job_queue |
107 | assert_match(/images\/test_schema\/\d{4}\/\d{4}\/rails.png/, Image.find(file.id).public_filename) | 107 | assert_match(/images\/test_schema\/\d{4}\/\d{4}\/rails.png/, Image.find(file.id).public_filename) |
@@ -111,7 +111,7 @@ class ImageTest < ActiveSupport::TestCase | @@ -111,7 +111,7 @@ class ImageTest < ActiveSupport::TestCase | ||
111 | 111 | ||
112 | should 'upload to path prefix folder if database is not postgresql' do | 112 | should 'upload to path prefix folder if database is not postgresql' do |
113 | uses_sqlite | 113 | uses_sqlite |
114 | - file = Image.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | 114 | + file = create(Image, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) |
115 | profile.update_attribute(:image_id, file.id) | 115 | profile.update_attribute(:image_id, file.id) |
116 | process_delayed_job_queue | 116 | process_delayed_job_queue |
117 | assert_match(/images\/\d{4}\/\d{4}\/rails.png/, Image.find(file.id).public_filename) | 117 | assert_match(/images\/\d{4}\/\d{4}\/rails.png/, Image.find(file.id).public_filename) |
@@ -119,7 +119,7 @@ class ImageTest < ActiveSupport::TestCase | @@ -119,7 +119,7 @@ class ImageTest < ActiveSupport::TestCase | ||
119 | end | 119 | end |
120 | 120 | ||
121 | should 'not allow script files to be uploaded without append .txt in the end' do | 121 | should 'not allow script files to be uploaded without append .txt in the end' do |
122 | - file = Image.create!(:uploaded_data => fixture_file_upload('files/hello_world.php', 'image/png')) | 122 | + file = create(Image, :uploaded_data => fixture_file_upload('files/hello_world.php', 'image/png')) |
123 | assert_equal 'hello_world.php.txt', file.filename | 123 | assert_equal 'hello_world.php.txt', file.filename |
124 | end | 124 | end |
125 | 125 |