diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-06-08 19:02:32 +0200 |
---|---|---|
committer | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-06-10 18:30:37 +0200 |
commit | 53201e0add36dd0ca796fa349108bc533890eedb (patch) | |
tree | 1284107c1b987b0fcd45ea70738b15f81df7710f /site | |
parent | Handle proxies attendance (diff) | |
download | council-webapp-53201e0add36dd0ca796fa349108bc533890eedb.tar.gz council-webapp-53201e0add36dd0ca796fa349108bc533890eedb.tar.bz2 council-webapp-53201e0add36dd0ca796fa349108bc533890eedb.zip |
Show slacking information in the application
Using participations
Diffstat (limited to 'site')
-rw-r--r-- | site/app/controllers/users_controller.rb | 8 | ||||
-rw-r--r-- | site/app/models/user.rb | 17 | ||||
-rw-r--r-- | site/app/views/taglibs/main_nav.dryml | 1 | ||||
-rw-r--r-- | site/app/views/users/current_council_slacking.dryml | 7 | ||||
-rw-r--r-- | site/config/initializers/custom_configs.rb | 2 | ||||
-rw-r--r-- | site/config/routes.rb | 1 | ||||
-rw-r--r-- | site/doc/sample_configs/council_term.yml | 1 | ||||
-rw-r--r-- | site/features/participations.feature | 11 | ||||
-rw-r--r-- | site/features/step_definitions/participations_steps.rb | 59 | ||||
-rw-r--r-- | site/spec/models/user_spec.rb | 68 |
10 files changed, 174 insertions, 1 deletions
diff --git a/site/app/controllers/users_controller.rb b/site/app/controllers/users_controller.rb index fa077fe..4fd360c 100644 --- a/site/app/controllers/users_controller.rb +++ b/site/app/controllers/users_controller.rb @@ -17,4 +17,12 @@ class UsersController < ApplicationController def voters render :json => ::Agenda.voters end + + def current_council_slacking + start = CustomConfig['CouncilTerm']['start_time'] + stop = Agenda.current.meeting_time - 1.minute + @slackings = ::User.council_member_is(true).collect do |user| + [user.name, user.slacking_status_in_period(start, stop)] + end + end end diff --git a/site/app/models/user.rb b/site/app/models/user.rb index 0cb75b4..f940ea4 100644 --- a/site/app/models/user.rb +++ b/site/app/models/user.rb @@ -53,6 +53,23 @@ class User < ActiveRecord::Base true end + def slacking_status_in_period(start_date, end_date) + num_status = 0 + agendas = Agenda.all :conditions => ['agendas.meeting_time BETWEEN ? AND ?', start_date, end_date], + :order => :meeting_time + for agenda in agendas + if Participation.participant_is(self).agenda_is(agenda).count == 0 + num_status += 1 if num_status < 3 + else + num_status = 0 if num_status == 1 + end + end + + a = ['Was on last meeting', 'Skipped last meeting', + 'Slacker', 'No more a council'] + a[num_status] + end + def can_appoint_a_proxy?(user) return false unless council_member? return false if user.council_member? diff --git a/site/app/views/taglibs/main_nav.dryml b/site/app/views/taglibs/main_nav.dryml index af60c6d..5f091c6 100644 --- a/site/app/views/taglibs/main_nav.dryml +++ b/site/app/views/taglibs/main_nav.dryml @@ -3,5 +3,6 @@ <nav-item href="#{base_url}/">Home</nav-item> <nav-item with="&Agenda"><ht key="agenda.nav_item" count="100"><model-name-human count="100"/></ht></nav-item> <nav-item href="&new_agenda_item_path">Suggest agenda item</nav-item> + <nav-item href="¤t_council_slacking_path">Current council attendance</nav-item> </navigation> </def> diff --git a/site/app/views/users/current_council_slacking.dryml b/site/app/views/users/current_council_slacking.dryml new file mode 100644 index 0000000..79bd59f --- /dev/null +++ b/site/app/views/users/current_council_slacking.dryml @@ -0,0 +1,7 @@ +<page> + <content:> + <collection with="&@slackings" class="collection slacking-statuses"> + <%= this.first %> - <%= this.last %> + </collection> + </content:> +</page> diff --git a/site/config/initializers/custom_configs.rb b/site/config/initializers/custom_configs.rb index dca866f..5e5ce89 100644 --- a/site/config/initializers/custom_configs.rb +++ b/site/config/initializers/custom_configs.rb @@ -1,4 +1,4 @@ CustomConfig = {} -for conf in ['bot', 'reminders'] +for conf in ['bot', 'reminders', 'council_term'] CustomConfig[conf.camelize] = YAML.load open("config/#{conf}.yml").read end diff --git a/site/config/routes.rb b/site/config/routes.rb index 2decbe6..0df79c8 100644 --- a/site/config/routes.rb +++ b/site/config/routes.rb @@ -4,6 +4,7 @@ Council::Application.routes.draw do match 'search' => 'front#search', :as => 'site_search' match 'users/voters' => 'users#voters', :as => 'voters' + match 'users/current_council_slacking' => 'users#current_council_slacking', :as => 'current_council_slacking' match 'agendas/current_items' => 'agendas#current_items', :as => 'current_items' match 'agendas/results' => 'agendas#results', :as => 'results' match 'agendas/reminders' => 'agendas#reminders', :as => 'reminders' diff --git a/site/doc/sample_configs/council_term.yml b/site/doc/sample_configs/council_term.yml new file mode 100644 index 0000000..3db917b --- /dev/null +++ b/site/doc/sample_configs/council_term.yml @@ -0,0 +1 @@ +start_time: --- 2011-05-09T21:12:15+02:00 diff --git a/site/features/participations.feature b/site/features/participations.feature index d273541..9b45e1b 100644 --- a/site/features/participations.feature +++ b/site/features/participations.feature @@ -8,3 +8,14 @@ Feature: In order to track presence on the council meetings 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 + + Scenario: View council slacking status + Given council term started a year ago + And some agendas + And some council members who attended properly + And some council members who skipped last meeting + And some slackers + And some slackers who skipped a meeting + When I am on the home page + And I follow "Current council attendance" + Then I should see list of all council members with proper indication of their attendance diff --git a/site/features/step_definitions/participations_steps.rb b/site/features/step_definitions/participations_steps.rb index b97e563..e4b48b6 100644 --- a/site/features/step_definitions/participations_steps.rb +++ b/site/features/step_definitions/participations_steps.rb @@ -27,3 +27,62 @@ 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 + +Given /^some agendas$/ do + for i in 1..11 + Factory(:agenda, :state => 'old', :meeting_time => i.months.ago) + end + Factory(:agenda) +end + +Given /^some council members who attended properly$/ do + users = users_factory([:council]*3) + for a in Agenda.all + for u in users + Factory(:participation, :participant => u, :agenda => a) + end + end +end + +Given /^some council members who skipped last meeting$/ do + users = users_factory([:council]*3) + for a in Agenda.all - [Agenda.last] + for u in users + Factory(:participation, :participant => u, :agenda => a) + end + end +end + +Given /^some slackers$/ do + users = users_factory([:council]*3) + i = 0 + for a in Agenda.all + next if i < 2 + for u in users + Factory(:participation, :participant => u, :agenda => a) + end + end +end + +Given /^some slackers who skipped a meeting$/ do + users = users_factory([:council]*3) + i = 0 + for a in Agenda.all - [Agenda.last] + next if i < 2 + for u in users + Factory(:participation, :participant => u, :agenda => a) + end + end +end + +Given /^council term started a year ago$/ do + CustomConfig['CouncilTerm']['start_time'] = 1.year.ago +end + +Then /^I should see list of all council members with proper indication of their attendance$/ do + start = CustomConfig['CouncilTerm']['start_time'] + stop = Agenda.current.meeting_time - 1.minute + for user in User.council_member_is(true) + Then "I should see \"#{user.name} - #{user.slacking_status_in_period(start, stop)}\" within \".collection.slacking-statuses\"" + end +end diff --git a/site/spec/models/user_spec.rb b/site/spec/models/user_spec.rb index bdffa30..2dd5bde 100644 --- a/site/spec/models/user_spec.rb +++ b/site/spec/models/user_spec.rb @@ -14,4 +14,72 @@ describe User do u.should_not be_guest u.should be_signed_up end + + describe '.slacking_status_in_period' do + it 'should give "Was on last meeting" slacking status to user who was on all meetings' do + u = users_factory(:council) + agendas = (1..10).collect do |i| + a = Factory(:agenda, :state => 'old') + Factory(:participation, :participant => u, :agenda => a) + a + end + u.slacking_status_in_period(agendas.first.meeting_time - 1.minute, + agendas.last.meeting_time + 1.minute).should == 'Was on last meeting' + end + + it 'should give "Was on last meeting" slacking status to user who was on last meeting and skipped some meetings in past (but not two consecutive)' do + u = users_factory(:council) + agendas = (1..10).collect do |i| + a = Factory(:agenda, :state => 'old') + Factory(:participation, :participant => u, :agenda => a) if i.even? + a + end + u.slacking_status_in_period(agendas.first.meeting_time - 1.minute, + agendas.last.meeting_time + 1.minute).should == 'Was on last meeting' + end + + it 'should give "Skipped last meeting" slacking status to user who was absent on last meeting and skipped some meetings in past (but not two consecutive)' do + u = users_factory(:council) + agendas = (1..10).collect do |i| + a = Factory(:agenda, :state => 'old') + Factory(:participation, :participant => u, :agenda => a) if i.odd? + a + end + u.slacking_status_in_period(agendas.first.meeting_time - 1.minute, + agendas.last.meeting_time + 1.minute).should == 'Skipped last meeting' + end + + it 'should give "Slacker" slacking status to user who was present on last meeting skipped two consecutive meeting in the past' do + u = users_factory(:council) + agendas = (1..10).collect do |i| + a = Factory(:agenda, :state => 'old') + Factory(:participation, :participant => u, :agenda => a) unless [1, 3, 5, 6].include?(i) + a + end + u.slacking_status_in_period(agendas.first.meeting_time - 1.minute, + agendas.last.meeting_time + 1.minute).should == 'Slacker' + end + + it 'should give "No more a council" slacking status to user who skipped two consecutive meeting in the past and the last one' do + u = users_factory(:council) + agendas = (1..10).collect do |i| + a = Factory(:agenda, :state => 'old') + Factory(:participation, :participant => u, :agenda => a) unless [1, 3, 5, 6, 10].include?(i) + a + end + 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 give "No more a council" slacking status to user who skipped two consecutive meeting in the past and then one more' do + u = users_factory(:council) + agendas = (1..10).collect do |i| + a = Factory(:agenda, :state => 'old') + Factory(:participation, :participant => u, :agenda => a) unless [5, 6, 8].include?(i) + a + end + u.slacking_status_in_period(agendas.first.meeting_time - 1.minute, + agendas.last.meeting_time + 1.minute).should == 'No more a council' + end + end end |