From 07aa98e94f04f4ea34d65aba14f17fd38132a158 Mon Sep 17 00:00:00 2001
From: andrew
Date: Sat, 17 Nov 2007 06:13:45 +0000
Subject: [PATCH] adding tags to page models
git-svn-id: http://svn.barleysodas.com/barleysodas/trunk@33 0f7b21a7-9e3a-4941-bbeb-ce5c7c368fa7
---
app/models/page.rb | 1 +
app/models/tag.rb | 2 ++
app/views/pages/_page.rhtml | 2 +-
app/views/pages/_page_form.rhtml | 5 ++++-
db/migrate/005_tags.rb | 18 ++++++++++++++++++
test/fixtures/tags.yml | 5 +++++
test/unit/tag_test.rb | 10 ++++++++++
7 files changed, 41 insertions(+), 2 deletions(-)
create mode 100644 app/models/tag.rb
create mode 100644 db/migrate/005_tags.rb
create mode 100644 test/fixtures/tags.yml
create mode 100644 test/unit/tag_test.rb
diff --git a/app/models/page.rb b/app/models/page.rb
index 3db489b..ff0cbab 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -12,6 +12,7 @@
#
class Page < ActiveRecord::Base
acts_as_versioned
+ acts_as_taggable
belongs_to :owner, :polymorphic => true
validates_presence_of :title
diff --git a/app/models/tag.rb b/app/models/tag.rb
new file mode 100644
index 0000000..972262c
--- /dev/null
+++ b/app/models/tag.rb
@@ -0,0 +1,2 @@
+class Tag < ActiveRecord::Base
+end
diff --git a/app/views/pages/_page.rhtml b/app/views/pages/_page.rhtml
index cb24886..65b8c54 100644
--- a/app/views/pages/_page.rhtml
+++ b/app/views/pages/_page.rhtml
@@ -11,7 +11,7 @@
<%= @page.html %>
+
+ <%= text_field 'page', 'tag_names' %>
+
diff --git a/db/migrate/005_tags.rb b/db/migrate/005_tags.rb
new file mode 100644
index 0000000..238ea4e
--- /dev/null
+++ b/db/migrate/005_tags.rb
@@ -0,0 +1,18 @@
+class Tags < ActiveRecord::Migration
+ def self.up
+ create_table :tags do |t|
+ t.column :name, :string
+ end
+ create_table :tags_pages, :id => false do |t|
+ t.column :tag_id, :integer
+ t.column :page_id, :integer
+ end
+ add_index :tags, :name
+ add_index :tags_pages, [ :tag_id, :page_id ]
+ end
+
+ def self.down
+ drop_table :tags
+ drop_table :tags_pages
+ end
+end
diff --git a/test/fixtures/tags.yml b/test/fixtures/tags.yml
new file mode 100644
index 0000000..b49c4eb
--- /dev/null
+++ b/test/fixtures/tags.yml
@@ -0,0 +1,5 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+ id: 1
+two:
+ id: 2
diff --git a/test/unit/tag_test.rb b/test/unit/tag_test.rb
new file mode 100644
index 0000000..6238c1e
--- /dev/null
+++ b/test/unit/tag_test.rb
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class TagTest < Test::Unit::TestCase
+ fixtures :tags
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end