2014-05-16 18:03:13 -04:00
|
|
|
require 'test_helper'
|
2015-08-09 17:43:40 -04:00
|
|
|
require 'support/html_entity_helper'
|
2007-03-30 04:36:52 +00:00
|
|
|
|
2012-04-19 00:02:42 +02:00
|
|
|
class ContextsControllerTest < ActionController::TestCase
|
2015-08-09 17:43:40 -04:00
|
|
|
include HTMLEntityHelper
|
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
fixtures :users, :preferences, :contexts
|
|
|
|
|
|
|
|
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
|
2020-08-20 18:33:36 +03:00
|
|
|
|
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
|
2018-11-03 11:00:27 -05:00
|
|
|
get :show, params: { :id => "1" }
|
2007-05-25 19:01:08 +00:00
|
|
|
assert_equal 'TRACKS::Context: agenda', assigns['page_title']
|
|
|
|
end
|
2016-01-24 00:52:23 +01:00
|
|
|
|
|
|
|
def test_shows_todos_when_hidden
|
|
|
|
c = contexts(:agenda)
|
|
|
|
todos = c.todos.active
|
|
|
|
assert_equal 6, todos.size
|
|
|
|
c.hide!
|
|
|
|
login_as :admin_user
|
2018-11-03 11:00:27 -05:00
|
|
|
get :show, params: { :id => '1'}
|
2016-01-24 00:52:23 +01:00
|
|
|
assert_equal 6, assigns['not_done_todos'].size
|
|
|
|
end
|
|
|
|
|
2007-05-25 19:01:08 +00:00
|
|
|
def test_show_renders_show_template
|
2007-10-09 05:17:28 +00:00
|
|
|
login_as :admin_user
|
2018-11-03 11:00:27 -05:00
|
|
|
get :show, params: { :id => "1" }
|
2007-05-25 19:01:08 +00:00
|
|
|
assert_template "contexts/show"
|
|
|
|
end
|
2020-08-20 18:33:36 +03:00
|
|
|
|
2012-05-01 09:39:53 +02:00
|
|
|
def test_get_edit_form_using_xhr
|
|
|
|
login_as(:admin_user)
|
2018-11-03 11:00:27 -05:00
|
|
|
get :edit, xhr: true, params: { :id => contexts(:errand).id }
|
2012-05-01 09:39:53 +02:00
|
|
|
assert_response 200
|
|
|
|
end
|
2012-04-19 00:02:42 +02:00
|
|
|
|
|
|
|
def test_create_context_via_ajax_increments_number_of_context
|
|
|
|
login_as :other_user
|
|
|
|
assert_ajax_create_increments_count '@newcontext'
|
2007-05-25 19:01:08 +00:00
|
|
|
end
|
2012-04-19 00:02:42 +02:00
|
|
|
|
2013-03-02 14:52:03 +01:00
|
|
|
def test_update_handles_invalid_state_change
|
|
|
|
login_as :admin_user
|
|
|
|
context = users(:admin_user).contexts.first
|
2018-11-03 11:00:27 -05:00
|
|
|
put :update, xhr: true, params: { :id => context.id, :context => {:name => "@name", :state => 'closed'} }
|
2013-03-02 14:52:03 +01:00
|
|
|
|
|
|
|
assert_response 200
|
|
|
|
assert /The context cannot be closed if you have uncompleted actions/.match(@response.body)
|
|
|
|
end
|
|
|
|
|
|
|
|
# TXT feed
|
2012-04-19 15:31:18 +02:00
|
|
|
def test_text_feed_content
|
|
|
|
login_as :admin_user
|
2018-11-03 11:00:27 -05:00
|
|
|
get :index, params: { :format => "txt" }
|
2020-08-20 18:33:36 +03:00
|
|
|
assert_equal 'text/plain', @response.media_type
|
2012-04-19 15:31:18 +02:00
|
|
|
assert !(/ /.match(@response.body))
|
|
|
|
end
|
2020-08-20 18:33:36 +03:00
|
|
|
|
2012-04-19 15:31:18 +02:00
|
|
|
def test_text_feed_not_accessible_to_anonymous_user_without_token
|
|
|
|
login_as nil
|
2018-11-03 11:00:27 -05:00
|
|
|
get :index, params: { :format => "txt" }
|
2012-04-19 15:31:18 +02:00
|
|
|
assert_response 401
|
|
|
|
end
|
2020-08-20 18:33:36 +03:00
|
|
|
|
2012-04-19 15:31:18 +02:00
|
|
|
def test_text_feed_not_accessible_to_anonymous_user_with_invalid_token
|
|
|
|
login_as nil
|
2018-11-03 11:00:27 -05:00
|
|
|
get :index, params: { :format => "txt", :token => 'foo' }
|
2012-04-19 15:31:18 +02:00
|
|
|
assert_response 401
|
|
|
|
end
|
2020-08-20 18:33:36 +03:00
|
|
|
|
2012-04-19 15:31:18 +02:00
|
|
|
def test_text_feed_accessible_to_anonymous_user_with_valid_token
|
|
|
|
login_as nil
|
2018-11-03 11:00:27 -05:00
|
|
|
get :index, params: { :format => "txt", :token => users(:admin_user).token }
|
2012-04-19 15:31:18 +02:00
|
|
|
assert_response :ok
|
2008-04-28 05:53:24 +00:00
|
|
|
end
|
2012-04-19 00:02:42 +02:00
|
|
|
|
2012-04-19 15:31:18 +02:00
|
|
|
# REST xml
|
|
|
|
def test_show_xml_renders_context_to_xml
|
|
|
|
login_as :admin_user
|
2018-11-03 11:00:27 -05:00
|
|
|
get :show, params: { :id => "1", :format => 'xml' }
|
2012-04-19 15:31:18 +02:00
|
|
|
assert_equal contexts(:agenda).to_xml( :except => :user_id ), @response.body
|
|
|
|
end
|
2020-08-20 18:33:36 +03:00
|
|
|
|
2012-04-19 15:31:18 +02:00
|
|
|
def test_show_with_nil_context_returns_404
|
|
|
|
login_as :admin_user
|
2018-11-03 11:00:27 -05:00
|
|
|
get :show, params: { :id => "0" }
|
2012-04-19 15:31:18 +02:00
|
|
|
assert_equal 'Context not found', @response.body
|
|
|
|
assert_response 404
|
|
|
|
end
|
2020-08-20 18:33:36 +03:00
|
|
|
|
2012-04-19 15:31:18 +02:00
|
|
|
def test_show_xml_with_nil_context_returns_404
|
|
|
|
login_as :admin_user
|
2018-11-03 11:00:27 -05:00
|
|
|
get :show, params: { :id => "0", :format => 'xml' }
|
2012-04-19 15:31:18 +02:00
|
|
|
assert_response 404
|
2015-08-09 17:43:40 -04:00
|
|
|
assert_select 'error', 'Context not found'
|
2012-04-19 15:31:18 +02:00
|
|
|
end
|
2012-04-19 00:02:42 +02:00
|
|
|
|
2020-08-20 18:33:36 +03:00
|
|
|
# RSS
|
2012-04-19 15:31:18 +02:00
|
|
|
def test_rss_feed_content
|
|
|
|
login_as :admin_user
|
2018-11-03 11:00:27 -05:00
|
|
|
get :index, params: { :format => "rss" }
|
2020-08-20 18:33:36 +03:00
|
|
|
assert_equal 'application/rss+xml', @response.media_type
|
2012-04-19 15:31:18 +02:00
|
|
|
#puts @response.body
|
2020-08-20 18:33:36 +03:00
|
|
|
|
2015-08-09 17:43:40 -04:00
|
|
|
assert_select 'rss[version="2.0"]' do
|
2012-04-19 15:31:18 +02:00
|
|
|
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
|
|
|
|
assert_select 'item', 10 do
|
|
|
|
assert_select 'title', /.+/
|
|
|
|
assert_select 'description' do
|
|
|
|
assert_select_encoded do
|
2015-08-09 17:43:40 -04:00
|
|
|
assert_select 'p', /\d+#{nbsp}actions. Context is (Active|Hidden)./
|
2012-04-19 15:31:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
%w(guid link).each do |node|
|
|
|
|
assert_select node, /http:\/\/test.host\/contexts\/.+/
|
|
|
|
end
|
2025-06-29 13:25:14 +03:00
|
|
|
assert_select 'pubDate', contexts(:agenda).created_at.to_formatted_s(:rfc822)
|
2012-04-19 15:31:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-08-20 18:33:36 +03:00
|
|
|
|
2012-04-19 15:31:18 +02:00
|
|
|
def test_rss_feed_not_accessible_to_anonymous_user_without_token
|
|
|
|
login_as nil
|
2018-11-03 11:00:27 -05:00
|
|
|
get :index, params: { :format => "rss" }
|
2012-04-19 15:31:18 +02:00
|
|
|
assert_response 401
|
|
|
|
end
|
2020-08-20 18:33:36 +03:00
|
|
|
|
2012-04-19 15:31:18 +02:00
|
|
|
def test_rss_feed_not_accessible_to_anonymous_user_with_invalid_token
|
|
|
|
login_as nil
|
2018-11-03 11:00:27 -05:00
|
|
|
get :index, params: { :format => "rss", :token => 'foo' }
|
2012-04-19 15:31:18 +02:00
|
|
|
assert_response 401
|
|
|
|
end
|
2020-08-20 18:33:36 +03:00
|
|
|
|
2012-04-19 15:31:18 +02:00
|
|
|
def test_rss_feed_accessible_to_anonymous_user_with_valid_token
|
|
|
|
login_as nil
|
2018-11-03 11:00:27 -05:00
|
|
|
get :index, params: { :format => "rss", :token => users(:admin_user).token }
|
2012-04-19 15:31:18 +02:00
|
|
|
assert_response :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
# ATOM
|
|
|
|
def test_atom_feed_content
|
|
|
|
login_as :admin_user
|
2018-11-03 11:00:27 -05:00
|
|
|
get :index, params: { :format => "atom" }
|
2020-08-20 18:33:36 +03:00
|
|
|
assert_equal 'application/atom+xml', @response.media_type
|
2015-08-09 17:43:40 -04:00
|
|
|
assert_equal 'http://www.w3.org/2005/Atom', html_document.children[0].namespace.href
|
|
|
|
assert_select 'feed' do
|
2012-04-19 15:31:18 +02:00
|
|
|
assert_select '>title', 'Tracks Contexts'
|
|
|
|
assert_select '>subtitle', "Lists all the contexts for #{users(:admin_user).display_name}"
|
|
|
|
assert_select 'entry', 10 do
|
|
|
|
assert_select 'title', /.+/
|
|
|
|
assert_select 'content[type="html"]' do
|
|
|
|
assert_select_encoded do
|
2015-08-09 17:43:40 -04:00
|
|
|
assert_select 'p', /\d+#{nbsp}actions. Context is (Active|Hidden)./
|
2012-04-19 15:31:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
assert_select 'published', /(#{Regexp.escape(contexts(:agenda).created_at.xmlschema)}|#{Regexp.escape(contexts(:library).created_at.xmlschema)})/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-08-20 18:33:36 +03:00
|
|
|
|
2012-04-19 15:31:18 +02:00
|
|
|
def test_atom_feed_not_accessible_to_anonymous_user_without_token
|
|
|
|
login_as nil
|
2018-11-03 11:00:27 -05:00
|
|
|
get :index, params: { :format => "atom" }
|
2012-04-19 15:31:18 +02:00
|
|
|
assert_response 401
|
|
|
|
end
|
2020-08-20 18:33:36 +03:00
|
|
|
|
2012-04-19 15:31:18 +02:00
|
|
|
def test_atom_feed_not_accessible_to_anonymous_user_with_invalid_token
|
|
|
|
login_as nil
|
2018-11-03 11:00:27 -05:00
|
|
|
get :index, params: { :format => "atom", :token => 'foo' }
|
2012-04-19 15:31:18 +02:00
|
|
|
assert_response 401
|
|
|
|
end
|
2020-08-20 18:33:36 +03:00
|
|
|
|
2012-04-19 15:31:18 +02:00
|
|
|
def test_atom_feed_accessible_to_anonymous_user_with_valid_token
|
|
|
|
login_as nil
|
2018-11-03 11:00:27 -05:00
|
|
|
get :index, params: { :format => "atom", :token => users(:admin_user).token }
|
2012-04-19 15:31:18 +02:00
|
|
|
assert_response :ok
|
|
|
|
end
|
2009-10-13 23:38:25 -04:00
|
|
|
end
|