<commit_before>require 'spec_helper'

describe AdminDashboardData do

  describe "rails_env_check" do
    subject { described_class.new.rails_env_check }

    it 'returns nil when running in production mode' do
      Rails.stubs(:env).returns('production')
      subject.should be_nil
    end

    it 'returns a string when running in development mode' do
      Rails.stubs(:env).returns('development')
      subject.should_not be_nil
    end

    it 'returns a string when running in test mode' do
      Rails.stubs(:env).returns('test')
      subject.should_not be_nil
    end
  end

  describe 'host_names_check' do
    subject { described_class.new.host_names_check }

    it 'returns nil when host_names is set' do
      Discourse.stubs(:current_hostname).returns('something.com')
      subject.should be_nil
    end

    it 'returns a string when host_name is localhost' do
      Discourse.stubs(:current_hostname).returns('localhost')
      subject.should_not be_nil
    end

    it 'returns a string when host_name is production.localhost' do
      Discourse.stubs(:current_hostname).returns('production.localhost')
      subject.should_not be_nil
    end
  end

  describe 'gc_checks' do
    subject { described_class.new.gc_checks }

    it 'returns nil when gc params are set' do
      ENV.stubs(:[]).with('RUBY_GC_MALLOC_LIMIT').returns(90000000)
      subject.should be_nil
    end

    it 'returns a string when gc params are not set' do
      ENV.stubs(:[]).with('RUBY_GC_MALLOC_LIMIT').returns(nil)
      subject.should_not be_nil
    end
  end

  describe 'sidekiq_check' do
    subject { described_class.new.sidekiq_check }

    it 'returns nil when sidekiq processed a job recently' do
      Jobs.stubs(:last_job_performed_at).returns(1.minute.ago)
      Jobs.stubs(:queued).returns(0)
      subject.should be_nil
    end

    it 'returns nil when last job processed was a long time ago, but no jobs are queued' do
      Jobs.stubs(:last_job_performed_at).returns(7.days.ago)
      Jobs.stubs(:queued).returns(0)
      subject.should be_nil
    end

    it 'returns nil when no jobs have ever been processed, but no jobs are queued' do
      Jobs.stubs(:last_job_performed_at).returns(nil)
      Jobs.stubs(:queued).returns(0)
      subject.should be_nil
    end

    it 'returns a string when no jobs were processed recently and some jobs are queued' do
      Jobs.stubs(:last_job_performed_at).returns(20.minutes.ago)
      Jobs.stubs(:queued).returns(1)
      subject.should_not be_nil
    end

    it 'returns a string when no jobs have ever been processed, and some jobs are queued' do
      Jobs.stubs(:last_job_performed_at).returns(nil)
      Jobs.stubs(:queued).returns(1)
      subject.should_not be_nil
    end
  end

  describe 'ram_check' do
    subject { described_class.new.ram_check }

    it 'returns nil when total ram is 1 GB' do
      MemInfo.any_instance.stubs(:mem_total).returns(1025272)
      subject.should be_nil
    end

    it 'returns nil when total ram cannot be determined' do
      MemInfo.any_instance.stubs(:mem_total).returns(nil)
      subject.should be_nil
    end

    it 'returns a string when total ram is less than 1 GB' do
      MemInfo.any_instance.stubs(:mem_total).returns(512636)
      subject.should_not be_nil
    end
  end

  describe 'send_consumer_email_check' do
    subject { described_class.new.send_consumer_email_check }

    it 'returns nil if gmail.com is not in the smtp_settings address' do
      ActionMailer::Base.stubs(:smtp_settings).returns({address: 'mandrillapp.com'})
      expect(subject).to be_nil
    end

    context 'gmail.com is in the smtp_settings address' do
      before { ActionMailer::Base.stubs(:smtp_settings).returns({address: 'smtp.<EMAIL>'}) }

      it 'returns nil in development env' do
        Rails.stubs(:env).returns('development')
        expect(subject).to be_nil
      end

      it 'returns a string when in production env' do
        Rails.stubs(:env).returns('production')
        expect(subject).to_not be_nil
      end
    end
  end

  describe 'default_logo_check' do
    subject { described_class.new.default_logo_check }

    describe 'favicon_url check' do
      before do
        SiteSetting.stubs(:logo_url).returns('/assets/my-logo.jpg')
        SiteSetting.stubs(:logo_small_url).returns('/assets/my-small-logo.jpg')
      end

      it 'returns a string when favicon_url is default' do
        expect(subject).to_not be_nil
      end<commit_msg>updated test with proper change of Rails.env during test<commit_after>require 'spec_helper'

describe AdminDashboardData do

  describe "rails_env_check" do
    subject { described_class.new.rails_env_check }

    it 'returns nil when running in production mode' do
      Rails.stubs(env: ActiveSupport::StringInquirer.new('production'))
      subject.should be_nil
    end

    it 'returns a string when running in development mode' do
      Rails.stubs(env: ActiveSupport::StringInquirer.new('development'))
      subject.should_not be_nil
    end

    it 'returns a string when running in test mode' do
      Rails.stubs(env: ActiveSupport::StringInquirer.new('test'))
      subject.should_not be_nil
    end
  end

  describe 'host_names_check' do
    subject { described_class.new.host_names_check }

    it 'returns nil when host_names is set' do
      Discourse.stubs(:current_hostname).returns('something.com')
      subject.should be_nil
    end

    it 'returns a string when host_name is localhost' do
      Discourse.stubs(:current_hostname).returns('localhost')
      subject.should_not be_nil
    end

    it 'returns a string when host_name is production.localhost' do
      Discourse.stubs(:current_hostname).returns('production.localhost')
      subject.should_not be_nil
    end
  end

  describe 'gc_checks' do
    subject { described_class.new.gc_checks }

    it 'returns nil when gc params are set' do
      ENV.stubs(:[]).with('RUBY_GC_MALLOC_LIMIT').returns(90000000)
      subject.should be_nil
    end

    it 'returns a string when gc params are not set' do
      ENV.stubs(:[]).with('RUBY_GC_MALLOC_LIMIT').returns(nil)
      subject.should_not be_nil
    end
  end

  describe 'sidekiq_check' do
    subject { described_class.new.sidekiq_check }

    it 'returns nil when sidekiq processed a job recently' do
      Jobs.stubs(:last_job_performed_at).returns(1.minute.ago)
      Jobs.stubs(:queued).returns(0)
      subject.should be_nil
    end

    it 'returns nil when last job processed was a long time ago, but no jobs are queued' do
      Jobs.stubs(:last_job_performed_at).returns(7.days.ago)
      Jobs.stubs(:queued).returns(0)
      subject.should be_nil
    end

    it 'returns nil when no jobs have ever been processed, but no jobs are queued' do
      Jobs.stubs(:last_job_performed_at).returns(nil)
      Jobs.stubs(:queued).returns(0)
      subject.should be_nil
    end

    it 'returns a string when no jobs were processed recently and some jobs are queued' do
      Jobs.stubs(:last_job_performed_at).returns(20.minutes.ago)
      Jobs.stubs(:queued).returns(1)
      subject.should_not be_nil
    end

    it 'returns a string when no jobs have ever been processed, and some jobs are queued' do
      Jobs.stubs(:last_job_performed_at).returns(nil)
      Jobs.stubs(:queued).returns(1)
      subject.should_not be_nil
    end
  end

  describe 'ram_check' do
    subject { described_class.new.ram_check }

    it 'returns nil when total ram is 1 GB' do
      MemInfo.any_instance.stubs(:mem_total).returns(1025272)
      subject.should be_nil
    end

    it 'returns nil when total ram cannot be determined' do
      MemInfo.any_instance.stubs(:mem_total).returns(nil)
      subject.should be_nil
    end

    it 'returns a string when total ram is less than 1 GB' do
      MemInfo.any_instance.stubs(:mem_total).returns(512636)
      subject.should_not be_nil
    end
  end

  describe 'send_consumer_email_check' do
    subject { described_class.new.send_consumer_email_check }

    it 'returns nil if gmail.com is not in the smtp_settings address' do
      ActionMailer::Base.stubs(:smtp_settings).returns({address: 'mandrillapp.com'})
      expect(subject).to be_nil
    end

    context 'gmail.com is in the smtp_settings address' do
      before { ActionMailer::Base.stubs(:smtp_settings).returns({address: 'smtp.gmail.com'}) }

      it 'returns nil in development env' do
        Rails.stubs(env: ActiveSupport::StringInquirer.new('development'))
        expect(subject).to be_nil
      end

      it 'returns a string when in production env' do
        Rails.stubs(env: ActiveSupport::StringInquirer.new('production'))
        expect(subject).to_not be_nil
      end
    end
  end

  describe 'default_logo_check' do
    subject { described_class.new.default_logo_check }

    describe 'favicon_url check' do
      before do
        SiteSetting.stubs(:logo_url).returns('/assets/my-logo.jpg')
        SiteSetting.stubs(:logo_small_url).returns('/assets/my-small-logo.jpg')
      end

      it 'returns a string when favicon_url is default' do
        expect(subject).to_not be_nil
      end
{'fraction_non_alphanumeric': 0.0861747615393049, 'fraction_numerical': 0.007016774476482842, 'mean_word_length': 3.192095588235294, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6122186', 'n_tokens_mistral': 2937, 'n_tokens_neox': 2817, 'n_words': 762}