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:
parent
1b078e9076
commit
ec58ca7450
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue