Gentoo Archives: gentoo-commits

From: "Petteri Räty" <betelgeuse@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/council-webapp:master commit in: site/config/initializers/, site/app/models/, site/spec/models/
Date: Tue, 05 Jul 2011 15:09:46
Message-Id: 13007157d546151228f6a34f580c23aa853163c9.betelgeuse@gentoo
1 commit: 13007157d546151228f6a34f580c23aa853163c9
2 Author: Joachim Filip Ignacy Bartosik <jbartosik <AT> gmail <DOT> com>
3 AuthorDate: Mon Jun 27 17:25:00 2011 +0000
4 Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
5 CommitDate: Tue Jul 5 09:58:08 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/council-webapp.git;a=commit;h=13007157
7
8 Agenda.current creates new agenda if needed
9
10 Removed agenda initializer as it is no longer needed.
11
12 ---
13 site/app/models/agenda.rb | 4 +++-
14 site/config/initializers/agenda.rb | 12 ------------
15 site/spec/models/agenda_spec.rb | 12 ++++++++++++
16 3 files changed, 15 insertions(+), 13 deletions(-)
17
18 diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb
19 index 46cf2d8..4a02dbb 100644
20 --- a/site/app/models/agenda.rb
21 +++ b/site/app/models/agenda.rb
22 @@ -48,7 +48,9 @@ class Agenda < ActiveRecord::Base
23 end
24
25 def self.current
26 - Agenda.state_is_not(:old).first
27 + result = Agenda.state_is_not(:old).first
28 + result = Agenda.create! unless result
29 + result
30 end
31
32 def self.transitions_available(user)
33
34 diff --git a/site/config/initializers/agenda.rb b/site/config/initializers/agenda.rb
35 deleted file mode 100644
36 index bdd35b9..0000000
37 --- a/site/config/initializers/agenda.rb
38 +++ /dev/null
39 @@ -1,12 +0,0 @@
40 -# If there are no active agendas create one
41 -begin
42 - return unless ['development', 'production'].include? Rails.env
43 - return if Agenda.state_is_not(:old).count > 0
44 - Agenda.create!
45 -rescue
46 - # Just ignore it. It will happen when:
47 - # * Everything is fine, but database is missing (eg. rake db:schema:load)
48 - # * It's safe to ignore this then
49 - # * Something is seriously wrong (like broken db)
50 - # * Users will notice this anyway
51 -end
52
53 diff --git a/site/spec/models/agenda_spec.rb b/site/spec/models/agenda_spec.rb
54 index b84f462..05212d0 100644
55 --- a/site/spec/models/agenda_spec.rb
56 +++ b/site/spec/models/agenda_spec.rb
57 @@ -233,6 +233,18 @@ describe Agenda do
58 end
59 end
60
61 + describe '#current?' do
62 + it 'should create new agenda if needed' do
63 + Agenda.count.should be_zero
64 + agenda = Agenda.current
65 + agenda2 = Agenda.current
66 + agenda.should be_a(Agenda)
67 + agenda2.should be_a(Agenda)
68 + Agenda.count.should be_equal(1)
69 + agenda.id.should be_equal(agenda2.id)
70 + end
71 + end
72 +
73 it 'should return proper voting_array' do
74 old_agenda = Factory(:agenda, :state => 'old')
75 current_agenda = Factory(:agenda)