public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/council-webapp:master commit in: site/app/models/, site/spec/models/
@ 2011-06-18 15:42 Petteri Räty
  0 siblings, 0 replies; 4+ messages in thread
From: Petteri Räty @ 2011-06-18 15:42 UTC (permalink / raw
  To: gentoo-commits

commit:     2b881b6ab25ff7b659548d1b7dc9e4b877081f14
Author:     Joachim Filip Ignacy Bartosik <jbartosik <AT> gmail <DOT> com>
AuthorDate: Mon Jun 13 11:44:07 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Jun 17 18:36:10 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/council-webapp.git;a=commit;h=2b881b6a

Improve Agenda model spec coverage

Fixed Agenda#current? - now it returns true for agendas in state meeting_ongoing.

---
 site/app/models/agenda.rb       |    2 +-
 site/spec/models/agenda_spec.rb |   43 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 1 deletions(-)

diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb
index 5be2d82..8f05e09 100644
--- a/site/app/models/agenda.rb
+++ b/site/app/models/agenda.rb
@@ -86,7 +86,7 @@ class Agenda < ActiveRecord::Base
   end
 
   def current?
-    ['open', 'submissions_closed'].include?(state.to_s)
+    ['open', 'submissions_closed', 'meeting_ongoing'].include?(state.to_s)
   end
 
   def voting_array

diff --git a/site/spec/models/agenda_spec.rb b/site/spec/models/agenda_spec.rb
index 29f0bcb..b9fbd36 100644
--- a/site/spec/models/agenda_spec.rb
+++ b/site/spec/models/agenda_spec.rb
@@ -204,4 +204,47 @@ describe Agenda do
 
     Agenda.irc_reminders.should be_empty
   end
+
+  it 'should return proper possible_transitions for each state' do
+    a = Factory(:agenda)
+    u = users_factory(:council)
+    a.possible_transitions.should == [["Close this agenda.", "agenda_close_path"]]
+    a.lifecycle.close!(u)
+    a.possible_transitions.should == [["Reopen this agenda.", "agenda_reopen_path"], ["Archive this agenda.", "agenda_archive_path"]]
+    a.lifecycle.archive!(u)
+    a.possible_transitions.should == []
+  end
+
+  describe '#current?' do
+    it 'should return true if agenda is in open state' do
+      Factory(:agenda).should be_current
+    end
+
+    it 'should return true if agenda is in submissions_closed state' do
+      Factory(:agenda, :state => 'submissions_closed').should be_current
+    end
+
+    it 'should return true if agenda is in meeting_ongoing state' do
+      Factory(:agenda, :state => 'meeting_ongoing').should be_current
+    end
+
+    it 'should return true if agenda is in old state' do
+      Factory(:agenda, :state => 'old').should_not be_current
+    end
+  end
+
+  it 'should return proper voting_array' do
+    old_agenda = Factory(:agenda, :state => 'old')
+    current_agenda = Factory(:agenda)
+    i1 = Factory(:agenda_item, :agenda => old_agenda)
+    i2 = Factory(:agenda_item, :agenda => current_agenda)
+    i3 = Factory(:agenda_item, :agenda => current_agenda)
+
+    v11 = Factory(:voting_option, :agenda_item => i1)
+    v21 = Factory(:voting_option, :agenda_item => i2)
+    v22 = Factory(:voting_option, :agenda_item => i2, :description => 'other')
+
+    old_agenda.voting_array.should == [[i1.title, [v11.description]]]
+    current_agenda.voting_array.should == [[i2.title, [v21.description, v22.description]], [i3.title, []]]
+  end
 end



^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [gentoo-commits] proj/council-webapp:master commit in: site/app/models/, site/spec/models/
@ 2011-07-05 15:09 Petteri Räty
  0 siblings, 0 replies; 4+ messages in thread
From: Petteri Räty @ 2011-07-05 15:09 UTC (permalink / raw
  To: gentoo-commits

commit:     38bfc2754eeb6db9697a1f258fc652875566e8ba
Author:     Joachim Filip Ignacy Bartosik <jbartosik <AT> gmail <DOT> com>
AuthorDate: Tue Jun 28 15:53:04 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Jul  5 09:58:11 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/council-webapp.git;a=commit;h=38bfc275

Show slacking status properly when there were no meetings yet.

---
 site/app/models/user.rb       |    3 +++
 site/spec/models/user_spec.rb |    6 ++++++
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/site/app/models/user.rb b/site/app/models/user.rb
index 7809e87..cde0df5 100644
--- a/site/app/models/user.rb
+++ b/site/app/models/user.rb
@@ -58,6 +58,9 @@ class User < ActiveRecord::Base
     num_status = 0
     agendas = Agenda.all :conditions => ['agendas.meeting_time BETWEEN ? AND ?', start_date, end_date],
                           :order => :meeting_time
+
+    return 'There were no meetings in this term yet' if agendas.count.zero?
+
     for agenda in agendas
       if Participation.participant_is(self).agenda_is(agenda).count == 0
         num_status += 1 if num_status < 3

diff --git a/site/spec/models/user_spec.rb b/site/spec/models/user_spec.rb
index 5246015..ad36761 100644
--- a/site/spec/models/user_spec.rb
+++ b/site/spec/models/user_spec.rb
@@ -81,6 +81,12 @@ describe User do
       u.slacking_status_in_period(agendas.first.meeting_time - 1.minute,
                                     agendas.last.meeting_time + 1.minute).should == 'No more a council'
     end
+
+    it 'should return "There were no meetings in this term yet" if there were no meeting yet' do
+      a = Factory(:agenda, :meeting_time => 1.year.from_now)
+      u = users_factory(:council)
+      u.slacking_status_in_period(1.year.ago, 1.month.from_now).should == "There were no meetings in this term yet"
+    end
   end
 
   it 'should allow no one to create' do



^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [gentoo-commits] proj/council-webapp:master commit in: site/app/models/, site/spec/models/
@ 2011-06-18 15:42 Petteri Räty
  0 siblings, 0 replies; 4+ messages in thread
From: Petteri Räty @ 2011-06-18 15:42 UTC (permalink / raw
  To: gentoo-commits

commit:     fe1df9d1e81c2ddcc09326e500ea14450dcb6739
Author:     Joachim Filip Ignacy Bartosik <jbartosik <AT> gmail <DOT> com>
AuthorDate: Mon Jun 13 11:23:44 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Jun 17 18:21:44 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/council-webapp.git;a=commit;h=fe1df9d1

Improve User model test coverage

---
 site/app/models/guest.rb      |    2 +-
 site/app/models/user.rb       |    4 +-
 site/spec/models/user_spec.rb |  107 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+), 2 deletions(-)

diff --git a/site/app/models/guest.rb b/site/app/models/guest.rb
index a6b93d5..43890a3 100644
--- a/site/app/models/guest.rb
+++ b/site/app/models/guest.rb
@@ -8,7 +8,7 @@ class Guest < Hobo::Model::Guest
     false
   end
 
-  def can_appoint_a_proxy?
+  def can_appoint_a_proxy?(user)
     false
   end
 end

diff --git a/site/app/models/user.rb b/site/app/models/user.rb
index f940ea4..087f0fe 100644
--- a/site/app/models/user.rb
+++ b/site/app/models/user.rb
@@ -40,7 +40,8 @@ class User < ActiveRecord::Base
   def update_permitted?
     acting_user.administrator? ||
       (acting_user == self && only_changed?(:email, :crypted_password,
-                                            :current_password, :password, :password_confirmation))
+                                            :current_password, :password,
+                                            :password_confirmation, :irc_nick))
     # Note: crypted_password has attr_protected so although it is permitted to change, it cannot be changed
     # directly from a form submission.
   end
@@ -74,6 +75,7 @@ class User < ActiveRecord::Base
     return false unless council_member?
     return false if user.council_member?
     return false unless Proxy.council_member_is(self).agenda_is(Agenda.current).count ==  0
+    return false unless Proxy.proxy_is(user).agenda_is(Agenda.current).count ==  0
     true
   end
 end

diff --git a/site/spec/models/user_spec.rb b/site/spec/models/user_spec.rb
index 2dd5bde..5246015 100644
--- a/site/spec/models/user_spec.rb
+++ b/site/spec/models/user_spec.rb
@@ -82,4 +82,111 @@ describe User do
                                     agendas.last.meeting_time + 1.minute).should == 'No more a council'
     end
   end
+
+  it 'should allow no one to create' do
+    for u in users_factory(AllRoles)
+      User.new.should_not be_creatable_by(u)
+    end
+  end
+
+  it 'should allow only administrators to destroy' do
+    for u in users_factory(:user, :council, :guest)
+      Factory(:user).should_not be_destroyable_by(u)
+    end
+
+    for u in users_factory(:admin, :council_admin)
+      Factory(:user).should be_destroyable_by(u)
+    end
+  end
+
+  it 'should allow everybody to view' do
+    for u1 in users_factory(AllRoles)
+      for u2 in users_factory(AllRoles - [:guest])
+        u2.should be_viewable_by(u1)
+      end
+    end
+  end
+
+  describe '#updatable_by?' do
+    it 'should return true if user changes own email, irc_nick and password' do
+      u = Factory(:user)
+      u.password = 'changed'
+      u.password_confirmation = 'changed'
+      u.current_password = 'changed'
+      u.crypted_password = 'changed'
+      u.irc_nick = 'changed'
+      u.email = 'changed@changed.com'
+      u.should be_updatable_by u
+    end
+
+    it 'should return false if user changes someone' do
+      u = Factory(:user)
+      u.should_not be_updatable_by(Factory(:user))
+    end
+
+    it 'should return true if administrator changes something' do
+      u = Factory(:user)
+      u.password = 'changed'
+      u.password_confirmation = 'changed'
+      u.current_password = 'changed'
+      u.crypted_password = 'changed'
+      u.email = 'changed@changed.com'
+      u.irc_nick = 'changed'
+      u.administrator = true
+      u.council_member = true
+      u.should be_updatable_by(users_factory(:admin))
+    end
+
+  end
+
+  describe '#can_appoint_a_proxy?' do
+    it 'should return false for users who are not council members' do
+      for u in users_factory(:user, :admin, :guest)
+        proxy = Factory(:user)
+        u.can_appoint_a_proxy?(proxy).should be_false
+      end
+    end
+
+    it 'should return true for council members who never appointed a proxy' do
+      for u in users_factory(:council, :council_admin)
+        proxy = Factory(:user)
+        u.can_appoint_a_proxy?(proxy).should be_true
+      end
+    end
+
+    it 'should return true for council members who appointed a proxy for past meeting' do
+      Factory(:agenda)
+      old_a = Factory(:agenda, :state => 'old')
+      for u in users_factory(:council, :council_admin)
+        proxy = Factory(:user)
+        Factory(:proxy, :council_member => u, :agenda => old_a)
+        u.can_appoint_a_proxy?(proxy).should be_true
+      end
+    end
+
+    it 'should return false for council members who appointed a proxy for current meeting' do
+      current_a = Factory(:agenda)
+      proxy = Factory(:user)
+      for u in users_factory(:council, :council_admin)
+        Factory(:proxy, :council_member => u, :agenda => current_a)
+        u.can_appoint_a_proxy?(proxy).should be_false
+      end
+    end
+
+    it 'should return false for council members checking if they can appoint another council member as proxy' do
+      proxy = users_factory(:council)
+      for u in users_factory(:council, :council_admin)
+        u.can_appoint_a_proxy?(proxy).should be_false
+      end
+    end
+
+    it 'should return false for council members checking if they can appoint someone who is a aleady a proxy for current meeting as proxy' do
+      a = Factory(:agenda)
+      proxy = users_factory(:user)
+      Factory(:proxy, :proxy => proxy, :agenda => a)
+      for u in users_factory(:council, :council_admin)
+        u.can_appoint_a_proxy?(proxy).should be_false
+      end
+    end
+  end
 end



^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [gentoo-commits] proj/council-webapp:master commit in: site/app/models/, site/spec/models/
@ 2011-06-10 16:46 Petteri Räty
  0 siblings, 0 replies; 4+ messages in thread
From: Petteri Räty @ 2011-06-10 16:46 UTC (permalink / raw
  To: gentoo-commits

commit:     cdabbcd4c068bf4591998b33a769187683eef17f
Author:     Joachim Filip Ignacy Bartosik <jbartosik <AT> gmail <DOT> com>
AuthorDate: Wed Jun  8 16:20:05 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Jun 10 16:21:04 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/council-webapp.git;a=commit;h=cdabbcd4

Handle proxies attendance

Mark council member who appointed proxy as present, not proxy.

---
 site/app/models/participation.rb       |    3 +++
 site/spec/models/participation_spec.rb |   12 +++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/site/app/models/participation.rb b/site/app/models/participation.rb
index b7ca39a..e76ebf5 100644
--- a/site/app/models/participation.rb
+++ b/site/app/models/participation.rb
@@ -37,6 +37,9 @@ class Participation < ActiveRecord::Base
     agenda = Agenda.current
     for nick in participant_nicks
       user = ::User.find_by_irc_nick(nick)
+      unless user.council_member?
+        user = Proxy.proxy_is(user).agenda_is(agenda)._?.first.council_member
+      end
       next if user.nil?
       Participation.create! :irc_nick => user.irc_nick,
                             :participant => user,

diff --git a/site/spec/models/participation_spec.rb b/site/spec/models/participation_spec.rb
index 242abde..395dc03 100644
--- a/site/spec/models/participation_spec.rb
+++ b/site/spec/models/participation_spec.rb
@@ -25,15 +25,21 @@ describe Participation do
       a = Factory(:agenda)
       Factory(:agenda, :state => 'old')
 
+      Factory(:proxy, :proxy => u.first,
+                      :council_member => non_participants.last,
+                      :agenda => a)
+
       results_hash = {
           'Whatever' => { u[0].irc_nick => 'Yes', u[1].irc_nick => 'Yes', u[2].irc_nick => 'Yes'},
           'Something else' => { u[0].irc_nick => 'Yes', u[1].irc_nick => 'No'}
       }
 
+      present = u - [u.first] + [non_participants.last]
       Participation.mark_participations(results_hash)
-      (Participation.all.*.irc_nick - u.*.irc_nick).should be_empty
-      (u.*.irc_nick - Participation.all.*.irc_nick).should be_empty
-      (u - Participation.all.*.participant).should be_empty
+      (Participation.all.*.irc_nick - present.*.irc_nick).should be_empty
+      (present.*.irc_nick - Participation.all.*.irc_nick).should be_empty
+      (present - Participation.all.*.participant).should be_empty
+      (Participation.all.*.participant - present).should be_empty
     end
   end
 end



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-07-05 15:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-18 15:42 [gentoo-commits] proj/council-webapp:master commit in: site/app/models/, site/spec/models/ Petteri Räty
  -- strict thread matches above, loose matches on Subject: below --
2011-07-05 15:09 Petteri Räty
2011-06-18 15:42 Petteri Räty
2011-06-10 16:46 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