Commit c35ca653 authored by Jarka Košanová's avatar Jarka Košanová Committed by Jose Vargas

Add spec for helper and simplify Issuable method

parent eef6b238
......@@ -145,20 +145,16 @@ module Issuable
def sort_by_attribute(method, excluded_labels: [])
sorted =
case method.to_s
when 'downvotes_desc' then order_downvotes_desc
when 'label_priority' then order_labels_priority(excluded_labels: excluded_labels)
when 'label_priority_asc' then order_labels_priority(excluded_labels: excluded_labels)
when 'label_priority_desc' then order_labels_priority('DESC', excluded_labels: excluded_labels)
when 'milestone' then order_milestone_due_asc
when 'milestone_due_asc' then order_milestone_due_asc
when 'milestone_due_desc' then order_milestone_due_desc
when 'popularity' then order_upvotes_desc
when 'popularity_desc' then order_upvotes_desc
when 'popularity_asc' then order_upvotes_asc
when 'priority' then order_due_date_and_labels_priority(excluded_labels: excluded_labels)
when 'priority_asc' then order_due_date_and_labels_priority(excluded_labels: excluded_labels)
when 'priority_desc' then order_due_date_and_labels_priority('DESC', excluded_labels: excluded_labels)
when 'upvotes_desc' then order_upvotes_desc
when 'downvotes_desc' then order_downvotes_desc
when 'label_priority', 'label_priority_asc' then order_labels_priority(excluded_labels: excluded_labels)
when 'label_priority_desc' then order_labels_priority('DESC', excluded_labels: excluded_labels)
when 'milestone', 'milestone_due_asc' then order_milestone_due_asc
when 'milestone_due_desc' then order_milestone_due_desc
when 'popularity', 'popularity_desc' then order_upvotes_desc
when 'popularity_asc' then order_upvotes_asc
when 'priority', 'priority_asc' then order_due_date_and_labels_priority(excluded_labels: excluded_labels)
when 'priority_desc' then order_due_date_and_labels_priority('DESC', excluded_labels: excluded_labels)
when 'upvotes_desc' then order_upvotes_desc
else order_by(method)
end
......
require 'spec_helper'
describe SortingHelper do
include ApplicationHelper
include IconsHelper
describe '#issuable_sort_option_title' do
it 'returns correct title for issuable_sort_option_overrides key' do
expect(issuable_sort_option_title('created_asc')).to eq('Created date')
end
it 'returns correct title for a valid sort value' do
expect(issuable_sort_option_title('priority')).to eq('Priority')
end
it 'returns nil for invalid sort value' do
expect(issuable_sort_option_title('invalid_key')).to eq(nil)
end
end
describe '#issuable_sort_direction_button' do
before do
allow(self).to receive(:request).and_return(double(path: 'http://test.com'))
end
it 'returns icon with sort-highest when sort is created_date' do
expect(issuable_sort_direction_button('created_date')).to include('sort-highest')
end
it 'returns icon with sort-lowest when sort is asc' do
expect(issuable_sort_direction_button('created_asc')).to include('sort-lowest')
end
it 'returns icon with sort-lowest when sorting by milestone' do
expect(issuable_sort_direction_button('milestone')).to include('sort-lowest')
end
it 'returns icon with sort-lowest when sorting by due_date' do
expect(issuable_sort_direction_button('due_date')).to include('sort-lowest')
end
end
end
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