Commit 66c09b81
Changed files (3)
app
controllers
api
views
api
v1
tutorials
spec
controllers
api
app/controllers/api/v1/tutorials_controller.rb
@@ -8,7 +8,6 @@ module Api
def create
@tutorial = current_user.tutorials.create!(tutorial_params)
current_user.tag(@tutorial, with: params[:tutorial][:tags], on: :tags)
- respond_with(@tutorial)
end
private
app/views/api/v1/tutorials/create.json.jbuilder
@@ -0,0 +1,3 @@
+json.tutorial do
+ json.partial! 'tutorial', tutorial: tutorial
+end
spec/controllers/api/v1/tutorials_controller_spec.rb
@@ -11,9 +11,8 @@ describe Api::V1::TutorialsController do
let(:my_tutorial) { create(:tutorial, user: user) }
let(:other_tutorial) { create(:tutorial) }
-
it "returns the users tutorials" do
- get :index, format: :json
+ xhr :get, :index
expect(assigns(:tutorials)).to include(my_tutorial)
expect(assigns(:tutorials)).to_not include(other_tutorial)
end
@@ -28,7 +27,7 @@ describe Api::V1::TutorialsController do
description: "Connect with your friends - and other fascinating people. Get in-the-moment updates on the things that interest you. And watch events unfold, in real time, from every angle.",
tags: "cake,cookie",
}
- post :create, tutorial: attributes, format: :json
+ xhr :post, :create, tutorial: attributes
expect(assigns(:tutorial)).to be_present
expect(assigns(:tutorial).url).to eql(attributes[:url])