I am using Faraday and Github-Api gems to log a user in with Github. In order to test any type of functionality, I have to mock this behavior. I am thinking that in my spec, I should say something like "if the new action is called (which is what pings the github-api), then redirect to the create action and pass in the parameters that it needs to create a user." I am not entirely sure how to do this. I realize that there are solutions for Oauth, modules with helper methods to mock this behavior, but I am adding tests to an app that someone else built so it has to stay as is. Any help or pointers would be greatly appreciated. I'm fairly new to testing as well so feel free to comment on the test itself.
Spec
require "rails_helper"
RSpec.feature "User submits a project" do
scenario "they see the index page for their projects" do
project = create(:project)
visit '/projects/new'
fill_in "project_title", with: project_title
fill_in "project_project_type", with: project_project_type
fill_in "project_description", with: project_description
fill_in "project_starts_at", with: project_starts_at
click_on "Create Project"
redirect_to '/projects'
expect(page).to have_project_title
end
end
Sessions Controller
def new
redirect_to "githubapiurlgoeshere"
end
def create
@user = User.find_or_create_from_auth_hash(auth_hash)
if @user.save
session[:token] = @user.token
session[:user_id] = @user.id
redirect_to root_path
else
flash[:notice] = "message here"
redirect_to root_path
end
end
Aucun commentaire:
Enregistrer un commentaire