From d0906c67e08b3eba06121e63ecb1717c513ea50e Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Nov 2014 21:19:09 -0700 Subject: restrict the number of tutorials that can be fetched at once. --- app/controllers/api/v1/tutorials_controller.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'app/controllers/api/v1/tutorials_controller.rb') diff --git a/app/controllers/api/v1/tutorials_controller.rb b/app/controllers/api/v1/tutorials_controller.rb index c257f707..a264a09b 100644 --- a/app/controllers/api/v1/tutorials_controller.rb +++ b/app/controllers/api/v1/tutorials_controller.rb @@ -1,10 +1,8 @@ module Api module V1 class TutorialsController < ApiController - respond_to :json - def index - respond_with(@tutorials = current_user.tutorials) + @tutorials = current_user.tutorials.page(page).per(per_page) end def create -- cgit v1.2.3 From 66c09b81c3a4baeb0ca39a1e87496cca53a43a7c Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 22 Nov 2014 21:26:43 -0700 Subject: render proper json when creating a new tutorial. --- app/controllers/api/v1/tutorials_controller.rb | 1 - app/views/api/v1/tutorials/create.json.jbuilder | 3 +++ spec/controllers/api/v1/tutorials_controller_spec.rb | 5 ++--- 3 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 app/views/api/v1/tutorials/create.json.jbuilder (limited to 'app/controllers/api/v1/tutorials_controller.rb') diff --git a/app/controllers/api/v1/tutorials_controller.rb b/app/controllers/api/v1/tutorials_controller.rb index a264a09b..8c75dbf0 100644 --- a/app/controllers/api/v1/tutorials_controller.rb +++ b/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 diff --git a/app/views/api/v1/tutorials/create.json.jbuilder b/app/views/api/v1/tutorials/create.json.jbuilder new file mode 100644 index 00000000..cfc0f35b --- /dev/null +++ b/app/views/api/v1/tutorials/create.json.jbuilder @@ -0,0 +1,3 @@ +json.tutorial do + json.partial! 'tutorial', tutorial: tutorial +end diff --git a/spec/controllers/api/v1/tutorials_controller_spec.rb b/spec/controllers/api/v1/tutorials_controller_spec.rb index 435e6136..7d7ef5c6 100644 --- a/spec/controllers/api/v1/tutorials_controller_spec.rb +++ b/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]) -- cgit v1.2.3