qa 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/lib/generators/qa/local/tables/mysql/mysql_generator.rb +43 -0
- data/lib/generators/qa/local/tables/tables_generator.rb +12 -0
- data/lib/qa/authorities/local/mysql_table_based_authority.rb +23 -0
- data/lib/qa/authorities/local/table_based_authority.rb +1 -0
- data/lib/qa/authorities/local.rb +1 -0
- data/lib/qa/version.rb +1 -1
- data/spec/lib/authorities/mysql_table_based_authority_spec.rb +55 -0
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: debb1457464aa8c952a8bc130618d1edcf86e7df
|
4
|
+
data.tar.gz: 93d2a32f54288ce095f2efd3ea322fe190c9f453
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f0664726f8224d72fa6b75f53d410c3f760dda40983fb7743c8dcd2e750fba8791042adbd883978b9b90ce12a9b8fafd4e2138f64efafc4632b672b02c93dfa
|
7
|
+
data.tar.gz: f00430c377ba7ad6e886ae5a6a4960d6f306ebb6c6222427350f7899ef3ad702bb1b2a9dcdd88022e1dc857930946afe502eb8b342d3411f692b1b09b8edc783
|
data/README.md
CHANGED
@@ -154,7 +154,7 @@ Make sure you register an account and enable it to see search results.
|
|
154
154
|
Ensure you can run a query like this:
|
155
155
|
|
156
156
|
```
|
157
|
-
http://api.geonames.org/searchJSON?q=port&&maxRows=
|
157
|
+
http://api.geonames.org/searchJSON?q=port&&maxRows=10&username=MY_ACCOUNT_NAME
|
158
158
|
```
|
159
159
|
|
160
160
|
Then you can set your username like this:
|
@@ -238,6 +238,12 @@ Run the generator to install configuration files and an example authority.
|
|
238
238
|
rails generate qa:local:tables
|
239
239
|
rake db:migrate
|
240
240
|
|
241
|
+
|
242
|
+
**Note: If you are using MYSQL as your database use the MSQL database generator instead**
|
243
|
+
|
244
|
+
rails generate qa:local:tables:mysql
|
245
|
+
rake db:migrate
|
246
|
+
|
241
247
|
This will create two tables/models Qa::LocalAuthority and Qa::LocalAuthorityEntry. You can then add terms to each:
|
242
248
|
|
243
249
|
language_auth = Qa::LocalAuthority.find_or_create_by(name: 'language')
|
@@ -253,10 +259,14 @@ Unfortunately, Rails doesn't have a mechnism for adding functional indexes to ta
|
|
253
259
|
CREATE INDEX "index_qa_local_authority_entries_on_lower_label" ON
|
254
260
|
"qa_local_authority_entries" (local_authority_id, lower(label))
|
255
261
|
|
262
|
+
**Note: If you are using MYSQL as your database and used the MSQL database gerator we tried to execute the correct SQL to create the virtual fields and indexes for you**
|
263
|
+
|
256
264
|
Finall you want register your authority in an initializer:
|
257
265
|
|
258
266
|
Qa::Authorities::Local.register_subauthority('languages', 'Qa::Authorities::Local::TableBasedAuthority')
|
259
267
|
|
268
|
+
**Note: If you are using MYSQL as your database and used the MSQL database gerator register the MysqlTableBasedAuthority instead of the TableBasedAuthority**
|
269
|
+
|
260
270
|
Then you can search for
|
261
271
|
|
262
272
|
/qa/search/local/languages?q=Fre
|
@@ -269,7 +279,6 @@ The entire list (up to the first 1000 terms) can also be returned using:
|
|
269
279
|
|
270
280
|
/qa/terms/local/languages/
|
271
281
|
|
272
|
-
|
273
282
|
### Medical Subject Headings (MeSH)
|
274
283
|
|
275
284
|
Provides autocompletion of [MeSH terms](http://www.nlm.nih.gov/mesh/introduction.html). This
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rails/generators/active_record/migration'
|
2
|
+
module Qa::Local
|
3
|
+
module Tables
|
4
|
+
class MysqlGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
include ActiveRecord::Generators::Migration
|
7
|
+
|
8
|
+
def migrations
|
9
|
+
|
10
|
+
unless defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) && ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
|
11
|
+
message = "Use the table based generator if you are not using mysql 'rails generate qa:local:tables'"
|
12
|
+
say_status("error", message, :red)
|
13
|
+
return 0
|
14
|
+
end
|
15
|
+
|
16
|
+
generate "model qa/local_authority name:string:uniq"
|
17
|
+
generate "model qa/local_authority_entry local_authority:references label:string uri:string:uniq lower_label:string"
|
18
|
+
migration_file = Dir.entries(File.join(destination_root,'db/migrate/'))
|
19
|
+
.reject{|name| !name.include?('create_qa_local_authority_entries')}.first
|
20
|
+
migration_file = File.join('db/migrate',migration_file)
|
21
|
+
gsub_file migration_file,
|
22
|
+
't.references :local_authority, index: true, foreign_key: true',
|
23
|
+
't.integer :local_authority_id, index: true'
|
24
|
+
insert_into_file migration_file, after: "add_index :qa_local_authority_entries, :uri, unique: true" do
|
25
|
+
"\n add_foreign_key :qa_local_authority_entries, :qa_local_authorities, column: :local_authority_id\n" \
|
26
|
+
" if ActiveRecord::Base.connection.instance_of? ActiveRecord::ConnectionAdapters::Mysql2Adapter\n" \
|
27
|
+
" remove_column :qa_local_authority_entries, :lower_label, :string\n" \
|
28
|
+
" execute(\"alter table qa_local_authority_entries add lower_label varchar(256) GENERATED ALWAYS AS (lower(label)) VIRTUAL\")\n" \
|
29
|
+
" end\n" \
|
30
|
+
" add_index :qa_local_authority_entries, [:lower_label, :local_authority_id], name: 'index_qa_local_authority_entries_on_lower_label_and_authority'"
|
31
|
+
end
|
32
|
+
|
33
|
+
message = "Rails doesn't support functional indexes in migrations, so we inserted an exec into the migration since you are specifying you are running with mysql.\n" \
|
34
|
+
"The excute will not be run for another database. The commands being run are: "\
|
35
|
+
" ALTER TABLE qa_local_authority_entries ADD lower_label VARCHAR(256) GENERATED ALWAYS AS (lower(label)) VIRTUAL" \
|
36
|
+
" CREATE INDEX index_qa_local_authority_entries_on_lower_label_and_authority ON qa_local_authority_entries (local_authority_id, lower_label)"
|
37
|
+
|
38
|
+
say_status("info", message, :yellow)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -5,8 +5,20 @@ module Qa::Local
|
|
5
5
|
include ActiveRecord::Generators::Migration
|
6
6
|
|
7
7
|
def migrations
|
8
|
+
if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) && ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
|
9
|
+
message = "Use the mysql table based generator if you are using mysql 'rails generate qa:local:tables:mysql'"
|
10
|
+
say_status("error", message, :red)
|
11
|
+
return 0
|
12
|
+
end
|
8
13
|
generate "model qa/local_authority name:string:uniq"
|
9
14
|
generate "model qa/local_authority_entry local_authority:references label:string uri:string:uniq"
|
15
|
+
migration_file = Dir.entries(File.join(destination_root,'db/migrate/'))
|
16
|
+
.reject{|name| !name.include?('create_qa_local_authority_entries')}.first
|
17
|
+
migration_file = File.join('db/migrate',migration_file)
|
18
|
+
gsub_file migration_file,
|
19
|
+
't.references :local_authority, index: true, foreign_key: true',
|
20
|
+
't.references :local_authority, foreign_key: { to_table: :qa_local_authorities }, index: true'
|
21
|
+
|
10
22
|
message = "Rails doesn't support functional indexes in migrations, so you'll have to add this manually:\n" \
|
11
23
|
"CREATE INDEX \"index_qa_local_authority_entries_on_lower_label\" ON \"qa_local_authority_entries\" (local_authority_id, lower(label))\n" \
|
12
24
|
" OR on Sqlite: \n" \
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Qa
|
2
|
+
module Authorities
|
3
|
+
module Local
|
4
|
+
#
|
5
|
+
class MysqlTableBasedAuthority < Local::TableBasedAuthority
|
6
|
+
def self.check_for_index
|
7
|
+
conn = ActiveRecord::Base.connection
|
8
|
+
if conn.table_exists?('qa_local_authority_entries') && conn.index_name_exists?(:qa_local_authority_entries, 'index_qa_local_authority_entries_on_lower_label_and_authority', :default).blank?
|
9
|
+
Rails.logger.error "You've installed mysql local authority tables, but you haven't indexed the lower label. Rails doesn't support functional indexes in migrations, so we tried to execute it for you but something went wrong...\n" \
|
10
|
+
'Make sure your table has a lower_label column which is virtuall created and that column is indexed' \
|
11
|
+
' ALTER TABLE qa_local_authority_entries ADD lower_label VARCHAR(256) GENERATED ALWAYS AS (lower(label)) VIRTUAL' \
|
12
|
+
' CREATE INDEX index_qa_local_authority_entries_on_lower_label_and_authority ON qa_local_authority_entries (local_authority_id, lower_label)'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def search(q)
|
17
|
+
return [] if q.blank?
|
18
|
+
output_set(base_relation.where('lower_label like ?', "#{q.downcase}%").limit(25))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -7,6 +7,7 @@ module Qa::Authorities
|
|
7
7
|
"CREATE INDEX \"index_qa_local_authority_entries_on_lower_label\" ON \"qa_local_authority_entries\" (local_authority_id, lower(label))\n" \
|
8
8
|
" OR on Sqlite: \n" \
|
9
9
|
"CREATE INDEX \"index_qa_local_authority_entries_on_lower_label\" ON \"qa_local_authority_entries\" (local_authority_id, label collate nocase)\n" \
|
10
|
+
" OR for MySQL use the MSQLTableBasedAuthority instead, since mysql does not support functional indexes."
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
data/lib/qa/authorities/local.rb
CHANGED
data/lib/qa/version.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Qa::Authorities::Local::MysqlTableBasedAuthority do
|
4
|
+
let(:language) { Qa::Authorities::Local.subauthority_for("language") }
|
5
|
+
let(:language_auth) { Qa::LocalAuthority.find_by(name: 'language') }
|
6
|
+
let(:base_relation) { Qa::LocalAuthorityEntry.where(name: 'language') }
|
7
|
+
before do
|
8
|
+
Qa::Authorities::Local.register_subauthority('language', described_class.to_s)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#check_for_index" do
|
12
|
+
let(:connection) { ActiveRecord::Base.connection }
|
13
|
+
before do
|
14
|
+
allow(ActiveRecord::Base).to receive(:connection).and_return(connection)
|
15
|
+
end
|
16
|
+
context "with no index" do
|
17
|
+
before do
|
18
|
+
#allow(connection).to receive(:index_name_exists?).and_return(nil)
|
19
|
+
end
|
20
|
+
it "outputs an error message" do
|
21
|
+
expect(Rails.logger).to receive(:error)
|
22
|
+
described_class.check_for_index
|
23
|
+
end
|
24
|
+
end
|
25
|
+
context "with index" do
|
26
|
+
before do
|
27
|
+
allow(connection).to receive(:index_name_exists?).and_return(true)
|
28
|
+
end
|
29
|
+
it "outputs an error message" do
|
30
|
+
expect(Rails.logger).not_to receive(:error)
|
31
|
+
described_class.check_for_index
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#search" do
|
37
|
+
context "with an empty query string" do
|
38
|
+
let(:expected) { [] }
|
39
|
+
it "should return no results" do
|
40
|
+
expect(Qa::LocalAuthorityEntry).not_to receive(:where)
|
41
|
+
expect(language.search("")).to eq(expected)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
context "with at least one matching entry" do
|
45
|
+
it "is case insensitive by using lower_lable column" do
|
46
|
+
expect(Qa::LocalAuthorityEntry).to receive(:where).with(local_authority: language_auth).and_return(base_relation)
|
47
|
+
expect(base_relation).to receive(:where).with("lower_label like ?","fre%").and_return(base_relation)
|
48
|
+
expect(base_relation).to receive(:limit).and_return([])
|
49
|
+
language.search("fRe")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Anderson
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2016-
|
18
|
+
date: 2016-08-08 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rails
|
@@ -23,20 +23,20 @@ dependencies:
|
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.2.0
|
27
27
|
- - "<"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '6.0'
|
30
30
|
type: :runtime
|
31
31
|
prerelease: false
|
32
32
|
version_requirements: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
34
|
- - ">="
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
36
|
+
version: 4.2.0
|
37
37
|
- - "<"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
39
|
+
version: '6.0'
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: faraday
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
@@ -209,6 +209,7 @@ files:
|
|
209
209
|
- lib/generators/qa/install/templates/config/oclcts-authorities.yml
|
210
210
|
- lib/generators/qa/local/USAGE
|
211
211
|
- lib/generators/qa/local/files/files_generator.rb
|
212
|
+
- lib/generators/qa/local/tables/mysql/mysql_generator.rb
|
212
213
|
- lib/generators/qa/local/tables/tables_generator.rb
|
213
214
|
- lib/generators/qa/local/tables/templates/add_index_to_local_authorities.rb
|
214
215
|
- lib/generators/qa/local/templates/config/authorities.yml
|
@@ -230,6 +231,7 @@ files:
|
|
230
231
|
- lib/qa/authorities/loc_subauthority.rb
|
231
232
|
- lib/qa/authorities/local.rb
|
232
233
|
- lib/qa/authorities/local/file_based_authority.rb
|
234
|
+
- lib/qa/authorities/local/mysql_table_based_authority.rb
|
233
235
|
- lib/qa/authorities/local/registry.rb
|
234
236
|
- lib/qa/authorities/local/table_based_authority.rb
|
235
237
|
- lib/qa/authorities/mesh.rb
|
@@ -280,6 +282,7 @@ files:
|
|
280
282
|
- spec/lib/authorities/loc_spec.rb
|
281
283
|
- spec/lib/authorities/local_spec.rb
|
282
284
|
- spec/lib/authorities/mesh_spec.rb
|
285
|
+
- spec/lib/authorities/mysql_table_based_authority_spec.rb
|
283
286
|
- spec/lib/authorities/oclcts_spec.rb
|
284
287
|
- spec/lib/authorities/table_based_authority_spec.rb
|
285
288
|
- spec/lib/authorities/tgnlang_spec.rb
|
@@ -350,6 +353,7 @@ test_files:
|
|
350
353
|
- spec/lib/authorities/loc_spec.rb
|
351
354
|
- spec/lib/authorities/local_spec.rb
|
352
355
|
- spec/lib/authorities/mesh_spec.rb
|
356
|
+
- spec/lib/authorities/mysql_table_based_authority_spec.rb
|
353
357
|
- spec/lib/authorities/oclcts_spec.rb
|
354
358
|
- spec/lib/authorities/table_based_authority_spec.rb
|
355
359
|
- spec/lib/authorities/tgnlang_spec.rb
|
@@ -360,4 +364,3 @@ test_files:
|
|
360
364
|
- spec/routing/route_spec.rb
|
361
365
|
- spec/spec_helper.rb
|
362
366
|
- spec/test_app_templates/lib/generators/test_app_generator.rb
|
363
|
-
has_rdoc:
|