Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dzaporozhets@gitlab.com>2015-02-06 21:08:44 +0300
committerDmitriy Zaporozhets <dzaporozhets@gitlab.com>2015-02-06 21:08:44 +0300
commitdd8dd92e501b7e980e913e7fa3a3efa5824d21fe (patch)
tree9494c3abe46aff03ad657f7f32ca147845d25232 /spec
parent6b61c9049815cdcc2b22a572441adba0e3dc230d (diff)
parentce0811ae5cf2c69ccf24e101b1ec1554a42e9856 (diff)
Merge branch 'api-default-order' into 'master'
Sorting refactoring * refactor sorting logic for web UI * refactor and document ordering for API: project, issues, merge requests * explicitly define ordering in models using default_scope See merge request !1476
Diffstat (limited to 'spec')
-rw-r--r--spec/features/admin/admin_users_spec.rb6
-rw-r--r--spec/features/issues_spec.rb18
-rw-r--r--spec/models/user_spec.rb6
-rw-r--r--spec/requests/api/merge_requests_spec.rb29
4 files changed, 34 insertions, 25 deletions
diff --git a/spec/features/admin/admin_users_spec.rb b/spec/features/admin/admin_users_spec.rb
index 82da19746f8..59c4ffb5624 100644
--- a/spec/features/admin/admin_users_spec.rb
+++ b/spec/features/admin/admin_users_spec.rb
@@ -32,14 +32,14 @@ describe "Admin::Users", feature: true do
it "should apply defaults to user" do
click_button "Create user"
- user = User.last
+ user = User.find_by(username: 'bang')
user.projects_limit.should == Gitlab.config.gitlab.default_projects_limit
user.can_create_group.should == Gitlab.config.gitlab.default_can_create_group
end
it "should create user with valid data" do
click_button "Create user"
- user = User.last
+ user = User.find_by(username: 'bang')
user.name.should == "Big Bang"
user.email.should == "bigbang@mail.com"
end
@@ -52,7 +52,7 @@ describe "Admin::Users", feature: true do
it "should send valid email to user with email & password" do
click_button "Create user"
- user = User.last
+ user = User.find_by(username: 'bang')
email = ActionMailer::Base.deliveries.last
email.subject.should have_content("Account was created")
email.text_part.body.should have_content(user.email)
diff --git a/spec/features/issues_spec.rb b/spec/features/issues_spec.rb
index e6fa376f3eb..29aeb6a400a 100644
--- a/spec/features/issues_spec.rb
+++ b/spec/features/issues_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe "Issues", feature: true do
+ include SortingHelper
+
let(:project) { create(:project) }
before do
@@ -80,7 +82,7 @@ describe "Issues", feature: true do
title: title)
end
- @issue = Issue.first # with title 'foobar'
+ @issue = Issue.find_by(title: 'foobar')
@issue.milestone = create(:milestone, project: project)
@issue.assignee = nil
@issue.save
@@ -130,14 +132,14 @@ describe "Issues", feature: true do
let(:later_due_milestone) { create(:milestone, due_date: '2013-12-12') }
it 'sorts by newest' do
- visit project_issues_path(project, sort: 'newest')
+ visit project_issues_path(project, sort: sort_value_recently_created)
first_issue.should include("foo")
last_issue.should include("baz")
end
it 'sorts by oldest' do
- visit project_issues_path(project, sort: 'oldest')
+ visit project_issues_path(project, sort: sort_value_oldest_created)
first_issue.should include("baz")
last_issue.should include("foo")
@@ -146,7 +148,7 @@ describe "Issues", feature: true do
it 'sorts by most recently updated' do
baz.updated_at = Time.now + 100
baz.save
- visit project_issues_path(project, sort: 'recently_updated')
+ visit project_issues_path(project, sort: sort_value_recently_updated)
first_issue.should include("baz")
end
@@ -154,7 +156,7 @@ describe "Issues", feature: true do
it 'sorts by least recently updated' do
baz.updated_at = Time.now - 100
baz.save
- visit project_issues_path(project, sort: 'last_updated')
+ visit project_issues_path(project, sort: sort_value_oldest_updated)
first_issue.should include("baz")
end
@@ -168,13 +170,13 @@ describe "Issues", feature: true do
end
it 'sorts by recently due milestone' do
- visit project_issues_path(project, sort: 'milestone_due_soon')
+ visit project_issues_path(project, sort: sort_value_milestone_soon)
first_issue.should include("foo")
end
it 'sorts by least recently due milestone' do
- visit project_issues_path(project, sort: 'milestone_due_later')
+ visit project_issues_path(project, sort: sort_value_milestone_later)
first_issue.should include("bar")
end
@@ -191,7 +193,7 @@ describe "Issues", feature: true do
end
it 'sorts with a filter applied' do
- visit project_issues_path(project, sort: 'oldest', assignee_id: user2.id)
+ visit project_issues_path(project, sort: sort_value_oldest_created, assignee_id: user2.id)
first_issue.should include("bar")
last_issue.should include("foo")
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 83341e516a5..629d51b960d 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -474,7 +474,7 @@ describe User do
@user = create :user, created_at: Date.today, last_sign_in_at: Date.today, name: 'Alpha'
@user1 = create :user, created_at: Date.today - 1, last_sign_in_at: Date.today - 1, name: 'Omega'
end
-
+
it "sorts users as recently_signed_in" do
User.sort('recent_sign_in').first.should == @user
end
@@ -484,11 +484,11 @@ describe User do
end
it "sorts users as recently_created" do
- User.sort('recently_created').first.should == @user
+ User.sort('created_desc').first.should == @user
end
it "sorts users as late_created" do
- User.sort('late_created').first.should == @user1
+ User.sort('created_asc').first.should == @user1
end
it "sorts users by name when nil is passed" do
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index 5795082f5cb..b5deb072cd1 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -26,30 +26,34 @@ describe API::API, api: true do
response.status.should == 200
json_response.should be_an Array
json_response.length.should == 3
- json_response.first['title'].should == merge_request.title
+ json_response.last['title'].should == merge_request.title
end
+
it "should return an array of all merge_requests" do
get api("/projects/#{project.id}/merge_requests?state", user)
response.status.should == 200
json_response.should be_an Array
json_response.length.should == 3
- json_response.first['title'].should == merge_request.title
+ json_response.last['title'].should == merge_request.title
end
+
it "should return an array of open merge_requests" do
get api("/projects/#{project.id}/merge_requests?state=opened", user)
response.status.should == 200
json_response.should be_an Array
json_response.length.should == 1
- json_response.first['title'].should == merge_request.title
+ json_response.last['title'].should == merge_request.title
end
+
it "should return an array of closed merge_requests" do
get api("/projects/#{project.id}/merge_requests?state=closed", user)
response.status.should == 200
json_response.should be_an Array
json_response.length.should == 2
- json_response.first['title'].should == merge_request_closed.title
- json_response.second['title'].should == merge_request_merged.title
+ json_response.second['title'].should == merge_request_closed.title
+ json_response.first['title'].should == merge_request_merged.title
end
+
it "should return an array of merged merge_requests" do
get api("/projects/#{project.id}/merge_requests?state=merged", user)
response.status.should == 200
@@ -69,9 +73,10 @@ describe API::API, api: true do
response.status.should == 200
json_response.should be_an Array
json_response.length.should == 3
- json_response.first['id'].should == @mr_earlier.id
- json_response.last['id'].should == @mr_later.id
+ json_response.last['id'].should == @mr_earlier.id
+ json_response.first['id'].should == @mr_later.id
end
+
it "should return an array of merge_requests in descending order" do
get api("/projects/#{project.id}/merge_requests?sort=desc", user)
response.status.should == 200
@@ -80,21 +85,23 @@ describe API::API, api: true do
json_response.first['id'].should == @mr_later.id
json_response.last['id'].should == @mr_earlier.id
end
+
it "should return an array of merge_requests ordered by updated_at" do
get api("/projects/#{project.id}/merge_requests?order_by=updated_at", user)
response.status.should == 200
json_response.should be_an Array
json_response.length.should == 3
- json_response.first['id'].should == @mr_earlier.id
- json_response.last['id'].should == @mr_later.id
+ json_response.last['id'].should == @mr_earlier.id
+ json_response.first['id'].should == @mr_later.id
end
+
it "should return an array of merge_requests ordered by created_at" do
get api("/projects/#{project.id}/merge_requests?sort=created_at", user)
response.status.should == 200
json_response.should be_an Array
json_response.length.should == 3
- json_response.first['id'].should == @mr_earlier.id
- json_response.last['id'].should == @mr_later.id
+ json_response.last['id'].should == @mr_earlier.id
+ json_response.first['id'].should == @mr_later.id
end
end
end