Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7928133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:39:24+00:00 2026-06-03T19:39:24+00:00

I am writing a test for file download during which I am using the

  • 0

I am writing a test for file download during which I am using the original_filename. I was able to mock the file upload using fixture_file_upload. But how to stub/mock the original_filename call.

def import_for_photo(picture_url, user)
  remote_photo = open(picture_url)
  remote_photo.original_filename = "#{user.id}.jpg"
  user.update_attributes({:picture => remote_photo})
end

The test

def test_import_for_photo
  fixture_file = fixture_file_upload(File.join('files', 'test.jpg'), 'image/jpeg')
  OpenURI.expects(:open_uri).returns(fixture_file)
  import_for_photo("http://dummy_url.com/dummy.jpg", users(:one))
  assert_equal "1.jpg", users(:one).reload.picture_file_name
end

Test output,

NoMethodError: undefined method `original_filename=' for #<File:/tmp/test.jpg20120512-4253-x673nc-0>

I know why this test fails, but how to fix it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:39:25+00:00Added an answer on June 3, 2026 at 7:39 pm

    Found out the solution. Instead of trying to stub :original_filename, I stubbed :original_filename= (notice the ‘=’) and my problem was solved !

    Here is the code

    def test_import_for_photo
      fixture_file = fixture_file_upload(File.join('files', 'test.jpg'), 'image/jpeg')
      fixture_file.expects(:original_filename=)
      OpenURI.expects(:open_uri).returns(fixture_file)
      import_for_photo("http://dummy_url.com/dummy.jpg", users(:one))
      assert_equal "1.jpg", users(:one).reload.picture_file_name
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a JUnit test for some code that produces an Excel file (which
I'm writing a simple test page to download a text file from a browser
I am writing a unit test that needs to access an image file that
I'm writing a file on a network drive into a new folder. string directory=@\\dir\test\
I'm writing some test cases, and I've got a test case that is using
I am writing a test program to copy some file in Application data folder
I am writing an application that would download and replace a pdf file only
I'm writing a test for a file parser class. The parse method receives a
I'm writing a unit test for file uploading feature of my web application. I
Hello guys I'm writing a test file for a program. where all the possible

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.