From a2aabeb599d294e7b4f47befb9d65b3b6a03ed2d Mon Sep 17 00:00:00 2001
From: Maxwell Salzberg <maxwell@joindiaspora.com>
Date: Fri, 16 Mar 2012 18:10:18 -0700
Subject: [PATCH] remove ActiveSupport::SecureRandom

---
 app/models/invitation_code.rb          | 2 +-
 app/models/photo.rb                    | 2 +-
 app/models/user.rb                     | 4 ++--
 lib/diaspora/guid.rb                   | 2 +-
 lib/tasks/generate_session_secret.rake | 2 +-
 lib/tasks/heroku.rake                  | 2 +-
 spec/factories.rb                      | 6 +++---
 spec/models/services/twitter_spec.rb   | 8 ++++----
 spec/models/user_spec.rb               | 2 +-
 9 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/app/models/invitation_code.rb b/app/models/invitation_code.rb
index e653648ce5..21bb1a74e4 100644
--- a/app/models/invitation_code.rb
+++ b/app/models/invitation_code.rb
@@ -23,7 +23,7 @@ class InvitationCode < ActiveRecord::Base
 
   def generate_token
     begin
-      self.token = ActiveSupport::SecureRandom.hex(6)
+      self.token = SecureRandom.hex(6)
     end while InvitationCode.exists?(:token => self[:token])
   end
 
diff --git a/app/models/photo.rb b/app/models/photo.rb
index 54b3a9f6bc..fa76787c51 100644
--- a/app/models/photo.rb
+++ b/app/models/photo.rb
@@ -71,7 +71,7 @@ class Photo < ActiveRecord::Base
     photo.pending = params[:pending] if params[:pending]
     photo.diaspora_handle = photo.author.diaspora_handle
 
-    photo.random_string = ActiveSupport::SecureRandom.hex(10)
+    photo.random_string = SecureRandom.hex(10)
 
     if params[:user_file]
       image_file = params.delete(:user_file)
diff --git a/app/models/user.rb b/app/models/user.rb
index 6d7abfb7c2..2ca3d6bb86 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -438,7 +438,7 @@ class User < ActiveRecord::Base
     self.unconfirmed_email = nil if unconfirmed_email.blank? || unconfirmed_email == email
 
     if unconfirmed_email_changed?
-      self.confirm_email_token = unconfirmed_email ? ActiveSupport::SecureRandom.hex(15) : nil
+      self.confirm_email_token = unconfirmed_email ? SecureRandom.hex(15) : nil
     end
   end
 
@@ -495,7 +495,7 @@ class User < ActiveRecord::Base
     end
     self[:email] = "deletedaccount_#{self[:id]}@example.org"
 
-    random_password = ActiveSupport::SecureRandom.hex(20)
+    random_password = SecureRandom.hex(20)
     self.password = random_password
     self.password_confirmation = random_password
     self.save(:validate => false)
diff --git a/lib/diaspora/guid.rb b/lib/diaspora/guid.rb
index 3a7b1d54d2..c94e56eacd 100644
--- a/lib/diaspora/guid.rb
+++ b/lib/diaspora/guid.rb
@@ -13,6 +13,6 @@ module Diaspora::Guid
 
   # @return [String] The model's guid.
   def set_guid
-    self.guid = ActiveSupport::SecureRandom.hex(8) if self.guid.blank?
+    self.guid = SecureRandom.hex(8) if self.guid.blank?
   end
 end
diff --git a/lib/tasks/generate_session_secret.rake b/lib/tasks/generate_session_secret.rake
index f6a1e85b54..efd55bbabd 100644
--- a/lib/tasks/generate_session_secret.rake
+++ b/lib/tasks/generate_session_secret.rake
@@ -3,7 +3,7 @@ namespace :generate do
   task :secret_token do
 
   path = File.join(Rails.root, 'config', 'initializers', 'secret_token.rb')
-  secret = ActiveSupport::SecureRandom.hex(40)
+  secret = SecureRandom.hex(40)
   File.open(path, 'w') do |f|
     f.write <<"EOF"
 #   Copyright (c) 2010-2011, Diaspora Inc.  This file is
diff --git a/lib/tasks/heroku.rake b/lib/tasks/heroku.rake
index 3b702d7fc0..32ca1a7816 100644
--- a/lib/tasks/heroku.rake
+++ b/lib/tasks/heroku.rake
@@ -9,7 +9,7 @@ namespace :heroku do
 
   task :generate_secret_token do
     puts "Generating and setting a new secret token"
-    token = ActiveSupport::SecureRandom.hex(40)#reloads secret token every time you reload vars.... this expires cookies, and kinda sucks
+    token = SecureRandom.hex(40)#reloads secret token every time you reload vars.... this expires cookies, and kinda sucks
     command = "#{HEROKU_CONFIG_ADD_COMMAND} SECRET_TOKEN=#{token}"
     puts command
     system command
diff --git a/spec/factories.rb b/spec/factories.rb
index 4f13b6ec63..bde89c3c0f 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -7,7 +7,7 @@
 # http://railscasts.com/episodes/158-factories-not-fixtures
 
 def r_str
-  ActiveSupport::SecureRandom.hex(3)
+  SecureRandom.hex(3)
 end
 
 FactoryGirl.define do
@@ -100,7 +100,7 @@ FactoryGirl.define do
   end
 
   factory(:photo) do
-    sequence(:random_string) {|n| ActiveSupport::SecureRandom.hex(10) }
+    sequence(:random_string) {|n| SecureRandom.hex(10) }
     association :author, :factory => :person
     after_build do |p|
       p.unprocessed_image.store! File.open(File.join(File.dirname(__FILE__), 'fixtures', 'button.png'))
@@ -237,7 +237,7 @@ FactoryGirl.define do
   end
 
   factory(:note, :parent => :status_message) do
-    text ActiveSupport::SecureRandom.hex(1000)
+    text SecureRandom.hex(1000)
   end
 
   factory(:rich_media, :parent => :status_message) do
diff --git a/spec/models/services/twitter_spec.rb b/spec/models/services/twitter_spec.rb
index e990a31752..cccd190948 100644
--- a/spec/models/services/twitter_spec.rb
+++ b/spec/models/services/twitter_spec.rb
@@ -30,17 +30,17 @@ describe Services::Twitter do
   end
   describe "message size limits" do
     before :each do
-      @long_message_start = ActiveSupport::SecureRandom.hex(25)
-      @long_message_end = ActiveSupport::SecureRandom.hex(25)
+      @long_message_start = SecureRandom.hex(25)
+      @long_message_end = SecureRandom.hex(25)
     end
 
     it "should not truncate a short message" do
-      short_message = ActiveSupport::SecureRandom.hex(20)
+      short_message = SecureRandom.hex(20)
       short_post = stub(:text => short_message )
       @service.public_message(short_post, '').should == short_message
     end
     it "should truncate a long message" do
-      long_message = ActiveSupport::SecureRandom.hex(220)
+      long_message = SecureRandom.hex(220)
       long_post = stub(:text => long_message )
       @service.public_message(long_post, '').should == long_message.first(137) + "..."
     end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 1738beda5c..30a29e910f 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -846,7 +846,7 @@ describe User do
     describe "#clear_account!" do
       it 'resets the password to a random string' do
         random_pass = "12345678909876543210"
-        ActiveSupport::SecureRandom.should_receive(:hex).and_return(random_pass)
+        SecureRandom.should_receive(:hex).and_return(random_pass)
         @user.clear_account!
         @user.valid_password?(random_pass)
       end
-- 
GitLab