Commit c82d3272c1ef371a91ca6bfac0b66a49986cf3f4

Authored by Rodrigo Souto
1 parent 3baef002

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 15 end
16 16  
17 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 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 22 end
23 23  
24 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 26 profile.update_attribute(:image_id, file.id)
27 27  
28 28 process_delayed_job_queue
... ... @@ -33,7 +33,7 @@ class ImageTest < ActiveSupport::TestCase
33 33 end
34 34  
35 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 37 profile.update_attribute(:image_id, file.id)
38 38  
39 39 process_delayed_job_queue
... ... @@ -64,7 +64,7 @@ class ImageTest < ActiveSupport::TestCase
64 64 end
65 65  
66 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 68 profile.update_attribute(:image_id, file.id)
69 69 process_delayed_job_queue
70 70  
... ... @@ -74,7 +74,7 @@ class ImageTest < ActiveSupport::TestCase
74 74 end
75 75  
76 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 78 profile.update_attribute(:image_id, file.id)
79 79 file.create_thumbnails
80 80  
... ... @@ -84,24 +84,24 @@ class ImageTest < ActiveSupport::TestCase
84 84  
85 85 should 'have a loading image to each size of thumbnails' do
86 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 89 end
90 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 93 # this test verifies whether it created background jobs also for the
94 94 # thumbnails!
95 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 98 image.save!
99 99 end
100 100 end
101 101  
102 102 should 'upload to a folder with same name as the schema if database is postgresql' do
103 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 105 profile.update_attribute(:image_id, file.id)
106 106 process_delayed_job_queue
107 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 111  
112 112 should 'upload to path prefix folder if database is not postgresql' do
113 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 115 profile.update_attribute(:image_id, file.id)
116 116 process_delayed_job_queue
117 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 119 end
120 120  
121 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 123 assert_equal 'hello_world.php.txt', file.filename
124 124 end
125 125  
... ...