mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-16 12:18:07 +01:00
The contexts controller gets more RESTy. It now supports XML, RSS, ATOM, HTML and plain text views of the contexts list.
Changes include:
* Update the URL on the Feeds page to use /contexts.rss or /contexts.txt instead of FeedController? link
* Add created_at and updated_at timestamps to contexts table to support ATOM feeds
Notes:
* This will break previous context listing feed subscriptions.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@423 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
6045a7a986
commit
fcab16a5c2
15 changed files with 202 additions and 40 deletions
24
tracks/test/fixtures/contexts.yml
vendored
24
tracks/test/fixtures/contexts.yml
vendored
|
|
@ -1,11 +1,19 @@
|
|||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
<%
|
||||
|
||||
def today
|
||||
Time.now.utc.to_s(:db)
|
||||
end
|
||||
|
||||
%>
|
||||
agenda:
|
||||
id: 1
|
||||
name: agenda
|
||||
position: 1
|
||||
hide: false
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
||||
call:
|
||||
id: 2
|
||||
|
|
@ -13,6 +21,8 @@ call:
|
|||
position: 2
|
||||
hide: false
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
||||
email:
|
||||
id: 3
|
||||
|
|
@ -20,6 +30,8 @@ email:
|
|||
position: 3
|
||||
hide: false
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
||||
errand:
|
||||
id: 4
|
||||
|
|
@ -27,6 +39,8 @@ errand:
|
|||
position: 4
|
||||
hide: false
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
||||
lab:
|
||||
id: 5
|
||||
|
|
@ -34,6 +48,8 @@ lab:
|
|||
position: 5
|
||||
hide: false
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
||||
library:
|
||||
id: 6
|
||||
|
|
@ -41,6 +57,8 @@ library:
|
|||
position: 6
|
||||
hide: false
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
||||
freetime:
|
||||
id: 7
|
||||
|
|
@ -48,6 +66,8 @@ freetime:
|
|||
position: 7
|
||||
hide: false
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
||||
office:
|
||||
id: 8
|
||||
|
|
@ -55,6 +75,8 @@ office:
|
|||
position: 8
|
||||
hide: false
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
||||
waitingfor:
|
||||
id: 9
|
||||
|
|
@ -62,3 +84,5 @@ waitingfor:
|
|||
position: 9
|
||||
hide: false
|
||||
user_id: 1
|
||||
created_at: <%= today %>
|
||||
updated_at: <%= today %>
|
||||
|
|
|
|||
|
|
@ -39,5 +39,107 @@ class ContextsControllerTest < TodoContainerControllerTestBase
|
|||
assert_rjs :show, 'status'
|
||||
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 slash ('/') character</ul></div>"
|
||||
end
|
||||
|
||||
def test_rss_feed_content
|
||||
@request.session['user_id'] = users(:admin_user).id
|
||||
get :index, { :format => "rss" }
|
||||
assert_equal 'application/rss+xml; charset=utf-8', @response.headers["Content-Type"]
|
||||
#puts @response.body
|
||||
|
||||
assert_xml_select 'rss[version="2.0"]' do
|
||||
assert_xml_select 'channel' do
|
||||
assert_xml_select '>title', 'Tracks Contexts'
|
||||
assert_xml_select '>description', "Lists all the contexts for #{users(:admin_user).display_name}."
|
||||
assert_xml_select 'language', 'en-us'
|
||||
assert_xml_select 'ttl', '40'
|
||||
end
|
||||
assert_xml_select 'item', 9 do
|
||||
assert_xml_select 'title', /.+/
|
||||
assert_xml_select 'description', /<p>\d+ actions. Context is (active|hidden). <\/p>/
|
||||
%w(guid link).each do |node|
|
||||
assert_xml_select node, /http:\/\/test.host\/contexts\/.+/
|
||||
end
|
||||
assert_xml_select 'pubDate', contexts(:agenda).created_at.to_s(:rfc822)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_rss_feed_not_accessible_to_anonymous_user_without_token
|
||||
@request.session['user_id'] = nil
|
||||
get :index, { :format => "rss" }
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
def test_rss_feed_not_accessible_to_anonymous_user_with_invalid_token
|
||||
@request.session['user_id'] = nil
|
||||
get :index, { :format => "rss", :token => 'foo' }
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
def test_rss_feed_accessible_to_anonymous_user_with_valid_token
|
||||
@request.session['user_id'] = nil
|
||||
get :index, { :format => "rss", :token => users(:admin_user).word }
|
||||
assert_response :ok
|
||||
end
|
||||
|
||||
def test_atom_feed_content
|
||||
@request.session['user_id'] = users(:admin_user).id
|
||||
get :index, { :format => "atom" }
|
||||
assert_equal 'application/atom+xml; charset=utf-8', @response.headers["Content-Type"]
|
||||
#puts @response.body
|
||||
|
||||
assert_xml_select 'feed[xmlns="http://www.w3.org/2005/Atom"]' do
|
||||
assert_xml_select '>title', 'Tracks Contexts'
|
||||
assert_xml_select '>subtitle', "Lists all the contexts for #{users(:admin_user).display_name}."
|
||||
assert_xml_select 'entry', 3 do
|
||||
assert_xml_select 'title', /.+/
|
||||
assert_xml_select 'content[type="html"]', /<p>\d+ actions. Context is (active|hidden). <\/p>/
|
||||
assert_xml_select 'published', contexts(:agenda).created_at.to_s(:rfc822)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_atom_feed_not_accessible_to_anonymous_user_without_token
|
||||
@request.session['user_id'] = nil
|
||||
get :index, { :format => "atom" }
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
def test_atom_feed_not_accessible_to_anonymous_user_with_invalid_token
|
||||
@request.session['user_id'] = nil
|
||||
get :index, { :format => "atom", :token => 'foo' }
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
def test_atom_feed_accessible_to_anonymous_user_with_valid_token
|
||||
@request.session['user_id'] = nil
|
||||
get :index, { :format => "atom", :token => users(:admin_user).word }
|
||||
assert_response :ok
|
||||
end
|
||||
|
||||
def test_text_feed_content
|
||||
@request.session['user_id'] = users(:admin_user).id
|
||||
get :index, { :format => "txt" }
|
||||
assert_equal 'text/plain; charset=utf-8', @response.headers["Content-Type"]
|
||||
#puts @response.body
|
||||
end
|
||||
|
||||
def test_text_feed_not_accessible_to_anonymous_user_without_token
|
||||
@request.session['user_id'] = nil
|
||||
get :index, { :format => "txt" }
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
def test_text_feed_not_accessible_to_anonymous_user_with_invalid_token
|
||||
@request.session['user_id'] = nil
|
||||
get :index, { :format => "txt", :token => 'foo' }
|
||||
assert_response 401
|
||||
end
|
||||
|
||||
def test_text_feed_accessible_to_anonymous_user_with_valid_token
|
||||
@request.session['user_id'] = nil
|
||||
get :index, { :format => "txt", :token => users(:admin_user).word }
|
||||
assert_response :ok
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ require 'contexts_controller'
|
|||
# Re-raise errors caught by the controller.
|
||||
class ContextsController; def rescue_action(e) raise e end; end
|
||||
|
||||
class ContextsControllerXmlApiTest < ActionController::IntegrationTest
|
||||
class ContextXmlApiTest < ActionController::IntegrationTest
|
||||
fixtures :users, :contexts
|
||||
|
||||
@@context_name = "@newcontext"
|
||||
|
|
@ -51,7 +51,7 @@ class ContextsControllerXmlApiTest < ActionController::IntegrationTest
|
|||
def test_creates_new_context
|
||||
initial_count = Context.count
|
||||
authenticated_post_xml_to_context_create
|
||||
assert_response_and_body_matches 200, %r|^<\?xml version="1.0" encoding="UTF-8"\?>\n<context>\n <hide type="integer">0</hide>\n <id type="integer">\d+</id>\n <name>#{@@context_name}</name>\n <position type="integer">1</position>\n</context>\n$|
|
||||
assert_response_and_body_matches 200, %r|^<\?xml version="1.0" encoding="UTF-8"\?>\n<context>\n <created-at type=\"datetime\">\d{4}+-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z</created-at>\n <hide type="integer">0</hide>\n <id type="integer">\d+</id>\n <name>#{@@context_name}</name>\n <position type="integer">1</position>\n <updated-at type=\"datetime\">\d{4}+-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z</updated-at>\n</context>\n$|
|
||||
assert_equal initial_count + 1, Context.count
|
||||
context1 = Context.find_by_name(@@context_name)
|
||||
assert_not_nil context1, "expected context '#{@@context_name}' to be created"
|
||||
|
|
|
|||
|
|
@ -72,11 +72,11 @@ class FeedSmokeTest < ActionController::IntegrationTest
|
|||
end
|
||||
|
||||
def test_all_contexts_rss
|
||||
assert_success "/contexts/feed/rss/admin/#{ users(:admin_user).word }"
|
||||
assert_success "/contexts.rss?token=#{ users(:admin_user).word }"
|
||||
end
|
||||
|
||||
def test_all_contexts_txt
|
||||
assert_success "/contexts/feed/text/admin/#{ users(:admin_user).word }"
|
||||
assert_success "/contexts.txt?token=#{ users(:admin_user).word }"
|
||||
end
|
||||
|
||||
def test_all_projects_rss
|
||||
|
|
|
|||
|
|
@ -107,6 +107,9 @@ class ContextTest < Test::Unit::TestCase
|
|||
def test_to_param_returns_url_friendly_name
|
||||
assert_equal 'agenda', @agenda.to_param
|
||||
end
|
||||
|
||||
|
||||
def test_title_reader_returns_name
|
||||
assert_equal @agenda.name, @agenda.title
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue