Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

small fixes

  • Loading branch information...
commit 54569c7a95b3e13c2d3b51ede1454be3a607ae41 1 parent b315a7b
@dimus dimus authored
View
9 app/controllers/name_resolvers_controller.rb
@@ -23,12 +23,21 @@ def create(from_get = false)
token = Base64.urlsafe_encode64(UUID.create_v4.raw_bytes)[0..-3]
status = ProgressStatus.working
message = "Submitted"
+
+ data_sources = []
+ opts[:data_sources].map do |ds_id|
+ ds_title = DataSource.find(ds_id).title.strip rescue nil
+ data_sources << { :id => ds_id, :title => ds_title } if ds_title
+ end
+
result = {
:id => token,
:url => "%s/name_resolvers/%s" % [Gni::Config.base_url, token],
:status => status.id,
:message => message,
+ :data_sources => data_sources,
:parameters => opts}
+
resolver = NameResolver.create!(
:data => new_data,
:result => result,
View
10 app/models/name_resolver.rb
@@ -8,8 +8,6 @@ class NameResolver < ActiveRecord::Base
serialize :options, Hash
serialize :result, Hash
- before_create :add_default_options
-
CONTEXT_THRESHOLD = 0.9
EXACT_STRING = 1
EXACT_CANONICAL = 2
@@ -18,8 +16,8 @@ class NameResolver < ActiveRecord::Base
MAX_DATA_SOURCES = 5
NAME_TYPES = { 1 => "uninomial", 2 => "binomial", 3 => "trinomial" }
MESSAGES = {
- :no_data_source => "No data sources found. Please provide from 1 to %s data source ids" % MAX_DATA_SOURCES,
- :too_many_data_sources => "Too many data sources. Please provide from 1 to %s data source ids" % MAX_DATA_SOURCES,
+ :no_data_source => "No data sources found. Please provide from 1 to %s for data_source_ids parameter" % MAX_DATA_SOURCES,
+ :too_many_data_sources => "Too many data sources. Please provide from 1 to %s for data_source_ids parameter" % MAX_DATA_SOURCES,
:no_names => "No name strings found. Please provide from 1 to %s name strings" % MAX_NAME_STRING,
:too_many_names => "Too many name strings. Please provide from 1 to %s name strings" % MAX_NAME_STRING,
:success => "OK",
@@ -394,10 +392,6 @@ def get_score(result)
result[:possible_cresonym] = auth_score < 0 && result[:score] > 0.9 ? true : false
end
- def add_default_options
- self.options = {:with_context => false, :data_sources => []}.merge(self.options)
- end
-
def format_result
r = result
if @with_context
View
12 spec/resources/name_resolver_spec.rb
@@ -6,7 +6,7 @@
it "should be able to use GET for resolving names" do
get("/name_resolvers.json",
:names => "Leiothrix argentauris (Hodgson, 1838)|Treron|Larus occidentalis wymani|Plantago major L.",
- :data_source_ids => "1|2")
+ :data_source_ids => "1|3")
body = last_response.body
res = JSON.parse(body, :symbolize_names => true)
res[:data].first[:results].first[:taxon_id].should == "6868221"
@@ -15,7 +15,7 @@
it "should not contain id field if user did not supply id" do
get("/name_resolvers.json",
:names => "Leiothrix argentauris (Hodgson, 1838)|Treron|Larus occidentalis wymani|Plantago major L.",
- :data_source_ids => "1|2")
+ :data_source_ids => "1|3")
body = last_response.body
res = JSON.parse(body, :symbolize_names => true)
res[:data].select { |r| r.has_key?(:id) }.size.should == 0
@@ -24,7 +24,7 @@
it "github #6: should be able to use GET for only uninomials" do
get("/name_resolvers.json",
:names => "Rhizoclonium",
- :data_source_ids => "1|2")
+ :data_source_ids => "1|3")
body = last_response.body
res = JSON.parse(body, :symbolize_names => true)
res.size.should > 0
@@ -33,7 +33,7 @@
it "should parse options correctly" do
get("/name_resolvers.json",
:names => "Leiothrix argentauris (Hodgson, 1838)|Treron|Larus occidentalis wymani|Plantago major L.",
- :data_source_ids => "1|2",
+ :data_source_ids => "1|3",
:with_context => false)
body = last_response.body
res = JSON.parse(body, :symbolize_names => true)
@@ -43,7 +43,7 @@
it "should be able to use POST for resolving names" do
post("/name_resolvers.json",
:data => "1|Leiothrix argentauris (Hodgson, 1838)\n2|Treron\n3|Larus occidentalis wymani\n4|Plantago major L.",
- :data_source_ids => "1|2")
+ :data_source_ids => "1|3")
body = last_response.body
res = JSON.parse(body, :symbolize_names => true)
res[:data].first[:results].first[:taxon_id].should == "6868221"
@@ -83,7 +83,7 @@
it "should produce an error if there are no names" do
get("/name_resolvers.json",
:names => "",
- :data_source_ids => "1|2",
+ :data_source_ids => "1|3",
:with_context => false)
body = last_response.body
res = JSON.parse(body, :symbolize_names => true)
Please sign in to comment.
Something went wrong with that request. Please try again.