rails rspec没有路线匹配

编程入门 行业动态 更新时间:2024-10-07 06:39:46
本文介绍了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没有路线匹配

本文发布于:2023-11-25 21:34:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631432.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路线   rails   rspec

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!