my
describe PaymentController do
it 'should assign amount_to_pay' do
get bank_payment_path, {id: "1"}
expect(assigns[:amount_to_pay]).to eq "123"
end
end
my error:
Error: ActionController::RoutingError: No route matches {:action=>"bank", :controller=>"payment"}
and rake routes:
bank_payment GET /payment/:id/bank(.:format) payment#bank
What is wrong there?
The request should be:
get :bank, id: "1"
Related
Have gone through othe similar questions but the problem is not solved.
Test:
expect{
post message_direct_create_path(friend.id), params: {message_direct:
FactoryBot.attributes_for(:message_direct, user_id: user.id,
friend_id: friend.id)}
}.to change{MessageDirect.count}.by(1)
Route:
post '/message_directs/:friend_id', to: 'message_directs#create', as: 'message_direct_create'
Error:
ActionController::UrlGenerationError:
No route matches {:action=>"/message_directs/1",
:controller=>"message_directs", :message_direct=>{:text=>"Sends
Message", :user_id=>1, :friend_id=>1}}
I have also tried
:create and "/message_directs/#{friend.id}" but the error is still same
I have the following code:
it 'should create' do
post :create, investor: VALID_CREATE_PARAMS
expect(response).to redirect_to(controller: 'admin/investors', action: 'show')
end
It generates following error:
1) Admin::InvestorsController create should create
Failure/Error: expect(response).to redirect_to(controller: 'admin/investors', action: 'show')
ActionController::UrlGenerationError:
No route matches {:action=>"show", :controller=>"admin/investors"}
The routes are
namespace :admin do
resources :investors
end
How can I fix this issue? I have no option to assert redirection with admin_investor_path, because I keep url params while redirecting.
Show action by default requires an id to be passed as well, without the id it can't generate the url
You need to add it like this:
expect(response).to redirect_to(controller: 'admin/investors', action: 'show', id: assigns(:investor).id )
I couldn't find a solution in the other relative questions, so I'm asking my own.
The problem is pretty straightforward. This is the error I'm getting:
Failure/Error: get 'api/v2/special_keys#show'
ActionController::UrlGenerationError:
No route matches {:action=>"api/v2/special_keys#show", :controller=>"api/v2/special_keys"}
This is my routes.rb:
resources :special_keys, only: [] do
collection do
get '', to: 'special_keys#show'
end
end
This is the output from rake routes:
GET /api/v2/special_keys(.:format) api/v2/special_keys#show {:format=>"json"}
And my spec:
require 'rails_helper'
describe Api::V2::SpecialKeysController do
describe 'GET #show' do
it 'gets the policy and signature' do
get '/api/v2/special_keys'
expect(response.status).to eql 200
end
end
end
Try to rewrite your test as:
require 'rails_helper'
describe Api::V2::SpecialKeysController do
describe 'GET #show' do
it 'gets the policy and signature' do
get '/api/v2/special_keys', {format: :json}
expect(response.status).to eql 200
end
end
end
Try:
resource :special_keys, only: [:show]
The singular tells the app, that there is only one. So it will only generate a show action that needs no id and no indexaction at all.
How can I negate the following test?
test "should route to post" do
post = posts(:one)
assert_routing "/posts/#{post.id}", {
controller: "posts",
action: "show",
id: "#{post.id}"
}
end
I want to test that the route /posts/1 does not exist.
This should work. This will test if the route for :new exists (might be overkill)
$> route.defaults #outputs: {:controller=>"posts", :action=>"index"}
test "shouldn't have route new" do
admin_routes = Rails.application.routes.routes.
select { |route| route.path.spec.to_s.starts_with? "/posts" }
admin_routes.each do |route|
assert_not route.defaults[:action].
include?('new'), "route :new is not allow to exist"
end
end
The only thing I can come up with is try the route and then assert an exception will be raised:
test "should route to post" do
post = posts(:one)
assert_raises Minitest::Assertion do
assert_routing "/posts/#{post.id}"
end
end
Or
assert_raises ActionController::UrlGenerationError do
get "/users/1"
end
But I don't like either of those to be honest.
I get the below error ActionController::UrlGenerationError.
ActionController::UrlGenerationError:
No route matches {:action=>"/accounts/100", :controller=>"accounts"}
Below is my code which throws this error.
it "can find an account" do
Account.should_receive(:find, with: {id: 2055, authorization: #auth}
get "/accounts/100", nil, {"AUTH_TOKEN" => #auth}
hashed_response = {
"#type" => "test",
"createdAt" => "2014-07-24T15:26:49",
"description" => "Something about test",
"disabled" => false
}
expect(response.status).to eq 200
expect(response.body).to eq(hashed_response.to_json);
end
I did a google on this and came to know that there is no routes defined for this. Below is my config/routes.rb file
Rails.application.routes.draw do
resources :accounts do
resources :holders
end
end
I presume this error is coming from a controller spec? If so, you simply use a symbol representing the action you want to call, not the URL itself.
eg. this is a show action, so you would use:
get :show, id: 100