Commit a3c6b6027928fffe73e8a91dd4ec09a9f0e5de6b
1 parent
2f568c12
Exists in
master
and in
11 other branches
rails4: fix uploaded file tests
Showing
4 changed files
with
12 additions
and
6 deletions
Show diff stats
app/models/thumbnail.rb
| 1 | class Thumbnail < ActiveRecord::Base | 1 | class Thumbnail < ActiveRecord::Base |
| 2 | + | ||
| 3 | + attr_accessible :uploaded_data | ||
| 4 | + # mass assigned by attachment_fu | ||
| 5 | + attr_accessible :content_type, :filename, :thumbnail_resize_options, :thumbnail, :parent_id | ||
| 6 | + | ||
| 2 | has_attachment :storage => :file_system, | 7 | has_attachment :storage => :file_system, |
| 3 | :content_type => :image, :max_size => 5.megabytes, processor: 'Rmagick' | 8 | :content_type => :image, :max_size => 5.megabytes, processor: 'Rmagick' |
| 4 | validates_as_attachment | 9 | validates_as_attachment |
| @@ -7,5 +12,4 @@ class Thumbnail < ActiveRecord::Base | @@ -7,5 +12,4 @@ class Thumbnail < ActiveRecord::Base | ||
| 7 | 12 | ||
| 8 | postgresql_attachment_fu | 13 | postgresql_attachment_fu |
| 9 | 14 | ||
| 10 | - attr_accessible :uploaded_data | ||
| 11 | end | 15 | end |
test/factories.rb
| @@ -31,7 +31,8 @@ module Noosfero::Factory | @@ -31,7 +31,8 @@ module Noosfero::Factory | ||
| 31 | if respond_to?(target) | 31 | if respond_to?(target) |
| 32 | send(target, attrs) | 32 | send(target, attrs) |
| 33 | else | 33 | else |
| 34 | - obj = build(name, attrs) | 34 | + obj = build name |
| 35 | + attrs.each{ |a, v| obj.send "#{a}=", v } | ||
| 35 | obj.save! | 36 | obj.save! |
| 36 | obj | 37 | obj |
| 37 | end | 38 | end |
test/test_helper.rb
| @@ -138,6 +138,7 @@ class ActiveSupport::TestCase | @@ -138,6 +138,7 @@ class ActiveSupport::TestCase | ||
| 138 | def find_tag_in_string text, options | 138 | def find_tag_in_string text, options |
| 139 | doc = Nokogiri::HTML.fragment text | 139 | doc = Nokogiri::HTML.fragment text |
| 140 | tag = doc.css(options[:tag]).first | 140 | tag = doc.css(options[:tag]).first |
| 141 | + return unless tag | ||
| 141 | content = tag.text.strip | 142 | content = tag.text.strip |
| 142 | 143 | ||
| 143 | attributes = {}; tag.attributes.each do |a, v| | 144 | attributes = {}; tag.attributes.each do |a, v| |
| @@ -146,7 +147,7 @@ class ActiveSupport::TestCase | @@ -146,7 +147,7 @@ class ActiveSupport::TestCase | ||
| 146 | attributes[a] = v.value | 147 | attributes[a] = v.value |
| 147 | end | 148 | end |
| 148 | 149 | ||
| 149 | - ret = tag.present? | 150 | + ret = true |
| 150 | ret &&= options[:attributes].blank? || attributes == options[:attributes] | 151 | ret &&= options[:attributes].blank? || attributes == options[:attributes] |
| 151 | ret &&= options[:content].blank? || content == options[:content] | 152 | ret &&= options[:content].blank? || content == options[:content] |
| 152 | ret | 153 | ret |
test/unit/uploaded_file_test.rb
| @@ -347,13 +347,13 @@ class UploadedFileTest < ActiveSupport::TestCase | @@ -347,13 +347,13 @@ class UploadedFileTest < ActiveSupport::TestCase | ||
| 347 | 'INVALID' => 5.megabytes, # use default for invalid input | 347 | 'INVALID' => 5.megabytes, # use default for invalid input |
| 348 | '1ZYX' => 5.megabytes, # use default for invalid input | 348 | '1ZYX' => 5.megabytes, # use default for invalid input |
| 349 | }.each do |input,output| | 349 | }.each do |input,output| |
| 350 | - test 'maximum upload size: convert %s into %s' % [input, output] do | 350 | + should 'maximum upload size: convert %s into %s' % [input, output] do |
| 351 | NOOSFERO_CONF.expects(:[]).with('max_upload_size').returns(input) | 351 | NOOSFERO_CONF.expects(:[]).with('max_upload_size').returns(input) |
| 352 | assert_equal output, UploadedFile.max_size | 352 | assert_equal output, UploadedFile.max_size |
| 353 | end | 353 | end |
| 354 | end | 354 | end |
| 355 | - test 'max_size should always return an integer' do | ||
| 356 | - NOOSFERO_CONF.expects(:[]).with('max_upload_size').returns("0.5 GB") | 355 | + should 'max_size should always return an integer' do |
| 356 | + NOOSFERO_CONF.expects(:[]).with('max_upload_size').returns("0.5 GB").at_least_once | ||
| 357 | assert_instance_of Fixnum, UploadedFile.max_size | 357 | assert_instance_of Fixnum, UploadedFile.max_size |
| 358 | end | 358 | end |
| 359 | 359 |