foreman/test/functional/reports_controller_test.rb @ be0b9bee
eafaf5f1 | Ohad Levy | require 'test_helper'
|
|
be0b9bee | Daniel Lobato | require 'functional/shared/report_host_permissions_test'
|
|
eafaf5f1 | Ohad Levy | ||
class ReportsControllerTest < ActionController::TestCase
|
|||
be0b9bee | Daniel Lobato | include ::ReportHostPermissionsTest
|
|
91ad276d | Greg Sutcliffe | ||
459e0feb | Paul Kelly | def test_index
|
|
aa1796f3 | Paul Kelly | get :index, {}, set_session_user
|
|
459e0feb | Paul Kelly | assert_response :success
|
|
assert_not_nil assigns('reports')
|
|||
assert_template 'index'
|
|||
ad386618 | José Luis Escalante | end
|
|
ff9305cd | Ohad Levy | ||
459e0feb | Paul Kelly | def test_show
|
|
e14b5758 | Greg Sutcliffe | report = FactoryGirl.create(:report)
|
|
get :show, {:id => report.id}, set_session_user
|
|||
459e0feb | Paul Kelly | assert_template 'show'
|
|
14ccd229 | José Luis Escalante | end
|
|
be0b9bee | Daniel Lobato | test '404 on show when id is blank' do
|
|
get :show, {:id => ' '}, set_session_user
|
|||
assert_response :missing
|
|||
assert_template 'common/404'
|
|||
end
|
|||
f3c1ecd3 | Ohad Levy | def test_show_last
|
|
2312cccf | Daniel Lobato | FactoryGirl.create(:report)
|
|
f3c1ecd3 | Ohad Levy | get :show, {:id => "last"}, set_session_user
|
|
assert_template 'show'
|
|||
end
|
|||
be0b9bee | Daniel Lobato | test '404 on last when no reports available' do
|
|
get :show, { :id => 'last', :host_id => FactoryGirl.create(:host) }, set_session_user
|
|||
assert_response :missing
|
|||
assert_template 'common/404'
|
|||
end
|
|||
f3c1ecd3 | Ohad Levy | def test_show_last_report_for_host
|
|
e14b5758 | Greg Sutcliffe | report = FactoryGirl.create(:report)
|
|
get :show, {:id => "last", :host_id => report.host.to_param}, set_session_user
|
|||
f3c1ecd3 | Ohad Levy | assert_template 'show'
|
|
end
|
|||
def test_render_404_when_invalid_report_for_a_host_is_requested
|
|||
get :show, {:id => "last", :host_id => "blalala.domain.com"}, set_session_user
|
|||
assert_response :missing
|
|||
assert_template 'common/404'
|
|||
end
|
|||
459e0feb | Paul Kelly | def test_destroy
|
|
e14b5758 | Greg Sutcliffe | report = FactoryGirl.create(:report)
|
|
aa1796f3 | Paul Kelly | delete :destroy, {:id => report}, set_session_user
|
|
459e0feb | Paul Kelly | assert_redirected_to reports_url
|
|
assert !Report.exists?(report.id)
|
|||
end
|
|||
070f070b | José Luis Escalante | ||
ad386618 | José Luis Escalante | test "should show report" do
|
|
create_a_report
|
|||
assert @report.save!
|
|||
070f070b | José Luis Escalante | ||
9c0e127b | Paul Kelly | get :show, {:id => @report.id}, set_session_user
|
|
ad386618 | José Luis Escalante | assert_response :success
|
|
end
|
|||
14ccd229 | José Luis Escalante | ||
test "should destroy report" do
|
|||
create_a_report
|
|||
assert @report.save!
|
|||
assert_difference('Report.count', -1) do
|
|||
9c0e127b | Paul Kelly | delete :destroy, {:id => @report.id}, set_session_user
|
|
14ccd229 | José Luis Escalante | end
|
|
assert_redirected_to reports_path
|
|||
end
|
|||
be0b9bee | Daniel Lobato | test 'cannot view the last report without hosts view permission' do
|
|
setup_user('view', 'reports')
|
|||
report = FactoryGirl.create(:report)
|
|||
get :show, { :id => 'last', :host_id => report.host.id }, set_session_user.merge(:user => User.current)
|
|||
assert_response :not_found
|
|||
ff9305cd | Ohad Levy | end
|
|
9fd7478e | Paul Kelly | ||
be0b9bee | Daniel Lobato | private
|
|
9fd7478e | Paul Kelly | ||
be0b9bee | Daniel Lobato | def create_a_report
|
|
@report = Report.import JSON.parse(File.read(File.expand_path(File.dirname(__FILE__) + "/../fixtures/report-empty.json")))
|
|||
9fd7478e | Paul Kelly | end
|
|
eafaf5f1 | Ohad Levy | end
|