2007-03-30 04:36:52 +00:00
require File . dirname ( __FILE__ ) + '/../test_helper'
require File . dirname ( __FILE__ ) + '/todo_container_controller_test_base'
require 'contexts_controller'
# Re-raise errors caught by the controller.
class ContextsController ; def rescue_action ( e ) raise e end ; end
class ContextsControllerTest < TodoContainerControllerTestBase
fixtures :users , :preferences , :contexts
def setup
perform_setup ( Context , ContextsController )
end
def test_contexts_list
2007-10-09 05:17:28 +00:00
login_as :admin_user
2007-03-30 04:36:52 +00:00
get :index
end
def test_create_context_via_ajax_increments_number_of_context
assert_ajax_create_increments_count '@newcontext'
end
def test_create_context_with_ajax_success_rjs
ajax_create '@newcontext'
assert_rjs :insert_html , :bottom , " list-contexts "
assert_rjs :sortable , 'list-contexts' , { :tag = > 'div' , :handle = > 'handle' , :complete = > visual_effect ( :highlight , 'list-contexts' ) , :url = > order_contexts_path }
# not yet sure how to write the following properly...
assert_rjs :call , " Form.reset " , " context-form "
assert_rjs :call , " Form.focusFirstElement " , " context-form "
end
2007-04-06 03:30:20 +00:00
def test_create_via_ajax_with_comma_in_name_does_not_increment_number_of_contexts
assert_ajax_create_does_not_increment_count 'foo,bar'
2007-03-30 04:36:52 +00:00
end
2007-04-06 03:30:20 +00:00
def test_create_with_comma_in_name_fails_with_rjs
ajax_create 'foo,bar'
2007-03-30 04:36:52 +00:00
assert_rjs :show , 'status'
2008-04-28 05:53:24 +00:00
# Not working with Rails 2.0 upgrade
# assert_rjs :update, 'status', "<div class=\"ErrorExplanation\" id=\"ErrorExplanation\"><h2>1 error prohibited this record from being saved</h2><p>There were problems with the following fields:</p><ul>Name cannot contain the comma (',') character</ul></div>"
2007-03-30 04:36:52 +00:00
end
def test_rss_feed_content
2007-10-09 05:17:28 +00:00
login_as :admin_user
2007-03-30 04:36:52 +00:00
get :index , { :format = > " rss " }
2008-04-28 05:53:24 +00:00
assert_equal 'application/rss+xml' , @response . content_type
2007-03-30 04:36:52 +00:00
#puts @response.body
assert_xml_select 'rss[version="2.0"]' do
assert_select 'channel' do
assert_select '>title' , 'Tracks Contexts'
assert_select '>description' , " Lists all the contexts for #{ users ( :admin_user ) . display_name } "
assert_select 'language' , 'en-us'
assert_select 'ttl' , '40'
end
2007-07-10 04:16:08 +00:00
assert_select 'item' , 10 do
2007-03-30 04:36:52 +00:00
assert_select 'title' , / .+ /
assert_select 'description' do
assert_select_encoded do
assert_select 'p' , / \ d+ actions. Context is (Active|Hidden). /
end
end
%w( guid link ) . each do | node |
assert_select node , / http: \/ \/ test.host \/ contexts \/ .+ /
end
assert_select 'pubDate' , contexts ( :agenda ) . created_at . to_s ( :rfc822 )
end
end
end
def test_rss_feed_not_accessible_to_anonymous_user_without_token
2007-10-09 05:17:28 +00:00
login_as nil
2007-03-30 04:36:52 +00:00
get :index , { :format = > " rss " }
assert_response 401
end
def test_rss_feed_not_accessible_to_anonymous_user_with_invalid_token
2007-10-09 05:17:28 +00:00
login_as nil
2007-03-30 04:36:52 +00:00
get :index , { :format = > " rss " , :token = > 'foo' }
assert_response 401
end
def test_rss_feed_accessible_to_anonymous_user_with_valid_token
2007-10-09 05:17:28 +00:00
login_as nil
2007-07-17 03:50:13 +00:00
get :index , { :format = > " rss " , :token = > users ( :admin_user ) . token }
2007-03-30 04:36:52 +00:00
assert_response :ok
end
def test_atom_feed_content
2007-10-09 05:17:28 +00:00
login_as :admin_user
2007-03-30 04:36:52 +00:00
get :index , { :format = > " atom " }
2008-04-28 05:53:24 +00:00
assert_equal 'application/atom+xml' , @response . content_type
2007-03-30 04:36:52 +00:00
#puts @response.body
assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do
assert_select '>title' , 'Tracks Contexts'
assert_select '>subtitle' , " Lists all the contexts for #{ users ( :admin_user ) . display_name } "
2007-07-10 04:16:08 +00:00
assert_select 'entry' , 10 do
2007-03-30 04:36:52 +00:00
assert_select 'title' , / .+ /
assert_select 'content[type="html"]' do
assert_select_encoded do
assert_select 'p' , / \ d+ actions. Context is (Active|Hidden). /
end
end
assert_select 'published' , / ( #{ contexts ( :agenda ) . created_at . xmlschema } | #{ contexts ( :library ) . created_at . xmlschema } ) /
end
end
end
def test_atom_feed_not_accessible_to_anonymous_user_without_token
2007-10-09 05:17:28 +00:00
login_as nil
2007-03-30 04:36:52 +00:00
get :index , { :format = > " atom " }
assert_response 401
end
def test_atom_feed_not_accessible_to_anonymous_user_with_invalid_token
2007-10-09 05:17:28 +00:00
login_as nil
2007-03-30 04:36:52 +00:00
get :index , { :format = > " atom " , :token = > 'foo' }
assert_response 401
end
def test_atom_feed_accessible_to_anonymous_user_with_valid_token
2007-10-09 05:17:28 +00:00
login_as nil
2007-07-17 03:50:13 +00:00
get :index , { :format = > " atom " , :token = > users ( :admin_user ) . token }
2007-03-30 04:36:52 +00:00
assert_response :ok
end
def test_text_feed_content
2007-10-09 05:17:28 +00:00
login_as :admin_user
2007-03-30 04:36:52 +00:00
get :index , { :format = > " txt " }
2008-04-28 05:53:24 +00:00
assert_equal 'text/plain' , @response . content_type
2007-03-30 04:36:52 +00:00
assert ! ( / / . match ( @response . body ) )
end
def test_text_feed_not_accessible_to_anonymous_user_without_token
2007-10-09 05:17:28 +00:00
login_as nil
2007-03-30 04:36:52 +00:00
get :index , { :format = > " txt " }
assert_response 401
end
def test_text_feed_not_accessible_to_anonymous_user_with_invalid_token
2007-10-09 05:17:28 +00:00
login_as nil
2007-03-30 04:36:52 +00:00
get :index , { :format = > " txt " , :token = > 'foo' }
assert_response 401
end
def test_text_feed_accessible_to_anonymous_user_with_valid_token
2007-10-09 05:17:28 +00:00
login_as nil
2007-07-17 03:50:13 +00:00
get :index , { :format = > " txt " , :token = > users ( :admin_user ) . token }
2007-03-30 04:36:52 +00:00
assert_response :ok
end
2007-05-25 19:01:08 +00:00
def test_show_sets_title
2007-10-09 05:17:28 +00:00
login_as :admin_user
2007-05-25 19:01:08 +00:00
get :show , { :id = > " 1 " }
assert_equal 'TRACKS::Context: agenda' , assigns [ 'page_title' ]
end
def test_show_renders_show_template
2007-10-09 05:17:28 +00:00
login_as :admin_user
2007-05-25 19:01:08 +00:00
get :show , { :id = > " 1 " }
assert_template " contexts/show "
end
def test_show_xml_renders_context_to_xml
2007-10-09 05:17:28 +00:00
login_as :admin_user
2007-05-25 19:01:08 +00:00
get :show , { :id = > " 1 " , :format = > 'xml' }
assert_equal contexts ( :agenda ) . to_xml ( :except = > :user_id ) , @response . body
end
def test_show_with_nil_context_returns_404
2007-10-09 05:17:28 +00:00
login_as :admin_user
2007-05-25 19:01:08 +00:00
get :show , { :id = > " 0 " }
assert_equal 'Context not found' , @response . body
assert_response 404
end
def test_show_xml_with_nil_context_returns_404
2007-10-09 05:17:28 +00:00
login_as :admin_user
2007-05-25 19:01:08 +00:00
get :show , { :id = > " 0 " , :format = > 'xml' }
assert_response 404
assert_xml_select 'error' , 'Context not found'
end
2008-04-28 05:53:24 +00:00
def protect_against_forgery?
false
end
2007-10-09 05:17:28 +00:00
end