rocket_pants icon indicating copy to clipboard operation
rocket_pants copied to clipboard

Route cannot be generated in Rspec 3

Open manuelmeurer opened this issue 10 years ago • 10 comments

I'm using Rocket Pants 1.10.0 with Rails 4.1.4 and Rspec 3.0.0. With previous Rspec version this worked:

describe API::V1::AccountsController do
  default_version 1

  describe 'POST create' do
    it 'works' do
      post :create
    end
  end
end

Now I get this error:

ActionController::UrlGenerationError:
No route matches {:action=>"create", :controller=>"api/v1/accounts", :version=>"1"}

When I change default_version 1 to default_version 'v1', the route is generated but in the log file it says:

Processing by API::V1::AccountsController#create as 
  Parameters: {"version"=>"v1"}
Exception raised: RocketPants::InvalidVersion: RocketPants::InvalidVersion

Relevant part of my routes.rb:

namespace :api, path: '', constraints: { subdomain: 'api' } do
  api version: 1, require_prefix: 'v', module: 'v1' do
    resource :account, only: :create
  end
end

Any idea what might cause this?

manuelmeurer avatar Jul 23 '14 14:07 manuelmeurer

Still having this problem, @Sutto any idea?

manuelmeurer avatar Aug 14 '14 10:08 manuelmeurer

Try that (allow_prefix):

api versions: 1, allow_prefix: 'v', module: "api/v1" do
  resources :projects,        only: [:index, :show, :create, :update]
end

fsmanuel avatar Nov 10 '14 13:11 fsmanuel

I kinda gave up on RocketPants due to this, so someone else will have to try this out.

manuelmeurer avatar Nov 11 '14 06:11 manuelmeurer

@manuelmeurer What gem/solution are you using?

fsmanuel avatar Nov 11 '14 07:11 fsmanuel

I was looking at https://github.com/rails-api/rails-api but since I need HTML rendering too, I'll probably go with regular Rails.

manuelmeurer avatar Nov 11 '14 08:11 manuelmeurer

Sorry guys - I feel like this is a bigger part of an issue and forgot about it quite a while ago, quite by accident. It'll be looked into again in the near future, and hopefully I can work out the correct solution then. Thanks! (and sorry :()

Sutto avatar May 20 '15 04:05 Sutto

I ran into the same situation. Any updates here?

ben-ole avatar Jul 05 '15 13:07 ben-ole

Same here.

strux avatar Aug 19 '15 23:08 strux

I'm having a similar problem with InvalidVersion exception being raised. I've tried everything and can't figure out the cause.

avitus avatar Feb 09 '16 22:02 avitus

Hmm I may be running into this as well, hitting it during testing getting: No route matches {:action=>"confirm", :controller=>"api/people", :version=>"3", :work_email=>"xxx"}

I would expect the controller params to be api/v3/people?

generated routes look correct: api/v3/people#confirm_email {:format=>"json", :version=>/(3)/}

Ah duh - fixed - when moving controllers around, don't forget to move your tests into the new module folder ;) :tada:

mbhnyc avatar Jul 06 '16 13:07 mbhnyc