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 @@ def view_permitted?(field) 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 @@ def test_migration(object, migration, prohibited, allowed, final_state) 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)