summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2017-07-07 11:38:01 +0200
committerJames Lopez <james@jameslopez.es>2017-07-07 11:38:01 +0200
commit377244dd45773a5d587eaf3b75ba64702229e34e (patch)
treefc5327b7d466bc3b352999792edd10e7e88ff566
parentbfe5f2d19f5be3dd4e039fa5b2b0b6b27c748db9 (diff)
downloadgitlab-ce-377244dd45773a5d587eaf3b75ba64702229e34e.tar.gz
refactor filters
-rw-r--r--app/finders/issuable_finder.rb14
-rw-r--r--app/finders/users_finder.rb14
-rw-r--r--lib/gitlab/database/created_at_filter.rb17
-rw-r--r--spec/requests/api/users_spec.rb2
4 files changed, 22 insertions, 25 deletions
diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb
index 7bc2117f61e..39427d83669 100644
--- a/app/finders/issuable_finder.rb
+++ b/app/finders/issuable_finder.rb
@@ -19,6 +19,8 @@
# iids: integer[]
#
class IssuableFinder
+ include Gitlab::Database::CreatedAtFilter
+
NONE = '0'.freeze
IRRELEVANT_PARAMS_FOR_CACHE_KEY = %i[utf8 sort page].freeze
@@ -408,18 +410,6 @@ class IssuableFinder
params[:non_archived].present? ? items.non_archived : items
end
- def by_created_at(items)
- if params[:created_after].present?
- items = items.where(items.klass.arel_table[:created_at].gteq(params[:created_after]))
- end
-
- if params[:created_before].present?
- items = items.where(items.klass.arel_table[:created_at].lteq(params[:created_before]))
- end
-
- items
- end
-
def current_user_related?
params[:scope] == 'created-by-me' || params[:scope] == 'authored' || params[:scope] == 'assigned-to-me'
end
diff --git a/app/finders/users_finder.rb b/app/finders/users_finder.rb
index ae031162892..c6bfc380c1c 100644
--- a/app/finders/users_finder.rb
+++ b/app/finders/users_finder.rb
@@ -14,6 +14,8 @@
# external: boolean
#
class UsersFinder
+ include Gitlab::Database::CreatedAtFilter
+
attr_accessor :current_user, :params
def initialize(current_user, params = {})
@@ -72,16 +74,4 @@ class UsersFinder
users.external
end
-
- def by_created_at(users)
- if params[:created_after].present?
- users = users.where(users.klass.arel_table[:created_at].gteq(params[:created_after]))
- end
-
- if params[:created_before].present?
- users = users.where(users.klass.arel_table[:created_at].lteq(params[:created_before]))
- end
-
- users
- end
end
diff --git a/lib/gitlab/database/created_at_filter.rb b/lib/gitlab/database/created_at_filter.rb
new file mode 100644
index 00000000000..3fa2770c65f
--- /dev/null
+++ b/lib/gitlab/database/created_at_filter.rb
@@ -0,0 +1,17 @@
+module Gitlab
+ module Database
+ module CreatedAtFilter
+ def by_created_at(items)
+ if params[:created_after].present?
+ items = items.where(items.klass.arel_table[:created_at].gteq(params[:created_after]))
+ end
+
+ if params[:created_before].present?
+ items = items.where(items.klass.arel_table[:created_at].lteq(params[:created_before]))
+ end
+
+ items
+ end
+ end
+ end
+end
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index 18b11a77494..ae1764c3d49 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -164,7 +164,7 @@ describe API::Users do
expect(response).to have_http_status(400)
end
- it "returns an user created before a specific date" do
+ it "returns a user created before a specific date" do
user = create(:user, created_at: Date.new(2000,1,1))
get api("/users?created_before=2000-01-02T00:00:00.060Z", admin)