diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-06-02 15:35:37 +0200 |
---|---|---|
committer | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-06-03 19:36:26 +0200 |
commit | 671b1a36e8ac7a2179839874bc4a59686b419ef1 (patch) | |
tree | 9cd2e2b169a9f6a971c25c9ccf766fee5768ff79 | |
parent | Manage proxies with web app (diff) | |
download | council-webapp-671b1a36e8ac7a2179839874bc4a59686b419ef1.tar.gz council-webapp-671b1a36e8ac7a2179839874bc4a59686b419ef1.tar.bz2 council-webapp-671b1a36e8ac7a2179839874bc4a59686b419ef1.zip |
List proxies as voters
So IRC bot will handle them properly
-rw-r--r-- | site/app/controllers/users_controller.rb | 2 | ||||
-rw-r--r-- | site/app/models/agenda.rb | 11 | ||||
-rw-r--r-- | site/spec/models/agenda_spec.rb | 12 |
3 files changed, 24 insertions, 1 deletions
diff --git a/site/app/controllers/users_controller.rb b/site/app/controllers/users_controller.rb index eccc510..fa077fe 100644 --- a/site/app/controllers/users_controller.rb +++ b/site/app/controllers/users_controller.rb @@ -15,6 +15,6 @@ class UsersController < ApplicationController end def voters - render :json => ::User.council_member_is(true).*.irc_nick + render :json => ::Agenda.voters end end diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb index f1224ff..22414d7 100644 --- a/site/app/models/agenda.rb +++ b/site/app/models/agenda.rb @@ -101,6 +101,17 @@ class Agenda < ActiveRecord::Base end end + def self.voters + # It's possible to rewrite this as SQL, but + # * this method is rarely called + # * it fetches little data + # So I think efficiency improvement would be insignificant. + # Joachim + council = ::User.council_member_is(true) + proxies = Agenda.current.proxies + [council - proxies.*.council_member + proxies.*.proxy].flatten.*.irc_nick + end + protected def there_is_only_one_non_archival_agenda return if(state.to_s == 'old') diff --git a/site/spec/models/agenda_spec.rb b/site/spec/models/agenda_spec.rb index 5943512..2a08210 100644 --- a/site/spec/models/agenda_spec.rb +++ b/site/spec/models/agenda_spec.rb @@ -135,4 +135,16 @@ describe Agenda do a2.voting_options.*.votes.flatten.*.voting_option.*.description.should == ['Yes', 'No', 'Dunno'] a3.voting_options.*.votes.flatten.*.voting_option.*.description.should == ['No', 'Dunno', 'Dunno'] end + + it 'should return proper voters' do + users = users_factory([:council]*3 + [:user]) + proxy = Factory(:proxy, :council_member => users.first, :proxy => users.last) + voters = Agenda.voters + + voters.length.should be_equal(3) + nicks = users.*.irc_nick - [users.first.irc_nick] + voters.length.should be_equal(nicks.length) + (voters - nicks).should be_empty + (nicks - voters).should be_empty + end end |