diff options
author | 2011-06-08 13:59:09 +0200 | |
---|---|---|
committer | 2011-06-10 18:21:02 +0200 | |
commit | 551ce28e97d8c7a9b29c810c1427a4f810598a01 (patch) | |
tree | 2631c22d29b02d48b734dc6853063807a7185f14 | |
parent | Plugin that sends reminders to users (diff) | |
download | council-webapp-551ce28e97d8c7a9b29c810c1427a4f810598a01.tar.gz council-webapp-551ce28e97d8c7a9b29c810c1427a4f810598a01.tar.bz2 council-webapp-551ce28e97d8c7a9b29c810c1427a4f810598a01.zip |
Receive list of meeting participants from IRC bot
-rw-r--r-- | site/app/controllers/agendas_controller.rb | 4 | ||||
-rw-r--r-- | site/app/models/agenda.rb | 7 | ||||
-rw-r--r-- | site/app/models/participation.rb | 12 | ||||
-rw-r--r-- | site/features/participations.feature | 8 | ||||
-rw-r--r-- | site/features/step_definitions/participations_steps.rb | 13 | ||||
-rw-r--r-- | site/spec/models/agenda_spec.rb | 6 | ||||
-rw-r--r-- | site/spec/models/participation_spec.rb | 19 |
7 files changed, 49 insertions, 20 deletions
diff --git a/site/app/controllers/agendas_controller.rb b/site/app/controllers/agendas_controller.rb index e0fd813..8760069 100644 --- a/site/app/controllers/agendas_controller.rb +++ b/site/app/controllers/agendas_controller.rb @@ -14,7 +14,9 @@ class AgendasController < ApplicationController end def results - Agenda.process_results JSON.parse(request.env["rack.input"].read) + data = JSON.parse(request.env["rack.input"].read) + Agenda.process_results data + Participation.mark_participations data end def reminders diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb index 55bc6cd..5be2d82 100644 --- a/site/app/models/agenda.rb +++ b/site/app/models/agenda.rb @@ -19,14 +19,7 @@ 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 - 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/participation.rb b/site/app/models/participation.rb index 95c4142..b7ca39a 100644 --- a/site/app/models/participation.rb +++ b/site/app/models/participation.rb @@ -31,4 +31,16 @@ class Participation < ActiveRecord::Base def name participant.name end + + def self.mark_participations(results) + participant_nicks = results.values.*.keys.flatten.uniq + agenda = Agenda.current + for nick in participant_nicks + user = ::User.find_by_irc_nick(nick) + next if user.nil? + Participation.create! :irc_nick => user.irc_nick, + :participant => user, + :agenda => agenda + end + end end diff --git a/site/features/participations.feature b/site/features/participations.feature index 69cb5dd..d273541 100644 --- a/site/features/participations.feature +++ b/site/features/participations.feature @@ -3,8 +3,8 @@ Feature: In order to track presence on the council meetings Scenario: When archiving agenda mark all council members as participants Given some council members + And an agenda 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 + When application got voting results from IRC bot + And I am on the current agenda page + Then I should see some council members as participants diff --git a/site/features/step_definitions/participations_steps.rb b/site/features/step_definitions/participations_steps.rb index fe3966c..b97e563 100644 --- a/site/features/step_definitions/participations_steps.rb +++ b/site/features/step_definitions/participations_steps.rb @@ -17,8 +17,13 @@ Given /^I am logged in as council member$/ do 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 +When /^application got voting results from IRC bot$/ do + Participation.mark_participations({ 'Some item' => + { User.first.irc_nick => 'Some vote', + User.last.irc_nick => 'Some other vote' } }) +end + +Then /^I should see some council members as participants$/ do + Then "I should see \"#{User.first.name}\" within \".collection.participations.participations-collection\"" + Then "I should see \"#{User.last.name}\" within \".collection.participations.participations-collection\"" end diff --git a/site/spec/models/agenda_spec.rb b/site/spec/models/agenda_spec.rb index 32fa2ba..29f0bcb 100644 --- a/site/spec/models/agenda_spec.rb +++ b/site/spec/models/agenda_spec.rb @@ -94,15 +94,13 @@ describe Agenda do 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 + it 'should not create 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 + agenda.participations.should be_empty end it 'should properly create votes' do Factory(:agenda) diff --git a/site/spec/models/participation_spec.rb b/site/spec/models/participation_spec.rb index eb2ecba..242abde 100644 --- a/site/spec/models/participation_spec.rb +++ b/site/spec/models/participation_spec.rb @@ -17,4 +17,23 @@ describe Participation do p.should be_viewable_by(u) end end + + describe '.mark_participations' do + it 'should properly create participations' do + u = users_factory(:user, :council, :council_admin) + non_participants = users_factory(:user, :council, :council_admin) + a = Factory(:agenda) + Factory(:agenda, :state => 'old') + + 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'} + } + + 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 + end + end end |