diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/request_controller.rb | 20 | ||||
-rw-r--r-- | app/models/info_request.rb | 34 |
2 files changed, 17 insertions, 37 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index b339134eb..44e4880c2 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -12,25 +12,13 @@ class RequestController < ApplicationController before_filter :check_read_only, :only => [ :new, :show_response, :describe_state, :upload_response ] protect_from_forgery :only => [ :new, :show_response, :describe_state, :upload_response ] # See ActionController::RequestForgeryProtection for details - def load_custom_states - @@custom_states_loaded = false + @@custom_states_loaded = false + begin if !ENV["RAILS_ENV"] == "test" - load_custom_states! - end - end - - def load_custom_states! - begin - # InfoRequestCustomStates may be `require`d in a theme - # plugin, or by a test - RequestController.send(:include, RequestControllerCustomStates) + include RequestControllerCustomStates @@custom_states_loaded = true - rescue NameError end - end - - def initialize - self.load_custom_states + rescue NameError end def show diff --git a/app/models/info_request.rb b/app/models/info_request.rb index c51e0c546..f7a8f58a2 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -80,7 +80,7 @@ class InfoRequest < ActiveRecord::Base 'blackhole' # just dump them ] - def enumerate_states + def self.enumerate_states states = [ 'waiting_response', 'waiting_clarification', @@ -96,15 +96,25 @@ class InfoRequest < ActiveRecord::Base ] if @@custom_states_loaded - states += self.theme_extra_states + states += InfoRequest.theme_extra_states end states end def must_be_valid_state errors.add(:described_state, "is not a valid state") if - !self.enumerate_states.include? described_state + !InfoRequest.enumerate_states.include? described_state end + + @@custom_states_loaded = false + begin + if !ENV["RAILS_ENV"] == "test" + include InfoRequestCustomStates + @@custom_states_loaded = true + end + rescue NameError + end + # only check on create, so existing models with mixed case are allowed def validate_on_create if !self.title.nil? && !MySociety::Validate.uses_mixed_capitals(self.title, 10) @@ -121,7 +131,6 @@ class InfoRequest < ActiveRecord::Base OLD_AGE_IN_DAYS = 21.days def after_initialize - self.load_custom_states if self.described_state.nil? self.described_state = 'waiting_response' end @@ -131,23 +140,6 @@ class InfoRequest < ActiveRecord::Base end end - def load_custom_states - @@custom_states_loaded = false - if !ENV["RAILS_ENV"] == "test" - load_custom_states! - end - end - - def load_custom_states! - begin - # InfoRequestCustomStates may be `require`d in a theme - # plugin, or by a test - InfoRequest.send(:include, InfoRequestCustomStates) - @@custom_states_loaded = true - rescue NameError - end - end - def visible_comments self.comments.find(:all, :conditions => 'visible') end |