aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2011-07-26 16:49:48 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2011-07-26 17:06:00 +0200
commit6c58eb40efb9f6eedc2f9d31b3ecf00780c25ad5 (patch)
tree205ce3bf153baa820e54e3400c0044bc4b33be95 /site/app/models
parentImprove controller readability (diff)
downloadcouncil-webapp-6c58eb40efb9f6eedc2f9d31b3ecf00780c25ad5.tar.gz
council-webapp-6c58eb40efb9f6eedc2f9d31b3ecf00780c25ad5.tar.bz2
council-webapp-6c58eb40efb9f6eedc2f9d31b3ecf00780c25ad5.zip
Cleanup Agenda.update_voting_options
Diffstat (limited to 'site/app/models')
-rw-r--r--site/app/models/agenda.rb13
-rw-r--r--site/app/models/agenda_item.rb12
2 files changed, 13 insertions, 12 deletions
diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb
index 75a9a23..29c57f5 100644
--- a/site/app/models/agenda.rb
+++ b/site/app/models/agenda.rb
@@ -78,18 +78,7 @@ class Agenda < ActiveRecord::Base
agenda = Agenda.current
options.each do |item_info|
item = AgendaItem.first :conditions => { :agenda_id => agenda, :title => item_info.first }
- new_descriptions = item_info[1]
- old_descriptions = item.voting_options.*.description
-
- (old_descriptions - new_descriptions).each do |description|
- option = VotingOption.first :conditions => { :agenda_item_id => item.id,
- :description => description }
- option.destroy
- end
-
- (new_descriptions - old_descriptions ).each do |description|
- VotingOption.create! :agenda_item => item, :description => description
- end
+ item.update_voting_options(item_info[1])
end
end
diff --git a/site/app/models/agenda_item.rb b/site/app/models/agenda_item.rb
index 938e2e1..e8874ff 100644
--- a/site/app/models/agenda_item.rb
+++ b/site/app/models/agenda_item.rb
@@ -56,6 +56,18 @@ class AgendaItem < ActiveRecord::Base
return acting_user == user if [nil, :title, :discussion, :body].include?(field)
end
+ def update_voting_options(new_descriptions)
+ old_descriptions = voting_options.*.description
+
+ (old_descriptions - new_descriptions).each do |description|
+ option = VotingOption.agenda_item_id_is(id).description_is(description).first
+ option.destroy
+ end
+
+ (new_descriptions - old_descriptions ).each do |description|
+ VotingOption.create! :agenda_item => self, :description => description
+ end
+ end
protected
# Updated discussion time for a single agenda item
# protected because we want to call it only from