solr_wrapper 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5611bbe18707e3c1151ebc12b5534beddaaf2bbf
4
- data.tar.gz: 4ff113c6e11117820fcfce18c8314c2a1c9d5714
3
+ metadata.gz: 8e4d41ab3bd1b628c5f948717dcf7f48d76d1106
4
+ data.tar.gz: 204dcf436957092b4f9e787f60ebcd3af028b390
5
5
  SHA512:
6
- metadata.gz: 57e9df554289cddd628c8b3a87926119821fd7ca66c41ab4444208b409df33663142b4d787df79bf7116b8280458e77e5fe5e4e7fd28615d98ad0914df6730e9
7
- data.tar.gz: c9d28c85027dc87f57b584190e4a2257cb2af14df5cf5cd3825e10a9eed98955f8509e565238b42dc02c99de01092e276736bf628c76ee176d42a0769a7ee91e
6
+ metadata.gz: d234f9ac3315f4a09edd69c759c174305e81ac55ff50165cffcb4a62d2a275fde28acb1c36dd500da796f24120e6ecc668ef70f130a0b9b2a003974e96673893
7
+ data.tar.gz: 2df041374409128b007c738f2824806bd249a3fce6a10c6400bd2da2273fbe2bb75dd63dc7848c977b57cc2b0e7c54e3b4117c485f7b519b71b99926817d389d
@@ -35,7 +35,7 @@ module SolrWrapper
35
35
  # Check if the port option has been explicitly set to nil.
36
36
  # this means to start solr wrapper on a random open port
37
37
  return nil if options.key?(:port) && !options[:port]
38
- options[:port] || SolrWrapper.default_instance_options[:port]
38
+ options.fetch(:port) { SolrWrapper.default_instance_options[:port] }.to_s
39
39
  end
40
40
 
41
41
  def download_path
@@ -78,8 +78,17 @@ module SolrWrapper
78
78
  options[:version_file]
79
79
  end
80
80
 
81
+ def collection_options
82
+ hash = options.fetch(:collection, {})
83
+ Configuration.slice(convert_keys(hash), :name, :dir)
84
+ end
85
+
81
86
  private
82
87
 
88
+ def self.slice(source, *keys)
89
+ keys.each_with_object({}) { |k, hash| hash[k] = source[k] if source.has_key?(k) }
90
+ end
91
+
83
92
  def read_config(config_file, verbose)
84
93
  default_configuration_paths.each do |p|
85
94
  path = File.expand_path(p)
@@ -97,7 +106,11 @@ module SolrWrapper
97
106
  $stderr.puts "Unable to parse config #{config_file}" if verbose
98
107
  return {}
99
108
  end
100
- config.each_with_object({}) { |(k, v), h| h[k.to_sym] = v.to_s }
109
+ convert_keys(config)
110
+ end
111
+
112
+ def convert_keys(hash)
113
+ hash.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
101
114
  end
102
115
 
103
116
  def default_configuration_paths
@@ -146,6 +146,7 @@ module SolrWrapper
146
146
  # @option options [String] :name
147
147
  # @option options [String] :dir
148
148
  def with_collection(options = {})
149
+ options = config.collection_options.merge(options)
149
150
  return yield if options.empty?
150
151
 
151
152
  name = create(options)
@@ -1,3 +1,3 @@
1
1
  module SolrWrapper
2
- VERSION = '0.7.2'
2
+ VERSION = '0.7.3'
3
3
  end
@@ -1 +1,4 @@
1
1
  port: 9999
2
+ collection:
3
+ dir: solr/config/
4
+ name: project-development
@@ -30,6 +30,15 @@ describe SolrWrapper::Configuration do
30
30
  it "uses values from the config file" do
31
31
  expect(config.port).to eq '9999'
32
32
  end
33
+ end
33
34
 
35
+ describe "#collection_options" do
36
+ before do
37
+ allow(config).to receive(:default_configuration_paths).and_return([])
38
+ end
39
+ let(:options) { { config: 'spec/fixtures/sample_config.yml' } }
40
+ it "uses values from the config file" do
41
+ expect(config.collection_options).to eq(name: 'project-development', dir: 'solr/config/')
42
+ end
34
43
  end
35
44
  end
@@ -6,17 +6,32 @@ describe SolrWrapper::Instance do
6
6
  let(:client) { SimpleSolrClient::Client.new(subject.url) }
7
7
 
8
8
  describe "#with_collection" do
9
- it "creates a new anonymous collection" do
10
- subject.wrap do |solr|
11
- solr.with_collection(dir: File.join(FIXTURES_DIR, "basic_configs")) do |collection_name|
12
- core = client.core(collection_name)
13
- unless defined? JRUBY_VERSION
14
- expect(core.schema.field('id').name).to eq 'id'
15
- expect(core.schema.field('id').stored).to eq true
9
+ context "without a name" do
10
+ it "creates a new anonymous collection" do
11
+ subject.wrap do |solr|
12
+ solr.with_collection(dir: File.join(FIXTURES_DIR, "basic_configs")) do |collection_name|
13
+ core = client.core(collection_name)
14
+ unless defined? JRUBY_VERSION
15
+ expect(core.schema.field('id').name).to eq 'id'
16
+ expect(core.schema.field('id').stored).to eq true
17
+ end
16
18
  end
17
19
  end
18
20
  end
19
21
  end
22
+ context "with a config file" do
23
+ before do
24
+ allow(solr_instance.config).to receive(:collection_options)
25
+ .and_return(name: 'project-development', dir: 'solr/config/')
26
+ allow(solr_instance).to receive(:delete)
27
+ end
28
+
29
+ it "creates a new collection with options from the config" do
30
+ expect(solr_instance).to receive(:create).with(
31
+ hash_including(name: "project-development", dir: anything))
32
+ solr_instance.with_collection(dir: File.join(FIXTURES_DIR, "basic_configs")) {}
33
+ end
34
+ end
20
35
  end
21
36
 
22
37
  describe 'exec' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solr_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-18 00:00:00.000000000 Z
11
+ date: 2016-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip