ACK - Okay !
--
Benjamin LAN-SUN-LUK
Le 28/03/09 14:24, « Darryl L. Pierce » <mcpierce(a)gmail.com> a écrit :
THIS PATCH REQUIRES A MIGRATION.
A new table and domain object, SprintMember, was created. This maps
users to the sprint for which they're a member.
Each sprint will now load its list of members and make them available
through the new "members" collection. Members can be added to the
membership list via the "sprint_members" association of Sprint.
Signed-off-by: Darryl L. Pierce <mcpierce(a)gmail.com>
---
app/models/sprint.rb | 4 ++
app/models/sprint_member.rb | 27 +++++++++++++++
db/migrate/027_create_sprint_members.rb | 33 ++++++++++++++++++
test/fixtures/sprint_members.yml | 3 ++
test/unit/sprint_member_test.rb | 56 +++++++++++++++++++++++++++++++
5 files changed, 123 insertions(+), 0 deletions(-)
create mode 100644 app/models/sprint_member.rb
create mode 100644 db/migrate/027_create_sprint_members.rb
create mode 100644 test/fixtures/sprint_members.yml
create mode 100644 test/unit/sprint_member_test.rb
diff --git a/app/models/sprint.rb b/app/models/sprint.rb
index f2cb1f9..b50938f 100644
--- a/app/models/sprint.rb
+++ b/app/models/sprint.rb
@@ -64,6 +64,10 @@ class Sprint < ActiveRecord::Base
belongs_to :product
belongs_to :team_lead, :class_name => 'User', :foreign_key =>
:team_lead_id
+ # sprint membership
+ has_many :sprint_members, :dependent => :destroy
+ has_many :members, :through => :sprint_members
+
has_many :backlog_items,
:order => '(select priority from user_stories where id = user_story_id)
ASC',
:dependent => :destroy
diff --git a/app/models/sprint_member.rb b/app/models/sprint_member.rb
new file mode 100644
index 0000000..20f8f72
--- /dev/null
+++ b/app/models/sprint_member.rb
@@ -0,0 +1,27 @@
+# sprint_member.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/>.
+#
+
+# A +SprintMember+ maps a user's membership to a sprint.
+class SprintMember < ActiveRecord::Base
+ validates_presence_of :sprint_id, :message => "A sprint is required."
+ validates_presence_of :member_id, :message => "A member is required."
+
+ validates_uniqueness_of :member_id, :scope => [:sprint_id]
+
+ belongs_to :sprint
+ belongs_to :member, :class_name => 'User', :foreign_key =>
'member_id'
+end
diff --git a/db/migrate/027_create_sprint_members.rb
b/db/migrate/027_create_sprint_members.rb
new file mode 100644
index 0000000..c6ccce5
--- /dev/null
+++ b/db/migrate/027_create_sprint_members.rb
@@ -0,0 +1,33 @@
+# 027_create_sprint_members.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 CreateSprintMembers < ActiveRecord::Migration
+ def self.up
+ create_table :sprint_members do |t|
+ t.integer :sprint_id, :null => false
+ t.integer :member_id, :null => false
+
+ t.timestamps
+ end
+
+ add_index :sprint_members, [:sprint_id, :member_id], :unique => true, :name =>
:single_membership
+ end
+
+ def self.down
+ drop_table :sprint_members
+ end
+end
diff --git a/test/fixtures/sprint_members.yml b/test/fixtures/sprint_members.yml
new file mode 100644
index 0000000..8cc07a2
--- /dev/null
+++ b/test/fixtures/sprint_members.yml
@@ -0,0 +1,3 @@
+mcpierce_active_sprint:
+ sprint_id: <%= Fixtures.identify(:active_sprint) %>
+ member_id: <%= Fixtures.identify(:mcpierce) %>
diff --git a/test/unit/sprint_member_test.rb b/test/unit/sprint_member_test.rb
new file mode 100644
index 0000000..da4e3bc
--- /dev/null
+++ b/test/unit/sprint_member_test.rb
@@ -0,0 +1,56 @@
+# 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/>.
+#
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class SprintTeamTest < ActiveSupport::TestCase
+ fixtures :sprint_members
+ fixtures :sprints
+ fixtures :users
+
+ def setup
+ @sprint = sprints(:inactive_sprint)
+ @team_lead = @sprint.team_lead
+ @member = users(:mcpierce)
+
+ @membership = SprintMember.new(:sprint => @sprint, :member => @member)
+ @existing_membership = sprint_members(:mcpierce_active_sprint)
+ end
+
+ # Ensures that a membership requires a sprint reference.
+ def test_sprint_is_required
+ @membership.sprint = nil
+ flunk "Membership requires a sprint." if @membership.valid?
+ end
+
+ # Ensures that a membership requires a user reference.
+ def test_member_is_required
+ @membership.member = nil
+ flunk "Membership requires a member." if @membership.valid?
+ end
+
+ # Ensures that a well-formed membership is valid.
+ def test_valid
+ flunk "There is a general validation error." unless @membership.valid?
+ end
+
+ # Ensures that a user cannot have two memberships to the same sprint.
+ def test_unique_memberships
+ membership = SprintMember.new(:sprint => @existing_membership.sprint,
+ :member => @existing_membership.member)
+ flunk "There is a problem with uniqueness constraints." if
membership.valid?
+ end
+end
--
1.6.0.6
_______________________________________________
projxp-devel mailing list
projxp-devel(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/projxp-devel