diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-07-07 23:52:17 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-07-07 23:52:17 +0300 |
commit | 94e2a286846ee8b8b36ac29ccae7d51cb19578d5 (patch) | |
tree | 6c85174841a33bf75e4be48cbe8814b4c3e36b27 /spec | |
parent | ac09bbdc18eed278cf7f1b6d24acc27a879ab00f (diff) | |
parent | 6d28ad844d154eb8f7b9b7b8683b42ce70101789 (diff) |
Merge branch 'feature/user-datetime-search-api-mysql' into 'master'
Add creation time filters to user search API for admins
Closes #29507
See merge request !12682
Diffstat (limited to 'spec')
-rw-r--r-- | spec/finders/users_finder_spec.rb | 11 | ||||
-rw-r--r-- | spec/requests/api/users_spec.rb | 29 |
2 files changed, 40 insertions, 0 deletions
diff --git a/spec/finders/users_finder_spec.rb b/spec/finders/users_finder_spec.rb index 780b309b45e..1bab6d64388 100644 --- a/spec/finders/users_finder_spec.rb +++ b/spec/finders/users_finder_spec.rb @@ -45,6 +45,17 @@ describe UsersFinder do expect(users).to contain_exactly(user, user1, user2, omniauth_user) end + + it 'filters by created_at' do + filtered_user_before = create(:user, created_at: 3.days.ago) + filtered_user_after = create(:user, created_at: Time.now + 3.days) + + users = described_class.new(user, + created_after: 2.days.ago, + created_before: Time.now + 2.days).execute + + expect(users.map(&:username)).not_to include([filtered_user_before.username, filtered_user_after.username]) + end end context 'with an admin user' do diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 70b94a09e6b..c34b88f0741 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -163,6 +163,35 @@ describe API::Users do expect(response).to have_http_status(400) end + + 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) + + expect(response).to have_http_status(200) + expect(json_response.size).to eq(1) + expect(json_response.first['username']).to eq(user.username) + end + + it "returns no users created before a specific date" do + create(:user, created_at: Date.new(2001, 1, 1)) + + get api("/users?created_before=2000-01-02T00:00:00.060Z", admin) + + expect(response).to have_http_status(200) + expect(json_response.size).to eq(0) + end + + it "returns users created before and after a specific date" do + user = create(:user, created_at: Date.new(2001, 1, 1)) + + get api("/users?created_before=2001-01-02T00:00:00.060Z&created_after=1999-01-02T00:00:00.060", admin) + + expect(response).to have_http_status(200) + expect(json_response.size).to eq(1) + expect(json_response.first['username']).to eq(user.username) + end end end |