Can I learn how to stub the method that is in the controller creation method? I need to write a specification for this, but I got these errors. I need to verify that the create method in the controller must execute the validate_fbid method before creating a new company record in the model.
Error:
1) Companies new company create with valid information
CompaniesController
def create company = Company.new(params[:company]) verifyfbid = validate_fbid(company) if verifyfbid != false if company.fbid.downcase == verifyfbid.downcase if company.save @message = "New company created." redirect_to root_path else @message = "Company create attempt failed. Please try again." render 'new' end else @message = "Company create attempt failed. Invalid facebook id." render 'new' end else @message = "Company create attempt failed. No such facebook id." render 'new' end end private def validate_fbid(company) uri = URI("http://graph.facebook.com/" + company.fbid) data = Net::HTTP.get(uri) username = JSON.parse(data)['username'] if username.nil? return false else "#{username}" end end
Requests / companies_spec.rb
context "#validate_fbid" do
source share