Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ProfilesControllerTest < ActionController::TestCase
- test "creates a new profile" do
- fixture_image = fixture_file_upload("#{RAILS_ROOT}/test/fixtures/files/avatar.jpg", 'image/jpeg')
- post :create, :profile=>{:username=>'johndoe',
- :password=>'mypass',
- :avatar => fixture_image
- }, :html => { :multipart => true }
- assert_response :success
- assert_not_nil Profile.find_by_username("johndoe")
- assert_not_nil Profile.find_by_username("johndoe").avatar
- end
- end
- @profile = Profile.new(params[:profile])
- @profile.save
- class Profile
- include MongoMapper::Document
- plugin Joint
- attachment :avatar
- end
- 1) Error:
- test_creates_a_new_profile(Api::ProfilesControllerTest):
- TypeError: can't convert ActionController::TestUploadedFile into String
- (eval):15:in `size'
- (eval):15:in `avatar='
- /Users/oliver/.rvm/gems/ruby-1.8.7-p302/gems/mongo_mapper-0.8.6/lib/mongo_mapper/plugins/keys.rb:183:in `send'
- def uploaded_file(path)
- pathname = Rails.root + 'test/fixtures/' + path
- filename = File.basename(path)
- tempfile = Tempfile.new(filename)
- content_type = MIME::Types.type_for(pathname.to_s).to_s
- FileUtils.copy_file(pathname, tempfile.path)
- (class << tempfile; self end).class_eval do
- alias local_path path
- define_method(:original_filename) { filename }
- define_method(:content_type) { content_type }
- end
- return tempfile
- end
Advertisement
Add Comment
Please, Sign In to add comment