aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--site/app/controllers/agendas_controller.rb3
-rw-r--r--site/app/controllers/front_controller.rb5
-rw-r--r--site/app/models/agenda.rb44
-rw-r--r--site/app/models/guest.rb2
-rw-r--r--site/app/models/proxy.rb6
-rw-r--r--site/app/models/user.rb11
-rw-r--r--site/config/application.rb2
-rw-r--r--site/spec/models/agenda_spec.rb43
-rw-r--r--site/spec/models/user_spec.rb107
-rw-r--r--site/spec/models/voting_option_spec.rb7
10 files changed, 197 insertions, 33 deletions
diff --git a/site/app/controllers/agendas_controller.rb b/site/app/controllers/agendas_controller.rb
index 8760069..c6865a1 100644
--- a/site/app/controllers/agendas_controller.rb
+++ b/site/app/controllers/agendas_controller.rb
@@ -25,8 +25,9 @@ class AgendasController < ApplicationController
private
def authenticate_bot
+ botconf = CustomConfig['Bot']
authenticate_or_request_with_http_basic do |user_name, password|
- user_name == CustomConfig['Bot']['user'] && password == CustomConfig['Bot']['password']
+ user_name == botconf['user'] && password == botconf['password']
end
end
end
diff --git a/site/app/controllers/front_controller.rb b/site/app/controllers/front_controller.rb
index 86e3201..dda167e 100644
--- a/site/app/controllers/front_controller.rb
+++ b/site/app/controllers/front_controller.rb
@@ -11,8 +11,9 @@ class FrontController < ApplicationController
end
def search
- if params[:query]
- site_search(params[:query])
+ query = params[:query]
+ if query
+ site_search(query)
end
end
diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb
index 5be2d82..baaac89 100644
--- a/site/app/models/agenda.rb
+++ b/site/app/models/agenda.rb
@@ -43,8 +43,8 @@ class Agenda < ActiveRecord::Base
true
end
- before_create do |a|
- a.meeting_time ||= Time.now
+ before_create do |agenda|
+ agenda.meeting_time ||= Time.now
end
def self.current
@@ -58,14 +58,14 @@ class Agenda < ActiveRecord::Base
end
def self.process_results(results)
- a = Agenda.current
+ agenda = Agenda.current
for item_title in results.keys
- i = AgendaItem.first :conditions => { :agenda_id => a, :title => item_title }
+ item = AgendaItem.first :conditions => { :agenda_id => agenda, :title => item_title }
votes = results[item_title]
for voter in votes.keys
- o = VotingOption.first :conditions => { :agenda_item_id => i.id, :description => votes[voter] }
- u = ::User.find_by_irc_nick voter
- Vote.create! :voting_option => o, :user => u
+ option = VotingOption.first :conditions => { :agenda_item_id => item.id, :description => votes[voter] }
+ user = ::User.find_by_irc_nick voter
+ Vote.create! :voting_option => option, :user => user
end
end
end
@@ -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
@@ -107,8 +107,8 @@ class Agenda < ActiveRecord::Base
# 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
+ proxies = Agenda.current.proxies.*
+ [council - proxies.council_member + proxies.proxy].flatten
end
def self.voters
@@ -131,32 +131,34 @@ class Agenda < ActiveRecord::Base
def self.irc_reminders
agenda = Agenda.current
+ meeting_time = agenda.meeting_time.strftime('%a %b %d %H:%M:%S %Y')
return {} if Time.now < agenda.time_for_reminders(:irc)
- return { 'remind_time' => agenda.meeting_time.strftime('%a %b %d %H:%M:%S %Y'),
- 'message' => "Remember about council meeting on #{agenda.meeting_time.to_s}",
+ return { 'remind_time' => meeting_time,
+ 'message' => "Remember about council meeting on #{meeting_time}",
'users' => Agenda.voters}
end
- before_save do |a|
- return true if a.new_record?
- return true unless a.meeting_time_changed?
- a.email_reminder_sent = false
+ before_save do |agenda|
+ return true if agenda.new_record?
+ return true unless agenda.meeting_time_changed?
+ agenda.email_reminder_sent = false
true
end
- after_save do |a|
- if a.new_record? or a.meeting_time_changed?
- Agenda.delay(:run_at => a.time_for_reminders(:email)).send_current_agenda_reminders
+ after_save do |agenda|
+ if agenda.new_record? or agenda.meeting_time_changed?
+ Agenda.delay(:run_at => agenda.time_for_reminders(:email)).send_current_agenda_reminders
end
end
protected
def there_is_only_one_non_archival_agenda
return if(state.to_s == 'old')
+ not_old_agendas = Agenda.state_is_not(:old)
if id.nil?
- return if Agenda.state_is_not(:old).count == 0
+ return if not_old_agendas.count == 0
else
- return if Agenda.state_is_not(:old).id_is_not(id).count == 0
+ return if not_old_agendas.id_is_not(id).count == 0
end
errors.add(:state, 'There can be only one non-archival agenda at time.')
end
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/proxy.rb b/site/app/models/proxy.rb
index 7be0a0b..1fdb93f 100644
--- a/site/app/models/proxy.rb
+++ b/site/app/models/proxy.rb
@@ -40,9 +40,9 @@ class Proxy < ActiveRecord::Base
true
end
- before_create do |p|
- p.council_member_nick = p.council_member.irc_nick
- p.proxy_nick = p.proxy.irc_nick
+ before_create do |proxy|
+ proxy.council_member_nick = proxy.council_member.irc_nick
+ proxy.proxy_nick = proxy.proxy.irc_nick
end
protected
diff --git a/site/app/models/user.rb b/site/app/models/user.rb
index f940ea4..7809e87 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
@@ -65,15 +66,17 @@ class User < ActiveRecord::Base
end
end
- a = ['Was on last meeting', 'Skipped last meeting',
+ text_statuses = ['Was on last meeting', 'Skipped last meeting',
'Slacker', 'No more a council']
- a[num_status]
+ text_statuses[num_status]
end
def can_appoint_a_proxy?(user)
+ agenda = Agenda.current
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.council_member_is(self).agenda_is(agenda).count == 0
+ return false unless Proxy.proxy_is(user).agenda_is(agenda).count == 0
true
end
end
diff --git a/site/config/application.rb b/site/config/application.rb
index 2b15039..306aff9 100644
--- a/site/config/application.rb
+++ b/site/config/application.rb
@@ -8,7 +8,7 @@ Bundler.require(:default, Rails.env) if defined?(Bundler)
module Council
class Application < Rails::Application
-
+
config.hobo.dryml_only_templates = true
# Settings in config/environments/* take precedence over those specified here.
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
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
diff --git a/site/spec/models/voting_option_spec.rb b/site/spec/models/voting_option_spec.rb
index 4a41067..2b6005c 100644
--- a/site/spec/models/voting_option_spec.rb
+++ b/site/spec/models/voting_option_spec.rb
@@ -38,4 +38,11 @@ describe VotingOption do
v2.should_not be_destroyable_by(u)
end
end
+
+ it 'should allow everyone to view' do
+ v = Factory(:voting_option)
+ for u in users_factory(AllRoles)
+ v.should be_viewable_by(u)
+ end
+ end
end