Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix dumbness, allow clean user deletion

  • Loading branch information...
commit 53ca27f1ffcce5ca3f4c3a52e6986fdc2da020e3 1 parent 3d89026
@ook authored
View
6 app/controllers/tasks_controller.rb
@@ -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
@@ -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
View
3  app/models/task.rb
@@ -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
View
8 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
@@ -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
View
2  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
View
4 test/unit/task_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.