all non-cucumber tests are passing

This commit is contained in:
Reinier Balt 2012-04-27 14:22:16 +02:00
parent 13b58f3a10
commit 63175c115b
46 changed files with 248 additions and 505 deletions

View file

@ -56,13 +56,7 @@ class ContextsController < ApplicationController
end
end
end
# Example XML usage: curl -H 'Accept: application/xml' -H 'Content-Type:
# application/xml'
# -u username:password
# -d '<request><context><name>new context_name</name></context></request>'
# http://our.tracks.host/contexts
#
def create
if params[:format] == 'application/xml' && params['exception']
render_failure "Expected post format is valid xml like so: <context><name>context name</name></context>.", 400
@ -77,7 +71,7 @@ class ContextsController < ApplicationController
end
format.xml do
if @context.new_record?
render_failure @context.errors.to_xml, 409
render_failure @context.errors.to_xml.html_safe, 409
else
head :created, :location => context_url(@context)
end

View file

@ -139,15 +139,9 @@ class ProjectsController < ApplicationController
end
end
# Example XML usage: curl -H 'Accept: application/xml' -H 'Content-Type:
# application/xml'
# -u username:password
# -d '<request><project><name>new project_name</name></project></request>'
# http://our.tracks.host/projects
#
def create
if params[:format] == 'application/xml' && params['exception']
render_failure "Expected post format is valid xml like so: <request><project><name>project name</name></project></request>."
render_failure "Expected post format is valid xml like so: <project><name>project name</name></project>.", 400
return
end
@project = current_user.projects.build(params['project'])
@ -161,7 +155,7 @@ class ProjectsController < ApplicationController
format.js { @down_count = current_user.projects.size }
format.xml do
if @project.new_record?
render_failure @project.errors.full_messages.join(', ')
render_failure @project.errors.to_xml.html_safe, 409
else
head :created, :location => project_url(@project), :text => @project.id
end

View file

@ -161,10 +161,10 @@ class RecurringTodosController < ApplicationController
format.html do
if @saved
notify :notice, t('todos.recurring_deleted_success'), 2.0
notify :notice, t('todos.recurring_deleted_success')
redirect_to :action => 'index'
else
notify :error, t('todos.error_deleting_recurring', :description => @recurring_todo.description), 2.0
notify :error, t('todos.error_deleting_recurring', :description => @recurring_todo.description)
redirect_to :action => 'index'
end
end

View file

@ -106,7 +106,7 @@ class StatsController < ApplicationController
# convert to array and fill in non-existing weeks with 0
@max_weeks = difference_in_weeks(@today, @actions_completion_time.last.completed_at)
@actions_completed_per_week_array = convert_to_weeks_running_array(@actions_completion_time, @max_weeks+1)
# stop the chart after 10 weeks
@count = [10, @max_weeks].min
@ -179,7 +179,7 @@ class StatsController < ApplicationController
# cut off chart at 52 weeks = one year
@count = [52, @max_weeks].min
@actions_open_per_week_array = convert_to_weeks_running_from_today_array(@actions_started, @max_weeks)
@actions_open_per_week_array = convert_to_weeks_running_from_today_array(@actions_started, @max_weeks+1)
@actions_open_per_week_array = cut_off_array(@actions_open_per_week_array, @count)
@max_actions = @actions_open_per_week_array.max
@ -440,7 +440,7 @@ class StatsController < ApplicationController
@pie_height=325
# get the current date wih time set to 0:0
@today = Time.zone.now.beginning_of_day
@today = Time.zone.now.utc.beginning_of_day
# define the number of seconds in a day
@seconds_per_day = 60*60*24
@ -633,38 +633,33 @@ class StatsController < ApplicationController
return selected_todo_ids
end
def convert_to_array(hash, upper_bound)
return Array.new(upper_bound){ |i| hash[i] }
end
# uses the supplied block to determine array of indexes in hash
# the block should return an array of indexes each is added to the hash and summed
def convert_to_hash(records)
def convert_to_array(records, upper_bound)
# use 0 to initialise action count to zero
hash = Hash.new(0)
records.each { |r| (yield r).each { |i| hash[i] += 1} }
return hash
a = Array.new(upper_bound){|i| 0 }
records.each { |r| (yield r).each { |i| a[i] += 1 } }
return a
end
def convert_to_months_from_today_array(records, array_size, date_method_on_todo)
return convert_to_array(convert_to_hash(records){ |r| [difference_in_months(@today, r.send(date_method_on_todo))]}, array_size)
return convert_to_array(records, array_size){ |r| [difference_in_months(@today, r.send(date_method_on_todo))]}
end
def convert_to_days_from_today_array(records, array_size, date_method_on_todo)
return convert_to_array(convert_to_hash(records){ |r| [difference_in_days(@today, r.send(date_method_on_todo))]}, array_size)
return convert_to_array(records, array_size){ |r| [difference_in_days(@today, r.send(date_method_on_todo))]}
end
def convert_to_weeks_from_today_array(records, array_size, date_method_on_todo)
return convert_to_array(convert_to_hash(records) { |r| [difference_in_weeks(@today, r.send(date_method_on_todo))]}, array_size)
return convert_to_array(records, array_size) { |r| [difference_in_weeks(@today, r.send(date_method_on_todo))]}
end
def convert_to_weeks_running_array(records, array_size)
return convert_to_array(convert_to_hash(records) { |r| [difference_in_weeks(r.completed_at, r.created_at)]}, array_size)
return convert_to_array(records, array_size) { |r| [difference_in_weeks(r.completed_at, r.created_at)]}
end
def convert_to_weeks_running_from_today_array(records, array_size)
hash = convert_to_hash(records) { |r| week_indexes_of(r) }
return convert_to_array(hash, array_size)
return convert_to_array(records, array_size) { |r| week_indexes_of(r) }
end
def week_indexes_of(record)
@ -698,14 +693,14 @@ class StatsController < ApplicationController
end
# assumes date1 > date2
# this results in the number of months before the month of date1, not taking days into account, so diff of 31-12 and 1-1 is 1 month!
# this results in the number of months before the month of date1, not taking days into account, so diff of 31-dec and 1-jan is 1 month!
def difference_in_months(date1, date2)
return (date1.year - date2.year)*12 + (date1.month - date2.month)
return (date1.utc.year - date2.utc.year)*12 + (date1.utc.month - date2.utc.month)
end
# assumes date1 > date2
def difference_in_days(date1, date2)
return ((date1.at_midnight-date2.at_midnight)/@seconds_per_day).to_i
return ((date1.utc.at_midnight-date2.utc.at_midnight)/@seconds_per_day).to_i
end
# assumes date1 > date2

View file

@ -11,10 +11,6 @@ class TodosController < ApplicationController
protect_from_forgery :except => :check_deferred
# # these are needed for todo_feed_content. TODO: remove this view stuff from controller
# include ActionView::Helpers::SanitizeHelper
# extend ActionView::Helpers::SanitizeHelper::ClassMethods
def with_feed_query_scope(&block)
unless TodosController.is_feed_request(request)
Todo.send(:where, ['todos.state = ?', 'active']) do
@ -143,8 +139,8 @@ class TodosController < ApplicationController
render :action => 'index'
end
format.xml { render :xml => @todos.to_xml( *to_xml_params ) }
format.rss
format.atom
format.rss { @feed_title, @feed_description = 'Tracks Actions', "Actions for #{current_user.display_name}" }
format.atom { @feed_title, @feed_description = 'Tracks Actions', "Actions for #{current_user.display_name}" }
format.text
format.ics
end
@ -192,7 +188,7 @@ class TodosController < ApplicationController
@todo.project_id = project.id
elsif !(p.project_id.nil? || p.project_id.blank?)
project = current_user.projects.find_by_id(p.project_id)
@todo.errors.add(:project, "unknown") if project.nil?
@todo.errors[:project] << "unknown" if project.nil?
end
if p.context_specified_by_name?
@ -202,33 +198,26 @@ class TodosController < ApplicationController
@todo.context_id = context.id
elsif !(p.context_id.nil? || p.context_id.blank?)
context = current_user.contexts.find_by_id(p.context_id)
@todo.errors.add(:context, "unknown") if context.nil?
@todo.errors[:context] << "unknown" if context.nil?
end
if @todo.errors.empty?
@todo.starred= (params[:new_todo_starred]||"").include? "true" if params[:new_todo_starred]
@todo.add_predecessor_list(predecessor_list)
# Fix for #977 because AASM overrides @state on creation
specified_state = @todo.state
@saved = @todo.save
@todo.update_state_from_project if @saved
else
@saved = false
end
unless (@saved == false) || tag_list.blank?
unless ( !@saved ) || tag_list.blank?
@todo.tag_with(tag_list)
@todo.tags.reload
end
if @saved
unless @todo.uncompleted_predecessors.empty? || @todo.state == 'project_hidden'
@todo.state = 'pending'
end
@todo.save
@todo.block! unless @todo.uncompleted_predecessors.empty? || @todo.state == 'project_hidden'
@saved = @todo.save
end
@todo.reload if @saved
@ -268,7 +257,7 @@ class TodosController < ApplicationController
if @saved
head :created, :location => todo_url(@todo)
else
render :xml => @todo.errors.to_xml, :status => 422
render_failure @todo.errors.to_xml.html_safe, 409
end
end
end
@ -1424,84 +1413,6 @@ class TodosController < ApplicationController
return !( all_list_uniq_ids.length == all_list_count )
end
# def render_text_feed
# lambda do
# render :action => 'index', :layout => false, :content_type => Mime::TEXT
# end
# end
#
# def render_ical_feed
# lambda do
# render :action => 'index', :layout => false, :content_type => Mime::ICS
# end
# end
#
# def self.is_feed_request(req)
# ['rss','atom','txt','ics'].include?(req.parameters[:format])
# end
#
# class FindConditionBuilder
#
# def initialize
# @queries = Array.new
# @params = Array.new
# end
#
# def add(query, param)
# @queries << query
# @params << param
# end
#
# def to_conditions
# [@queries.join(' AND ')] + @params
# end
# end
# def render_rss_feed
# lambda do
# render_rss_feed_for @todos, :feed => todo_feed_options,
# :item => {
# :title => :description,
# :link => lambda { |t| @project_feed.nil? ? context_url(t.context) : project_url(t.project) },
# :guid => lambda { |t| todo_url(t) },
# :description => todo_feed_content
# }
# end
# end
#
# def todo_feed_options
# options = Todo.feed_options(current_user)
# options[:title] = @feed_title
# return options
# end
#
# def todo_feed_content
# # TODO: move view stuff into view, also the includes at the top
# lambda do |i|
# item_notes = i.rendered_notes if i.notes?
# due = "<div>#{t('todos.feeds.due', :date => format_date(i.due))}</div>\n" if i.due?
# done = "<div>#{t('todos.feeds.completed', :date => format_date(i.completed_at))}</div>\n" if i.completed?
# context_link = "<a href=\"#{ context_url(i.context) }\">#{ i.context.name }</a>"
# if i.project_id?
# project_link = "<a href=\"#{ project_url(i.project) }\">#{ i.project.name }</a>"
# else
# project_link = "<em>#{t('common.none')}</em>"
# end
# "#{done||''}#{due||''}#{item_notes||''}\n<div>#{t('common.project')}: #{project_link}</div>\n<div>#{t('common.context')}: #{context_link}</div>"
# end
# end
#
# def render_atom_feed
# lambda do
# render_atom_feed_for @todos, :feed => todo_feed_options,
# :item => {
# :title => :description,
# :link => lambda { |t| context_url(t.context) },
# :description => todo_feed_content,
# :author => lambda { |p| nil }
# }
# end
# end
class TodoCreateParamsHelper
def initialize(params, prefs)

View file

@ -65,7 +65,7 @@ class UsersController < ApplicationController
# POST /users POST /users.xml
def create
if params['exception']
render_failure "Expected post format is valid xml like so: <request><login>username</login><password>abc123</password></request>."
render_failure "Expected post format is valid xml like so: <user><login>username</login><password>abc123</password></user>."
return
end
respond_to do |format|
@ -112,23 +112,21 @@ class UsersController < ApplicationController
return
end
format.xml do
unless User.find_by_id_and_is_admin(session['user_id'], true)
unless current_user && current_user.is_admin
render :text => "401 Unauthorized: Only admin users are allowed access to this function.", :status => 401
return
end
unless check_create_user_params
render_failure "Expected post format is valid xml like so: <request><login>username</login><password>abc123</password></request>."
render_failure "Expected post format is valid xml like so: <user><login>username</login><password>abc123</password></user>.", 400
return
end
user = User.new(params[:request])
if Tracks::Config.auth_schemes.include?('cas') && session[:cas_user]
user.auth_type = "cas" #if they area cas user
end
user.password_confirmation = params[:request][:password]
if user.save
user = User.new(params[:user])
user.password_confirmation = params[:user][:password]
saved = user.save
unless user.new_record?
render :text => t('users.user_created'), :status => 200
else
render_failure user.errors.to_xml
render_failure user.errors.to_xml, 409
end
return
end
@ -144,9 +142,9 @@ class UsersController < ApplicationController
respond_to do |format|
format.html do
if @saved
notify :notice, t('users.successfully_deleted_user', :username => @deleted_user.login), 2.0
notify :notice, t('users.successfully_deleted_user', :username => @deleted_user.login)
else
notify :error, t('users.failed_to_delete_user', :username => @deleted_user.login), 2.0
notify :error, t('users.failed_to_delete_user', :username => @deleted_user.login)
end
redirect_to users_url
end
@ -204,11 +202,11 @@ class UsersController < ApplicationController
end
def check_create_user_params
return false unless params.has_key?(:request)
return false unless params[:request].has_key?(:login)
return false if params[:request][:login].empty?
return false unless params[:request].has_key?(:password)
return false if params[:request][:password].empty?
return false unless params.has_key?(:user)
return false unless params[:user].has_key?(:login)
return false if params[:user][:login].empty?
return false unless params[:user].has_key?(:password)
return false if params[:user][:password].empty?
return true
end