mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
Getting functional tests running.
This commit is contained in:
parent
fd433d76d8
commit
76340b780c
22 changed files with 267 additions and 216 deletions
16
Gemfile.lock
16
Gemfile.lock
|
|
@ -41,13 +41,14 @@ GEM
|
||||||
coffee-script-source
|
coffee-script-source
|
||||||
execjs
|
execjs
|
||||||
coffee-script-source (1.3.1)
|
coffee-script-source (1.3.1)
|
||||||
|
daemons (1.0.10)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
execjs (1.3.0)
|
execjs (1.3.0)
|
||||||
multi_json (~> 1.0)
|
multi_json (~> 1.0)
|
||||||
|
gem_plugin (0.2.3)
|
||||||
highline (1.5.2)
|
highline (1.5.2)
|
||||||
hike (1.2.1)
|
hike (1.2.1)
|
||||||
htmlentities (4.3.1)
|
htmlentities (4.3.1)
|
||||||
httpclient (2.2.4)
|
|
||||||
i18n (0.6.0)
|
i18n (0.6.0)
|
||||||
journey (1.0.3)
|
journey (1.0.3)
|
||||||
jquery-rails (2.0.2)
|
jquery-rails (2.0.2)
|
||||||
|
|
@ -59,7 +60,10 @@ GEM
|
||||||
mime-types (~> 1.16)
|
mime-types (~> 1.16)
|
||||||
treetop (~> 1.4.8)
|
treetop (~> 1.4.8)
|
||||||
mime-types (1.18)
|
mime-types (1.18)
|
||||||
multi_json (1.2.0)
|
mongrel (1.2.0.pre2)
|
||||||
|
daemons (~> 1.0.10)
|
||||||
|
gem_plugin (~> 0.2.3)
|
||||||
|
multi_json (1.3.2)
|
||||||
mysql2 (0.3.11)
|
mysql2 (0.3.11)
|
||||||
nokogiri (1.4.7)
|
nokogiri (1.4.7)
|
||||||
polyglot (0.3.3)
|
polyglot (0.3.3)
|
||||||
|
|
@ -97,13 +101,12 @@ GEM
|
||||||
railties (~> 3.2.0)
|
railties (~> 3.2.0)
|
||||||
sass (>= 3.1.10)
|
sass (>= 3.1.10)
|
||||||
tilt (~> 1.3)
|
tilt (~> 1.3)
|
||||||
soap4r (1.5.8)
|
soap4r-ruby1.9 (2.0.5)
|
||||||
httpclient (>= 2.1.1)
|
|
||||||
sprockets (2.1.2)
|
sprockets (2.1.2)
|
||||||
hike (~> 1.2)
|
hike (~> 1.2)
|
||||||
rack (~> 1.0)
|
rack (~> 1.0)
|
||||||
tilt (~> 1.1, != 1.3.0)
|
tilt (~> 1.1, != 1.3.0)
|
||||||
sqlite3 (1.3.5)
|
sqlite3 (1.3.6)
|
||||||
swf_fu (2.0.1)
|
swf_fu (2.0.1)
|
||||||
coffee-script
|
coffee-script
|
||||||
rails (~> 3.1)
|
rails (~> 3.1)
|
||||||
|
|
@ -132,12 +135,13 @@ DEPENDENCIES
|
||||||
htmlentities (~> 4.3.0)
|
htmlentities (~> 4.3.0)
|
||||||
jquery-rails
|
jquery-rails
|
||||||
mail
|
mail
|
||||||
|
mongrel (= 1.2.0.pre2)
|
||||||
mysql2
|
mysql2
|
||||||
rails (= 3.2.3)
|
rails (= 3.2.3)
|
||||||
rails_autolink
|
rails_autolink
|
||||||
sanitize (~> 1.2.1)
|
sanitize (~> 1.2.1)
|
||||||
sass-rails (~> 3.2.3)
|
sass-rails (~> 3.2.3)
|
||||||
soap4r (~> 1.5.8)
|
soap4r-ruby1.9
|
||||||
sqlite3
|
sqlite3
|
||||||
swf_fu
|
swf_fu
|
||||||
uglifier (>= 1.0.3)
|
uglifier (>= 1.0.3)
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ module ApplicationHelper
|
||||||
# actions or multiple actions
|
# actions or multiple actions
|
||||||
#
|
#
|
||||||
def count_undone_todos_phrase(todos_parent)
|
def count_undone_todos_phrase(todos_parent)
|
||||||
@controller.count_undone_todos_phrase(todos_parent)
|
controller.count_undone_todos_phrase(todos_parent)
|
||||||
end
|
end
|
||||||
|
|
||||||
def count_undone_todos_phrase_text(todos_parent)
|
def count_undone_todos_phrase_text(todos_parent)
|
||||||
|
|
@ -268,5 +268,13 @@ module ApplicationHelper
|
||||||
all_done_todos_path
|
all_done_todos_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_list_of_error_messages_for(model)
|
||||||
|
error_messages = ""
|
||||||
|
if model.errors.any?
|
||||||
|
list_of_messages = model.errors.full_messages.inject("") { |all, msg| all += content_tag(:li, msg) }
|
||||||
|
error_messages = content_tag(:ul, list_of_messages)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,14 @@ module TodosHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def collapsed_notes_image(todo)
|
def collapsed_notes_image(todo)
|
||||||
link = link_to(image_tag( 'blank.png', :width=>'16', :height=>'16', :border=>'0' ), "#", {:class => 'show_notes', :title => 'Show notes'})
|
link = link_to(
|
||||||
notes = content_tag(:div, {:class => "todo_notes", :id => dom_id(todo, 'notes'), :style => "display:none"}) { todo.rendered_notes.html_safe }
|
image_tag( 'blank.png', :width=>'16', :height=>'16', :border=>'0' ),
|
||||||
|
"#",
|
||||||
|
{:class => 'show_notes', :title => 'Show notes'})
|
||||||
|
notes = content_tag(:div, {
|
||||||
|
:class => "todo_notes",
|
||||||
|
:id => dom_id(todo, 'notes'),
|
||||||
|
:style => "display:none"}) { raw todo.rendered_notes }
|
||||||
return link+notes
|
return link+notes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ class Preference < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :sms_context, :class_name => 'Context'
|
belongs_to :sms_context, :class_name => 'Context'
|
||||||
|
|
||||||
|
attr_accessible :date_format, :week_starts, :show_number_completed, :show_completed_projects_in_sidebar,
|
||||||
|
:show_hidden_contexts_in_sidebar, :staleness_starts, :due_style, :admin_email
|
||||||
|
|
||||||
def self.due_styles
|
def self.due_styles
|
||||||
{ :due_in_n_days => 0, :due_on => 1}
|
{ :due_in_n_days => 0, :due_on => 1}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,15 @@
|
||||||
<div id="context_new" class="context_new" style="display:block">
|
<div id="context_new" class="context_new" style="display:block">
|
||||||
<%= form_for(@new_context, :html => {:id => 'context-form',:name=>'context',:class => "inline-form", :method => :post }) do -%>
|
<%= form_for(@new_context, :html => {:id => 'context-form',:name=>'context',:class => "inline-form", :method => :post }) do -%>
|
||||||
|
|
||||||
<div id="error_status"><%= error_messages_for('context') %></div>
|
<div id="error_status">
|
||||||
|
<% if @new_context.errors.any? -%>
|
||||||
|
<ul>
|
||||||
|
<% @new_context.errors.full_messages.each do |msg| %>
|
||||||
|
<li><%= msg %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
<% end -%>
|
||||||
|
</div>
|
||||||
|
|
||||||
<label for="context_name"><%= t 'contexts.context_name' %></label><br />
|
<label for="context_name"><%= t 'contexts.context_name' %></label><br />
|
||||||
<%= text_field( "context", "name", :tabindex => next_tab_index ) %><br />
|
<%= text_field( "context", "name", :tabindex => next_tab_index ) %><br />
|
||||||
|
|
@ -26,5 +26,5 @@ function html_for_context_listing() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function html_for_error_messages() {
|
function html_for_error_messages() {
|
||||||
return "<%= escape_javascript(error_messages_for('context')) %>";
|
return "<%= escape_javascript(get_list_of_error_messages_for(@context)) %>";
|
||||||
}
|
}
|
||||||
|
|
@ -8,5 +8,5 @@
|
||||||
|
|
||||||
<div id="input_box">
|
<div id="input_box">
|
||||||
<%= render :partial => "shared/add_new_item_form" %>
|
<%= render :partial => "shared/add_new_item_form" %>
|
||||||
<%= render :file => "sidebar/sidebar.html.erb" %>
|
<%= render :file => "sidebar/sidebar" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ function replace_context_form_with_updated_context() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function html_for_error_messages() {
|
function html_for_error_messages() {
|
||||||
return "<%= escape_javascript(error_messages_for('context')) %>";
|
return "<%= escape_javascript(get_list_of_error_messages_for(@context)) %>";
|
||||||
}
|
}
|
||||||
|
|
||||||
function html_for_context_listing() {
|
function html_for_context_listing() {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,21 @@
|
||||||
<div id="display_box">
|
<div id="display_box">
|
||||||
|
|
||||||
<div id="edit_error_status"><%= error_messages_for(:user) + error_messages_for(:prefs) %></div>
|
<div id="edit_error_status">
|
||||||
|
<% if @user.errors.any? -%>
|
||||||
|
<ul>
|
||||||
|
<% @user.errors.full_messages.each do |msg| %>
|
||||||
|
<li><%= msg %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
<% end -%>
|
||||||
|
<% if @prefs.errors.any? -%>
|
||||||
|
<ul>
|
||||||
|
<% @prefs.errors.full_messages.each do |msg| %>
|
||||||
|
<li><%= msg %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
<% end -%>
|
||||||
|
</div>
|
||||||
|
|
||||||
<%= form_tag :action => 'update' do %>
|
<%= form_tag :action => 'update' do %>
|
||||||
<div id="tabs">
|
<div id="tabs">
|
||||||
|
|
|
||||||
|
|
@ -98,5 +98,5 @@ function html_for_project_settings() {
|
||||||
-%>
|
-%>
|
||||||
|
|
||||||
function html_for_error_messages() {
|
function html_for_error_messages() {
|
||||||
return "<%= escape_javascript(error_messages_for('project')) %>";
|
return "<%= escape_javascript(get_list_of_error_messages_for(@project)) %>";
|
||||||
}
|
}
|
||||||
|
|
@ -7,13 +7,13 @@
|
||||||
<input type="hidden" id="new_todo_starred" name="new_todo_starred" value="false" />
|
<input type="hidden" id="new_todo_starred" name="new_todo_starred" value="false" />
|
||||||
|
|
||||||
<div id="error_status">
|
<div id="error_status">
|
||||||
<% if todo.errors.any? -%>
|
<% if todo.errors.any? -%>
|
||||||
<ul>
|
<ul>
|
||||||
<% todo.errors.full_messages.each do |msg| %>
|
<% todo.errors.full_messages.each do |msg| %>
|
||||||
<li><%= msg %></li>
|
<li><%= msg %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<label for="todo_description" style="float:left"><%= Todo.human_attribute_name('description') %></label>
|
<label for="todo_description" style="float:left"><%= Todo.human_attribute_name('description') %></label>
|
||||||
|
|
|
||||||
|
|
@ -110,14 +110,7 @@ function html_for_new_context() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function html_for_error_messages() {
|
function html_for_error_messages() {
|
||||||
<%
|
return "<%= escape_javascript(get_list_of_error_messages_for(@todo)) %>";
|
||||||
error_messages = ""
|
|
||||||
if @todo.errors.any?
|
|
||||||
list_of_messages = @todo.errors.full_messages.inject("") { |all, msg| all += context_tag(:li, msg) }
|
|
||||||
error_messages = content_tag(:ul, list_of_messages)
|
|
||||||
end
|
|
||||||
-%>
|
|
||||||
return "<%= escape_javascript(error_messages) %>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_predecessors(next_steps) {
|
function update_predecessors(next_steps) {
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,8 @@ Tracksapp::Application.routes.draw do
|
||||||
|
|
||||||
match "tickler" => "todos#list_deferred"
|
match "tickler" => "todos#list_deferred"
|
||||||
match 'review' => "projects#review"
|
match 'review' => "projects#review"
|
||||||
|
match 'login' => 'users#login'
|
||||||
|
match 'login_cas' => 'users#login_cas'
|
||||||
match 'logout' => 'users#logout'
|
match 'logout' => 'users#logout'
|
||||||
match 'calendar' => "todos#calendar"
|
match 'calendar' => "todos#calendar"
|
||||||
match 'done' => "stats#done", :as => 'done_overview'
|
match 'done' => "stats#done", :as => 'done_overview'
|
||||||
|
|
@ -112,6 +114,18 @@ Tracksapp::Application.routes.draw do
|
||||||
end
|
end
|
||||||
match 'todos/tag/:name' => 'todos#tag', :as => :tag
|
match 'todos/tag/:name' => 'todos#tag', :as => :tag
|
||||||
|
|
||||||
|
resources :users do
|
||||||
|
member do
|
||||||
|
get 'change_password'
|
||||||
|
get 'change_auth_type'
|
||||||
|
get 'complete'
|
||||||
|
post 'update_password'
|
||||||
|
post 'update_auth_type'
|
||||||
|
post 'refresh_token'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
match 'signup' => "users#new"
|
||||||
|
|
||||||
resources :notes
|
resources :notes
|
||||||
|
|
||||||
# map.resources :users,
|
# map.resources :users,
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ module LoginSystem
|
||||||
# store current uri in the session.
|
# store current uri in the session.
|
||||||
# we can return to this location by calling return_location
|
# we can return to this location by calling return_location
|
||||||
def store_location
|
def store_location
|
||||||
session['return-to'] = request.request_uri
|
session['return-to'] = request.url
|
||||||
end
|
end
|
||||||
|
|
||||||
# move to the last store_location call or to the passed default one
|
# move to the last store_location call or to the passed default one
|
||||||
|
|
|
||||||
|
|
@ -1,140 +1,12 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/todo_container_controller_test_base')
|
|
||||||
require 'contexts_controller'
|
|
||||||
|
|
||||||
# Re-raise errors caught by the controller.
|
class ContextsControllerTest < ActionController::TestCase
|
||||||
class ContextsController; def rescue_action(e) raise e end; end
|
|
||||||
|
|
||||||
class ContextsControllerTest < TodoContainerControllerTestBase
|
|
||||||
fixtures :users, :preferences, :contexts
|
fixtures :users, :preferences, :contexts
|
||||||
|
|
||||||
def setup
|
|
||||||
perform_setup(Context, ContextsController)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_contexts_list
|
def test_contexts_list
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
get :index
|
get :index
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create_context_via_ajax_increments_number_of_context
|
|
||||||
assert_ajax_create_increments_count '@newcontext'
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_via_ajax_with_comma_in_name_does_not_increment_number_of_contexts
|
|
||||||
assert_ajax_create_does_not_increment_count 'foo,bar'
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_rss_feed_content
|
|
||||||
login_as :admin_user
|
|
||||||
get :index, { :format => "rss" }
|
|
||||||
assert_equal 'application/rss+xml', @response.content_type
|
|
||||||
#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
|
|
||||||
assert_select 'item', 10 do
|
|
||||||
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
|
|
||||||
login_as nil
|
|
||||||
get :index, { :format => "rss" }
|
|
||||||
assert_response 401
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_rss_feed_not_accessible_to_anonymous_user_with_invalid_token
|
|
||||||
login_as nil
|
|
||||||
get :index, { :format => "rss", :token => 'foo' }
|
|
||||||
assert_response 401
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_rss_feed_accessible_to_anonymous_user_with_valid_token
|
|
||||||
login_as nil
|
|
||||||
get :index, { :format => "rss", :token => users(:admin_user).token }
|
|
||||||
assert_response :ok
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_atom_feed_content
|
|
||||||
login_as :admin_user
|
|
||||||
get :index, { :format => "atom" }
|
|
||||||
assert_equal 'application/atom+xml', @response.content_type
|
|
||||||
#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}"
|
|
||||||
assert_select 'entry', 10 do
|
|
||||||
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', /(#{Regexp.escape(contexts(:agenda).created_at.xmlschema)}|#{Regexp.escape(contexts(:library).created_at.xmlschema)})/
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_atom_feed_not_accessible_to_anonymous_user_without_token
|
|
||||||
login_as nil
|
|
||||||
get :index, { :format => "atom" }
|
|
||||||
assert_response 401
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_atom_feed_not_accessible_to_anonymous_user_with_invalid_token
|
|
||||||
login_as nil
|
|
||||||
get :index, { :format => "atom", :token => 'foo' }
|
|
||||||
assert_response 401
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_atom_feed_accessible_to_anonymous_user_with_valid_token
|
|
||||||
login_as nil
|
|
||||||
get :index, { :format => "atom", :token => users(:admin_user).token }
|
|
||||||
assert_response :ok
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_text_feed_content
|
|
||||||
login_as :admin_user
|
|
||||||
get :index, { :format => "txt" }
|
|
||||||
assert_equal 'text/plain', @response.content_type
|
|
||||||
assert !(/ /.match(@response.body))
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_text_feed_not_accessible_to_anonymous_user_without_token
|
|
||||||
login_as nil
|
|
||||||
get :index, { :format => "txt" }
|
|
||||||
assert_response 401
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_text_feed_not_accessible_to_anonymous_user_with_invalid_token
|
|
||||||
login_as nil
|
|
||||||
get :index, { :format => "txt", :token => 'foo' }
|
|
||||||
assert_response 401
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_text_feed_accessible_to_anonymous_user_with_valid_token
|
|
||||||
login_as nil
|
|
||||||
get :index, { :format => "txt", :token => users(:admin_user).token }
|
|
||||||
assert_response :ok
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_show_sets_title
|
def test_show_sets_title
|
||||||
login_as :admin_user
|
login_as :admin_user
|
||||||
|
|
@ -147,28 +19,16 @@ class ContextsControllerTest < TodoContainerControllerTestBase
|
||||||
get :show, { :id => "1" }
|
get :show, { :id => "1" }
|
||||||
assert_template "contexts/show"
|
assert_template "contexts/show"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_show_xml_renders_context_to_xml
|
def test_create_context_via_ajax_increments_number_of_context
|
||||||
login_as :admin_user
|
login_as :other_user
|
||||||
get :show, { :id => "1", :format => 'xml' }
|
assert_ajax_create_increments_count '@newcontext'
|
||||||
assert_equal contexts(:agenda).to_xml( :except => :user_id ), @response.body
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_show_with_nil_context_returns_404
|
def test_create_via_ajax_with_comma_in_name_does_not_increment_number_of_contexts
|
||||||
login_as :admin_user
|
login_as :other_user
|
||||||
get :show, { :id => "0" }
|
assert_ajax_create_does_not_increment_count 'foo,bar'
|
||||||
assert_equal 'Context not found', @response.body
|
|
||||||
assert_response 404
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_show_xml_with_nil_context_returns_404
|
|
||||||
login_as :admin_user
|
|
||||||
get :show, { :id => "0", :format => 'xml' }
|
|
||||||
assert_response 404
|
|
||||||
assert_xml_select 'error', 'Context not found'
|
|
||||||
end
|
|
||||||
|
|
||||||
def protect_against_forgery?
|
|
||||||
false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
134
test/functional/move_these_to_context_controller_test.rb
Normal file
134
test/functional/move_these_to_context_controller_test.rb
Normal file
|
|
@ -0,0 +1,134 @@
|
||||||
|
|
||||||
|
def test_rss_feed_content
|
||||||
|
login_as :admin_user
|
||||||
|
get :index, { :format => "rss" }
|
||||||
|
assert_equal 'application/rss+xml', @response.content_type
|
||||||
|
#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
|
||||||
|
assert_select 'item', 10 do
|
||||||
|
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
|
||||||
|
login_as nil
|
||||||
|
get :index, { :format => "rss" }
|
||||||
|
assert_response 401
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rss_feed_not_accessible_to_anonymous_user_with_invalid_token
|
||||||
|
login_as nil
|
||||||
|
get :index, { :format => "rss", :token => 'foo' }
|
||||||
|
assert_response 401
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rss_feed_accessible_to_anonymous_user_with_valid_token
|
||||||
|
login_as nil
|
||||||
|
get :index, { :format => "rss", :token => users(:admin_user).token }
|
||||||
|
assert_response :ok
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_atom_feed_content
|
||||||
|
login_as :admin_user
|
||||||
|
get :index, { :format => "atom" }
|
||||||
|
assert_equal 'application/atom+xml', @response.content_type
|
||||||
|
#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}"
|
||||||
|
assert_select 'entry', 10 do
|
||||||
|
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', /(#{Regexp.escape(contexts(:agenda).created_at.xmlschema)}|#{Regexp.escape(contexts(:library).created_at.xmlschema)})/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_atom_feed_not_accessible_to_anonymous_user_without_token
|
||||||
|
login_as nil
|
||||||
|
get :index, { :format => "atom" }
|
||||||
|
assert_response 401
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_atom_feed_not_accessible_to_anonymous_user_with_invalid_token
|
||||||
|
login_as nil
|
||||||
|
get :index, { :format => "atom", :token => 'foo' }
|
||||||
|
assert_response 401
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_atom_feed_accessible_to_anonymous_user_with_valid_token
|
||||||
|
login_as nil
|
||||||
|
get :index, { :format => "atom", :token => users(:admin_user).token }
|
||||||
|
assert_response :ok
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_text_feed_content
|
||||||
|
login_as :admin_user
|
||||||
|
get :index, { :format => "txt" }
|
||||||
|
assert_equal 'text/plain', @response.content_type
|
||||||
|
assert !(/ /.match(@response.body))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_text_feed_not_accessible_to_anonymous_user_without_token
|
||||||
|
login_as nil
|
||||||
|
get :index, { :format => "txt" }
|
||||||
|
assert_response 401
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_text_feed_not_accessible_to_anonymous_user_with_invalid_token
|
||||||
|
login_as nil
|
||||||
|
get :index, { :format => "txt", :token => 'foo' }
|
||||||
|
assert_response 401
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_text_feed_accessible_to_anonymous_user_with_valid_token
|
||||||
|
login_as nil
|
||||||
|
get :index, { :format => "txt", :token => users(:admin_user).token }
|
||||||
|
assert_response :ok
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_show_xml_renders_context_to_xml
|
||||||
|
login_as :admin_user
|
||||||
|
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
|
||||||
|
login_as :admin_user
|
||||||
|
get :show, { :id => "0" }
|
||||||
|
assert_equal 'Context not found', @response.body
|
||||||
|
assert_response 404
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_show_xml_with_nil_context_returns_404
|
||||||
|
login_as :admin_user
|
||||||
|
get :show, { :id => "0", :format => 'xml' }
|
||||||
|
assert_response 404
|
||||||
|
assert_xml_select 'error', 'Context not found'
|
||||||
|
end
|
||||||
|
|
||||||
|
def protect_against_forgery?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
@ -1,20 +1,16 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||||
require 'preferences_controller'
|
|
||||||
|
|
||||||
# Re-raise errors caught by the controller.
|
|
||||||
class PreferencesController; def rescue_action(e) raise e end; end
|
|
||||||
|
|
||||||
class PreferencesControllerTest < ActionController::TestCase
|
class PreferencesControllerTest < ActionController::TestCase
|
||||||
fixtures :users, :preferences
|
fixtures :users, :preferences
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
assert_equal "test", ENV['RAILS_ENV']
|
assert_equal "test", Rails.env
|
||||||
assert_equal "change-me", Tracks::Config.salt
|
assert_equal "change-me", Tracks::Config.salt
|
||||||
end
|
end
|
||||||
|
|
||||||
test "render_date_format requires login" do
|
test "render_date_format requires login" do
|
||||||
get :render_date_format
|
get :render_date_format
|
||||||
assert_redirected_to :controller => 'login', :action => 'login'
|
assert_redirected_to login_path
|
||||||
end
|
end
|
||||||
|
|
||||||
test "calling render_date_format returns date" do
|
test "calling render_date_format returns date" do
|
||||||
|
|
@ -31,7 +27,7 @@ class PreferencesControllerTest < ActionController::TestCase
|
||||||
|
|
||||||
test "index page requires login" do
|
test "index page requires login" do
|
||||||
get :index # should fail because no login
|
get :index # should fail because no login
|
||||||
assert_redirected_to :controller => 'login', :action => 'login'
|
assert_redirected_to login_path
|
||||||
end
|
end
|
||||||
|
|
||||||
test "index sets prefs and user" do
|
test "index sets prefs and user" do
|
||||||
|
|
|
||||||
|
|
@ -17,21 +17,5 @@ class TodoContainerControllerTestBase < ActionController::TestCase
|
||||||
assert true
|
assert true
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_ajax_create_increments_count(name)
|
|
||||||
assert_count_after_ajax_create(name, @initial_count + 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_ajax_create_does_not_increment_count(name)
|
|
||||||
assert_count_after_ajax_create(name, @initial_count)
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_count_after_ajax_create(name, expected_count)
|
|
||||||
ajax_create(name)
|
|
||||||
assert_equal(expected_count, @container_class.count)
|
|
||||||
end
|
|
||||||
|
|
||||||
def ajax_create(name)
|
|
||||||
xhr :post, :create, @container_class.name.downcase.to_sym => {:name => name}
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,11 @@ class ActiveSupport::TestCase
|
||||||
fixtures :all
|
fixtures :all
|
||||||
|
|
||||||
# Add more helper methods to be used by all tests here...
|
# Add more helper methods to be used by all tests here...
|
||||||
|
def assert_value_changed(object, method = nil)
|
||||||
|
initial_value = object.send(method)
|
||||||
|
yield
|
||||||
|
assert_not_equal initial_value, object.send(method), "#{object}##{method}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module Tracks
|
module Tracks
|
||||||
|
|
@ -23,6 +28,37 @@ module Tracks
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class ActionController::TestCase
|
||||||
|
def login_as(user)
|
||||||
|
@request.session['user_id'] = user ? users(user).id : nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def assert_ajax_create_increments_count(name)
|
||||||
|
assert_count_after_ajax_create(name, get_class_count + 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
def assert_ajax_create_does_not_increment_count(name)
|
||||||
|
assert_count_after_ajax_create(name, get_class_count)
|
||||||
|
end
|
||||||
|
|
||||||
|
def assert_count_after_ajax_create(name, expected_count)
|
||||||
|
ajax_create(name)
|
||||||
|
assert_equal(expected_count, get_class_count)
|
||||||
|
end
|
||||||
|
|
||||||
|
def ajax_create(name)
|
||||||
|
xhr :post, :create, @controller.class.name.downcase.to_sym => {:name => name}
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def get_class_count
|
||||||
|
model = @controller.class.to_s.tableize.split("_")[0].camelcase.singularize #don't ask... converts ContextsController to Context
|
||||||
|
eval("#{model}.count")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
class ActiveSupport::TestCase
|
class ActiveSupport::TestCase
|
||||||
|
|
||||||
# Generates a random string of ascii characters (a-z, "1 0")
|
# Generates a random string of ascii characters (a-z, "1 0")
|
||||||
|
|
@ -43,14 +79,4 @@ class ActiveSupport::TestCase
|
||||||
assert_equal date1.strftime("%d-%m-%y"), date2.strftime("%d-%m-%y")
|
assert_equal date1.strftime("%d-%m-%y"), date2.strftime("%d-%m-%y")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Test::Unit::TestCase
|
|
||||||
|
|
||||||
def assert_value_changed(object, method = nil)
|
|
||||||
initial_value = object.send(method)
|
|
||||||
yield
|
|
||||||
assert_not_equal initial_value, object.send(method), "#{object}##{method}"
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue