diff options
author | Gareth Rees <gareth@mysociety.org> | 2014-10-20 10:36:32 +0100 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2014-10-29 13:01:11 +0000 |
commit | d64a0dc5945152b2b90d2209140eb4170825761f (patch) | |
tree | 4b72702a2d1feb3c12d2ae65a4682d1d5c220948 | |
parent | 1dab89cdda34a7f50ac5aab217b3dbb9155231e9 (diff) |
Move PostRedirect class methods to top of file
-rw-r--r-- | app/models/post_redirect.rb | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb index 6f288b471..770f06a02 100644 --- a/app/models/post_redirect.rb +++ b/app/models/post_redirect.rb @@ -33,6 +33,28 @@ class PostRedirect < ActiveRecord::Base after_initialize :generate_token + + # Makes a random token, suitable for using in URLs e.g confirmation + # messages. + def self.generate_random_token + MySociety::Util.generate_token + end + + # Used by (rspec) test code only + def self.get_last_post_redirect + # TODO: yeuch - no other easy way of getting the token so we can check + # the redirect URL, as it is by definition opaque to the controller + # apart from in the place that it redirects to. + post_redirects = PostRedirect.find_by_sql("select * from post_redirects order by id desc limit 1") + post_redirects.size.should == 1 + return post_redirects[0] + end + + # Called from cron job delete-old-things + def self.delete_old_post_redirects + PostRedirect.delete_all "updated_at < (now() - interval '2 months')" + end + # We store YAML version of POST parameters in the database def post_params=(params) self.post_params_yaml = params.to_yaml @@ -58,26 +80,6 @@ class PostRedirect < ActiveRecord::Base return $1 end - # Makes a random token, suitable for using in URLs e.g confirmation messages. - def self.generate_random_token - MySociety::Util.generate_token - end - - # Used by (rspec) test code only - def self.get_last_post_redirect - # TODO: yeuch - no other easy way of getting the token so we can check - # the redirect URL, as it is by definition opaque to the controller - # apart from in the place that it redirects to. - post_redirects = PostRedirect.find_by_sql("select * from post_redirects order by id desc limit 1") - post_redirects.size.should == 1 - return post_redirects[0] - end - - # Called from cron job delete-old-things - def self.delete_old_post_redirects - PostRedirect.delete_all "updated_at < (now() - interval '2 months')" - end - private def generate_token |