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?
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
You can then load this in the spec_helper.rb file
Finally, you can use this in the test
Now, that should test your asset list correctly.
EDIT: Just realised, I’m using FactoryGirl/Devise here, you may or may not be!