<commit_before>require 'rails_helper'

cohort_course_count = 10

cohort = Figaro.env.cohorts.split(',').last

cohort_two = Figaro.env.cohorts.split(',').first
cohort_two_title = cohort_two.gsub('_', ' ').capitalize

describe 'the home page', type: :feature do
  before do
    (1..cohort_course_count).each do |i|
      create(:course,
             id: i.to_s,
             slug: "course_#{i}",
             cohort: cohort
      )
      create(:course,
             id: (i + cohort_course_count).to_s,
             slug: "course_#{i}",
             cohort: cohort_two
      )
      create(:user, id: i.to_s)
      create(:courses_user,
             id: i.to_s,
             course_id: i.to_s,
             user_id: i.to_s
      )
      create(:article,
             id: i.to_s,
             title: 'Selfie',
             namespace: 0
      )
      create(:revision,
             id: i.to_s,
             user_id: i.to_s,
             article_id: i.to_s,
             date: '2015-03-01'.to_date,
             characters: 9000
      )
    end
    Course.update_all_caches
  end

  before :each do
    if page.driver.is_a?(Capybara::Webkit::Driver)
      page.driver.allow_url 'fonts.googleapis.com'
      page.driver.allow_url 'maxcdn.bootstrapcdn.com'
      # page.driver.block_unknown_urls  # suppress warnings
    end
    visit root_path
  end

  describe 'header' do
    it 'should display number of courses accurately' do
      course_count = Course.cohort(cohort).count
      stat_text = "#{course_count} WikiEdu Courses"
      expect(page.find('.stat-display')).to have_content stat_text
    end

    it 'should display number of students accurately' do
      student_count = User.role('student').count
      stat_text = "#{student_count} Student Editors"
      expect(page.find('.stat-display')).to have_content stat_text
    end

    it 'should display number of characters added accurately' do
      character_count = Course.all.sum(:character_sum)
      stat_text = "#{character_count} Characters Added"
      expect(page.find('.stat-display')).to have_content stat_text
    end

    it 'should display number of views accurately' do
      character_count = Course.all.sum(:view_sum)
      stat_text = "#{character_count} Article Views"<commit_msg>Make home_page_spec independent of the locale<commit_after>require 'rails_helper'

cohort_course_count = 10

cohort = Figaro.env.cohorts.split(',').last

cohort_two = Figaro.env.cohorts.split(',').first
cohort_two_title = cohort_two.gsub('_', ' ').capitalize

describe 'the home page', type: :feature do
  before do
    (1..cohort_course_count).each do |i|
      create(:course,
             id: i.to_s,
             slug: "course_#{i}",
             cohort: cohort
      )
      create(:course,
             id: (i + cohort_course_count).to_s,
             slug: "course_#{i}",
             cohort: cohort_two
      )
      create(:user, id: i.to_s)
      create(:courses_user,
             id: i.to_s,
             course_id: i.to_s,
             user_id: i.to_s
      )
      create(:article,
             id: i.to_s,
             title: 'Selfie',
             namespace: 0
      )
      create(:revision,
             id: i.to_s,
             user_id: i.to_s,
             article_id: i.to_s,
             date: '2015-03-01'.to_date,
             characters: 9000
      )
    end
    Course.update_all_caches
  end

  before :each do
    if page.driver.is_a?(Capybara::Webkit::Driver)
      page.driver.allow_url 'fonts.googleapis.com'
      page.driver.allow_url 'maxcdn.bootstrapcdn.com'
      # page.driver.block_unknown_urls  # suppress warnings
    end
    visit root_path
  end

  describe 'header' do
    it 'should display number of courses accurately' do
      course_count = Course.cohort(cohort).count
      stat_text = "#{course_count} #{I18n.t('course.course_description')}"
      expect(page.find('.stat-display')).to have_content stat_text
    end

    it 'should display number of students accurately' do
      student_count = User.role('student').count
      stat_text = "#{student_count} #{I18n.t('course.students')}"
      expect(page.find('.stat-display')).to have_content stat_text
    end

    it 'should display number of characters added accurately' do
      character_count = Course.all.sum(:character_sum)
      stat_text = "#{character_count} #{I18n.t('metrics.char_added')}"
      expect(page.find('.stat-display')).to have_content stat_text
    end

    it 'should display number of views accurately' do
      character_count = Course.all.sum(:view_sum)
      stat_text = "#{character_count} #{I18n.t('metrics.view_count_description')}"
{'fraction_non_alphanumeric': 0.11459459459459459, 'fraction_numerical': 0.008648648648648649, 'mean_word_length': 2.3815789473684212, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '498500', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1481, 'n_words': 314}