<commit_before>require 'spec_helper'

describe IssuesFinder do
  let(:user) { create :user }
  let(:user2) { create :user }
  let(:project1) { create(:project) }
  let(:project2) { create(:project) }
  let(:issue1) { create(:issue, assignee: user, project: project1) }
  let(:issue2) { create(:issue, assignee: user, project: project2) }
  let(:issue3) { create(:issue, assignee: user2, project: project2) }

  before do
    project1.team << [user, :master]
    project2.team << [user, :developer]
    project2.team << [user2, :developer]
  end

  describe :execute do
    before :each do
      issue1
      issue2
      issue3
    end

    it 'should filter by all' do
      params = { scope: "all", state: 'opened' }
      issues = IssuesFinder.new.execute(user, params)
      issues.size.should == 3
    end

    it 'should filter by assignee' do
      params = { scope: "assigned-to-me", state: 'opened' }
      issues = IssuesFinder.new.execute(user, params)
      issues.size.should == 2
    end

    it 'should filter by project' do
      params = { scope: "assigned-to-me", state: 'opened', project_id: project1.id }
      issues = IssuesFinder.new.execute(user, params)
      issues.size.should == 1
    end

    it 'should be empty for unauthorized user' do
      params = { scope: "all", state: 'opened' }
      issues = IssuesFinder.new.execute(nil, params)
      issues.size.should be_zero
    end

    it 'should not include unauthorized issues' do
      params = { scope: "all", state: 'opened' }
      issues = IssuesFinder.new.execute(user2, params)
      issues.size.should == 2
      issues.should_not include(issue1)
      issues.should include(issue2)
      issues.should include(issue3)
    end
  end
end<commit_msg>More tests for issues finder<commit_after>require 'spec_helper'

describe IssuesFinder do
  let(:user) { create :user }
  let(:user2) { create :user }
  let(:project1) { create(:project) }
  let(:project2) { create(:project) }
  let(:milestone) { create(:milestone, project: project1) }
  let(:issue1) { create(:issue, author: user, assignee: user, project: project1, milestone: milestone) }
  let(:issue2) { create(:issue, author: user, assignee: user, project: project2) }
  let(:issue3) { create(:issue, author: user2, assignee: user2, project: project2) }

  before do
    project1.team << [user, :master]
    project2.team << [user, :developer]
    project2.team << [user2, :developer]
  end

  describe :execute do
    before :each do
      issue1
      issue2
      issue3
    end

    context 'scope: all' do
      it 'should filter by all' do
        params = { scope: "all", state: 'opened' }
        issues = IssuesFinder.new.execute(user, params)
        issues.size.should == 3
      end

      it 'should filter by assignee id' do
        params = { scope: "all", assignee_id: user.id, state: 'opened' }
        issues = IssuesFinder.new.execute(user, params)
        issues.size.should == 2
      end

      it 'should filter by author id' do
        params = { scope: "all", author_id: user2.id, state: 'opened' }
        issues = IssuesFinder.new.execute(user, params)
        issues.should == [issue3]
      end

      it 'should filter by milestone id' do
        params = { scope: "all", milestone_id: milestone.id, state: 'opened' }
        issues = IssuesFinder.new.execute(user, params)
        issues.should == [issue1]
      end

      it 'should be empty for unauthorized user' do
        params = { scope: "all", state: 'opened' }
        issues = IssuesFinder.new.execute(nil, params)
        issues.size.should be_zero
      end

      it 'should not include unauthorized issues' do
        params = { scope: "all", state: 'opened' }
        issues = IssuesFinder.new.execute(user2, params)
        issues.size.should == 2
        issues.should_not include(issue1)
        issues.should include(issue2)
        issues.should include(issue3)
      end
    end

    context 'personal scope' do
      it 'should filter by assignee' do
        params = { scope: "assigned-to-me", state: 'opened' }
        issues = IssuesFinder.new.execute(user, params)
        issues.size.should == 2
      end

      it 'should filter by project' do
        params = { scope: "assigned-to-me", state: 'opened', project_id: project1.id }
        issues = IssuesFinder.new.execute(user, params)
        issues.size.should == 1
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12088161781413315, 'fraction_numerical': 0.013178822994773916, 'mean_word_length': 2.72419627749577, 'pattern_counts': {'":': 0, '<': 15, '<?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': '3849233', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1347, 'n_words': 391}