bookmark api: handle string position, fixes CNVS-20628

test plan:
  * POST this body to /ap/v1/users/self/bookmarks

{"name": "Grades List", "url": "/courses/833052/grades", "position": "0"}

  * verify that the creation succeeds and sets position to 0

Change-Id: I8504d16c110fd7fefd5796861efaf6a951045e92
Reviewed-on: https://gerrit.instructure.com/54695
Tested-by: Jenkins
Reviewed-by: Jacob Fugal <jacob@instructure.com>
QA-Review: August Thornton <august@instructure.com>
Product-Review: Braden Anderson <braden@instructure.com>
This commit is contained in:
Braden Anderson 2015-05-20 11:00:33 -06:00 committed by Braden Anderson
parent 1b078e9076
commit ec58ca7450
2 changed files with 11 additions and 4 deletions

View File

@ -5,6 +5,10 @@
# "id": "Bookmark",
# "description": "",
# "properties": {
# "id": {
# "example": 1,
# "type": "integer"
# },
# "name": {
# "example": "Biology 101",
# "type": "string"
@ -148,7 +152,7 @@ class Bookmarks::BookmarksController < ApplicationController
end
def set_position
params[:position] ? @bookmark.insert_at(params[:position]) : true
params[:position] ? @bookmark.insert_at(params[:position].to_i) : true
end
def render_errors

View File

@ -10,7 +10,7 @@ describe Bookmarks::BookmarksController do
context "when user is logged in" do
let(:u) { user }
let(:bookmark) { Bookmarks::Bookmark.create(user_id: u.id, name: 'bio 101', url: '/courses/1') }
let!(:bookmark) { Bookmarks::Bookmark.create(user_id: u.id, name: 'bio 101', url: '/courses/1') }
before(:each) do
user_session(u)
@ -67,16 +67,19 @@ describe Bookmarks::BookmarksController do
end
it "should append by default" do
bookmark
post 'create', params
expect(Bookmarks::Bookmark.order(:id).last).to be_last
end
it "should set position" do
bookmark
post 'create', params.merge(position: 1)
expect(Bookmarks::Bookmark.order(:id).last).to_not be_last
end
it "should handle position strings" do
post 'create', params.merge(position: "1")
expect(Bookmarks::Bookmark.order(:id).last).to_not be_last
end
end
describe "PUT 'update'" do