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 8461675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:56:32+00:00 2026-06-10T13:56:32+00:00

I have a model where I use the method to upload images In Image

  • 0

I have a model where I use the method to upload images

In Image controller I call
DataFile.save_image_file(params[:upload])

My code data_file.rb

      def self.save_image_file(upload)
        file_name = upload['datafile'].original_filename  if  (upload['datafile'] !='')    
        file = upload['datafile'].read    

        file_type = file_name.split('.').last
        new_name_file = Time.now.to_i
        name_folder = new_name_file
        new_file_name_with_type = "#{new_name_file}." + file_type
        new_file_name_thumb_with_type = "#{new_name_file}-thumb." + file_type

        image_root = "#{RAILS_CAR_IMAGES}"


          Dir.mkdir(image_root + "#{name_folder}");
          File.open(image_root + "#{name_folder}/" + new_file_name_with_type, "wb")  do |f|  
            f.write(file)
          end

[new_name_file, new_file_name_with_type, new_file_name_thumb_with_type]

      end

I want to test it in RSpec

data_file_spec.rb

require 'spec_helper'

describe DataFile do
  describe "Should save image file" do 


    before(:each) do
      @file = fixture_file_upload('/files/test-bus-1.jpg', 'image/jpg')
    end

    it "Creating new car name and thumb name" do
      @get_array = save_file(@file)
      @get_array[:new_name_file].should_not be_nil
    end

  end
end

But test doesn’t work

Failure/Error: @file = fixture_file_upload(‘/files/test-bus-1.jpg’, ‘image/jpg’)
NoMethodError:
undefined method `fixture_file_upload’ for #

  • 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-10T13:56:34+00:00Added an answer on June 10, 2026 at 1:56 pm

    You need to include ActionDispatch::TestProcess. Try something like:

    require 'spec_helper'
    
    describe DataFile do
      describe "Should save image file" do 
        let(:file) do
          extend ActionDispatch::TestProcess
          fixture_file_upload('/files/test-bus-1.jpg', 'image/jpg')
        end
    
        it "Creating new car name and thumb name" do
          @get_array = save_file(file)
          @get_array[:new_name_file].should_not be_nil
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use Acceleo in order to generate code with a model I have made.
I have a model where I want to use a class method to set
i have a model named test.rb and when i use @tests=Test.new in my controller
im trying to upload images to facebook. The code i have now is working.
I have a method that I've started to use in multiple models for Webscraping,
In my project I have a model where I use Imagekit to process an
I have page where I use model which can have different types (depending by
I use backbone.js and have a model without a collection. In the view I
I have a project which exposes object model to use by different types of
i have a simple question. if i use play.db.ebean.Model to have my Model extend

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.