aboutsummaryrefslogtreecommitdiff
path: root/site
diff options
context:
space:
mode:
Diffstat (limited to 'site')
-rw-r--r--site/app/models/agenda.rb2
-rw-r--r--site/app/models/agenda_item.rb13
-rw-r--r--site/db/schema.rb3
-rw-r--r--site/spec/models/agenda_item_spec.rb19
-rw-r--r--site/spec/models/agenda_spec.rb17
5 files changed, 44 insertions, 10 deletions
diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb
index baaac89..65f45b4 100644
--- a/site/app/models/agenda.rb
+++ b/site/app/models/agenda.rb
@@ -91,7 +91,7 @@ class Agenda < ActiveRecord::Base
def voting_array
agenda_items.collect do |item|
- [item.title, item.voting_options.*.description]
+ [item.title, item.voting_options.*.description, item.timelimits]
end
end
diff --git a/site/app/models/agenda_item.rb b/site/app/models/agenda_item.rb
index f590bb1..0ce60ea 100644
--- a/site/app/models/agenda_item.rb
+++ b/site/app/models/agenda_item.rb
@@ -7,6 +7,7 @@ class AgendaItem < ActiveRecord::Base
discussion :string
body :text
rejected :boolean, :default => false
+ timelimits :text, :null => false, :default => ''
timestamps
end
@@ -14,6 +15,8 @@ class AgendaItem < ActiveRecord::Base
belongs_to :agenda
has_many :voting_options
+ validate :timelimits_entered_properly
+
# --- Permissions --- #
def create_permitted?
return false if acting_user.guest?
@@ -50,4 +53,14 @@ class AgendaItem < ActiveRecord::Base
return false unless agenda.nil?
return acting_user == user if [nil, :title, :discussion, :body].include?(field)
end
+
+ protected
+ def timelimits_entered_properly
+ regexp = /^\d+:\d+( .*)?$/
+ for line in timelimits.split("\n")
+ unless line.match regexp
+ errors.add(:timelimits, "Line '#{line}' doensn't match '<minutes>:<seconds> <message>'")
+ end
+ end
+ end
end
diff --git a/site/db/schema.rb b/site/db/schema.rb
index 071ff84..bc8535a 100644
--- a/site/db/schema.rb
+++ b/site/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110606170332) do
+ActiveRecord::Schema.define(:version => 20110624141720) do
create_table "agenda_items", :force => true do |t|
t.string "title"
@@ -21,6 +21,7 @@ ActiveRecord::Schema.define(:version => 20110606170332) do
t.datetime "updated_at"
t.integer "user_id"
t.integer "agenda_id"
+ t.text "timelimits", :default => "", :null => false
end
add_index "agenda_items", ["agenda_id"], :name => "index_agenda_items_on_agenda_id"
diff --git a/site/spec/models/agenda_item_spec.rb b/site/spec/models/agenda_item_spec.rb
index 3df2a59..72ee0bb 100644
--- a/site/spec/models/agenda_item_spec.rb
+++ b/site/spec/models/agenda_item_spec.rb
@@ -100,4 +100,23 @@ describe AgendaItem do
a.should_not be_editable_by(u, :agenda)
end
end
+
+ it 'should make sure timelimits are valid' do
+ valid_timelimits = ["", "0:0", "1:1 message", "1:2 longer message",
+ "30:40 a few messages\n5:60 as separate lines"]
+ invalid_timelimits = ["a:0", "1:", "2:a", ":0", " 1:1 message",
+ "30:40 a few messages\n\n5:60 and an empty line",
+ "30:40 a few messages\n5:60 and an wrong line\na:"]
+
+ valid_timelimits.each do |limit|
+ Factory(:agenda_item, :timelimits => limit).should be_valid
+ end
+
+ invalid_timelimits.each do |limit|
+ item = AgendaItem.new :title => 'title', :timelimits => limit
+ item.should_not be_valid
+ item.errors.length.should be_equal(1)
+ item.errors[:timelimits].should_not be_nil
+ end
+ end
end
diff --git a/site/spec/models/agenda_spec.rb b/site/spec/models/agenda_spec.rb
index b9fbd36..34db02f 100644
--- a/site/spec/models/agenda_spec.rb
+++ b/site/spec/models/agenda_spec.rb
@@ -126,9 +126,9 @@ describe Agenda do
Vote.count.should be_equal(9)
- u[0].votes.*.voting_option.*.description.should == ['Yes', 'Yes', 'Dunno']
- u[1].votes.*.voting_option.*.description.should == ['Yes', 'No', 'Dunno']
- u[2].votes.*.voting_option.*.description.should == ['Yes', 'Dunno', 'No']
+ u[0].votes.*.voting_option.*.description.sort.should == ['Dunno', 'Yes', 'Yes']
+ u[1].votes.*.voting_option.*.description.sort.should == ['Dunno', 'No', 'Yes']
+ u[2].votes.*.voting_option.*.description.sort.should == ['Dunno', 'No', 'Yes']
a1.voting_options.*.votes.flatten.*.voting_option.*.description.should == ['Yes', 'Yes', 'Yes']
a2.voting_options.*.votes.flatten.*.voting_option.*.description.should == ['Yes', 'No', 'Dunno']
a3.voting_options.*.votes.flatten.*.voting_option.*.description.should == ['No', 'Dunno', 'Dunno']
@@ -236,15 +236,16 @@ describe Agenda do
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)
+ i1 = Factory(:agenda_item, :agenda => old_agenda, :timelimits => '0:0')
+ i2 = Factory(:agenda_item, :agenda => current_agenda, :timelimits => "10:0 Ten minutes passed")
+ i3 = Factory(:agenda_item, :agenda => current_agenda, :timelimits => "0:10 Ten seconds passed")
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, []]]
+ old_agenda.voting_array.should == [[i1.title, [v11.description], i1.timelimits]]
+ current_agenda.voting_array.should == [[i2.title, [v21.description, v22.description],
+ i2.timelimits], [i3.title, [], i3.timelimits]]
end
end