Add a preference to hide hidden contexts in the sidebar.

Rework the preferences as a model unto itself and clean up the view and controller code around preferences.



git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@321 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2006-09-17 06:53:33 +00:00
parent d74635d229
commit 50211a3ebe
30 changed files with 236 additions and 200 deletions

View file

@ -74,7 +74,7 @@ class ApplicationController < ActionController::Base
def get_current_user
@user = User.find(session['user_id']) if session['user_id']
@prefs = @user.preferences unless @user.nil?
@prefs = @user.preference unless @user.nil?
end
def get_admin_user
@ -83,7 +83,7 @@ class ApplicationController < ActionController::Base
def parse_date_per_user_prefs( s )
return nil if s == ''
Date.strptime(s, @user.preferences["date_format"])
Date.strptime(s, @user.preference.date_format)
end
def init_data_for_sidebar

View file

@ -1,5 +1,5 @@
class LoginController < ApplicationController
model :user
model :user, :preference
layout 'login'
skip_before_filter :set_session_expiration
@ -34,7 +34,7 @@ class LoginController < ApplicationController
@user = get_new_user
else # all other situations (i.e. a non-admin is logged in, or no one is logged in, but we have some users)
@page_title = "No signups"
@admin_email = admin.preferences["admin_email"]
@admin_email = admin.preference.admin_email
render :action => "nosignup"
end
end
@ -51,7 +51,7 @@ class LoginController < ApplicationController
user.is_admin = true if User.find_all.empty?
if user.save
@user = User.authenticate(user.login, params['user']['password'])
@user.preferences = { "date_format" => "%d/%m/%Y", "week_starts" => "1", "no_completed" => "5", "staleness_starts" => "7", "due_style" => "1", "admin_email" => "butshesagirl@rousette.org.uk"}
@user.create_preference
@user.save
flash['notice'] = "Signup successful for user #{@user.login}."
redirect_back_or_default :controller => "todo", :action => "index"

View file

@ -22,7 +22,7 @@ class TodoController < ApplicationController
# If you've set no_completed to zero, the completed items box
# isn't shown on the home page
max_completed = @user.preferences["no_completed"].to_i-1
max_completed = @user.preference.show_number_completed - 1
@done = nil
if max_completed > 0
@done = Todo.find(:all,

View file

@ -50,29 +50,20 @@ class UserController < ApplicationController
def preferences
@page_title = "TRACKS::Preferences"
@prefs = @user.preferences
@prefs = @user.preference
end
def edit_preferences
@page_title = "TRACKS::Edit Preferences"
@prefs = @user.preferences
@prefs = @user.preference
render :action => "preference_edit_form", :object => @prefs
end
def update_preferences
@user.preferences = { "date_format" => "#{params['prefs']['date_format']}",
"week_starts" => "#{params['prefs']['week_starts']}",
"no_completed" => "#{params['prefs']['no_completed']}",
"staleness_starts" => "#{params['prefs']['staleness_starts']}",
"show_completed_projects_on_home_page" => "#{params['prefs']['show_completed_projects_on_home_page']}",
"due_style" => "#{params['prefs']['due_style']}",
"admin_email" => "#{params['prefs']['admin_email']}",
"refresh" => "#{params['prefs']['refresh']}"
}
@user.first_name = params['user']['first_name']
@user.last_name = params['user']['last_name']
if @user.save
user_success = @user.update_attributes(params['user'])
prefs_success = @user.preference.update_attributes(params['prefs'])
if user_success && prefs_success
redirect_to :action => 'preferences'
else
render :action => 'edit_preferences'

View file

@ -6,7 +6,7 @@ module ApplicationHelper
#
def format_date(date)
if date
date_format = @user.preferences["date_format"]
date_format = @user.preference.date_format
formatted_date = date.strftime("#{date_format}")
else
formatted_date = ''
@ -72,7 +72,7 @@ module ApplicationHelper
"<a title='" + format_date(due) + "'><span class=\"amber\">Due Tomorrow</span></a> "
# due 2-7 days away
when 2..7
if @user.preferences["due_style"] == "1"
if @user.preference.due_style == "1"
"<a title='" + format_date(due) + "'><span class=\"orange\">Due on " + due.strftime("%A") + "</span></a> "
else
"<a title='" + format_date(due) + "'><span class=\"orange\">Due in " + @days.to_s + " days</span></a> "

View file

@ -44,11 +44,11 @@ module TodoHelper
def staleness_class(item)
if item.due || item.done?
return ""
elsif item.created_at < (@user.preferences["staleness_starts"].to_i*3).days.ago
elsif item.created_at < (@user.preference.staleness_starts * 3).days.ago
return " stale_l3"
elsif item.created_at < (@user.preferences["staleness_starts"].to_i*2).days.ago
elsif item.created_at < (@user.preference.staleness_starts * 2).days.ago
return " stale_l2"
elsif item.created_at < (@user.preferences["staleness_starts"].to_i).days.ago
elsif item.created_at < (@user.preference.staleness_starts).days.ago
return " stale_l1"
else
return ""
@ -76,7 +76,7 @@ module TodoHelper
"<a title='" + format_date(due) + "'><span class=\"amber\">Show Tomorrow</span></a> "
# due 2-7 days away
when 2..7
if @user.preferences["due_style"] == "1"
if @user.preference.due_style == 1
"<a title='" + format_date(due) + "'><span class=\"orange\">Show on " + due.strftime("%A") + "</span></a> "
else
"<a title='" + format_date(due) + "'><span class=\"orange\">Show in " + @days.to_s + " days</span></a> "
@ -99,8 +99,8 @@ module TodoHelper
end
def calendar_setup( input_field )
date_format = @user.preferences["date_format"]
week_starts = @user.preferences["week_starts"]
date_format = @user.preference.date_format
week_starts = @user.preference.week_starts
str = "Calendar.setup({ ifFormat:\"#{date_format}\""
str << ",firstDay:#{week_starts},showOthers:true,range:[2004, 2010]"
str << ",step:1,inputField:\"" + input_field + "\",cache:true,align:\"TR\" })\n"

View file

@ -35,7 +35,7 @@ class Context < ActiveRecord::Base
todos = Todo.find :all, :conditions => ["todos.context_id = ? AND todos.type = ? AND todos.done = ?", id, "Immediate", true],
:order => "completed DESC",
:include => [:context, :project],
:limit => @user.preferences["no_completed"].to_i
:limit => @user.preference.show_number_completed
end
def hidden?

View file

@ -0,0 +1,18 @@
class Preference < ActiveRecord::Base
belongs_to :user
def self.day_number_to_name_map
{ 0 => "Sunday",
1 => "Monday",
2 => "Tuesday",
3 => "Wednesday",
4 => "Thursday",
5 => "Friday",
6 => "Saturday"}
end
def hide_completed_actions?
return show_number_completed == 0
end
end

View file

@ -44,7 +44,7 @@ class Project < ActiveRecord::Base
todos = Todo.find :all, :conditions => ["todos.project_id = ? AND todos.type = ? AND todos.done = ?", id, "Immediate", true],
:order => "completed DESC",
:include => [:context, :project],
:limit => @user.preferences["no_completed"].to_i
:limit => @user.preference.show_number_completed
end

View file

@ -1,14 +1,12 @@
require 'digest/sha1'
# this model expects a certain database layout and its based on the name/login pattern.
class User < ActiveRecord::Base
has_many :contexts, :order => "position ASC"
has_many :projects, :order => "position ASC"
has_many :todos, :order => "completed DESC, created_at DESC"
has_many :notes, :order => "created_at DESC"
has_one :preference
serialize :preferences
attr_protected :is_admin
def self.authenticate(login, pass)

View file

@ -8,7 +8,7 @@
<%= render :partial => "context/context", :locals => { :context => @context, :collapsible => false } %>
<% unless @done.empty? -%>
<%= render :partial => "todo/completed", :locals => { :done => @done, :collapsible => false, :append_descriptor => "in this context (last #{@user.preferences["no_completed"]})" } %>
<%= render :partial => "todo/completed", :locals => { :done => @done, :collapsible => false, :append_descriptor => "in this context (last #{@user.preference.show_number_completed})" } %>
<% end -%>
</div><!-- [end:display_box] -->

View file

@ -2,7 +2,7 @@ if @saved
page.remove "item-#{@item.id}-container"
if @item.done?
# Don't try to insert contents into a non-existent container!
unless @user.preferences["no_completed"].to_i == 0
unless @user.preference.hide_completed_actions?
page.insert_html :top, "completed", :partial => 'todo/item', :locals => { :parent_container_type => "completed" }
page.visual_effect :highlight, "item-#{@item.id}", {'startcolor' => "'#99ff99'"}
if @down_count == '0'

View file

@ -2,7 +2,7 @@ if @saved
page.remove "item-#{@item.id}-container"
if @item.done?
# Don't try to insert contents into a non-existent container!
unless @user.preferences["no_completed"].to_i == 0
unless @user.preference.hide_completed_actions?
page.insert_html :top, "completed", :partial => 'todo/item', :locals => { :parent_container_type => "project" }
page.visual_effect :highlight, "item-#{@item.id}", {'startcolor' => "'#99ff99'"}
if @down_count == '0'

View file

@ -6,7 +6,7 @@
<% end -%>
</ul>
<% if @user.preferences['show_completed_projects_on_home_page'].downcase == 'true' %>
<% if @user.preference.show_completed_projects_in_sidebar %>
<h3>Completed Projects:</h3>
<ul>
<% for project in @projects.reject{|p| !p.done? } -%>
@ -24,6 +24,7 @@
<% end -%>
</ul>
<% if @user.preference.show_hidden_contexts_in_sidebar %>
<h3>Hidden Contexts:</h3>
<ul>
<% for context in @contexts.reject{|c| !c.hide? } -%>
@ -31,3 +32,4 @@
:name => urlize(context.name) } ) + " (" + count_undone_todos(context,"actions") + ")" %></li>
<% end -%>
</ul>
<% end %>

View file

@ -5,7 +5,7 @@ if @saved
# page.call "fadeAndRemoveItem", "item-#{@item.id}-container"
if @item.done?
# Don't try to insert contents into a non-existent container!
unless @user.preferences["no_completed"].to_i == 0
unless @user.preference.hide_completed_actions?
page.insert_html :top, "completed", :partial => 'todo/item', :locals => { :parent_container_type => "completed" }
page.visual_effect :highlight, "item-#{@item.id}", {'startcolor' => "'#99ff99'"}
end

View file

@ -3,15 +3,16 @@
<p>The preference settings should mostly be self-explanatory, but some hints are included below: </p>
<ul>
<li><strong>first name and last name:</strong> Used for display purposes if set</li>
<li><strong>staleness starts:</strong> the number of days before items with no due date get marked as stale (with a yellow highlight)</li>
<li><strong>date format:</strong> the format in which you'd like dates to be shown. For example, for the date 31st January 2006, %d/%m/%Y will show 31/01/2006, %b-%e-%y will show Jan-31-06. See the <a href="http://uk2.php.net/strftime" title="PHP strftime manual">strftime manual</a> for more formatting options for the date.</li>
<li><strong>no completed:</strong> number of completed actions to show on the home page. If you set this to zero, the completed actions box will not be shown on the home page or on the individual context or project pages. You can still see all your completed items by clicking the 'Done' link in the navigation bar at the top of each page.</li>
<li><strong>week starts:</strong> day of the week shown as the start of the week on the popup calendar.</li>
<li><strong>due style:</strong> style in which due dates are shown, e.g. "Due in 3 days", "Due on Wednesday"</li>
<li><strong>show completed projects in sidebar:</strong> whether or not projects marked as complete are shown in the sidebar on the home page and elsewhere</li>
<li><strong>show hidden contexts in sidebar:</strong> whether or not contexts marked as hidden are shown in the sidebar on the home page and elsewhere</li>
<% if @user.is_admin? %>
<li><strong>admin email:</strong> email address for the admin user of Tracks (displayed on the signup page for users to contact to obtain an account)</li>
<% end %>
<li><strong>week starts:</strong> day of the week shown as the start of the week on the popup calendar.</li>
<li><strong>show completed projects on home page:</strong> whether or not projects marked as complete are shown on the home page sidebar</li>
<li><strong>due style:</strong> style in which due dates are shown, e.g. "Due in 3 days", "Due on Wednesday"</li>
<li><strong>staleness starts:</strong> the number of days before items with no due date get marked as stale (with a yellow highlight)</li>
<li><strong>date format:</strong> the format in which you'd like dates to be shown. For example, for the date 31st January 2006, %d/%m/%Y will show 31/01/2006, %b-%e-%y will show Jan-31-06. See the <a href="http://uk2.php.net/strftime" title="PHP strftime manual">strftime manual</a> for more formatting options for the date.</li>
<li><strong>show number completed:</strong> number of completed actions to show on the home page. If you set this to zero, the completed actions box will not be shown on the home page or on the individual context or project pages. You can still see all your completed items by clicking the 'Done' link in the navigation bar at the top of each page.</li>
<li><strong>refresh:</strong> automatic refresh interval for each of the pages (in minutes)</li>
</ul>
</div>
@ -27,94 +28,36 @@
<td><label>last name:</label></td>
<td><%= text_field 'user', 'last_name' %></td>
</tr>
<tr>
<td><label>week starts:</label></td>
<td>
<select name="prefs[week_starts]" >
<% day_num_to_name = { "0" => "Sunday",
"1" => "Monday",
"2" => "Tuesday",
"3" => "Wednesday",
"4" => "Thursday",
"5" => "Friday",
"6" => "Saturday"}
day_num_to_name.sort.each do |number, day| %>
<option value="<%= number%>"
<% if number == @prefs['week_starts'] %>
selected="true"
<% end %>
><%= day %></option>
<% end %>
</select>
</td>
</tr>
<tr>
<td><label>due style:</label></td>
<td>
<select name="prefs[due_style]" >
<option value="0"
<% if @prefs['due_style'] == "0" %>
selected="true"
<% end %>
>Due in ___ days</option>
<%
def table_row(pref_name, nowrap_label = false, &block)
nowrap_attribute = nowrap_label ? ' nowrap="nowrap"' : ''
s = %Q|<tr>\n<td#{nowrap_attribute}><label>#{pref_name.gsub(/_/,' ')}:</label></td>\n<td>\n|
s << yield
s << "\n</td></tr>"
s
end
def row_with_select_field(pref_name, collection = [true,false], nowrap_label = false)
table_row(pref_name, nowrap_label) { select('prefs', pref_name, collection) }
end
def row_with_text_field(pref_name, nowrap_label = false)
table_row(pref_name, nowrap_label) { text_field('prefs', pref_name) }
end
%>
<%= row_with_select_field("week_starts", Preference.day_number_to_name_map.invert.sort{|a,b| a[1]<=>b[1]})%>
<%= row_with_select_field("due_style", [['Due in ___ days',0],['Due on _______',1]]) %>
<%= row_with_select_field("show_completed_projects_in_sidebar") %>
<%= row_with_select_field("show_hidden_contexts_in_sidebar") %>
<% if @user.is_admin? %> <%= row_with_text_field('admin_email') %> <% end %>
<%= row_with_text_field('staleness_starts', true) %>
<%= row_with_text_field('date_format') %>
<%= row_with_text_field('show_number_completed') %>
<%= row_with_text_field('refresh') %>
<option value="1"
<% if @prefs['due_style'] == "1" %>
selected="true"
<% end %>
>Due on _______</option>
</select>
</td>
</tr>
<tr>
<td><label>show completed projects on home page:</label></td>
<td>
<select name="prefs[show_completed_projects_on_home_page]" >
<option value="true"
<% if @prefs['show_completed_projects_on_home_page'] == "true" %>
selected="true"
<% end %>
>True</option>
<option value="false"
<% if @prefs['show_completed_projects_on_home_page'] == "false" %>
selected="true"
<% end %>
>False</option>
</select>
</td>
</tr>
<% if @user.is_admin? %>
<tr>
<td><label>admin email:</label></td>
<td>
<input name="prefs[admin_email]" type="text" value="<%= @prefs['admin_email'] %>" >
</td>
</tr>
<% end %>
<tr>
<td nowrap="true"><label>staleness starts:</label></td>
<td>
<input name="prefs[staleness_starts]" type="text" value="<%= @prefs['staleness_starts'] %>" >
</td>
</tr>
<tr>
<td><label>date format:</label></td>
<td>
<input name="prefs[date_format]" type="text" value="<%= @prefs['date_format'] %>" >
</td>
</tr>
<tr>
<td><label>no completed:</label></td>
<td>
<input name="prefs[no_completed]" type="text" value="<%= @prefs['no_completed'] %>" >
</td>
</tr>
<tr>
<td><label>refresh:</label></td>
<td>
<input name="prefs[refresh]" type="text" value="<%= @prefs['refresh'] %>" >
</td>
</tr>
<tr><td><%= submit_tag "Update" %></td>
<td><%= link_to "Cancel", :controller => 'user', :action => 'preferences' %></td>
</tr>

View file

@ -11,40 +11,23 @@
<ul id="prefs">
<li>First name: <span class="highlight"><%= @user.first_name %></span></li>
<li>Last name: <span class="highlight"><%= @user.last_name %></span></li>
<li>Date format: <span class="highlight"><%= @prefs["date_format"] %></span></li>
<li>Week starts on: <span class="highlight">
<% case @prefs["week_starts"]
when "0"
%> Sunday <%
when "1"
%> Monday <%
when "2"
%> Tuesday <%
when "3"
%> Wednesday <%
when "4"
%> Thursday <%
when "5"
%> Friday <%
when "6"
%> Saturday <%
end
%>
</span></li>
<li>Show the last <span class="highlight"><%= @prefs["no_completed"] %></span> completed items on the home page</li>
<li>Show completed projects on the home page: <span class="highlight"><%= @prefs["show_completed_projects_on_home_page"] %></span></li>
<li>Staleness starts after <span class="highlight"><%= @prefs["staleness_starts"] %></span> days</li>
<li>Date format: <span class="highlight"><%= @prefs.date_format %></span></li>
<li>Week starts on: <span class="highlight"><%= Preference.day_number_to_name_map[@prefs.week_starts] %></span></li>
<li>Show the last <span class="highlight"><%= @prefs.show_number_completed %></span> completed items on the home page</li>
<li>Show completed projects in sidebar: <span class="highlight"><%= @prefs.show_completed_projects_in_sidebar %></span></li>
<li>Show hidden contexts in sidebar: <span class="highlight"><%= @prefs.show_hidden_contexts_in_sidebar %></span></li>
<li>Staleness starts after <span class="highlight"><%= @prefs.staleness_starts %></span> days</li>
<li>Due style: <span class="highlight">
<% if @prefs["due_style"] == "0" %>
<% if @prefs.due_style == "0" %>
Due in ___ days
<% else %>
Due on ________
<% end %>
</span></li>
<% if @user.is_admin? %>
<li>Admin email: <span class="highlight"><%= @prefs["admin_email"] %></span></li>
<li>Admin email: <span class="highlight"><%= @prefs.admin_email %></span></li>
<% end %>
<li>Refresh interval (in minutes): <span class="highlight"><%= @prefs["refresh"] %></span></li>
<li>Refresh interval (in minutes): <span class="highlight"><%= @prefs.refresh %></span></li>
</ul>
<%= link_to "Edit preferences", :controller => 'user', :action => 'edit_preferences' %> |
<%= link_to 'Change password', :controller => 'user', :action => 'change_password' %>

View file

@ -1,13 +0,0 @@
class PrefToShowHideCompletedProjectsOnHomePage < ActiveRecord::Migration
def self.up
@users = User.find(:all)
@users.each do |user|
user.preferences.merge!({"show_completed_projects_on_home_page" => true})
user.save
end
end
def self.down
end
end

View file

@ -0,0 +1,22 @@
class PrefToShowHideSidebarItems < ActiveRecord::Migration
class User < ActiveRecord::Base; serialize :preferences; end
def self.up
@users = User.find(:all)
@users.each do |user|
user.preferences.merge!({"show_completed_projects_in_sidebar" => true})
user.preferences.merge!({"show_hidden_contexts_in_sidebar" => true})
user.save
end
end
def self.down
@users = User.find(:all)
@users.each do |user|
user.preferences.delete("show_completed_projects_in_sidebar")
user.preferences.delete("show_hidden_contexts_in_sidebar")
user.save
end
end
end

View file

@ -0,0 +1,23 @@
class AddPreferencesModel < ActiveRecord::Migration
class User < ActiveRecord::Base; serialize :preferences; end
def self.up
create_table :preferences do |t|
t.column :user_id, :integer, :null => false
t.column :date_format, :string, :limit => 40, :null => false, :default => '%d/%m/%Y'
t.column :week_starts, :integer, :null => false, :default => 0
t.column :show_number_completed, :integer, :null => false, :default => 5
t.column :staleness_starts, :integer, :null => false, :default => 7
t.column :show_completed_projects_in_sidebar, :boolean, :default => true, :null => false
t.column :show_hidden_contexts_in_sidebar, :boolean, :default => true, :null => false
t.column :due_style, :integer, :null => false, :default => 0
t.column :admin_email, :string, :limit => 255, :null => false, :default => 'butshesagirl@rousette.org.uk'
t.column :refresh, :integer, :null => false, :default => 0
end
end
def self.down
drop_table :preferences
end
end

View file

@ -0,0 +1,40 @@
class ConvertPreferences < ActiveRecord::Migration
class User < ActiveRecord::Base; has_one :preference; serialize :preferences; end
def self.up
@users = User.find(:all)
@users.each do |user|
user.create_preference
user.preference.date_format = user.preferences['date_format']
user.preference.week_starts = user.preferences['week_starts']
user.preference.show_number_completed = user.preferences['show_number_completed']
user.preference.staleness_starts = user.preferences['staleness_starts']
user.preference.show_completed_projects_in_sidebar = user.preferences['show_completed_projects_in_sidebar']
user.preference.show_hidden_contexts_in_sidebar = user.preferences['show_hidden_contexts_in_sidebar']
user.preference.due_style = user.preferences['due_style']
user.preference.admin_email = user.preferences['admin_email']
user.preference.refresh = user.preferences['refresh']
user.preference.save!
end
remove_column :users, :preferences
end
def self.down
add_column :users, :preferences, :text
@users = User.find(:all)
@users.each do |user|
user.preferences = { "date_format" => "#{user.preference.date_format}",
"week_starts" => "#{user.preference.week_starts}",
"no_completed" => "#{user.preference.show_number_completed}",
"staleness_starts" => "#{user.preference.staleness_starts}",
"show_completed_projects_in_sidebar" => "#{user.preference.show_completed_projects_in_sidebar}",
"show_hidden_contexts_in_sidebar" => "#{user.preference.show_hidden_contexts_in_sidebar}",
"due_style" => "#{user.preference.due_style}",
"admin_email" => "#{user.preference.admin_email}",
"refresh" => "#{user.preference.refresh}"
}
user.save
end
end
end

View file

@ -2,7 +2,7 @@
# migrations feature of ActiveRecord to incrementally modify your database, and
# then regenerate this schema definition.
ActiveRecord::Schema.define(:version => 11) do
ActiveRecord::Schema.define(:version => 13) do
create_table "contexts", :force => true do |t|
t.column "name", :string, :default => "", :null => false
@ -19,6 +19,19 @@ ActiveRecord::Schema.define(:version => 11) do
t.column "updated_at", :datetime
end
create_table "preferences", :force => true do |t|
t.column "user_id", :integer, :default => 0, :null => false
t.column "date_format", :string, :limit => 40, :default => "%d/%m/%Y", :null => false
t.column "week_starts", :integer, :default => 0, :null => false
t.column "show_number_completed", :integer, :default => 5, :null => false
t.column "staleness_starts", :integer, :default => 14, :null => false
t.column "show_completed_projects_in_sidebar", :boolean, :default => true, :null => false
t.column "show_hidden_contexts_in_sidebar", :boolean, :default => true, :null => false
t.column "due_style", :integer, :default => 0, :null => false
t.column "admin_email", :string, :default => "", :null => false
t.column "refresh", :integer, :default => 0, :null => false
end
create_table "projects", :force => true do |t|
t.column "name", :string, :default => "", :null => false
t.column "position", :integer, :default => 0, :null => false
@ -54,7 +67,6 @@ ActiveRecord::Schema.define(:version => 11) do
t.column "password", :string, :limit => 40
t.column "word", :string
t.column "is_admin", :integer, :limit => 4, :default => 0, :null => false
t.column "preferences", :text
t.column "first_name", :string
t.column "last_name", :string
end

26
tracks/test/fixtures/preferences.yml vendored Normal file
View file

@ -0,0 +1,26 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
admin_user_prefs:
id: 1
user_id: 1
staleness_starts: 7
date_format: "%d/%m/%Y"
show_number_completed: 5
show_completed_projects_in_sidebar: true
show_hidden_contexts_in_sidebar: true
admin_email: butshesagirl@rousette.org.uk
week_starts: 1
due_style: 0
refresh: 0
other_user_prefs:
id: 2
user_id: 2
staleness_starts: 7
date_format: "%d/%m/%Y"
show_number_completed: 5
show_completed_projects_in_sidebar: true
show_hidden_contexts_in_sidebar: true
admin_email: butshesagirl@rousette.org.uk
week_starts: 1
due_style: 0
refresh: 0

View file

@ -5,14 +5,8 @@ admin_user:
password: <%= Digest::SHA1.hexdigest("#{User.get_salt()}--abracadabra--") %>
word: <%= Digest::SHA1.hexdigest("adminSat Feb 25 17:14:00 GMT 20060.236961325863376") %>
is_admin: true
preferences:
staleness_starts: "7"
date_format: "%d/%m/%Y"
no_completed: "5"
admin_email: butshesagirl@rousette.org.uk
weeks_starts: "1"
due_style: "0"
refresh: "0"
first_name: Admin
last_name: Schmadmin
other_user:
id: 2
@ -20,11 +14,5 @@ other_user:
password: <%= Digest::SHA1.hexdigest("#{User.get_salt()}--sesame--") %>
word: <%= Digest::SHA1.hexdigest("janeSun Feb 19 14:42:45 GMT 20060.408173979260027") %>
is_admin: false
preferences:
staleness_starts: "7"
date_format: "%d/%m/%Y"
no_completed: "5"
admin_email: butshesagirl@rousette.org.uk
weeks_starts: "1"
due_style: "0"
refresh: "0"
first_name: Jane
last_name: Doe

View file

@ -6,7 +6,7 @@ require_dependency "login_system"
class LoginController; def rescue_action(e) raise e end; end
class LoginControllerTest < Test::Unit::TestCase
fixtures :users
fixtures :preferences, :users
def setup
assert_equal "test", ENV['RAILS_ENV']
@ -87,7 +87,7 @@ class LoginControllerTest < Test::Unit::TestCase
get :logout # logout the admin user
assert_equal newbie.login, "newbie"
assert newbie.is_admin == false || newbie.is_admin == 0
assert_not_nil newbie.preferences # have user preferences been created?
assert_not_nil newbie.preference # have user preferences been created?
user = login('newbie', 'newbiepass', 'on') # log in the new user
assert_redirected_to :controller => 'todo', :action => 'index'
assert_equal 'newbie', user.login

View file

@ -44,7 +44,6 @@ class UserControllerTest < Test::Unit::TestCase
assert_response :success
assert_equal assigns['page_title'], "TRACKS::Preferences"
assert_not_nil assigns['prefs']
assert_equal assigns['prefs'].length, 7
end
def test_edit_preferences
@ -55,7 +54,6 @@ class UserControllerTest < Test::Unit::TestCase
assert_response :success
assert_equal assigns['page_title'], "TRACKS::Edit Preferences"
assert_not_nil assigns['prefs']
assert_equal assigns['prefs'].length, 7
assert_template 'user/preference_edit_form'
end
@ -64,9 +62,9 @@ class UserControllerTest < Test::Unit::TestCase
#
def test_update_preferences
@request.session['user_id'] = users(:admin_user).id # log in the admin user
post :update_preferences, {:user => { :first_name => 'Jane', :last_name => 'Doe'}, :prefs => { :date_format => "%m-%d-%Y", :week_starts => "0", :no_completed => "10", :staleness_starts => "14", :due_style => "1", :admin_email => "my.email@domain.com" }}
post :update_preferences, {:user => { :first_name => 'Jane', :last_name => 'Doe'}, :prefs => { :date_format => "%m-%d-%Y", :week_starts => "0", :show_number_completed => "10", :show_completed_projects_in_sidebar => "false", :show_hidden_contexts_in_sidebar => "false", :staleness_starts => "14", :due_style => "1", :admin_email => "my.email@domain.com" }}
updated_admin_user = User.find(users(:admin_user).id)
assert_not_nil updated_admin_user.preferences
assert_not_nil updated_admin_user.preference
assert_equal 'Jane', updated_admin_user.first_name
assert_equal 'Doe', updated_admin_user.last_name
assert_redirected_to :action => 'preferences'

View file

@ -50,10 +50,10 @@ class ContextControllerXmlApiTest < ActionController::IntegrationTest
assert_response_and_body 404, "Name cannot contain the slash ('/') character"
end
def test_creates_new_project
def test_creates_new_context
initial_count = Context.count
authenticated_post_xml_to_context_create
assert_response_and_body 200, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<context>\n <name>#{@@context_name}</name>\n <hide type=\"integer\">0</hide>\n <id type=\"integer\">0</id>\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 <name>#{@@context_name}</name>\n <hide type="integer">0</hide>\n <id type="integer">\d+</id>\n <position type="integer">1</position>\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"

View file

@ -53,7 +53,7 @@ class ProjectControllerXmlApiTest < ActionController::IntegrationTest
def test_creates_new_project
initial_count = Project.count
authenticated_post_xml_to_project_create
assert_response_and_body 200, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project>\n <name>#{@@project_name}</name>\n <done type=\"integer\">0</done>\n <id type=\"integer\">0</id>\n <description></description>\n <position type=\"integer\">1</position>\n</project>\n"
assert_response_and_body_matches 200, %r|^<\?xml version="1\.0" encoding="UTF-8"\?>\n<project>\n <name>#{@@project_name}</name>\n <done type=\"integer\">0</done>\n <id type=\"integer\">[0-9]+</id>\n <description></description>\n <position type=\"integer\">1</position>\n</project>\n$|
assert_equal initial_count + 1, Project.count
project1 = Project.find_by_name(@@project_name)
assert_not_nil project1, "expected project '#{@@project_name}' to be created"

View file

@ -1,7 +1,7 @@
require "#{File.dirname(__FILE__)}/../test_helper"
class StoriesTest < ActionController::IntegrationTest
fixtures :users, :projects, :contexts, :todos, :notes
fixtures :users, :preferences, :projects, :contexts, :todos, :notes
def setup
assert_test_environment_ok

View file

@ -71,11 +71,16 @@ class ActionController::IntegrationTest
}.merge(headers)
end
def assert_response_and_body (type, body, message = nil)
def assert_response_and_body(type, body, message = nil)
#puts @response.body
assert_response type, message
assert_equal body, @response.body, message
end
end
def assert_response_and_body_matches(type, body_regex, message = nil)
assert_response type, message
assert_match body_regex, @response.body, message
end
def assert_401_unauthorized
assert_response_and_body 401, "401 Unauthorized: You are not authorized to interact with Tracks."