Commit 3942c095 authored by Nick Kipling's avatar Nick Kipling

Added check for sort param and spacing in tests

parent e37cb267
......@@ -7,14 +7,22 @@ module Groups
before_action :verify_packages_enabled!
def index
@sort = sort_value
@packages = ::Packages::GroupPackagesFinder.new(current_user, group)
.execute
.sort_by_attribute(@sort = params[:sort] || sort_value_recently_created)
.sort_by_attribute(@sort)
.page(params[:page])
end
private
def sort_value
return params[:sort] if packages_sort_options_hash.key?(params[:sort])
sort_value_recently_created
end
def verify_packages_enabled!
render_404 unless group.packages_feature_available?
end
......
......@@ -79,6 +79,7 @@ describe 'Group Packages' do
it 'sorts by created date descending by default' do
visit group_packages_path(group)
expect(sort_dropdown_button_text).to eq(sort_title_created_date)
expect(first_package).to include(bbb_package.name)
expect(last_package).to include(aaa_package.name)
......@@ -86,6 +87,7 @@ describe 'Group Packages' do
it 'handles an invalid param' do
visit group_packages_path(group, sort: 'garbage') # bad sort param
expect(sort_dropdown_button_text).to eq(sort_title_created_date)
expect(first_package).to include(bbb_package.name)
expect(last_package).to include(aaa_package.name)
......@@ -93,6 +95,7 @@ describe 'Group Packages' do
it 'sorts by created date descending' do
visit group_packages_path(group, sort: sort_value_recently_created)
expect(sort_dropdown_button_text).to eq(sort_title_created_date)
expect(first_package).to include(bbb_package.name)
expect(last_package).to include(aaa_package.name)
......@@ -100,6 +103,7 @@ describe 'Group Packages' do
it 'sorts by created date ascending' do
visit group_packages_path(group, sort: sort_value_oldest_created)
expect(sort_dropdown_button_text).to eq(sort_title_created_date)
expect(first_package).to include(aaa_package.name)
expect(last_package).to include(bbb_package.name)
......@@ -107,6 +111,7 @@ describe 'Group Packages' do
it 'sorts by name descending' do
visit group_packages_path(group, sort: sort_value_name_desc)
expect(sort_dropdown_button_text).to eq(sort_title_name)
expect(first_package).to include(bbb_package.name)
expect(last_package).to include(aaa_package.name)
......@@ -114,6 +119,7 @@ describe 'Group Packages' do
it 'sorts by name ascending' do
visit group_packages_path(group, sort: sort_value_name)
expect(sort_dropdown_button_text).to eq(sort_title_name)
expect(first_package).to include(aaa_package.name)
expect(last_package).to include(bbb_package.name)
......@@ -121,6 +127,7 @@ describe 'Group Packages' do
it 'sorts by version descending' do
visit group_packages_path(group, sort: sort_value_version_desc)
expect(sort_dropdown_button_text).to eq(sort_title_version)
expect(first_package).to include(bbb_package.name)
expect(last_package).to include(aaa_package.name)
......@@ -128,6 +135,7 @@ describe 'Group Packages' do
it 'sorts by version ascending' do
visit group_packages_path(group, sort: sort_value_version_asc)
expect(sort_dropdown_button_text).to eq(sort_title_version)
expect(first_package).to include(aaa_package.name)
expect(last_package).to include(bbb_package.name)
......@@ -135,6 +143,7 @@ describe 'Group Packages' do
it 'sorts by project descending' do
visit group_packages_path(group, sort: sort_value_project_name_desc)
expect(sort_dropdown_button_text).to eq(sort_title_project_name)
expect(first_package).to include(bbb_package.name)
expect(last_package).to include(aaa_package.name)
......@@ -142,6 +151,7 @@ describe 'Group Packages' do
it 'sorts by project ascending' do
visit group_packages_path(group, sort: sort_value_project_name_asc)
expect(sort_dropdown_button_text).to eq(sort_title_project_name)
expect(first_package).to include(aaa_package.name)
expect(last_package).to include(bbb_package.name)
......@@ -154,6 +164,7 @@ describe 'Group Packages' do
it 'sorts by type descending' do
visit group_packages_path(group, sort: sort_value_type_desc)
expect(sort_dropdown_button_text).to eq(sort_title_type)
expect(first_package).to include(npm_package.name)
expect(last_package).to include(maven_package.name)
......@@ -161,6 +172,7 @@ describe 'Group Packages' do
it 'sorts by type ascending' do
visit group_packages_path(group, sort: sort_value_type_asc)
expect(sort_dropdown_button_text).to eq(sort_title_type)
expect(first_package).to include(maven_package.name)
expect(last_package).to include(npm_package.name)
......
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