Skip to content

Commit 0f28a70

Browse files
author
Chad Nelson
committed
Generate solr conf and .solr_wrapper.yml
Add tests for new generators Rename .solr_wrapper ile to .solr_wrapper.yml
1 parent 21f9baa commit 0f28a70

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

.solr_wrapper .solr_wrapper.yml

File renamed without changes.

lib/generators/blacklight/solr5_generator.rb

+16-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22

33
module Blacklight
44
class Solr5Generator < Rails::Generators::Base
5+
6+
# Set source_root to grab .solr_wrapper and solr config dir
7+
# from the root of the blacklight gem
8+
source_root Blacklight.root
9+
510
desc <<-EOF
611
This generator makes the following changes to your application:
712
1. Installs solr_wrapper into your application
8-
2. Adds rsolr to your Gemfile
13+
2. Copies default blacklight solr config directory into your application
14+
3. Copies default .solr_wrapper into your application
15+
4. Adds rsolr to your Gemfile
916
EOF
1017

1118
def install_solrwrapper
@@ -16,6 +23,14 @@ def install_solrwrapper
1623
append_to_file "Rakefile", "\nrequire 'solr_wrapper/rake_task' unless Rails.env.production?\n"
1724
end
1825

26+
def copy_solr_conf
27+
directory 'solr', 'solr'
28+
end
29+
30+
def solr_wrapper_config
31+
copy_file '.solr_wrapper.yml', '.solr_wrapper.yml'
32+
end
33+
1934
def add_rsolr_gem
2035
gem 'rsolr', '~> 1.0'
2136
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
require 'spec_helper'
2+
require 'generators/blacklight/solr5_generator'
3+
4+
describe Blacklight::Solr5Generator do
5+
let(:destination) { Dir.mktmpdir }
6+
7+
describe "#solr_wrapper_config" do
8+
let(:generator) { described_class.new }
9+
let(:files_to_test) {[
10+
File.join("#{destination}", '.solr_wrapper.yml')
11+
]}
12+
13+
before do
14+
generator.destination_root = destination
15+
generator.solr_wrapper_config
16+
17+
end
18+
19+
after do
20+
files_to_test.each { |file| File.delete(file) if File.exist?(file) }
21+
end
22+
23+
it "creates config files" do
24+
files_to_test.each do |file|
25+
expect(File).to exist(file), "Expected #{file} to exist"
26+
end
27+
end
28+
end
29+
30+
describe "#copy_solr_conf" do
31+
let(:generator) { described_class.new }
32+
let(:dirs_to_test) {[
33+
File.join("#{destination}", 'solr'),
34+
File.join("#{destination}", 'solr/conf')]}
35+
let(:files_to_test) {[
36+
File.join("#{destination}", 'solr/conf/solrconfig.xml')
37+
]}
38+
39+
before do
40+
generator.destination_root = destination
41+
generator.copy_solr_conf
42+
end
43+
44+
after do
45+
dirs_to_test.each { |dir| FileUtils.rm_rf(Dir.glob(dir)) if File.directory?(dir) }
46+
end
47+
48+
it "creates solr directory" do
49+
dirs_to_test.each do |dir|
50+
expect(File).to exist(dir), "Expected #{dir} to exist"
51+
end
52+
end
53+
54+
it "copies solr config files" do
55+
files_to_test.each do |file|
56+
expect(File).to exist(file), "Expected #{file} to exist"
57+
end
58+
end
59+
end
60+
end

0 commit comments

Comments
 (0)