mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-27 01:24:07 +01:00
get all unit tests running again. Seems we have some pretty old code in there :-)
This commit is contained in:
parent
e964769553
commit
fd4fb6df9e
19 changed files with 255 additions and 284 deletions
|
|
@ -9,15 +9,12 @@ class Context < ActiveRecord::Base
|
|||
scope :hidden, :conditions => { :hide => true }
|
||||
|
||||
acts_as_list :scope => :user, :top_of_list => 0
|
||||
# extend NamePartFinder
|
||||
# include Tracks::TodoList
|
||||
|
||||
attr_protected :user
|
||||
|
||||
validates_presence_of :name, :message => "context must have a name"
|
||||
validates_length_of :name, :maximum => 255, :message => "context name must be less than 256 characters"
|
||||
validates_uniqueness_of :name, :message => "already exists", :scope => "user_id"
|
||||
# validates_does_not_contain :name, :string => ',', :message => "cannot contain the comma (',') character"
|
||||
|
||||
def self.feed_options(user)
|
||||
# TODO: move to view or helper
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
class MessageGateway < ActionMailer::Base
|
||||
include ActionView::Helpers::SanitizeHelper
|
||||
extend ActionView::Helpers::SanitizeHelper::ClassMethods
|
||||
# include ActionView::Helpers::SanitizeHelper
|
||||
# extend ActionView::Helpers::SanitizeHelper::ClassMethods
|
||||
|
||||
def receive(email)
|
||||
puts "email = #{email}"
|
||||
address = ''
|
||||
if SITE_CONFIG['email_dispatch'] == 'to'
|
||||
address = email.to[0]
|
||||
|
|
@ -10,9 +11,9 @@ class MessageGateway < ActionMailer::Base
|
|||
address = email.from[0]
|
||||
end
|
||||
|
||||
user = User.find(:first, :include => [:preference], :conditions => ["preferences.sms_email = ?", address.strip])
|
||||
user = User.where("preferences.sms_email" => address.strip).first(:include => [:preference])
|
||||
if user.nil?
|
||||
user = User.find(:first, :include => [:preference], :conditions => ["preferences.sms_email = ?", address.strip[1,100]])
|
||||
user = User.where("preferences.sms_email" => address.strip[1.100]).first(:include => [:preference])
|
||||
end
|
||||
return if user.nil?
|
||||
context = user.prefs.sms_context
|
||||
|
|
@ -25,7 +26,7 @@ class MessageGateway < ActionMailer::Base
|
|||
body_part = email.parts.find{|m| m.content_type == "text/plain"}
|
||||
notes = sanitize body_part.body.strip
|
||||
else
|
||||
if email.subject.empty?
|
||||
if email.subject && email.subject.blank?
|
||||
description = sanitize email.body.strip
|
||||
notes = nil
|
||||
else
|
||||
|
|
@ -35,7 +36,7 @@ class MessageGateway < ActionMailer::Base
|
|||
end
|
||||
|
||||
# stupid T-Mobile often sends the same message multiple times
|
||||
return if user.todos.find(:first, :conditions => {:description => description})
|
||||
return if user.todos.where(:description => description).first
|
||||
|
||||
todo = Todo.from_rich_message(user, context.id, description, notes)
|
||||
todo.save!
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@ class Tag < ActiveRecord::Base
|
|||
validates_presence_of :name
|
||||
validates_uniqueness_of :name, :case_sensitive => false
|
||||
|
||||
attr_accessible :name
|
||||
|
||||
before_create :before_create
|
||||
|
||||
# Callback to strip extra spaces from the tagname before saving it. If you
|
||||
# allow tags to be renamed later, you might want to use the
|
||||
# <tt>before_save</tt> callback instead.
|
||||
|
|
|
|||
|
|
@ -2,12 +2,18 @@
|
|||
# The Tagging join model.
|
||||
|
||||
class Tagging < ActiveRecord::Base
|
||||
|
||||
attr_accessible :taggable_id, :tag
|
||||
|
||||
belongs_to :tag
|
||||
belongs_to :taggable, :polymorphic => true
|
||||
|
||||
after_destroy :after_destroy
|
||||
|
||||
private
|
||||
|
||||
# This callback makes sure that an orphaned <tt>Tag</tt> is deleted if it no longer tags anything.
|
||||
def after_destroy
|
||||
tag.destroy_without_callbacks if tag and tag.taggings.count == 0
|
||||
tag.destroy if tag and tag.taggings.count == 0
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -104,7 +104,23 @@ class Todo < ActiveRecord::Base
|
|||
validates_length_of :notes, :maximum => 60000, :allow_nil => true
|
||||
validates_presence_of :show_from, :if => :deferred?
|
||||
validates_presence_of :context
|
||||
validate :check_show_from_in_future
|
||||
validate :check_circular_dependencies
|
||||
|
||||
def check_show_from_in_future
|
||||
if !show_from.blank? && show_from < user.date
|
||||
errors.add("show_from", I18n.t('models.todo.error_date_must_be_future'))
|
||||
end
|
||||
end
|
||||
|
||||
def check_circular_dependencies
|
||||
unless @predecessor_array.nil? # Only validate predecessors if they changed
|
||||
@predecessor_array.each do |todo|
|
||||
errors.add("Depends on:", "Adding '#{todo.specification}' would create a circular dependency") if is_successor?(todo)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(*args)
|
||||
super(*args)
|
||||
@predecessor_array = nil # Used for deferred save of predecessors
|
||||
|
|
@ -121,7 +137,7 @@ class Todo < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def uncompleted_predecessors?
|
||||
return !uncompleted_predecessors.all(true).empty?
|
||||
return !uncompleted_predecessors.all.empty?
|
||||
end
|
||||
|
||||
# Returns a string with description <context, project>
|
||||
|
|
@ -130,17 +146,6 @@ class Todo < ActiveRecord::Base
|
|||
return "\'#{self.description}\' <\'#{self.context.title}\'; \'#{project_name}\'>"
|
||||
end
|
||||
|
||||
def validate
|
||||
if !show_from.blank? && show_from < user.date
|
||||
errors.add("show_from", I18n.t('models.todo.error_date_must_be_future'))
|
||||
end
|
||||
unless @predecessor_array.nil? # Only validate predecessors if they changed
|
||||
@predecessor_array.each do |todo|
|
||||
errors.add("Depends on:", "Adding '#{h(todo.specification)}' would create a circular dependency") if is_successor?(todo)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def save_predecessors
|
||||
unless @predecessor_array.nil? # Only save predecessors if they changed
|
||||
current_array = self.predecessors
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ class User < ActiveRecord::Base
|
|||
has_many :contexts,
|
||||
:order => 'position ASC',
|
||||
:dependent => :delete_all do
|
||||
# def find_by_params(params)
|
||||
# find(params['id'] || params['context_id']) || nil
|
||||
# end
|
||||
def find_by_params(params)
|
||||
find(params['id'] || params['context_id']) || nil
|
||||
end
|
||||
def update_positions(context_ids)
|
||||
context_ids.each_with_index {|id, position|
|
||||
context = self.detect { |c| c.id == id.to_i }
|
||||
|
|
@ -23,9 +23,9 @@ class User < ActiveRecord::Base
|
|||
has_many :projects,
|
||||
:order => 'projects.position ASC',
|
||||
:dependent => :delete_all do
|
||||
# def find_by_params(params)
|
||||
# find(params['id'] || params['project_id'])
|
||||
# end
|
||||
def find_by_params(params)
|
||||
find(params['id'] || params['project_id'])
|
||||
end
|
||||
def update_positions(project_ids)
|
||||
project_ids.each_with_index {|id, position|
|
||||
project = self.detect { |p| p.id == id.to_i }
|
||||
|
|
@ -100,17 +100,16 @@ class User < ActiveRecord::Base
|
|||
validates_confirmation_of :password
|
||||
validates_length_of :login, :within => 3..80
|
||||
validates_uniqueness_of :login, :on => :create
|
||||
# validates_presence_of :open_id_url, :if => :using_openid?
|
||||
validate :validate_auth_type
|
||||
|
||||
before_create :crypt_password, :generate_token
|
||||
before_update :crypt_password
|
||||
# before_save :normalize_open_id_url
|
||||
|
||||
#for will_paginate plugin
|
||||
cattr_accessor :per_page
|
||||
@@per_page = 5
|
||||
|
||||
def validate
|
||||
def validate_auth_type
|
||||
unless Tracks::Config.auth_schemes.include?(auth_type)
|
||||
errors.add("auth_type", "not a valid authentication type (#{auth_type})")
|
||||
end
|
||||
|
|
@ -137,25 +136,15 @@ class User < ActiveRecord::Base
|
|||
return candidate if candidate.auth_type.eql?("cas")
|
||||
end
|
||||
|
||||
if Tracks::Config.auth_schemes.include?('open_id')
|
||||
# hope the user enters the correct data
|
||||
return candidate if candidate.auth_type.eql?("open_id")
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
# def self.find_by_open_id_url(raw_identity_url)
|
||||
# normalized_open_id_url = OpenIdAuthentication.normalize_identifier(raw_identity_url)
|
||||
# find(:first, :conditions => ['open_id_url = ?', normalized_open_id_url])
|
||||
# end
|
||||
|
||||
def self.no_users_yet?
|
||||
count == 0
|
||||
end
|
||||
|
||||
def self.find_admin
|
||||
find(:first, :conditions => [ "is_admin = ?", true ])
|
||||
where(:is_admin => true).first
|
||||
end
|
||||
|
||||
def to_param
|
||||
|
|
@ -230,37 +219,22 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def sha1(s)
|
||||
Digest::SHA1.hexdigest salted s
|
||||
Digest::SHA1.hexdigest(salted(s))
|
||||
end
|
||||
|
||||
def hash(s)
|
||||
BCrypt::Password.create s
|
||||
def create_hash(s)
|
||||
BCrypt::Password.create(s)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def crypt_password
|
||||
return if password.blank?
|
||||
write_attribute("crypted_password", hash(password)) if password == password_confirmation
|
||||
write_attribute("crypted_password", self.create_hash(password)) if password == password_confirmation
|
||||
end
|
||||
|
||||
def password_required?
|
||||
auth_type == 'database' && crypted_password.blank? || !password.blank?
|
||||
end
|
||||
|
||||
# def using_openid?
|
||||
# auth_type == 'open_id'
|
||||
# end
|
||||
#
|
||||
# def normalize_open_id_url
|
||||
# return if open_id_url.nil?
|
||||
#
|
||||
# # fixup empty url value
|
||||
# if open_id_url.empty?
|
||||
# self.open_id_url = nil
|
||||
# return
|
||||
# end
|
||||
#
|
||||
# self.open_id_url = OpenIdAuthentication.normalize_identifier(open_id_url)
|
||||
# end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue