require 'setup' spec :api do it 'should contain only public non-inherited methods' do c = mock_controller { basic_auth {} digest_auth {} token_auth {} error(500) {} before {} around {} after {} use proc {} sessions :cookies engine :ERB layout :main define_layout(:main) {} define_layout(:file, file: :file) define_template(:main) {} define_template(:file, file: :file) define_template_var(:var) {} } assert(c.api).empty? end it 'should inherit api methods' do a = mock_controller { def x; end } b = mock_controller(a) { def y; end } assert(b.api).include?(:x) assert(b.api).include?(:y) end context :private_api do it 'should contain auth methods' do c = mock_controller { basic_auth {} digest_auth {} token_auth {} } assert(c.private_api).include?(:basic_auth) assert(c.private_api).include?(:__basic_auth__get__) assert(c.private_api).include?(:digest_auth) assert(c.private_api).include?(:__digest_auth__get__) assert(c.private_api).include?(:token_auth) end it 'should contain error handler methods' do c = mock_controller { error(500) {} } assert(c.private_api).include?(:error_handlers) assert(c.private_api).include?(:__404_error_handler__) assert(c.private_api).include?(:__409_error_handler__) assert(c.private_api).include?(:__501_error_handler__) end it 'should contain filters methods' do c = mock_controller { before {} around {} after {} } assert(c.private_api).include?(:before) assert(c.private_api).include?(:'__before_*__') assert(c.private_api).include?(:around) assert(c.private_api).include?(:'__around_*__') assert(c.private_api).include?(:after) assert(c.private_api).include?(:'__after_*__') end it 'should contain middleware methods' do c = mock_controller { use proc {} } assert(c.private_api).include?(:middleware) end it 'should contain session methods' do c = mock_controller { sessions :cookies } assert(c.private_api).include?(:sessions) end context :render do it 'should contain engine methods' do c = mock_controller { engine :ERB } assert(c.private_api).include?(:engine) end it 'should contain engine methods when engine defined as block' do c = mock_controller { engine {:ERB} } assert(c.private_api).include?(:engine) assert(c.private_api).include?(:__rocketio_engine__) end it 'should contain layout methods' do c = mock_controller { layout :main define_layout(:main) {} define_layout(:file, file: :file) } assert(c.private_api).include?(:layout) assert(c.private_api).include?(:layouts) assert(c.private_api).include?(:__file_layout_file__) assert(c.private_api).include?(:__file_layout__) end it 'should contain template methods' do c = mock_controller { define_template(:main) {} define_template(:file, file: :file) } assert(c.private_api).include?(:templates) assert(c.private_api).include?(:__file_template_file__) assert(c.private_api).include?(:__file_template__) end it 'should contain template_var methods' do c = mock_controller { define_template_var(:var) {} } assert(c.private_api).include?(:__template_vars__) assert(c.private_api).include?(:__var_template_var__) end end end end