THIS PATCH REQUIRES A MIGRATION
The new table contains a foreign key to the author, and includes the
data and body of the message. It also includes a reference to another
message if the current is in reply to another message.
Signed-off-by: Darryl L. Pierce <mcpierce(a)gmail.com>
---
app/models/message.rb | 2 +
db/migrate/018_create_messages.rb | 38 +++++++++++++++++++++++++++++++++++++
test/fixtures/messages.yml | 11 ++++++++++
test/unit/message_test.rb | 8 +++++++
4 files changed, 59 insertions(+), 0 deletions(-)
create mode 100644 app/models/message.rb
create mode 100644 db/migrate/018_create_messages.rb
create mode 100644 test/fixtures/messages.yml
create mode 100644 test/unit/message_test.rb
diff --git a/app/models/message.rb b/app/models/message.rb
new file mode 100644
index 0000000..590e3e3
--- /dev/null
+++ b/app/models/message.rb
@@ -0,0 +1,2 @@
+class Message < ActiveRecord::Base
+end
diff --git a/db/migrate/018_create_messages.rb b/db/migrate/018_create_messages.rb
new file mode 100644
index 0000000..7d1197a
--- /dev/null
+++ b/db/migrate/018_create_messages.rb
@@ -0,0 +1,38 @@
+# 018_create_messages.rb
+# Copyright (C) 2009, Darryl L. Pierce <mcpierce(a)gmail.com>
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <
http://www.gnu.org/licenses/>.
+#
+
+class CreateMessages < ActiveRecord::Migration
+ def self.up
+ create_table :messages do |t|
+ t.integer :author_id, :null => false
+ t.datetime :posted, :null => false
+ t.integer :reference_id, :null => true
+ t.text :body, :null => false
+
+ t.timestamps
+ end
+
+ execute 'alter table messages add constraint fk_message_author
+ foreign key(author_id) references users(id)'
+ execute 'alter table messages add constraint fk_message_references
+ foreign key(reference_id) references messages(id)'
+ end
+
+ def self.down
+ drop_table :messages
+ end
+end
diff --git a/test/fixtures/messages.yml b/test/fixtures/messages.yml
new file mode 100644
index 0000000..a621608
--- /dev/null
+++ b/test/fixtures/messages.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at
http://ar.rubyonrails.org/classes/Fixtures.html
+
+one:
+ author_id: 1
+ posted: 2009-05-06 08:19:35
+ body: MyText
+
+two:
+ author_id: 1
+ posted: 2009-05-06 08:19:35
+ body: MyText
diff --git a/test/unit/message_test.rb b/test/unit/message_test.rb
new file mode 100644
index 0000000..eb11506
--- /dev/null
+++ b/test/unit/message_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class MessageTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
--
1.6.0.6