diff options
author | 2011-06-27 19:25:00 +0200 | |
---|---|---|
committer | 2011-07-05 11:58:08 +0200 | |
commit | 13007157d546151228f6a34f580c23aa853163c9 (patch) | |
tree | cbe38a64d774edd9c41d8fcbaecae0d008142591 | |
parent | Application receives data from bot (diff) | |
download | council-webapp-13007157d546151228f6a34f580c23aa853163c9.tar.gz council-webapp-13007157d546151228f6a34f580c23aa853163c9.tar.bz2 council-webapp-13007157d546151228f6a34f580c23aa853163c9.zip |
Agenda.current creates new agenda if needed
Removed agenda initializer as it is no longer needed.
-rw-r--r-- | site/app/models/agenda.rb | 4 | ||||
-rw-r--r-- | site/config/initializers/agenda.rb | 12 | ||||
-rw-r--r-- | site/spec/models/agenda_spec.rb | 12 |
3 files changed, 15 insertions, 13 deletions
diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb index 46cf2d8..4a02dbb 100644 --- a/site/app/models/agenda.rb +++ b/site/app/models/agenda.rb @@ -48,7 +48,9 @@ class Agenda < ActiveRecord::Base end def self.current - Agenda.state_is_not(:old).first + result = Agenda.state_is_not(:old).first + result = Agenda.create! unless result + result end def self.transitions_available(user) diff --git a/site/config/initializers/agenda.rb b/site/config/initializers/agenda.rb deleted file mode 100644 index bdd35b9..0000000 --- a/site/config/initializers/agenda.rb +++ /dev/null @@ -1,12 +0,0 @@ -# If there are no active agendas create one -begin - return unless ['development', 'production'].include? Rails.env - return if Agenda.state_is_not(:old).count > 0 - Agenda.create! -rescue - # Just ignore it. It will happen when: - # * Everything is fine, but database is missing (eg. rake db:schema:load) - # * It's safe to ignore this then - # * Something is seriously wrong (like broken db) - # * Users will notice this anyway -end diff --git a/site/spec/models/agenda_spec.rb b/site/spec/models/agenda_spec.rb index b84f462..05212d0 100644 --- a/site/spec/models/agenda_spec.rb +++ b/site/spec/models/agenda_spec.rb @@ -233,6 +233,18 @@ describe Agenda do end end + describe '#current?' do + it 'should create new agenda if needed' do + Agenda.count.should be_zero + agenda = Agenda.current + agenda2 = Agenda.current + agenda.should be_a(Agenda) + agenda2.should be_a(Agenda) + Agenda.count.should be_equal(1) + agenda.id.should be_equal(agenda2.id) + end + end + it 'should return proper voting_array' do old_agenda = Factory(:agenda, :state => 'old') current_agenda = Factory(:agenda) |