Update documentation to note the use of use integration tests/request specs for *all* versioning strategies #32

bploetz opened this Issue Jan 29, 2013 · 4 comments


None yet
3 participants

bploetz commented Jan 29, 2013

As noted here:


If you're using the path versioning strategy, you still need to use integration tests/request spec, but the docs only call this out for HTTP Header and Request Parameter versioning strategies. Clearly this applies to all strategies, so update the docs.

mrzasa commented Jan 30, 2013

Is it possible to make it working with regular controller tests? API controllers are not that different than the web controllers so it seems to be a good idea to be able to test them using the same method.


bploetz commented Jan 30, 2013

I honestly don't know why controller specs don't work with the path versioning strategy. Ultimately it's Rails under the hood that is not finding the route in the test, but it does find it when you run rake routes or actually hit the path with the app running. Could be a Rails issue. I'll have to dig into it more and report back here.

mrzasa commented Jan 31, 2013

I found another strange behaviour. When I use versionist, I'm not able to use mocks in specs. Even though I mock a method, the regular implementation is called.

 class Api::V1::ItemsController < Api::V1::BaseController    
  def index
    render json:'anything'

My spec:

describe Api::V1::ItemsController do
  describe "#create" do
    before(:each) do
    it "shows items" do
      get :index, data:"data", format: :json

During debugging I tried to compare Tool constant in the spec and in the controller and they are not equal (== returned false). Once I removed api_version from my routes and replaced it with namespace it started to work correctly.

EDIT: it doesn't work without versionist as well. It's possible that mocks just doesn't work in Rails integration tests (quite reasonable approach). Still it's a good idea to enable testing vesionist controllers in normal controller specs (to enable mocks for example).

xdmnl commented Oct 2, 2013

Using get :index, use_route: 'api/v1' seems to fix the issue of Rails not finding the route (at least with the Path Strategy).
However, it raises another error:

Failure/Error: get :index, use_route: 'api/v1'
       Missing template api/v1/base/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :arb, :jbuilder, :haml]}. Searched in:
         * "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x000000092fa9f0>"

I do have a view file in app/views/api/v1/base/index.json.jbuilder.

bploetz added a commit that referenced this issue Jan 6, 2015

@bploetz bploetz closed this Jan 6, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment