<commit_before>require 'spec_helper'

describe 'stats/file.html.erb', type: :view do
  describe 'usage statistics' do
    let(:file_set) {
      stub_model(FileSet, id: '123',
                          title: ['file1.txt'])
    }

    let(:no_stats) {
      allow_message_expectations_on_nil
      allow(FileUsage).to receive(:new)
      stub_model(FileUsage,
                 created: Date.parse('2014-01-01'),
                 total_pageviews: 0,
                 total_downloads: 0,
                 to_flot: []
                )
    }

    let(:stats) {
      allow(FileUsage).to receive(:new)
      stub_model(FileUsage,
                 created: Date.parse('2014-01-01'),
                 total_pageviews: 9,
                 total_downloads: 4,
                 to_flot: [[1_396_422_000_000, 2], [1_396_508_400_000, 3], [1_396_594_800_000, 4]]
                )
    }

    before do
      assign(:file_set, file_set)
      assign(:stats, no_stats)
    end

    context 'when no analytics results returned' do
      before do
        assign(:pageviews, 0)
      end

      it 'shows 0 visits' do
        render
        page = Capybara::Node::Simple.new(rendered)
        expect(page).to have_selector('div.alert-info', text: /0 views and 0 downloads since January 1, 2014/i, count: 1)
      end<commit_msg>Minor refactor of stat view test<commit_after>require 'spec_helper'

describe 'stats/file.html.erb', type: :view do
  describe 'usage statistics' do
    before :each do
      allow_message_expectations_on_nil
      expect(FileUsage).to receive(:new)
    end

    let(:no_stats) {
      stub_model(FileUsage,
                 created: Date.parse('2014-01-01'),
                 total_pageviews: 0,
                 total_downloads: 0,
                 to_flot: []
                )
    }

    let(:stats) {
      stub_model(FileUsage,
                 created: Date.parse('2014-01-01'),
                 total_pageviews: 9,
                 total_downloads: 4,
                 to_flot: [[1_396_422_000_000, 2], [1_396_508_400_000, 3], [1_396_594_800_000, 4]]
                )
    }

    context 'when no analytics results returned' do
      before do
        assign(:stats, no_stats)
        assign(:pageviews, 0)
      end

      it 'shows 0 visits' do
        render
        page = Capybara::Node::Simple.new(rendered)
        expect(page).to have_selector('div.alert-info', text: /0 views and 0 downloads since January 1, 2014/i, count: 1)
      end
{'fraction_non_alphanumeric': 0.10588235294117647, 'fraction_numerical': 0.06004056795131846, 'mean_word_length': 1.8808411214953271, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2477922', 'n_tokens_mistral': 874, 'n_tokens_neox': 757, 'n_words': 171}