<commit_before># frozen_string_literal: true

require 'rails_helper'

describe DashboardController do
  describe '#index' do
    let(:course) { create(:course, end: 2.days.ago) }
    let(:admin) { create(:admin) }

    context 'when the user is not logged it' do
      it 'redirects to landing page' do
        get 'index'
        expect(response.status).to eq(302)
      end
    end

    context 'when user is an admin' do
      before do
        allow(controller).to receive(:current_user).and_return(admin)
        create(:courses_user, user_id: admin.id, course_id: course.id)
      end

      it 'sets past courses to include just-ended ones' do
        get 'index'
        expect(assigns(:pres).past.count).to eq(1)
      end
    end

    context 'when the blog is down' do
      before do
        allow(controller).to receive(:current_user).and_return(admin)
        Rails.cache.clear
      end

      it 'sets @blog_posts to empty array' do
        stub_const('DashboardController::BLOG_FEED_URL', 'https://wikiedu.org/not_a_feed')
        VCR.use_cassette 'wikiedu.org/feed' do
          get 'index'
        end
        expect(assigns(:blog_posts)).to eq([])
      end
    end
  end
end
<commit_msg>conver dashboard controller test to request type<commit_after># frozen_string_literal: true

require 'rails_helper'

describe DashboardController, type: :request do
  describe '#index' do
    let(:course) { create(:course, end: 2.days.ago) }
    let(:admin) { create(:admin) }

    context 'when the user is not logged it' do
      it 'redirects to landing page' do
        get '/course_creator'
        expect(response.status).to eq(302)
      end
    end

    context 'when user is an admin' do
      before do
        allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(admin)
        create(:courses_user, user_id: admin.id, course_id: course.id)
      end

      it 'sets past courses to include just-ended ones' do
        get '/course_creator'
        expect(assigns(:pres).past.count).to eq(1)
      end
    end

    context 'when the blog is down' do
      before do
        allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(admin)
        Rails.cache.clear
      end

      it 'sets @blog_posts to empty array' do
        stub_const('DashboardController::BLOG_FEED_URL', 'https://wikiedu.org/not_a_feed')
        VCR.use_cassette 'wikiedu.org/feed' do
          get '/course_creator'
        end
        expect(assigns(:blog_posts)).to eq([])
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.0995687965503724, 'fraction_numerical': 0.003920031360250882, 'mean_word_length': 2.677233429394813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '2003234', 'n_tokens_mistral': 807, 'n_tokens_neox': 787, 'n_words': 216}