I have a variable in my sessions controller.
session[:facebook_profile_id] = @user_info['id']
@user_info['id'] is an int. Example: 123
I then use that session variable in my main controller to get a profile object from the database.
def show
@facebook_profile = FacebookProfile.find_by_facebook_id(session[:facebook_profile_id])
end
The new object is found using the session variable and is used in my application, so my rspec test fails without it.
Here is my Factory for FacebookProfile:
FactoryGirl.define do
factory :facebook_profile do |f|
f.facebook_id 123
end
end
In my spec test for the application, I create the Factory instance before each test:
FactoryGirl.create(:facebook_profile).should be_valid
How do I set the session[:facebook_profile_id] variable in my spec test so that the lookup for @facebook_profile doesn't fail?
I've tried stubbing, but couldn't get it to work. Also, I've been trying this in my features spec. Should I be doing this in the controller spec?
If your purpose is functional testing, it's simple to just assign it directly in test
# describe .....
session[:facebook_profile_id] = 123
# end
After assignment you can get the variable directly as well
session[:facebook_profile_id]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With