public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Petteri Räty" <betelgeuse@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/council-webapp:master commit in: site/app/models/
Date: Mon,  1 Aug 2011 14:38:16 +0000 (UTC)	[thread overview]
Message-ID: <6c58eb40efb9f6eedc2f9d31b3ecf00780c25ad5.betelgeuse@gentoo> (raw)

commit:     6c58eb40efb9f6eedc2f9d31b3ecf00780c25ad5
Author:     Joachim Filip Ignacy Bartosik <jbartosik <AT> gmail <DOT> com>
AuthorDate: Tue Jul 26 14:49:48 2011 +0000
Commit:     Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Tue Jul 26 15:06:00 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/council-webapp.git;a=commit;h=6c58eb40

Cleanup Agenda.update_voting_options

---
 site/app/models/agenda.rb      |   13 +------------
 site/app/models/agenda_item.rb |   12 ++++++++++++
 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



             reply	other threads:[~2011-08-01 14:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-01 14:38 Petteri Räty [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-08-01 14:38 [gentoo-commits] proj/council-webapp:master commit in: site/app/models/ Petteri Räty
2011-08-01 14:38 Petteri Räty
2011-08-01 14:38 Petteri Räty
2011-08-01 14:38 Petteri Räty
2011-06-18 15:42 Petteri Räty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6c58eb40efb9f6eedc2f9d31b3ecf00780c25ad5.betelgeuse@gentoo \
    --to=betelgeuse@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox