just a simple question for a render json call I'm trying to test. I'm still learning rspec, and have tried everything and can't seem to get this to work. I keep getting an ActionController::RoutingError, even though I defined the route and the call to the api itself works.
In my controller I have the method:
class PlacesController < ApplicationController
def objects
@objects = Place.find(params[:id]).objects.active
render json: @objects.map(&:api)
end
end
with the render json: @objects.map(&:api), I'm calling the api method in the Object model
class Object
def api
{ id: id,
something: something,
something_else: something_else,
etc: etc,
...
}
end
end
My routes file:
get "places/:id/objects" => "places#objects"
my rspec: spec/controllers/places_controller_spec.rb
describe "objects" do
it "GET properties" do
m = FactoryGirl.create :object_name, _id: "1", shape: "square"
get "/places/#{m._id}/objects", {}, { "Accept" => "application/json" }
expect(response.status).to eq 200
body = JSON.parse(response.body)
expect(body["shape"]).to eq "square"
end
end
I keep getting the error
Failure/Error: get "/places/1/objects", {}, { "Accept" => "application/json" }
ActionController::RoutingError:
No route matches {:controller=>"places", :action=>"/places/1/objects"}
Any help would be much appreciated, thanks.