foreman/test/functional/api/v1/reports_controller_test.rb @ d213e460
d076d573 | Joseph Mitchell Magen | require 'test_helper'
|
|
d213e460 | Daniel Lobato | require 'functional/shared/report_host_permissions_test'
|
|
d076d573 | Joseph Mitchell Magen | ||
class Api::V1::ReportsControllerTest < ActionController::TestCase
|
|||
d213e460 | Daniel Lobato | include ::ReportHostPermissionsTest
|
|
d076d573 | Joseph Mitchell Magen | test "should get index" do
|
|
8ab96869 | Joseph Mitchell Magen | get :index, { }
|
|
d076d573 | Joseph Mitchell Magen | assert_response :success
|
|
assert_not_nil assigns(:reports)
|
|||
reports = ActiveSupport::JSON.decode(@response.body)
|
|||
assert !reports.empty?
|
|||
end
|
|||
test "should show individual record" do
|
|||
8ab96869 | Joseph Mitchell Magen | get :show, { :id => reports(:report).to_param }
|
|
d076d573 | Joseph Mitchell Magen | assert_response :success
|
|
show_response = ActiveSupport::JSON.decode(@response.body)
|
|||
assert !show_response.empty?
|
|||
end
|
|||
test "should destroy report" do
|
|||
8ab96869 | Joseph Mitchell Magen | assert_difference('Report.count', -1) do
|
|
delete :destroy, { :id => reports(:report).to_param }
|
|||
d076d573 | Joseph Mitchell Magen | end
|
|
assert_response :success
|
|||
end
|
|||
25d4ca6d | Joseph Mitchell Magen | test "should get reports for given host only" do
|
|
e14b5758 | Greg Sutcliffe | report = FactoryGirl.create(:report)
|
|
get :index, {:host_id => report.host.to_param }
|
|||
25d4ca6d | Joseph Mitchell Magen | assert_response :success
|
|
assert_not_nil assigns(:reports)
|
|||
reports = ActiveSupport::JSON.decode(@response.body)
|
|||
assert !reports.empty?
|
|||
71291a46 | Dmitri Dolguikh | assert_equal 1, reports.count
|
|
25d4ca6d | Joseph Mitchell Magen | end
|
|
test "should return empty result for host with no reports" do
|
|||
e14b5758 | Greg Sutcliffe | host = FactoryGirl.create(:host)
|
|
get :index, {:host_id => host.to_param }
|
|||
25d4ca6d | Joseph Mitchell Magen | assert_response :success
|
|
assert_not_nil assigns(:reports)
|
|||
reports = ActiveSupport::JSON.decode(@response.body)
|
|||
assert reports.empty?
|
|||
71291a46 | Dmitri Dolguikh | assert_equal 0, reports.count
|
|
25d4ca6d | Joseph Mitchell Magen | end
|
|
test "should get last report" do
|
|||
e14b5758 | Greg Sutcliffe | reports = FactoryGirl.create_list(:report, 5)
|
|
25d4ca6d | Joseph Mitchell Magen | get :last
|
|
assert_response :success
|
|||
assert_not_nil assigns(:report)
|
|||
report = ActiveSupport::JSON.decode(@response.body)
|
|||
assert !report.empty?
|
|||
e14b5758 | Greg Sutcliffe | assert_equal reports.last, Report.find(report['report']['id'])
|
|
25d4ca6d | Joseph Mitchell Magen | end
|
|
test "should get last report for given host only" do
|
|||
e14b5758 | Greg Sutcliffe | main_report = FactoryGirl.create(:report)
|
|
2312cccf | Daniel Lobato | FactoryGirl.create_list(:report, 5)
|
|
e14b5758 | Greg Sutcliffe | get :last, {:host_id => main_report.host.to_param }
|
|
25d4ca6d | Joseph Mitchell Magen | assert_response :success
|
|
assert_not_nil assigns(:report)
|
|||
report = ActiveSupport::JSON.decode(@response.body)
|
|||
assert !report.empty?
|
|||
e14b5758 | Greg Sutcliffe | assert_equal main_report, Report.find(report['report']['id'])
|
|
25d4ca6d | Joseph Mitchell Magen | end
|
|
test "should give error if no last report for given host" do
|
|||
e14b5758 | Greg Sutcliffe | host = FactoryGirl.create(:host)
|
|
get :last, {:host_id => host.to_param }
|
|||
46338cd7 | Daniel Lobato | assert_response :not_found
|
|
25d4ca6d | Joseph Mitchell Magen | end
|
|
d213e460 | Daniel Lobato | ||
test 'cannot view the last report without hosts view permission' do
|
|||
setup_user('view', 'reports')
|
|||
report = FactoryGirl.create(:report)
|
|||
get :last, { :host_id => report.host.id }, set_session_user.merge(:user => User.current)
|
|||
assert_response :not_found
|
|||
end
|
|||
d076d573 | Joseph Mitchell Magen | end
|