Skip to content

Commit

Permalink
Fix dumbness, allow clean user deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
ook committed Dec 23, 2008
1 parent 3d89026 commit 53ca27f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
6 changes: 2 additions & 4 deletions app/controllers/tasks_controller.rb
Expand Up @@ -6,7 +6,7 @@ def index
@tasks = current_user.tasks
@dated_tasks = current_user.tasks.dated
@later_tasks = current_user.tasks.later
@categories = current_user.categories
@categories = current_user.categories_values

unless cookies[:been_here]
@first_time = true
Expand Down Expand Up @@ -40,9 +40,7 @@ def new
end

def edit
puts current_user
puts current_user.categories.size
@categories = current_user.categories.sort
@categories = current_user.categories_values
respond_to do |format|
format.html
format.js
Expand Down
3 changes: 2 additions & 1 deletion app/models/task.rb
Expand Up @@ -46,7 +46,8 @@ def extract_category_from_name
extracted_category, extracted_name = /^(?:\[([^\]]+)\]|)\s?(.*)$/.match(self.name)[1,2]

if extracted_category
self.category = Category.find_or_create_by_name_and_user_id(extracted_category, user.id)
self.category = Category.find_by_name_and_user_id(extracted_category, user.id)
self.category ||= Category.create(:name => extracted_category, :user_id => user.id)
self.name = extracted_name
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/models/user.rb
@@ -1,6 +1,7 @@
require 'digest/sha1'
class User < ActiveRecord::Base
has_many :tasks
has_many :tasks, :dependent => :destroy
has_many :categories, :dependent => :destroy

# Virtual attribute for the unencrypted password
attr_accessor :password
Expand Down Expand Up @@ -61,9 +62,8 @@ def forget_me
save(false)
end

def categories
# tasks.find(:all).collect(&:category).reject(&:blank?).uniq.collect(&:name).sort
Category.find_all_by_user_id(id).collect(&:name).sort
def categories_values
categories.collect(&:name).sort
end

protected
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/004_add_user_id_to_tasks.rb
@@ -1,6 +1,6 @@
class AddUserIdToTasks < ActiveRecord::Migration
def self.up
add_column :tasks, :user_id, :integer
add_column :tasks, :user_id, :integer, :null => false
end

def self.down
Expand Down
4 changes: 2 additions & 2 deletions test/unit/task_test.rb
Expand Up @@ -60,8 +60,8 @@ def test_extract_category_from_name
end

def test_find_all_categories
assert_equal %w(Miscellaneous Project), users(:quentin).categories
assert_equal %w(Project), users(:aaron).categories
assert_equal %w(Miscellaneous Project), users(:quentin).categories_values
assert_equal %w(Project), users(:aaron).categories_values
end

def test_extract_due_date_from_name_with_idioms
Expand Down

0 comments on commit 53ca27f

Please sign in to comment.