Skip to content

Commit 4488ea5

Browse files
committed
[STORE] Added the Persistence::Repository module and client integration
1 parent 6e199e4 commit 4488ea5

File tree

7 files changed

+102
-2
lines changed

7 files changed

+102
-2
lines changed

elasticsearch-persistence/elasticsearch-persistence.gemspec

+4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ Gem::Specification.new do |s|
2121
s.extra_rdoc_files = [ "README.md", "LICENSE.txt" ]
2222
s.rdoc_options = [ "--charset=UTF-8" ]
2323

24+
s.add_dependency "elasticsearch", '> 0.4'
25+
2426
s.add_development_dependency "bundler", "~> 1.5"
2527
s.add_development_dependency "rake"
2628

29+
s.add_development_dependency "elasticsearch-extensions"
30+
2731
s.add_development_dependency "shoulda-context"
2832
s.add_development_dependency "mocha"
2933
s.add_development_dependency "turn"
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1-
require "elasticsearch/persistence/version"
1+
require 'elasticsearch'
2+
3+
require 'elasticsearch/persistence/version'
4+
5+
require 'elasticsearch/persistence/client'
6+
require 'elasticsearch/persistence/repository'
27

38
module Elasticsearch
49
module Persistence
5-
# Your code goes here...
10+
11+
# :nodoc:
12+
module ClassMethods
13+
def client
14+
@client ||= Elasticsearch::Client.new
15+
end
16+
17+
def client=(client)
18+
@client = client
19+
end
20+
end
21+
22+
extend ClassMethods
623
end
724
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Elasticsearch
2+
module Persistence
3+
4+
module Client
5+
def client client=nil
6+
@client ||= Elasticsearch::Persistence.client
7+
end
8+
9+
def client=(client)
10+
@client = client
11+
end
12+
end
13+
14+
end
15+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Elasticsearch
2+
module Persistence
3+
4+
module Repository
5+
include Elasticsearch::Persistence::Client
6+
end
7+
end
8+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'test_helper'
2+
3+
class Elasticsearch::Persistence::ModuleTest < Test::Unit::TestCase
4+
context "The Persistence module" do
5+
6+
context "client" do
7+
should "have a default client" do
8+
client = Elasticsearch::Persistence.client
9+
assert_not_nil client
10+
assert_instance_of Elasticsearch::Transport::Client, client
11+
end
12+
13+
should "allow to set a client" do
14+
begin
15+
Elasticsearch::Persistence.client = "Foobar"
16+
assert_equal "Foobar", Elasticsearch::Persistence.client
17+
ensure
18+
Elasticsearch::Persistence.client = nil
19+
end
20+
end
21+
end
22+
end
23+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'test_helper'
2+
3+
class Elasticsearch::Persistence::RepositoryClientTest < Test::Unit::TestCase
4+
context "A repository client" do
5+
class DummyReposistory
6+
include Elasticsearch::Persistence::Repository
7+
end
8+
9+
setup do
10+
@shoulda_subject = DummyReposistory.new
11+
end
12+
13+
should "have a default client" do
14+
assert_not_nil subject.client
15+
assert_instance_of Elasticsearch::Transport::Client, subject.client
16+
end
17+
18+
should "allow to set a client" do
19+
begin
20+
subject.client = "Foobar"
21+
assert_equal "Foobar", subject.client
22+
ensure
23+
subject.client = nil
24+
end
25+
end
26+
end
27+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'test_helper'
2+
3+
class Elasticsearch::Persistence::RepositoryModuleTest < Test::Unit::TestCase
4+
context "The repository module" do
5+
end
6+
end

0 commit comments

Comments
 (0)