From f9e6f668981f6f57d41c34d68a84879a48593269 Mon Sep 17 00:00:00 2001
From: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Date: Thu, 5 Feb 2015 22:40:35 -0800
Subject: [PATCH] Fix tests

---
 spec/features/admin/admin_users_spec.rb  |  6 +++---
 spec/features/issues_spec.rb             | 18 +++++++++--------
 spec/requests/api/merge_requests_spec.rb | 25 +++++++++++++-----------
 3 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/spec/features/admin/admin_users_spec.rb b/spec/features/admin/admin_users_spec.rb
index 82da19746f861..59c4ffb562487 100644
--- a/spec/features/admin/admin_users_spec.rb
+++ b/spec/features/admin/admin_users_spec.rb
@@ -32,14 +32,14 @@
 
     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 @@
 
     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 e6fa376f3eb98..29aeb6a400abd 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 @@
                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 @@
     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 @@
     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 @@
     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 @@
       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 @@
       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/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index 0870a298eff86..b5deb072cd128 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -26,7 +26,7 @@
         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
@@ -34,7 +34,7 @@
         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
@@ -42,7 +42,7 @@
         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
@@ -50,8 +50,8 @@
         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
@@ -73,9 +73,10 @@
           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
@@ -84,21 +85,23 @@
           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
-- 
GitLab