From 46997c6a89c6115c64f6e0c8836bb3b598fcd433 Mon Sep 17 00:00:00 2001
From: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Date: Wed, 15 Jan 2014 16:32:56 +0200
Subject: [PATCH] Remove unnecessary contexts

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
---
 app/contexts/filter_context.rb              | 58 ------------------
 app/contexts/issues/list_context.rb         | 39 -------------
 app/contexts/merge_requests_load_context.rb | 38 ------------
 spec/contexts/filter_context_spec.rb        | 65 ---------------------
 4 files changed, 200 deletions(-)
 delete mode 100644 app/contexts/filter_context.rb
 delete mode 100644 app/contexts/issues/list_context.rb
 delete mode 100644 app/contexts/merge_requests_load_context.rb
 delete mode 100644 spec/contexts/filter_context_spec.rb

diff --git a/app/contexts/filter_context.rb b/app/contexts/filter_context.rb
deleted file mode 100644
index fb0d42cf8..000000000
--- a/app/contexts/filter_context.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-class FilterContext
-  attr_accessor :klass, :current_user, :params
-
-  def initialize(klass, current_user, params)
-    @klass = klass
-    @current_user = current_user
-    @params = params
-  end
-
-  def execute
-    items = by_scope
-    items = by_state(items)
-    items = by_project(items)
-    items = by_search(items)
-  end
-
-  private
-
-  def by_scope
-    table_name = klass.table_name
-
-    case params[:scope]
-    when 'authored' then
-      current_user.send(table_name)
-    when 'all' then
-      klass.of_projects(current_user.authorized_projects.pluck(:id))
-    else
-      current_user.send("assigned_#{table_name}")
-    end
-  end
-
-  def by_state(items)
-    case params[:status]
-    when 'closed'
-      items.closed
-    when 'all'
-      items
-    else
-      items.opened
-    end
-  end
-
-  def by_project(items)
-    if params[:project_id].present?
-      items = items.of_projects(params[:project_id])
-    end
-
-    items
-  end
-
-  def by_search(items)
-    if params[:search].present?
-      items = items.search(params[:search])
-    end
-
-    items
-  end
-end
diff --git a/app/contexts/issues/list_context.rb b/app/contexts/issues/list_context.rb
deleted file mode 100644
index 6de14d8cd..000000000
--- a/app/contexts/issues/list_context.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-module Issues
-  class ListContext < BaseContext
-    attr_accessor :issues
-
-    def execute
-      @issues = @project.issues
-
-      @issues = case params[:state]
-                when 'all' then @issues
-                when 'closed' then @issues.closed
-                else @issues.opened
-                end
-
-      @issues = case params[:scope]
-                when 'assigned-to-me' then @issues.assigned_to(current_user)
-                when 'created-by-me' then @issues.authored(current_user)
-                else @issues
-                end
-
-      @issues = @issues.tagged_with(params[:label_name]) if params[:label_name].present?
-      @issues = @issues.includes(:author, :project)
-
-      # Filter by specific assignee_id (or lack thereof)?
-      if params[:assignee_id].present?
-        @issues = @issues.where(assignee_id: (params[:assignee_id] == '0' ? nil : params[:assignee_id]))
-      end
-
-      # Filter by specific milestone_id (or lack thereof)?
-      if params[:milestone_id].present?
-        @issues = @issues.where(milestone_id: (params[:milestone_id] == '0' ? nil : params[:milestone_id]))
-      end
-
-      # Sort by :sort param
-      @issues = @issues.sort(params[:sort])
-
-      @issues
-    end
-  end
-end
diff --git a/app/contexts/merge_requests_load_context.rb b/app/contexts/merge_requests_load_context.rb
deleted file mode 100644
index 3559ebf7a..000000000
--- a/app/contexts/merge_requests_load_context.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-# Build collection of Merge Requests
-# based on filtering passed via params for @project
-class MergeRequestsLoadContext < BaseContext
-  def execute
-    merge_requests = @project.merge_requests
-
-    merge_requests = case params[:state]
-                     when 'all' then merge_requests
-                     when 'closed' then merge_requests.closed
-                     else merge_requests.opened
-                     end
-
-    merge_requests = case params[:scope]
-                     when 'assigned-to-me' then merge_requests.assigned_to(current_user)
-                     when 'created-by-me' then merge_requests.authored(current_user)
-                     else merge_requests
-                     end
-
-
-    merge_requests = merge_requests.page(params[:page]).per(20)
-    merge_requests = merge_requests.includes(:author, :source_project, :target_project).order("created_at desc")
-
-    # Filter by specific assignee_id (or lack thereof)?
-    if params[:assignee_id].present?
-      merge_requests = merge_requests.where(assignee_id: (params[:assignee_id] == '0' ? nil : params[:assignee_id]))
-    end
-
-    # Filter by specific milestone_id (or lack thereof)?
-    if params[:milestone_id].present?
-      merge_requests = merge_requests.where(milestone_id: (params[:milestone_id] == '0' ? nil : params[:milestone_id]))
-    end
-
-    # Sort by :sort param
-    merge_requests = merge_requests.sort(params[:sort])
-
-    merge_requests
-  end
-end
diff --git a/spec/contexts/filter_context_spec.rb b/spec/contexts/filter_context_spec.rb
deleted file mode 100644
index 06aef5d7e..000000000
--- a/spec/contexts/filter_context_spec.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-require 'spec_helper'
-
-describe FilterContext do
-  let(:user) { create :user }
-  let(:user2) { create :user }
-  let(:project1) { create(:project) }
-  let(:project2) { create(:project) }
-  let(:merge_request1) { create(:merge_request, author: user, source_project: project1, target_project: project2) }
-  let(:merge_request2) { create(:merge_request, author: user, source_project: project2, target_project: project1) }
-  let(:merge_request3) { create(:merge_request, author: user, source_project: project2, target_project: project2) }
-  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]
-  end
-
-  describe 'merge requests' do
-    before :each do
-      merge_request1
-      merge_request2
-      merge_request3
-    end
-
-    it 'should filter by scope' do
-      params = { scope: 'authored' }
-      merge_requests = FilterContext.new(MergeRequest, user, params).execute
-      merge_requests.size.should == 3
-    end
-
-    it 'should filter by project' do
-      params = { project_id: project1.id, scope: 'authored' }
-      merge_requests = FilterContext.new(MergeRequest, user, params).execute
-      merge_requests.size.should == 1
-    end
-  end
-
-  describe 'issues' do
-    before :each do
-      issue1
-      issue2
-      issue3
-    end
-
-    it 'should filter by all' do
-      params = { scope: "all" }
-      issues = FilterContext.new(Issue, user, params).execute
-      issues.size.should == 3
-    end
-
-    it 'should filter by assignee' do
-      params = {}
-      issues = FilterContext.new(Issue, user, params).execute
-      issues.size.should == 2
-    end
-
-    it 'should filter by project' do
-      params = { project_id: project1.id }
-      issues = FilterContext.new(Issue, user, params).execute
-      issues.size.should == 1
-    end
-  end
-end
-- 
2.30.9