Revision 6ea38911
Added by Djebran Lezzoum almost 6 years ago
test/controllers/api/v2/bookmarks_controller_test.rb | ||
---|---|---|
get :show, params: { :id => bookmarks(:one).to_param }
|
||
assert_response :success
|
||
show_response = ActiveSupport::JSON.decode(@response.body)
|
||
assert !show_response.empty?
|
||
refute show_response.empty?
|
||
end
|
||
|
||
test "should create bookmark with valid name and query" do
|
||
... | ... | |
post :create, params: { :bookmark => simple_bookmark }
|
||
end
|
||
assert_response :created
|
||
assert_equal JSON.parse(@response.body)['controller'], simple_bookmark[:controller], "Can't create bookmark with controller #{simple_bookmark[:controller]}"
|
||
assert_equal JSON.parse(@response.body)['name'], simple_bookmark[:name], "Can't create bookmark with name #{simple_bookmark[:name]}"
|
||
assert_equal JSON.parse(@response.body)['query'], simple_bookmark[:query], "Can't create bookmark with query #{simple_bookmark[:query]}"
|
||
response = JSON.parse(@response.body)
|
||
assert_equal simple_bookmark[:controller], response['controller'], "Can't create bookmark with controller #{simple_bookmark[:controller]}"
|
||
assert_equal simple_bookmark[:name], response['name'], "Can't create bookmark with name #{simple_bookmark[:name]}"
|
||
assert_equal simple_bookmark[:query], response['query'], "Can't create bookmark with query #{simple_bookmark[:query]}"
|
||
end
|
||
|
||
test "should create bookmark with a dot" do
|
||
... | ... | |
end
|
||
|
||
test "should create bookmark with public true" do
|
||
bookmark_attr = simple_bookmark.merge(:public => true)
|
||
assert_difference('Bookmark.count') do
|
||
post :create, params: { :bookmark => simple_bookmark }
|
||
post :create, params: { :bookmark => bookmark_attr }
|
||
end
|
||
assert_response :created
|
||
assert_equal JSON.parse(@response.body)['controller'], simple_bookmark[:controller], "Can't create bookmark with controller #{simple_bookmark[:controller]}"
|
||
assert_equal JSON.parse(@response.body)['public'], simple_bookmark[:public], "Can't create bookmark with public #{simple_bookmark[:public]}"
|
||
response = JSON.parse(@response.body)
|
||
assert_equal bookmark_attr[:controller], response['controller'], "Can't create bookmark with controller #{bookmark_attr[:controller]}"
|
||
assert_equal bookmark_attr[:public], response['public'], "Can't create bookmark with public #{bookmark_attr[:public]}"
|
||
end
|
||
|
||
test "should create bookmark with public false" do
|
||
bookmark_attr = simple_bookmark.merge(:public => false)
|
||
assert_difference('Bookmark.count') do
|
||
post :create, params: { :bookmark => simple_bookmark.merge(:public => false) }
|
||
post :create, params: { :bookmark => bookmark_attr }
|
||
end
|
||
assert_response :created
|
||
assert_equal JSON.parse(@response.body)['controller'], simple_bookmark[:controller], "Can't create bookmark with controller #{simple_bookmark[:controller]}"
|
||
assert_equal JSON.parse(@response.body)['public'], false, "Can't create bookmark with public false"
|
||
response = JSON.parse(@response.body)
|
||
assert_equal bookmark_attr[:controller], response['controller'], "Can't create bookmark with controller #{bookmark_attr[:controller]}"
|
||
assert_equal bookmark_attr[:public], response['public'], "Can't create bookmark with public #{bookmark_attr[:public]}"
|
||
end
|
||
|
||
test "should update bookmark with public false" do
|
||
put :update, params: { :id => bookmarks(:one).to_param, :bookmark => dot_bookmark }
|
||
assert_response :success
|
||
assert_equal JSON.parse(@response.body)['public'], false, "Can't update bookmark with public value false"
|
||
assert_equal false, JSON.parse(@response.body)['public'], "Can't update bookmark with public value false"
|
||
end
|
||
|
||
test "should update bookmark with public true" do
|
||
bookmark = FactoryBot.create(:bookmark, :controller => "hosts", :public => false)
|
||
put :update, params: { :id => bookmark.id, :bookmark => {:public => true} }
|
||
assert_response :success
|
||
assert_equal JSON.parse(@response.body)['public'], true, "Can't update bookmark with public value true"
|
||
assert_equal true, JSON.parse(@response.body)['public'], "Can't update bookmark with public value true"
|
||
end
|
||
|
||
test "should destroy bookmark" do
|
||
... | ... | |
post :create, params: { :bookmark => simple_bookmark.merge(:query => '') }
|
||
end
|
||
assert_response :unprocessable_entity
|
||
assert_match "Query can't be blank", @response.body
|
||
end
|
||
|
||
test "should not create bookmark empty public" do
|
||
... | ... | |
post :create, params: { :bookmark => simple_bookmark.merge(:public => nil) }
|
||
end
|
||
assert_response :unprocessable_entity
|
||
assert_match 'Public is not included in the list', @response.body
|
||
end
|
||
|
||
test "should not create bookmark with already taken name" do
|
||
... | ... | |
post :create, params: { :bookmark => simple_bookmark.merge(:name => bookmarks(:one).name) }
|
||
end
|
||
assert_response :unprocessable_entity
|
||
assert_match 'Name has already been taken', @response.body
|
||
end
|
||
|
||
test "should not create bookmark with invalid name" do
|
||
... | ... | |
post :create, params: { :bookmark => simple_bookmark.merge(:name => '') }
|
||
end
|
||
assert_response :unprocessable_entity
|
||
assert_match "Name can't be blank", @response.body
|
||
end
|
||
|
||
test "should not update bookmark with empty query" do
|
Also available in: Unified diff
Refs #23132 - Robottelo tests - bookmarks (#5818)