Project

General

Profile

« Previous | Next » 

Revision b1ac29e9

Added by Lukas Zapletal about 6 years ago

Fixes #23379 - proxy stubs on API level

View differences:

test/controllers/smart_proxies_controller_test.rb
basic_pagination_per_page_test
setup do
SmartProxy.any_instance.stubs(:associate_features).returns(true)
ProxyAPI::Features.any_instance.stubs(:features => Feature.name_map.keys)
end
def test_index
......
end
def test_create_valid
ProxyAPI::Features.any_instance.stubs(:features => Feature.name_map.keys)
SmartProxy.any_instance.stubs(:valid?).returns(true)
SmartProxy.any_instance.stubs(:to_s).returns("puppet")
post :create, params: { :smart_proxy => {:name => "MySmartProxy", :url => "http://nowhere.net:8000"} }, session: set_session_user
......
def test_refresh
proxy = smart_proxies(:one)
SmartProxy.any_instance.stubs(:associate_features).returns(true)
SmartProxy.any_instance.stubs(:features).returns([features(:dns)])
post :refresh, params: { :id => proxy }, session: set_session_user
assert_redirected_to smart_proxies_url
assert_equal "No changes found when refreshing features from DHCP Proxy.", flash[:success]
......
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, params: { :id => proxy }, session: set_session_user
assert_redirected_to smart_proxies_url
......
errors = ActiveModel::Errors.new(Host::Managed.new)
errors.add :base, "Unable to communicate with the proxy: it is down"
SmartProxy.any_instance.stubs(:errors).returns(errors)
SmartProxy.any_instance.stubs(:associate_features).returns(true)
post :refresh, params: { :id => proxy }, session: set_session_user
assert_redirected_to smart_proxies_url
assert_equal "Unable to communicate with the proxy: it is down", flash[:error]

Also available in: Unified diff