1 |
commit: 6c58eb40efb9f6eedc2f9d31b3ecf00780c25ad5 |
2 |
Author: Joachim Filip Ignacy Bartosik <jbartosik <AT> gmail <DOT> com> |
3 |
AuthorDate: Tue Jul 26 14:49:48 2011 +0000 |
4 |
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Jul 26 15:06:00 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/council-webapp.git;a=commit;h=6c58eb40 |
7 |
|
8 |
Cleanup Agenda.update_voting_options |
9 |
|
10 |
--- |
11 |
site/app/models/agenda.rb | 13 +------------ |
12 |
site/app/models/agenda_item.rb | 12 ++++++++++++ |
13 |
2 files changed, 13 insertions(+), 12 deletions(-) |
14 |
|
15 |
diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb |
16 |
index 75a9a23..29c57f5 100644 |
17 |
--- a/site/app/models/agenda.rb |
18 |
+++ b/site/app/models/agenda.rb |
19 |
@@ -78,18 +78,7 @@ class Agenda < ActiveRecord::Base |
20 |
agenda = Agenda.current |
21 |
options.each do |item_info| |
22 |
item = AgendaItem.first :conditions => { :agenda_id => agenda, :title => item_info.first } |
23 |
- new_descriptions = item_info[1] |
24 |
- old_descriptions = item.voting_options.*.description |
25 |
- |
26 |
- (old_descriptions - new_descriptions).each do |description| |
27 |
- option = VotingOption.first :conditions => { :agenda_item_id => item.id, |
28 |
- :description => description } |
29 |
- option.destroy |
30 |
- end |
31 |
- |
32 |
- (new_descriptions - old_descriptions ).each do |description| |
33 |
- VotingOption.create! :agenda_item => item, :description => description |
34 |
- end |
35 |
+ item.update_voting_options(item_info[1]) |
36 |
end |
37 |
end |
38 |
|
39 |
|
40 |
diff --git a/site/app/models/agenda_item.rb b/site/app/models/agenda_item.rb |
41 |
index 938e2e1..e8874ff 100644 |
42 |
--- a/site/app/models/agenda_item.rb |
43 |
+++ b/site/app/models/agenda_item.rb |
44 |
@@ -56,6 +56,18 @@ class AgendaItem < ActiveRecord::Base |
45 |
return acting_user == user if [nil, :title, :discussion, :body].include?(field) |
46 |
end |
47 |
|
48 |
+ def update_voting_options(new_descriptions) |
49 |
+ old_descriptions = voting_options.*.description |
50 |
+ |
51 |
+ (old_descriptions - new_descriptions).each do |description| |
52 |
+ option = VotingOption.agenda_item_id_is(id).description_is(description).first |
53 |
+ option.destroy |
54 |
+ end |
55 |
+ |
56 |
+ (new_descriptions - old_descriptions ).each do |description| |
57 |
+ VotingOption.create! :agenda_item => self, :description => description |
58 |
+ end |
59 |
+ end |
60 |
protected |
61 |
# Updated discussion time for a single agenda item |
62 |
# protected because we want to call it only from |