Commit 2e3f0b08 authored by Felipe Artur's avatar Felipe Artur

Remove old specs and add new ones

parent 673bc07c
...@@ -6,7 +6,7 @@ module MilestoneActions ...@@ -6,7 +6,7 @@ module MilestoneActions
format.html { redirect_to milestone_redirect_path } format.html { redirect_to milestone_redirect_path }
format.json do format.json do
render json: tabs_json("shared/milestones/_merge_requests_tab", { render json: tabs_json("shared/milestones/_merge_requests_tab", {
merge_requests: @milestone.merge_requests.sort('priority'), merge_requests: @milestone.sorted_merge_requests,
show_project_name: true show_project_name: true
}) })
end end
......
...@@ -62,12 +62,16 @@ module Milestoneish ...@@ -62,12 +62,16 @@ module Milestoneish
due_date && due_date.past? due_date && due_date.past?
end end
def sorted_merge_requests
merge_requests.sort('label_priority')
end
private private
def count_issues_by_state(user) def count_issues_by_state(user)
memoize_per_user(user, :count_issues_by_state) do memoize_per_user(user, :count_issues_by_state) do
# Need to group and count using ruby array to not break # Need to group and count using ruby array to not break
# label ordering # label ordering. Also it saves a SQL query.
issues_visible_to_user(user).to_a.group_by(&:state) issues_visible_to_user(user).to_a.group_by(&:state)
end end
end end
...@@ -81,6 +85,6 @@ module Milestoneish ...@@ -81,6 +85,6 @@ module Milestoneish
# override in a class that includes this module to get a faster query # override in a class that includes this module to get a faster query
# from IssuesFinder # from IssuesFinder
def issues_finder_params def issues_finder_params
{ sort: 'priority' } { sort: 'label_priority' }
end end
end end
...@@ -23,7 +23,7 @@ describe 'Dashboard milestone tabs', :js, :feature do ...@@ -23,7 +23,7 @@ describe 'Dashboard milestone tabs', :js, :feature do
it 'loads merge requests async' do it 'loads merge requests async' do
click_link 'Merge Requests' click_link 'Merge Requests'
expect(page).to have_selector('.merge_requests-sortable-list') expect(page).to have_selector('.milestone-merge_requests-list')
end end
it 'loads participants async' do it 'loads participants async' do
......
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
# expect(issue_target).to have_selector('.issuable-row') # expect(issue_target).to have_selector('.issuable-row')
# end # end
# end # end
>>>>>>> Remove Drag and drop and sorting from milestone view
# context 'merge requests' do # context 'merge requests' do
# let(:merge_request) { page.find_by_id('merge_requests-list-unassigned').find('li') } # let(:merge_request) { page.find_by_id('merge_requests-list-unassigned').find('li') }
...@@ -73,13 +72,8 @@ ...@@ -73,13 +72,8 @@
# end # end
# end # end
<<<<<<< 5f42009f8dcc29d559ee415e92c88858e361f063
def create_and_drag_issue(params = {})
@issue = create(:issue, params.merge(title: 'Foo', project: project, milestone: milestone))
=======
# def create_and_drag_issue(params = {}) # def create_and_drag_issue(params = {})
# create(:issue, params.merge(title: 'Foo', project: project, milestone: milestone)) # create(:issue, params.merge(title: 'Foo', project: project, milestone: milestone))
>>>>>>> Remove Drag and drop and sorting from milestone view
# visit namespace_project_milestone_path(project.namespace, project, milestone) # visit namespace_project_milestone_path(project.namespace, project, milestone)
# scroll_into_view('.milestone-content') # scroll_into_view('.milestone-content')
......
...@@ -19,12 +19,47 @@ describe Milestone, 'Milestoneish' do ...@@ -19,12 +19,47 @@ describe Milestone, 'Milestoneish' do
let!(:closed_security_issue_3) { create(:issue, :confidential, :closed, project: project, author: author, milestone: milestone) } let!(:closed_security_issue_3) { create(:issue, :confidential, :closed, project: project, author: author, milestone: milestone) }
let!(:closed_security_issue_4) { create(:issue, :confidential, :closed, project: project, assignees: [assignee], milestone: milestone) } let!(:closed_security_issue_4) { create(:issue, :confidential, :closed, project: project, assignees: [assignee], milestone: milestone) }
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, milestone: milestone) } let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, milestone: milestone) }
let(:label_1) { create(:label, title: 'label_1', project: project, priority: 1) }
let(:label_2) { create(:label, title: 'label_2', project: project, priority: 2) }
let(:label_3) { create(:label, title: 'label_3', project: project) }
before do before do
project.team << [member, :developer] project.team << [member, :developer]
project.team << [guest, :guest] project.team << [guest, :guest]
end end
describe '#issues_visible_to_user' do
it 'sorts issues by label priority' do
issue.labels << label_1
security_issue_1.labels << label_2
closed_issue_1.labels << label_3
issues = milestone.issues_visible_to_user(member)
expect(issues.first).to eq(issue)
expect(issues.second).to eq(security_issue_1)
expect(issues.third).not_to eq(closed_issue_1)
end
end
describe '#sorted_merge_requests' do
let(:merge_request_1) { create(:merge_request, :simple, source_project: project, source_branch: 'branch_1', milestone: milestone) }
let(:merge_request_2) { create(:merge_request, :simple, source_project: project, source_branch: 'branch_2', milestone: milestone) }
let(:merge_request_3) { create(:merge_request, :simple, source_project: project, source_branch: 'branch_3', milestone: milestone) }
it 'sorts merge requests by label priority' do
merge_request_2.labels << label_1
merge_request_1.labels << label_2
merge_request_3.labels << label_3
merge_requests = milestone.sorted_merge_requests
expect(merge_requests.first).to eq(merge_request_2)
expect(merge_requests.second).to eq(merge_request_1)
expect(merge_requests.third).to eq(merge_request_3)
end
end
describe '#closed_items_count' do describe '#closed_items_count' do
it 'does not count confidential issues for non project members' do it 'does not count confidential issues for non project members' do
expect(milestone.closed_items_count(non_member)).to eq 2 expect(milestone.closed_items_count(non_member)).to eq 2
......
...@@ -3,6 +3,7 @@ require 'spec_helper' ...@@ -3,6 +3,7 @@ require 'spec_helper'
describe GroupMilestone, models: true do describe GroupMilestone, models: true do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:project) { create(:empty_project, group: group) } let(:project) { create(:empty_project, group: group) }
let(:project_2) { create(:empty_project, group: group) }
let(:project_milestone) do let(:project_milestone) do
create(:milestone, title: "Milestone v1.2", project: project) create(:milestone, title: "Milestone v1.2", project: project)
end end
......
...@@ -144,35 +144,6 @@ describe Milestone, models: true do ...@@ -144,35 +144,6 @@ describe Milestone, models: true do
end end
end end
describe '#sort_issues' do
let(:milestone) { create(:milestone) }
let(:issue1) { create(:issue, milestone: milestone, position: 1) }
let(:issue2) { create(:issue, milestone: milestone, position: 2) }
let(:issue3) { create(:issue, milestone: milestone, position: 3) }
let(:issue4) { create(:issue, position: 42) }
it 'sorts the given issues' do
milestone.sort_issues([issue3.id, issue2.id, issue1.id])
issue1.reload
issue2.reload
issue3.reload
expect(issue1.position).to eq(3)
expect(issue2.position).to eq(2)
expect(issue3.position).to eq(1)
end
it 'ignores issues not part of the milestone' do
milestone.sort_issues([issue3.id, issue2.id, issue1.id, issue4.id])
issue4.reload
expect(issue4.position).to eq(42)
end
end
describe '.search' do describe '.search' do
let(:milestone) { create(:milestone, title: 'foo', description: 'bar') } let(:milestone) { create(:milestone, title: 'foo', description: 'bar') }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment