<commit_before>require 'rails_helper'

RSpec.feature "File browser", type: :feature do
  given!(:user) { create(:user, password: "<PASSWORD>", password_confirmation: "<PASSWORD>") }
  given!(:unauthorized_project) { Project.create(name: "Management", owner: create(:user)) }

  background do
    @unauthorized_attachments = []
    user.projects.create!(name: "UI Design", owner: user)
    user.projects.create!(name: "Engineering", owner: user)

    unauthorized_project.stories.create(name: "First time flow", owner: unauthorized_project.owner).tap do |story|
      @unauthorized_attachments << create(:attachment, story: story)
    end

    sign_in_with user.email, "hunter212"
  end

  context "when user has no files" do
    scenario "displays a friendly message" do
      visit "/files"
      expect(page).to have_content "You don’t have any files across your projects"
    end
  end

  context "when user has some files" do
    background do
      @attachments = []
      user.projects.each do |project|
        story = create(:story, project: project, owner: user)
        @attachments << create(:attachment, story: story)
        @attachments << create(:attachment, story: story)
      end
    end

    scenario "displays those files" do<commit_msg>test, set attachment on a comment<commit_after>require 'rails_helper'

RSpec.feature "File browser", type: :feature do
  given!(:user) { create(:user, password: "<PASSWORD>", password_confirmation: "<PASSWORD>") }
  given!(:unauthorized_project) { Project.create(name: "Management", owner: create(:user)) }

  background do
    @unauthorized_attachments = []
    user.projects.create!(name: "UI Design", owner: user)
    user.projects.create!(name: "Engineering", owner: user)

    unauthorized_project.stories.create(name: "First time flow", owner: unauthorized_project.owner).tap do |story|
      @unauthorized_attachments << create(:attachment, story: story)
    end

    sign_in_with user.email, "hunter212"
  end

  context "when user has no files" do
    scenario "displays a friendly message" do
      visit "/files"
      expect(page).to have_content "You don’t have any files across your projects"
    end
  end

  context "when user has some files" do
    background do
      @attachments = []
      user.projects.each do |project|
        story = create(:story, project: project, owner: user)
        comment = create(:comment)
        @attachments << create(:attachment, story: story, attachable: comment)
        @attachments << create(:attachment, story: story, attachable: comment)
      end
    end

    scenario "displays those files" do
{'fraction_non_alphanumeric': 0.11604749138261203, 'fraction_numerical': 0.002297970126388357, 'mean_word_length': 3.8280961182994453, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 7, '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': '4313406', 'n_tokens_mistral': 759, 'n_tokens_neox': 738, 'n_words': 228}