mebla 1.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +6 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +79 -0
- data/LICENSE.txt +20 -0
- data/README.md +250 -0
- data/Rakefile +57 -0
- data/TODO.md +12 -0
- data/VERSION +1 -0
- data/lib/generators/mebla/install/USAGE +7 -0
- data/lib/generators/mebla/install/install_generator.rb +46 -0
- data/lib/generators/mebla/install/templates/mebla.yml +15 -0
- data/lib/mebla/configuration.rb +73 -0
- data/lib/mebla/context.rb +225 -0
- data/lib/mebla/errors/mebla_configuration_exception.rb +10 -0
- data/lib/mebla/errors/mebla_error.rb +14 -0
- data/lib/mebla/errors/mebla_fatal.rb +14 -0
- data/lib/mebla/errors/mebla_index_exception.rb +10 -0
- data/lib/mebla/errors/mebla_synchronization_exception.rb +9 -0
- data/lib/mebla/log_subscriber.rb +77 -0
- data/lib/mebla/mongoid/mebla.rb +258 -0
- data/lib/mebla/railtie.rb +38 -0
- data/lib/mebla/result_set.rb +85 -0
- data/lib/mebla/tasks.rb +42 -0
- data/lib/mebla.rb +137 -0
- data/mebla.gemspec +248 -0
- data/spec/fixtures/models.rb +37 -0
- data/spec/fixtures/mongoid.yml +3 -0
- data/spec/mebla/indexing_spec.rb +63 -0
- data/spec/mebla/searching_spec.rb +73 -0
- data/spec/mebla/synchronization_spec.rb +45 -0
- data/spec/mebla_helper.rb +33 -0
- data/spec/mebla_spec.rb +27 -0
- data/spec/spec_helper.rb +50 -0
- data/spec/support/mongoid.rb +3 -0
- data/spec/support/rails.rb +13 -0
- metadata +696 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Mebla" do
|
4
|
+
describe "searching" do
|
5
|
+
before(:each) do
|
6
|
+
Mebla.context.rebuild_index
|
7
|
+
MongoidAlpha.create! :name => "Testing index", :value => 1, :cost => 2.0
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should search and return the only relevant result" do
|
11
|
+
results=MongoidAlpha.search do
|
12
|
+
query { string "name: Testing index" }
|
13
|
+
end
|
14
|
+
|
15
|
+
results.count.should == 1
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should search and return the only relevant result, and cast it into the correct class type" do
|
19
|
+
results=MongoidAlpha.search do
|
20
|
+
query { string "name: Testing index" }
|
21
|
+
end
|
22
|
+
|
23
|
+
results.first.class.should == MongoidAlpha
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "multiple types" do
|
27
|
+
before(:each) do
|
28
|
+
MongoidBeta.create! :name => "Testing index"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should search and return all results of all class types" do
|
32
|
+
results=Mebla.search do
|
33
|
+
query { string "name: Testing index" }
|
34
|
+
end
|
35
|
+
|
36
|
+
results.count.should == 2
|
37
|
+
(results.each.collect{|e| e.class} & [MongoidAlpha, MongoidBeta]).should =~ [MongoidAlpha, MongoidBeta]
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should search and return only results from the searched class type" do
|
41
|
+
results=MongoidAlpha.search do
|
42
|
+
query { string "name: Testing index" }
|
43
|
+
end
|
44
|
+
|
45
|
+
results.count.should == 1
|
46
|
+
results.first.class.should == MongoidAlpha
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "embedded documents" do
|
51
|
+
before(:each) do
|
52
|
+
beta = MongoidBeta.create! :name => "Embedor parent"
|
53
|
+
beta.mongoid_gammas.create :name => "Embedded", :value => 1
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should search and return the only relevant result" do
|
57
|
+
results=MongoidGamma.search do
|
58
|
+
query { string "name: Embedded" }
|
59
|
+
end
|
60
|
+
|
61
|
+
results.count.should == 1
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should search and return the only relevant result, and cast it into the correct class type" do
|
65
|
+
results=MongoidGamma.search do
|
66
|
+
query { string "name: Embedded" }
|
67
|
+
end
|
68
|
+
|
69
|
+
results.first.class.should == MongoidGamma
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Mebla" do
|
4
|
+
describe "synchronization" do
|
5
|
+
before(:each) do
|
6
|
+
Mebla.context.rebuild_index
|
7
|
+
MongoidAlpha.create! :name => "Testing index", :value => 1, :cost => 2.0
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should index new documents automatically" do
|
11
|
+
mdocument = MongoidAlpha.first
|
12
|
+
lambda {Mebla.context.slingshot_index.retrieve(:mongoid_alpha, mdocument.id.to_s)}.should_not raise_error
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should remove deleted documents from index automatically" do
|
16
|
+
mdocument = MongoidAlpha.first
|
17
|
+
doc_id = mdocument.id.to_s
|
18
|
+
mdocument.destroy
|
19
|
+
|
20
|
+
lambda {MongoidAlpha.slingshot_index.retrieve(:mongoid_alpha, doc_id)}.should raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should update the index automatically when a document is updated" do
|
24
|
+
udocument = MongoidAlpha.first
|
25
|
+
udocument.update_attributes(:cost => 3.1)
|
26
|
+
|
27
|
+
result = Mebla.context.slingshot_index.retrieve(:mongoid_alpha, udocument.id.to_s)
|
28
|
+
result[:cost].should == 3.1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "embedded documents" do
|
33
|
+
before(:each) do
|
34
|
+
beta = MongoidBeta.create! :name => "Embedor parent"
|
35
|
+
beta.mongoid_gammas.create :name => "Embedded", :value => 1
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should index embedded documents automatically and link to the parent" do
|
39
|
+
mdocument = MongoidBeta.first.mongoid_gammas.first
|
40
|
+
lambda {
|
41
|
+
Slingshot::Configuration.client.get "#{Mebla::Configuration.instance.url}/#{Mebla.context.slingshot_index_name}/mongoid_gamma/#{mdocument.id.to_s}?routing=#{mdocument.mongoid_beta.id.to_s}"
|
42
|
+
}.should_not raise_error
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class MeblaHelper
|
2
|
+
attr_accessor :host, :username, :password
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@host = "localhost"
|
6
|
+
@username = ""
|
7
|
+
@password = ""
|
8
|
+
|
9
|
+
Mebla.configure do |config|
|
10
|
+
index = "mebla"
|
11
|
+
host = "localhost"
|
12
|
+
port = 9200
|
13
|
+
end
|
14
|
+
|
15
|
+
if File.exist?("spec/fixtures/mongoid.yml")
|
16
|
+
config = YAML.load(File.open("spec/fixtures/mongoid.yml"))
|
17
|
+
@host = config["host"]
|
18
|
+
@username = config["username"]
|
19
|
+
@password = config["password"]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_mongoid
|
24
|
+
Mongoid.configure do |config|
|
25
|
+
name = "mebla"
|
26
|
+
host = @host
|
27
|
+
username = @username
|
28
|
+
password = @password
|
29
|
+
config.allow_dynamic_fields = false
|
30
|
+
config.master = Mongo::Connection.new.db(name)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/mebla_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Mebla" do
|
4
|
+
describe "loading" do
|
5
|
+
!(defined?(Mongoid).nil?).should == true
|
6
|
+
!(defined?(Slingshot).nil?).should == true
|
7
|
+
!(defined?(Configuration).nil?).should == true
|
8
|
+
!(defined?(Context).nil?).should == true
|
9
|
+
!(defined?(LogSubscriber).nil?).should == true
|
10
|
+
!(defined?(ResultSet).nil?).should == true
|
11
|
+
!(defined?(Errors).nil?).should == true
|
12
|
+
!(defined?(Mongoid::Mebla).nil?).should == true
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "configuration" do
|
16
|
+
it "should hold the correct data" do
|
17
|
+
Mebla::Configuration.instance.index.should == "mebla"
|
18
|
+
Mebla::Configuration.instance.host.should == "localhost"
|
19
|
+
Mebla::Configuration.instance.port.should == 9200
|
20
|
+
Mebla::Configuration.instance.logger.nil?.should == false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "url should return a valid url based on the host and port" do
|
24
|
+
Mebla::Configuration.instance.url.should == "http://localhost:9200"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'mebla'
|
5
|
+
require 'bundler'
|
6
|
+
|
7
|
+
Bundler.require :default, :development
|
8
|
+
|
9
|
+
require "#{File.dirname(__FILE__)}/mebla_helper"
|
10
|
+
require "#{File.dirname(__FILE__)}/../lib/mebla"
|
11
|
+
|
12
|
+
# Requires supporting files with custom matchers and macros, etc,
|
13
|
+
# in ./support/ and its subdirectories.
|
14
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
require 'database_cleaner'
|
18
|
+
|
19
|
+
mebla = MeblaHelper.new
|
20
|
+
mebla.setup_mongoid
|
21
|
+
|
22
|
+
require "#{File.dirname(__FILE__)}/fixtures/models"
|
23
|
+
|
24
|
+
config.before(:all) do
|
25
|
+
%w(tmp tmp/config tmp/log).each do |path|
|
26
|
+
FileUtils.mkdir_p "#{Dir.pwd}/#{path}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
config.after(:all) do
|
31
|
+
FileUtils.rm_r "#{Dir.pwd}/tmp" rescue nil
|
32
|
+
end
|
33
|
+
|
34
|
+
config.before(:suite) do
|
35
|
+
DatabaseCleaner.strategy = :truncation
|
36
|
+
DatabaseCleaner.orm = "mongoid"
|
37
|
+
end
|
38
|
+
|
39
|
+
config.before(:each) do
|
40
|
+
DatabaseCleaner.clean
|
41
|
+
end
|
42
|
+
|
43
|
+
config.before(:suite) do
|
44
|
+
Mebla.context.create_index
|
45
|
+
end
|
46
|
+
|
47
|
+
config.after(:suite) do
|
48
|
+
Mebla.context.drop_index
|
49
|
+
end
|
50
|
+
end
|