Commit 83f48698f6f8aff8cf7a6f8eaa708b844f78dafa

Authored by AntonioTerceiro
1 parent 1abaaf1a

ActionItem96: creating task class



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@610 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/task.rb 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +class Task < ActiveRecord::Base
  2 + belongs_to :requestor, :class_name => 'Profile', :foreign_key => :requestor_id
  3 + belongs_to :target, :class_name => 'Profile', :foreign_key => :target_id
  4 +end
... ...
db/migrate/017_create_tasks.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +class CreateTasks < ActiveRecord::Migration
  2 + def self.up
  3 + create_table :tasks do |t|
  4 +
  5 + t.column :data, :text
  6 + t.column :status, :integer
  7 +
  8 + t.column :requestor_id, :integer
  9 + t.column :target_id, :integer
  10 + end
  11 + end
  12 +
  13 + def self.down
  14 + drop_table :tasks
  15 + end
  16 +end
... ...
test/unit/task_test.rb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class TaskTest < Test::Unit::TestCase
  4 +
  5 + def test_relationship_with_requestor
  6 + t = Task.new
  7 + assert_raise ActiveRecord::AssociationTypeMismatch do
  8 + t.requestor = 1
  9 + end
  10 + assert_nothing_raised do
  11 + t.requestor = Profile.new
  12 + end
  13 + end
  14 +
  15 + def test_relationship_with_target
  16 + t = Task.new
  17 + assert_raise ActiveRecord::AssociationTypeMismatch do
  18 + t.target = 1
  19 + end
  20 + assert_nothing_raised do
  21 + t.target = Profile.new
  22 + end
  23 + end
  24 +end
... ...