Joost (1) [Avatar] Offline
#1
Hello,

I am using your book as a guideline to develop a similar API.

There is something that is not clear to me.
In chapter 13 you state:
"YouÂ’ll require the token attribute to be passed through in every API request, because without it you cannot be sure of who is doing what with the API. "

What method/configuration forces the passing of the token in the params when executing the 'get "#{url}.json"' ?

Here is my spec

require "spec_helper"

describe "api/v1/paintings", :type => :api do
let(:user) { create_user! }
let(:token) { user.authentication_token }
before do
@painting = FactoryGirl.create(:painting, user: user)
FactoryGirl.create(:painting, :name => "Not created by me 1"smilie
FactoryGirl.create(:painting, :name => "Not created by me 2"smilie
FactoryGirl.create(:painting, :name => "Not created by me 3"smilie
FactoryGirl.create(:painting, :name => "Not created by me 4"smilie
end
context "paintings viewable by this user" do
let(:url) { "/api/v1/paintings" }
it "json" do
get "#{url}.json"
paintings_json = user.paintings.to_json
last_response.body.should eql(paintings_json)
last_response.status.should eql(200)
paintings = JSON.parse(last_response.body)
paintings.any? do |p|
p["painting"]["name"] == "Mona Lisa"
end.should be_true
end
end
end

When I launch the spec before implementing my api paintings_controller.rb

I get the following:

Failures:

1) api/v1/paintings paintings viewable by this user json
Failure/Error: get "#{url}.json"
ActionController::RoutingError:
uninitialized constant Api::V1:smilieaintingsController
# ./spec/apis/v1/paintings_spec.rb:17:in `block (3 levels) in <top (required)>'

Finished in 0.68432 seconds
1 example, 1 failure

As you can see I don't get the part of the " :token => token" as specified in your book.

Failures: 1) /api/v1/projects projects viewable by this user index JSON
Failure/Error: get "#{url}.json", :token => token uninitialized constant Api::V1:smilierojectsController

Thanks in advance for any feedback,

Joost