Revision d076d573
Added by Joseph Magen over 11 years ago
- ID d076d5731d733bbc6210c81d3b11ed7d2ba8b9d7
test/functional/api/v1/bookmarks_controller_test.rb | ||
---|---|---|
|
||
|
||
bookmark_base = {
|
||
:public => false,
|
||
:public => false,
|
||
:controller => "hosts"
|
||
}
|
||
|
||
simple_bookmark = bookmark_base.merge({
|
||
:name => "foo-bar",
|
||
:query => "bar"
|
||
})
|
||
:name => "foo-bar",
|
||
:query => "bar"
|
||
})
|
||
|
||
dot_bookmark = bookmark_base.merge({
|
||
:name => "facts.architecture",
|
||
:query => " facts.architecture = x86_64"
|
||
})
|
||
:name => "facts.architecture",
|
||
:query => " facts.architecture = x86_64"
|
||
})
|
||
|
||
|
||
test "should get index" do
|
||
as_user :admin do
|
||
get :index, {}
|
||
get :index, { }
|
||
end
|
||
assert_response :success
|
||
assert_not_nil assigns(:bookmarks)
|
||
... | ... | |
|
||
test "should show bookmark" do
|
||
as_user :admin do
|
||
get :show, {:id => bookmarks(:one).to_param}
|
||
get :show, { :id => bookmarks(:one).to_param }
|
||
end
|
||
assert_response :success
|
||
show_response = ActiveSupport::JSON.decode(@response.body)
|
||
assert !show_response.empty?
|
||
end
|
||
|
||
test "should create bookmark" do
|
||
as_user :admin do
|
||
assert_difference('Bookmark.count') do
|
||
post :create, {:bookmark => simple_bookmark}
|
||
post :create, { :bookmark => simple_bookmark }
|
||
end
|
||
end
|
||
assert_response :success
|
||
... | ... | |
test "should create bookmark with a dot" do
|
||
as_user :admin do
|
||
assert_difference('Bookmark.count') do
|
||
post :create, {:bookmark => dot_bookmark}
|
||
post :create, { :bookmark => dot_bookmark }
|
||
end
|
||
end
|
||
assert_response :success
|
||
end
|
||
|
||
test "should update bookmark" do
|
||
as_user :admin do
|
||
put :update, {:id => bookmarks(:one).to_param, :bookmark => {} }
|
||
as_user :admin do
|
||
put :update, { :id => bookmarks(:one).to_param, :bookmark => { } }
|
||
end
|
||
assert_response :success
|
||
end
|
||
... | ... | |
test "should destroy bookmark" do
|
||
as_user :admin do
|
||
assert_difference('Bookmark.count', -1) do
|
||
delete :destroy, {:id => bookmarks(:one).to_param}
|
||
delete :destroy, { :id => bookmarks(:one).to_param }
|
||
end
|
||
end
|
||
assert_response :success
|
Also available in: Unified diff
This commit adds most of the functionality required for API v1
The overall goal was to extract the existing JSON response
overall controllers, and to move them to a seperate name space.
this include same request and response generated using
APIPIE_RECORD=examples rake test:api
whats missing:
1. Permissions checks for all new controllers
2. Nested routes (e.g. /hosts/id/reports)
3. running tests with oauth/basic_auth (instead of as_admin {get /})