-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CrossRef specific sorts and some specs for both PLOS and CrossRef…
… sorting. Also fixes the repeated sort parameter in URL, by using the queryString module and changing the sort parameter instead of appending it. Closes #59.
- Loading branch information
Showing
9 changed files
with
175 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'spec_helper' | ||
|
||
describe "sorting results", type: :feature, vcr: true do | ||
if Search.plos? | ||
it "sorts PLOS", js: true do | ||
visit "/" | ||
fill_in "everything", with: "cancer" | ||
click_button "Search" | ||
page.should have_select("sort", options: SolrRequest::SORTS.keys) | ||
end | ||
elsif Search.crossref? | ||
it "sorts CrossRef", js: true do | ||
visit "/" | ||
fill_in "everything", with: "cancer" | ||
click_button "Search" | ||
page.should have_select("sort", options: SearchCrossref::SORTS.keys) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/*! | ||
query-string | ||
Parse and stringify URL query strings | ||
https://github.com/sindresorhus/query-string | ||
by Sindre Sorhus | ||
MIT License | ||
*/ | ||
(function () { | ||
'use strict'; | ||
var queryString = {}; | ||
|
||
queryString.parse = function (str) { | ||
if (typeof str !== 'string') { | ||
return {}; | ||
} | ||
|
||
str = str.trim().replace(/^(\?|#)/, ''); | ||
|
||
if (!str) { | ||
return {}; | ||
} | ||
|
||
return str.trim().split('&').reduce(function (ret, param) { | ||
var parts = param.replace(/\+/g, ' ').split('='); | ||
var key = parts[0]; | ||
var val = parts[1]; | ||
|
||
key = decodeURIComponent(key); | ||
// missing `=` should be `null`: | ||
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters | ||
val = val === undefined ? null : decodeURIComponent(val); | ||
|
||
if (!ret.hasOwnProperty(key)) { | ||
ret[key] = val; | ||
} else if (Array.isArray(ret[key])) { | ||
ret[key].push(val); | ||
} else { | ||
ret[key] = [ret[key], val]; | ||
} | ||
|
||
return ret; | ||
}, {}); | ||
}; | ||
|
||
queryString.stringify = function (obj) { | ||
return obj ? Object.keys(obj).map(function (key) { | ||
var val = obj[key]; | ||
|
||
if (Array.isArray(val)) { | ||
return val.map(function (val2) { | ||
return encodeURIComponent(key) + '=' + encodeURIComponent(val2); | ||
}).join('&'); | ||
} | ||
|
||
return encodeURIComponent(key) + '=' + encodeURIComponent(val); | ||
}).join('&') : ''; | ||
}; | ||
|
||
if (typeof define === 'function' && define.amd) { | ||
define(function() { return queryString; }); | ||
} else if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = queryString; | ||
} else { | ||
window.queryString = queryString; | ||
} | ||
})(); |