public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/council-webapp:master commit in: site/db/, site/features/, site/app/models/, site/spec/models/, site/spec/, ...
@ 2011-05-24 16:58 Petteri Räty
  0 siblings, 0 replies; only message in thread
From: Petteri Räty @ 2011-05-24 16:58 UTC (permalink / raw
  To: gentoo-commits

commit:     8fcbeab8bf791e9b2b793bb85ee5faea80338ac7
Author:     Joachim Filip Ignacy Bartosik <jbartosik <AT> gmail <DOT> com>
AuthorDate: Tue May 17 15:14:01 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue May 24 16:55:39 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/council-webapp.git;a=commit;h=8fcbeab8

Basic meeting participation tracing

When archiving agenda mark all council members as participants. Remember
their names and irc_nicks.

---
 site/app/models/agenda.rb                          |   10 +++++-
 site/app/models/agenda_item.rb                     |    4 +-
 site/app/models/participation.rb                   |   34 ++++++++++++++++++++
 site/app/viewhints/agenda_hints.rb                 |    2 +-
 site/db/schema.rb                                  |   14 +++++++-
 site/features/participations.feature               |   10 ++++++
 .../step_definitions/participations_steps.rb       |   24 ++++++++++++++
 site/spec/factories.rb                             |    2 +
 site/spec/models/agenda_item_spec.rb               |    2 +-
 site/spec/models/agenda_spec.rb                    |   11 ++++++
 site/spec/models/participation_spec.rb             |   20 +++++++++++
 11 files changed, 127 insertions(+), 6 deletions(-)

diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb
index 5998ae8..f8f90df 100644
--- a/site/app/models/agenda.rb
+++ b/site/app/models/agenda.rb
@@ -8,6 +8,7 @@ class Agenda < ActiveRecord::Base
   end
 
   has_many :agenda_items
+  has_many :participations
 
   lifecycle do
     state :open, :default => true
@@ -16,7 +17,14 @@ class Agenda < ActiveRecord::Base
     transition :close, {:open => :submissions_closed}, :available_to => '::Agenda.transitions_available(acting_user)'
     transition :reopen, {:submissions_closed=> :open}, :available_to => '::Agenda.transitions_available(acting_user)'
     transition :archive, {:submissions_closed => :old}, :available_to =>  '::Agenda.transitions_available(acting_user)' do
-      Agenda.new.save!
+      ActiveRecord::Base.transaction do
+        Agenda.new.save!
+        ::User.council_member_is(true).each do |participant|
+          Participation.create! :irc_nick => participant.irc_nick,
+                                :participant => participant,
+                                :agenda => self
+        end
+      end
     end
   end
 

diff --git a/site/app/models/agenda_item.rb b/site/app/models/agenda_item.rb
index 1bb3a36..f5108bd 100644
--- a/site/app/models/agenda_item.rb
+++ b/site/app/models/agenda_item.rb
@@ -21,7 +21,7 @@ class AgendaItem < ActiveRecord::Base
   end
 
   def update_permitted?
-    return false if agenda._?.state == 'archived'
+    return false if agenda._?.state == 'old'
     return false if user_changed?
     return true if acting_user.council_member?
     return true if acting_user.administrator?
@@ -42,7 +42,7 @@ class AgendaItem < ActiveRecord::Base
   def edit_permitted?(field)
     return false if field == :rejected && !agenda.nil?
     return false if field == :agenda && rejected?
-    return false if agenda._?.state == 'archived'
+    return false if agenda._?.state == 'old'
     return false if field == :user
     return true if acting_user.administrator?
     return true if acting_user.council_member?

diff --git a/site/app/models/participation.rb b/site/app/models/participation.rb
new file mode 100644
index 0000000..95c4142
--- /dev/null
+++ b/site/app/models/participation.rb
@@ -0,0 +1,34 @@
+class Participation < ActiveRecord::Base
+
+  hobo_model # Don't put anything above this
+
+  fields do
+    irc_nick :string
+    timestamps
+  end
+
+  belongs_to :participant, :class_name => 'User'
+  belongs_to :agenda
+
+  # --- Permissions --- #
+
+  def create_permitted?
+    false
+  end
+
+  def update_permitted?
+    false
+  end
+
+  def destroy_permitted?
+    false
+  end
+
+  def view_permitted?(field)
+    true
+  end
+
+  def name
+    participant.name
+  end
+end

diff --git a/site/app/viewhints/agenda_hints.rb b/site/app/viewhints/agenda_hints.rb
index 05c7b96..46daf34 100644
--- a/site/app/viewhints/agenda_hints.rb
+++ b/site/app/viewhints/agenda_hints.rb
@@ -1,5 +1,5 @@
 class AgendaHints < Hobo::ViewHints
 
-  children :agenda_items
+  children :agenda_items, :participations
 
 end

diff --git a/site/db/schema.rb b/site/db/schema.rb
index edd7ee0..cf1a791 100644
--- a/site/db/schema.rb
+++ b/site/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20110523180314) do
+ActiveRecord::Schema.define(:version => 20110523180453) do
 
   create_table "agenda_items", :force => true do |t|
     t.string   "title"
@@ -36,6 +36,18 @@ ActiveRecord::Schema.define(:version => 20110523180314) do
 
   add_index "agendas", ["state"], :name => "index_agendas_on_state"
 
+  create_table "participations", :force => true do |t|
+    t.string   "name"
+    t.string   "irc_nick"
+    t.datetime "created_at"
+    t.datetime "updated_at"
+    t.integer  "participant_id"
+    t.integer  "agenda_id"
+  end
+
+  add_index "participations", ["agenda_id"], :name => "index_participations_on_agenda_id"
+  add_index "participations", ["participant_id"], :name => "index_participations_on_participant_id"
+
   create_table "users", :force => true do |t|
     t.string   "salt",                      :limit => 40
     t.string   "remember_token"

diff --git a/site/features/participations.feature b/site/features/participations.feature
new file mode 100644
index 0000000..69cb5dd
--- /dev/null
+++ b/site/features/participations.feature
@@ -0,0 +1,10 @@
+Feature: In order to track presence on the council meetings
+  I want the application to store participations
+
+  Scenario: When archiving agenda mark all council members as participants
+    Given some council members
+    And I am logged in as council member
+    And an closed agenda
+    When I am on the current agenda page
+    And I archive current agenda
+    Then I should see all council members as participants

diff --git a/site/features/step_definitions/participations_steps.rb b/site/features/step_definitions/participations_steps.rb
new file mode 100644
index 0000000..fe3966c
--- /dev/null
+++ b/site/features/step_definitions/participations_steps.rb
@@ -0,0 +1,24 @@
+Given /^some council members$/ do
+  (1..8).each do |n|
+    u = User.new
+    u.name = "Member no #{n}"
+    u.email = "member-#{n}@example.com"
+    u.irc_nick = "member-#{n}"
+    u.password = "Example"
+    u.council_member = true
+    u.save!
+  end
+end
+
+Given /^I am logged in as council member$/ do
+  When 'I am on the login page'
+  When 'I fill in "login" with "member-1@example.com"'
+  When 'I fill in "password" with "Example"'
+  When 'I press "Login"'
+end
+
+Then /^I should see all council members as participants$/ do
+  User.council_member_is(true).each do |m|
+    Then "I should see \"#{m.name}\" within \".collection.participations.participations-collection\""
+  end
+end

diff --git a/site/spec/factories.rb b/site/spec/factories.rb
index 3211032..7405ee9 100644
--- a/site/spec/factories.rb
+++ b/site/spec/factories.rb
@@ -11,3 +11,5 @@ end
 Factory.define :agenda do |a|; end
 
 Factory.define :agenda_item do |a|; end
+
+Factory.define :participation do |p|; end

diff --git a/site/spec/models/agenda_item_spec.rb b/site/spec/models/agenda_item_spec.rb
index 95d7659..3df2a59 100644
--- a/site/spec/models/agenda_item_spec.rb
+++ b/site/spec/models/agenda_item_spec.rb
@@ -49,7 +49,7 @@ describe AgendaItem do
 
   it 'should allow no one edit and update items assigned to archived agenda' do
     owner = Factory(:user)
-    agenda = Factory(:agenda, :state => 'archived')
+    agenda = Factory(:agenda, :state => 'old')
     a = Factory(:agenda_item, :user => owner, :agenda => agenda)
     for u in users_factory(AllRoles) + [owner]
       a.should_not be_editable_by(u)

diff --git a/site/spec/models/agenda_spec.rb b/site/spec/models/agenda_spec.rb
index 0a69551..14a1178 100644
--- a/site/spec/models/agenda_spec.rb
+++ b/site/spec/models/agenda_spec.rb
@@ -93,4 +93,15 @@ describe Agenda do
     a1.meeting_time.strftime('%Y-%m-%d').should == today
     a2.meeting_time.strftime('%Y-%m-%d').should_not == today
   end
+
+  it 'should add all council members and only them as participants when archived' do
+    users_factory(:user, :admin)
+    users_factory(:council, :council)
+    council_names = User.council_member_is(true).collect{ |c| c.name }
+    agenda = Factory(:agenda, :state => 'submissions_closed')
+    agenda.lifecycle.archive!(User.council_member_is(true).first)
+
+    (council_names - agenda.participations.*.participant.*.name).should be_empty
+    (agenda.participations.*.participant.*.name - council_names).should be_empty
+  end
 end

diff --git a/site/spec/models/participation_spec.rb b/site/spec/models/participation_spec.rb
new file mode 100644
index 0000000..eb2ecba
--- /dev/null
+++ b/site/spec/models/participation_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe Participation do
+  it 'should not allow anyone to create, edit, update or destroy' do
+    p = Factory(:participation)
+    for u in users_factory(AllRoles)
+      p.should_not be_creatable_by(u)
+      p.should_not be_editable_by(u)
+      p.should_not be_updatable_by(u)
+      p.should_not be_destroyable_by(u)
+    end
+  end
+
+  it 'should allow everybody to view' do
+    p = Factory(:participation)
+    for u in users_factory(AllRoles)
+      p.should be_viewable_by(u)
+    end
+  end
+end



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-05-24 16:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-24 16:58 [gentoo-commits] proj/council-webapp:master commit in: site/db/, site/features/, site/app/models/, site/spec/models/, site/spec/, Petteri Räty

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox