riak-record 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/Gemfile.lock +37 -0
- data/Guardfile +11 -0
- data/README.md +70 -14
- data/TODO.md +8 -0
- data/VERSION +1 -1
- data/lib/riak_record/associations.rb +49 -0
- data/lib/riak_record/base.rb +146 -0
- data/lib/riak_record/finder.rb +125 -0
- data/lib/riak_record.rb +6 -0
- data/riak-record.gemspec +22 -5
- data/spec/riak_record/associations_spec.rb +93 -0
- data/spec/riak_record/base_spec.rb +204 -0
- data/spec/riak_record/finder_spec.rb +163 -0
- data/spec/riak_record_spec.rb +4 -0
- data/spec/spec_helper.rb +9 -3
- metadata +54 -4
- data/lib/riak-record.rb +0 -77
- data/spec/riak-record_spec.rb +0 -102
data/spec/riak-record_spec.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
class ExampleA < RiakRecord
|
4
|
-
bucket_name 'example_a'
|
5
|
-
record_attributes :attribute1, :attribute2
|
6
|
-
end
|
7
|
-
|
8
|
-
class ExampleB < RiakRecord
|
9
|
-
bucket_name 'example_b'
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "RiakRecord" do
|
13
|
-
it "should set the bucket name on each instance of RiakRecord class" do
|
14
|
-
expect(ExampleA.bucket_name).to eq('example_a')
|
15
|
-
expect(ExampleB.bucket_name).to eq('example_b')
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should share a client among all classes" do
|
19
|
-
expect(ExampleA.client).to_not eq(nil)
|
20
|
-
expect(ExampleA.client).to eq(ExampleB.client)
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "new" do
|
24
|
-
context "when passed in an RObject" do
|
25
|
-
let(:robject) { Riak::RObject.new("a-key") }
|
26
|
-
let(:record) { ExampleA.new(robject) }
|
27
|
-
it "should wrap it" do
|
28
|
-
expect(record.riak_object).to eq(robject)
|
29
|
-
expect(record).to be_a(ExampleA)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
context "when passed in a string" do
|
33
|
-
let(:key) { 'judy' }
|
34
|
-
let(:record) { ExampleA.new(key) }
|
35
|
-
it "should create an RObject with that id" do
|
36
|
-
expect(record).to be_a(ExampleA)
|
37
|
-
expect(record.riak_object).to be_a(Riak::RObject)
|
38
|
-
expect(record.riak_object.key).to eq(key)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
context "when passed in nil" do
|
42
|
-
let(:record) { ExampleA.new() }
|
43
|
-
it "should create an RObject with no id" do
|
44
|
-
expect(record).to be_a(ExampleA)
|
45
|
-
expect(record.riak_object).to be_a(Riak::RObject)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "find" do
|
51
|
-
let(:bucket){ double }
|
52
|
-
let(:array){ Array.new }
|
53
|
-
before :each do
|
54
|
-
allow(ExampleA).to receive(:bucket).and_return(bucket)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should take an array and return an array" do
|
58
|
-
expect(bucket).to receive(:get_many).with(array).and_return([])
|
59
|
-
ExampleA.find(array)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should take a string and return nil if not found" do
|
63
|
-
e = Riak::FailedRequest.new("not found")
|
64
|
-
allow(e).to receive(:not_found?).and_return(true)
|
65
|
-
allow(bucket).to receive(:get).with("a-key").and_raise(e)
|
66
|
-
expect( ExampleA.find("a-key") ).to be_nil
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should take a string and return an instance of Example" do
|
70
|
-
allow(bucket).to receive(:get).with("a-key").and_return(Riak::RObject.new("a-key"))
|
71
|
-
expect( ExampleA.find("a-key") ).to be_an_instance_of(ExampleA)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe "record_attributes" do
|
76
|
-
let(:riak_object) { Riak::RObject.new("obj").tap{|r| r.data = data } }
|
77
|
-
let(:data) { {:attribute1 => "1"} }
|
78
|
-
let(:record) { ExampleA.new(riak_object) }
|
79
|
-
it "should read and write each attribute" do
|
80
|
-
expect{
|
81
|
-
record.attribute1=('b')
|
82
|
-
}.to change{record.attribute1}.from("1").to('b')
|
83
|
-
|
84
|
-
expect{
|
85
|
-
record.attribute2 = 'c'
|
86
|
-
}.to change{record.attribute2}.from(nil).to('c')
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should return attribute from riak_object data" do
|
91
|
-
expect( ExampleA.new(riak_object).attribute1 ).to eq("1")
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
describe "namespacing buckets" do
|
97
|
-
it "should prepend namespace to bucket name" do
|
98
|
-
RiakRecord.namespace = "namespace_test"
|
99
|
-
expect(ExampleA.bucket_name).to eq("namespace_test:-:example_a")
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|