本文介绍了rails rspec没有路线匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试测试我的路线(它们对于实际请求而言正常工作)并收到此错误:
I'm trying to test my routes (they work fine for real requests) and get this error:
ActionController::UrlGenerationError: No route matches {:action=>"api/login", :controller=>"login", :email=>"a@a", :password=>"super_secure"}我看过很多类似的问题,但找不到确切的答案我的问题。
I've looked at a bunch of similar questions but could not find a precise answer for my problem.
我的路线是:
Rails.application.routes.draw do post 'api/login' => 'login#email_login'我的测试是
describe LoginController do it 'works fine' do password = 'super_secure' salt = BCrypt::Engine.generate_salt.to_s hash_password = BCrypt::Engine.hash_secret(password, salt).to_s user_login = FactoryGirl.create(:user_login, user_hash: hash_password, salt: salt, email: 'a@a') post 'api/login', password: password, email: user_login.email expect(response).to be_success end end最后,我的 LoginController 是:
class LoginController < ActionController::Base protect_from_forgery except: [:email_login], with: :exception def email_login auth = UserLogin.auth(params[:email], params[:password]) return render text: 'unauthorized', status: 401 unless auth[:user] return render json: auth end end我尝试了多种方法将数据传递给post方法,但是它们都失败了...
I've tried different ways to pass the data to the post method but they all failed...
您有一个线索,对您有帮助!
It you have a clue, that would help!
推荐答案在测试中,尝试调整路径,就像这样:
In your test, try adjusting your path, like this:
post '/api/login', password: password, email: user_login.email更多推荐
rails rspec没有路线匹配
发布评论