ACK - Works great ;)
--
Benjamin LAN-SUN-LUK
Le 25/11/08 17:10, « Darryl L. Pierce » <mcpierce(a)gmail.com> a écrit :
From: Darryl L. Pierce <dpierce(a)redhat.com>
A mailing list is now validated for format, but is not required
for a product to created.
Created a new colgroup for details tables to make sure the label
is shown at a minimum size.
Signed-off-by: Darryl L. Pierce <dpierce(a)redhat.com>
---
app/models/product.rb | 6 +++++
app/views/products/_edit.html.erb | 20 ++++++++++++++----
app/views/products/show.html.erb | 18 ++++++++++++++--
db/migrate/021_add_mailing_list_to_product.rb | 26 +++++++++++++++++++++++++
db/schema.rb | 25 +++--------------------
public/stylesheets/details.css | 8 +++++++
public/stylesheets/forms.css | 8 +++++++
test/unit/product_test.rb | 21 +++++++++++++++++--
8 files changed, 100 insertions(+), 32 deletions(-)
create mode 100644 db/migrate/021_add_mailing_list_to_product.rb
diff --git a/app/models/product.rb b/app/models/product.rb
index fc2523f..18a6fe6 100644
--- a/app/models/product.rb
+++ b/app/models/product.rb
@@ -27,6 +27,12 @@ class Product < ActiveRecord::Base
validates_presence_of :name,
:message => 'A product must have a name.'
+ validates_format_of :mailing_list,
+ :allow_blank => true,
+ :allow_nil => true,
+ :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i,
+ :message => 'Mailing list must be a valid email address.'
+
belongs_to :project
belongs_to :owner,
:class_name => 'User',
diff --git a/app/views/products/_edit.html.erb b/app/views/products/_edit.html.erb
index 60c818c..e554591 100644
--- a/app/views/products/_edit.html.erb
+++ b/app/views/products/_edit.html.erb
@@ -11,6 +11,11 @@
<%= hidden_field :product, :project_id %>
<table class="edit">
+ <colgroup>
+ <col class="label" />
+ <col class="value" />
+ </colgroup>
+
<tbody>
<tr>
<td class="label-required">Project</td>
@@ -18,11 +23,11 @@
</tr>
<tr>
- <td class="label-required">Name</td>
- <td class="value">
- <%= form.text_field :name %>
- <%= error_message_on(:product, :name) %>
- </td>
+ <td class="label-required">Name</td>
+ <td class="value">
+ <%= form.text_field :name %>
+ <%= error_message_on(:product, :name) %>
+ </td>
</tr>
<tr>
@@ -43,6 +48,11 @@
</tr>
<tr>
+ <td class="label">Mailing list</td>
+ <td class="value"><%= form.text_field :mailing_list
%></td>
+ </tr>
+
+ <tr>
<td class="label">Description</td>
<td class="value">
<%= form.text_area :description %>
diff --git a/app/views/products/show.html.erb b/app/views/products/show.html.erb
index 3cbaf63..ac843a2 100644
--- a/app/views/products/show.html.erb
+++ b/app/views/products/show.html.erb
@@ -1,4 +1,9 @@
<table class="detail">
+ <colgroup>
+ <col class="label" />
+ <col class="value" />
+ </colgroup>
+
<thead>
<tr>
<th class="title" colspan="2"><%= "Details For
#{(a)product.name}" %></th>
@@ -25,6 +30,13 @@
<td class="value"><%= link_to @product.owner.display_name,
user_path((a)product.owner) %></td>
</tr>
+ <% unless @product.mailing_list.empty? %>
+ <tr>
+ <td class="label">Mailing list:</td>
+ <td class="value"><%= mail_to @product.mailing_list,
@product.mailing_list %>
+ </tr>
+ <% end %>
+
<tr>
<td class="label">For Project:</td>
<td class="value"><%= link_to @product.project.name,
project_path((a)product.project) %></td>
@@ -35,9 +47,9 @@
<td class="value">
<%= link_to "#{(a)product.active_roles.size > 0 ?
@product.active_roles.size : 'No'} Active Members",
product_roles_path(@product) %>
- <% if @product.is_owner?(@user) %>
- <%= "(#{(a)product.pending_roles.size > 0 ?
@product.pending_roles.size : 'No'} Role Requests)" %>
- <% end %>
+ <% if @product.is_owner?(@user) %>
+ <%= "(#{(a)product.pending_roles.size > 0 ?
@product.pending_roles.size : 'No'} Role Requests)" %>
+ <% end %>
</td>
</tr>
diff --git a/db/migrate/021_add_mailing_list_to_product.rb
b/db/migrate/021_add_mailing_list_to_product.rb
new file mode 100644
index 0000000..a0c1ffa
--- /dev/null
+++ b/db/migrate/021_add_mailing_list_to_product.rb
@@ -0,0 +1,26 @@
+# 021_add_mailing_list_to_product.rb
+# Copyright (C) 2008, 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 AddMailingListToProduct < ActiveRecord::Migration
+ def self.up
+ add_column :products, :mailing_list, :string, :limit => 128, :null => true
+ end
+
+ def self.down
+ remove_column :products, :mailing_list
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 6215516..ce24b1e 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20) do
+ActiveRecord::Schema.define(:version => 21) do
create_table "backlog_items", :force => true do |t|
t.integer "sprint_id",
:null => false
@@ -23,7 +23,6 @@ ActiveRecord::Schema.define(:version => 20) do
end
add_index "backlog_items", ["sprint_id",
"user_story_id"], :name =>
"index_backlog_items_on_sprint_id_and_user_story_id", :unique => true
- add_index "backlog_items", ["user_story_id"], :name =>
"fk_backlog_items_user_story"
create_table "notifications", :force => true do |t|
t.integer "user_id"
@@ -43,21 +42,19 @@ ActiveRecord::Schema.define(:version => 20) do
t.boolean "is_approved", :default => false
end
- add_index "product_roles", ["user_id", "product_id"],
:name => "index_product_roles_on_user_id_and_product_id", :unique => true
- add_index "product_roles", ["product_id"], :name =>
"fk_user_role_product"
- add_index "product_roles", ["role_id"], :name =>
"fk_user_role_role"
+ add_index "product_roles", ["product_id", "user_id"],
:name => "index_product_roles_on_user_id_and_product_id", :unique => true
create_table "products", :force => true do |t|
t.integer "project_id"
t.integer "owner_id"
- t.string "name", :limit => 128
+ t.string "name", :limit => 128
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
+ t.string "mailing_list", :limit => 128
end
add_index "products", ["name"], :name =>
"index_products_on_name", :unique => true
- add_index "products", ["project_id"], :name =>
"fk_products_project"
create_table "projects", :force => true do |t|
t.integer "owner_id", :null => false
@@ -69,7 +66,6 @@ ActiveRecord::Schema.define(:version => 20) do
end
add_index "projects", ["name"], :name =>
"index_projects_on_name", :unique => true
- add_index "projects", ["owner_id"], :name =>
"fk_product_owner"
create_table "remaining_hours_estimates", :force => true do |t|
t.integer "backlog_item_id", :null =>
false
@@ -80,9 +76,6 @@ ActiveRecord::Schema.define(:version => 20) do
t.datetime "estimated_on", :null =>
false
end
- add_index "remaining_hours_estimates", ["backlog_item_id"], :name
=> "fk_remaining_hours_item"
- add_index "remaining_hours_estimates", ["user_id"], :name =>
"fk_remaining_hours_user"
-
create_table "roles", :force => true do |t|
t.string "name", :null =>
false
t.boolean "can_manage_backlog_items", :default => false, :null =>
false
@@ -114,8 +107,6 @@ ActiveRecord::Schema.define(:version => 20) do
t.integer "status", :default => 0, :null =>
false
end
- add_index "sprints", ["product_id"], :name =>
"fk_sprint_product"
-
create_table "tasks", :force => true do |t|
t.integer "backlog_item_id",
:null => false
t.integer "primary_id",
:null => false
@@ -127,10 +118,6 @@ ActiveRecord::Schema.define(:version => 20) do
t.datetime "updated_at"
end
- add_index "tasks", ["backlog_item_id"], :name =>
"fk_task_backlog_item"
- add_index "tasks", ["primary_id"], :name =>
"fk_task_primary"
- add_index "tasks", ["backup_id"], :name =>
"fk_task_backup"
-
create_table "user_privileges", :force => true do |t|
t.integer "user_id", :null => false
t.boolean "admin_projects", :default => false, :null => false
@@ -139,8 +126,6 @@ ActiveRecord::Schema.define(:version => 20) do
t.datetime "updated_at"
end
- add_index "user_privileges", ["user_id"], :name =>
"fk_privilege_user"
-
create_table "user_stories", :force => true do |t|
t.integer "product_id"
t.integer "priority"
@@ -151,8 +136,6 @@ ActiveRecord::Schema.define(:version => 20) do
t.datetime "updated_at"
end
- add_index "user_stories", ["product_id"], :name =>
"fk_user_story_product"
-
create_table "user_verifications", :force => true do |t|
t.integer "user_id", :null => false
t.string "token", :limit => 16, :null => false
diff --git a/public/stylesheets/details.css b/public/stylesheets/details.css
index 07ab512..82bacdf 100644
--- a/public/stylesheets/details.css
+++ b/public/stylesheets/details.css
@@ -1,3 +1,11 @@
+table.detail col.label {
+ min-width: 25%;
+}
+
+table.detail col.value {
+ width: 90%;
+}
+
table.detail {
width: 100%;
padding: 5px 15px 5px 15px;
diff --git a/public/stylesheets/forms.css b/public/stylesheets/forms.css
index 0452925..a1d1b7d 100644
--- a/public/stylesheets/forms.css
+++ b/public/stylesheets/forms.css
@@ -3,6 +3,14 @@
font-weight: bold;
}
+table.edit col.label {
+ min-width: 25%;
+}
+
+table.edit col.value {
+ width: 90%;
+}
+
table.edit, table.edit td.label, table.edit td.label-required {
background: #f7f7f7;
}
diff --git a/test/unit/product_test.rb b/test/unit/product_test.rb
index c994a15..e016e5d 100644
--- a/test/unit/product_test.rb
+++ b/test/unit/product_test.rb
@@ -26,9 +26,10 @@ class ProductTest < ActiveSupport::TestCase
@project = projects(:projxp)
@new_product = Product.new(
- :project_id => @project.id,
- :owner_id => @project.owner.id,
- :name => "Test Product")
+ :project_id => @project.id,
+ :owner_id => @project.owner.id,
+ :name => "Test Product",
+ :mailing_list => 'test(a)projxp.org')
@existing_product = products(:projxp_web)
@owner = @existing_product.owner
@@ -50,6 +51,20 @@ class ProductTest < ActiveSupport::TestCase
flunk "Products must have an owner." if @new_product.valid?
end
+ # Ensures that a mailing list must be well formed if present.
+ def test_valid_fails_with_bad_mailing_list
+ @new_product.mailing_list = 'farkle'
+
+ flunk "Products must have a well-formatted mailing list." if
@new_product.valid?
+ end
+
+ # Ensures that a mailing list is not required.
+ def test_valid_without_mailing_list
+ @new_product.mailing_list = ""
+
+ flunk "A mailing list is not required." unless @new_product.valid?
+ end
+
# Ensures that a well-formed product is valid.
def test_valid
flunk "There is a general validation problem." unless @new_product.valid?
--
1.6.0.3
_______________________________________________
projxp-devel mailing list
projxp-devel(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/projxp-devel