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

  • Home
  • SEARCH
  • 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 7724771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:46:18+00:00 2026-06-01T04:46:18+00:00

I am currently trying to make a dropbox-esque application from a tutorial and I

  • 0

I am currently trying to make a dropbox-esque application from a tutorial and I am having trouble trying to figure out how I would test this controller.

this is the AssetsController page

    def index
       @assets = current_user.assets
    end

    def show
       @assets = current_user.assets.find(params[:id])

Also, assets belong_to :user and user has_many :assets

How would I go about putting that into an rspec test?

  • 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-01T04:46:19+00:00Added an answer on June 1, 2026 at 4:46 am

    Firstly, be very careful about AssetsController.

    Assuming you are using Rails 3, the “assets_path” is also the path used to load your application assets, and hence, anything you write to the session in that controller will be ignored silently. Probably not what you want! I’d strongly consider renaming the controller.

    I’d first create the user in a sign-in block

    module ControllerMacros
      def login_user
        before(:each) do
          @request.env["devise.mapping"] = Devise.mappings[:user]
          @user = Factory.create(:user)
          sign_in @user
        end
      end
    end
    

    You can then load this in the spec_helper.rb file

    RSpec.configure do |config|
      config.include Devise::TestHelpers, :type => :controller
      config.extend ControllerMacros, :type => :controller
    end
    

    Finally, you can use this in the test

    describe MyController do
      context "#index" do
        login_user
        before(:each) do
          @assets = []
          5.times{ @assets << Factory.create(:asset, :user => @user)}
        end
    
        it "should test index" do
          get :index
          assigns(:assets).should eq(@assets)
        end
      end
    end
    

    Now, that should test your asset list correctly.

    EDIT: Just realised, I’m using FactoryGirl/Devise here, you may or may not be!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a very difficult time trying to figure out how to make my
I'm currently trying to make some ajax post between cross-domains by following this tutorial
I'm currently trying to make a small application that performs different duties. Right now
I am currently trying to make a sectioned table like this: Section 1: Entry
I am currently trying to make an application that allows the user to create
i'm currently trying to make a asp.net mvc3 app. in the sample application which
I'm trying to make a multi-language application with Symfony2 and I'm currently trying to
Currently I'm trying to make a flowchart, this is the code I've got so
I'm currently trying to make a RPG game and I'm running into some trouble.
I am currently trying to make a call to this function call. Here's the

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.