foreman/test/functional/smart_proxies_controller_test.rb @ 428b1cfb
06823dc7 | Ohad Levy | require 'test_helper'
|
|
class SmartProxiesControllerTest < ActionController::TestCase
|
|||
def test_index
|
|||
c4547812 | Paul Kelly | get :index, {}, set_session_user
|
|
06823dc7 | Ohad Levy | assert_template 'index'
|
|
end
|
|||
def test_new
|
|||
c4547812 | Paul Kelly | get :new, {}, set_session_user
|
|
06823dc7 | Ohad Levy | assert_template 'new'
|
|
end
|
|||
def test_create_invalid
|
|||
SmartProxy.any_instance.stubs(:valid?).returns(false)
|
|||
c4547812 | Paul Kelly | post :create, {}, set_session_user
|
|
06823dc7 | Ohad Levy | assert_template 'new'
|
|
end
|
|||
def test_create_valid
|
|||
SmartProxy.any_instance.stubs(:valid?).returns(true)
|
|||
dbb7c2f2 | Paul Kelly | SmartProxy.any_instance.stubs(:to_s).returns("puppet")
|
|
c4547812 | Paul Kelly | post :create, {}, set_session_user
|
|
06823dc7 | Ohad Levy | assert_redirected_to smart_proxies_url
|
|
end
|
|||
def test_edit
|
|||
c4547812 | Paul Kelly | get :edit, {:id => SmartProxy.first}, set_session_user
|
|
06823dc7 | Ohad Levy | assert_template 'edit'
|
|
end
|
|||
def test_update_invalid
|
|||
SmartProxy.any_instance.stubs(:valid?).returns(false)
|
|||
c4547812 | Paul Kelly | put :update, {:id => SmartProxy.first}, set_session_user
|
|
06823dc7 | Ohad Levy | assert_template 'edit'
|
|
end
|
|||
def test_update_valid
|
|||
SmartProxy.any_instance.stubs(:valid?).returns(true)
|
|||
c4547812 | Paul Kelly | put :update, {:id => SmartProxy.first}, set_session_user
|
|
06823dc7 | Ohad Levy | assert_redirected_to smart_proxies_url
|
|
end
|
|||
def test_destroy
|
|||
proxy = SmartProxy.first
|
|||
proxy.subnets.clear
|
|||
proxy.domains.clear
|
|||
c4547812 | Paul Kelly | delete :destroy, {:id => proxy}, set_session_user
|
|
06823dc7 | Ohad Levy | assert_redirected_to smart_proxies_url
|
|
assert !SmartProxy.exists?(proxy.id)
|
|||
end
|
|||
b28fdce4 | Ohad Levy | ||
c3d8dd61 | Dominic Cleal | def test_refresh
|
|
proxy = smart_proxies(:one)
|
|||
SmartProxy.any_instance.stubs(:associate_features).returns(true)
|
|||
post :refresh, {:id => proxy}, set_session_user
|
|||
assert_redirected_to smart_proxies_url
|
|||
assert_equal "No changes found when refreshing features from DHCP Proxy.", flash[:notice]
|
|||
end
|
|||
def test_refresh_change
|
|||
proxy = smart_proxies(:one)
|
|||
SmartProxy.any_instance.stubs(:associate_features).returns(true)
|
|||
SmartProxy.any_instance.stubs(:features).returns([features(:dns)]).then.returns([features(:dns), features(:tftp)])
|
|||
post :refresh, {:id => proxy}, set_session_user
|
|||
assert_redirected_to smart_proxies_url
|
|||
assert_equal "Successfully refreshed features from DHCP Proxy.", flash[:notice]
|
|||
end
|
|||
def test_refresh_fail
|
|||
proxy = smart_proxies(:one)
|
|||
errors = ActiveModel::Errors.new(Host::Managed.new)
|
|||
errors.add :base, "Unable to communicate with the proxy: it's down"
|
|||
SmartProxy.any_instance.stubs(:errors).returns(errors)
|
|||
SmartProxy.any_instance.stubs(:associate_features).returns(true)
|
|||
post :refresh, {:id => proxy}, set_session_user
|
|||
assert_redirected_to smart_proxies_url
|
|||
assert_equal "Unable to communicate with the proxy: it's down", flash[:error]
|
|||
end
|
|||
428b1cfb | Joseph Magen | test "should search by name" do
|
|
get :index, { :search => "name=\"DNS Proxy\"" }, set_session_user
|
|||
assert_response :success
|
|||
refute_empty assigns(:smart_proxies)
|
|||
assert assigns(:smart_proxies).include?(smart_proxies(:three))
|
|||
end
|
|||
test "should search by feature" do
|
|||
get :index, { :search => "feature=DNS" }, set_session_user
|
|||
assert_response :success
|
|||
refute_empty assigns(:smart_proxies)
|
|||
assert assigns(:smart_proxies).include?(smart_proxies(:three))
|
|||
end
|
|||
06823dc7 | Ohad Levy | end
|