boombera 0.2.3 → 0.3.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.
- data/Gemfile +1 -0
- data/Gemfile.lock +15 -0
- data/VERSION +1 -1
- data/boombera.gemspec +4 -2
- data/lib/boombera.rb +5 -8
- data/lib/boombera/content_item.rb +36 -41
- data/lib/boombera/information.rb +6 -6
- data/spec/integration/boombera_spec.rb +17 -28
- data/spec/lib/boombera/content_item_spec.rb +79 -18
- data/spec/lib/boombera_spec.rb +14 -16
- metadata +13 -3
- data/spec/lib/boombera/content_item_map_resolver_spec.rb +0 -66
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,11 +2,13 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
ZenTest (4.5.0)
|
5
|
+
archive-tar-minitar (0.5.2)
|
5
6
|
autotest (4.4.6)
|
6
7
|
ZenTest (>= 4.4.1)
|
7
8
|
autotest-fsevent (0.2.5)
|
8
9
|
sys-uname
|
9
10
|
autotest-growl (0.2.9)
|
11
|
+
columnize (0.3.2)
|
10
12
|
couchrest (1.0.2)
|
11
13
|
json (~> 1.5.1)
|
12
14
|
mime-types (~> 1.15)
|
@@ -18,6 +20,8 @@ GEM
|
|
18
20
|
git (>= 1.2.5)
|
19
21
|
rake
|
20
22
|
json (1.5.1)
|
23
|
+
linecache19 (0.5.12)
|
24
|
+
ruby_core_source (>= 0.1.4)
|
21
25
|
mime-types (1.16)
|
22
26
|
rake (0.9.0)
|
23
27
|
rcov (0.9.9)
|
@@ -36,9 +40,19 @@ GEM
|
|
36
40
|
rspec-expectations (2.6.0)
|
37
41
|
diff-lcs (~> 1.1.2)
|
38
42
|
rspec-mocks (2.6.0)
|
43
|
+
ruby-debug-base19 (0.11.25)
|
44
|
+
columnize (>= 0.3.1)
|
45
|
+
linecache19 (>= 0.5.11)
|
46
|
+
ruby_core_source (>= 0.1.4)
|
47
|
+
ruby-debug19 (0.11.6)
|
48
|
+
columnize (>= 0.3.1)
|
49
|
+
linecache19 (>= 0.5.11)
|
50
|
+
ruby-debug-base19 (>= 0.11.19)
|
39
51
|
ruby2ruby (1.2.5)
|
40
52
|
ruby_parser (~> 2.0)
|
41
53
|
sexp_processor (~> 3.0)
|
54
|
+
ruby_core_source (0.1.5)
|
55
|
+
archive-tar-minitar (>= 0.5.2)
|
42
56
|
ruby_parser (2.0.6)
|
43
57
|
sexp_processor (~> 3.0)
|
44
58
|
sexp_processor (3.0.5)
|
@@ -58,3 +72,4 @@ DEPENDENCIES
|
|
58
72
|
rdoc (~> 3.6.1)
|
59
73
|
reek (~> 1.2.8)
|
60
74
|
rspec (~> 2.6.0)
|
75
|
+
ruby-debug19 (~> 0.11.6)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/boombera.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{boombera}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["John Wilger"]
|
@@ -32,7 +32,6 @@ Gem::Specification.new do |s|
|
|
32
32
|
"lib/boombera/content_item.rb",
|
33
33
|
"lib/boombera/information.rb",
|
34
34
|
"spec/integration/boombera_spec.rb",
|
35
|
-
"spec/lib/boombera/content_item_map_resolver_spec.rb",
|
36
35
|
"spec/lib/boombera/content_item_spec.rb",
|
37
36
|
"spec/lib/boombera_spec.rb",
|
38
37
|
"spec/spec_helper.rb"
|
@@ -57,6 +56,7 @@ Gem::Specification.new do |s|
|
|
57
56
|
s.add_development_dependency(%q<autotest>, ["~> 4.4.6"])
|
58
57
|
s.add_development_dependency(%q<autotest-growl>, ["~> 0.2.9"])
|
59
58
|
s.add_development_dependency(%q<autotest-fsevent>, ["~> 0.2.5"])
|
59
|
+
s.add_development_dependency(%q<ruby-debug19>, ["~> 0.11.6"])
|
60
60
|
else
|
61
61
|
s.add_dependency(%q<couchrest>, ["~> 1.0.2"])
|
62
62
|
s.add_dependency(%q<rspec>, ["~> 2.6.0"])
|
@@ -68,6 +68,7 @@ Gem::Specification.new do |s|
|
|
68
68
|
s.add_dependency(%q<autotest>, ["~> 4.4.6"])
|
69
69
|
s.add_dependency(%q<autotest-growl>, ["~> 0.2.9"])
|
70
70
|
s.add_dependency(%q<autotest-fsevent>, ["~> 0.2.5"])
|
71
|
+
s.add_dependency(%q<ruby-debug19>, ["~> 0.11.6"])
|
71
72
|
end
|
72
73
|
else
|
73
74
|
s.add_dependency(%q<couchrest>, ["~> 1.0.2"])
|
@@ -80,6 +81,7 @@ Gem::Specification.new do |s|
|
|
80
81
|
s.add_dependency(%q<autotest>, ["~> 4.4.6"])
|
81
82
|
s.add_dependency(%q<autotest-growl>, ["~> 0.2.9"])
|
82
83
|
s.add_dependency(%q<autotest-fsevent>, ["~> 0.2.5"])
|
84
|
+
s.add_dependency(%q<ruby-debug19>, ["~> 0.11.6"])
|
83
85
|
end
|
84
86
|
end
|
85
87
|
|
data/lib/boombera.rb
CHANGED
@@ -110,7 +110,8 @@ class Boombera
|
|
110
110
|
# +body+:: can be # any object that can convert to JSON.
|
111
111
|
# +path+:: should be a String with /-separated tokens (i.e. "/foo/bar/baz").
|
112
112
|
def put(path, body)
|
113
|
-
content_item = get_pointer(path)
|
113
|
+
content_item = ContentItem.get_pointer(path, database) \
|
114
|
+
and content_item.body = body
|
114
115
|
content_item ||= ContentItem.new(path, body, database)
|
115
116
|
content_item.save
|
116
117
|
end
|
@@ -119,7 +120,7 @@ class Boombera
|
|
119
120
|
# is found. If +path+ is mapped to another ContentItem, the resolved
|
120
121
|
# ContentItem will be returned.
|
121
122
|
def get(path)
|
122
|
-
ContentItem
|
123
|
+
ContentItem.get(path, database)
|
123
124
|
end
|
124
125
|
|
125
126
|
# Creates a content mapping so that two paths can reference the same content
|
@@ -131,17 +132,13 @@ class Boombera
|
|
131
132
|
#
|
132
133
|
# raises:: InvalidMapping
|
133
134
|
def map(path, source_path)
|
134
|
-
content_map =
|
135
|
+
content_map = ContentItem.get_pointer(path, database) \
|
136
|
+
|| ContentItem.new(path, nil, database)
|
135
137
|
content_map.map_to source_path
|
136
138
|
content_map.save
|
137
139
|
end
|
138
140
|
|
139
141
|
private
|
140
|
-
|
141
|
-
def get_pointer(path)
|
142
|
-
ContentItem::MapResolver.new(path, database, :resolve_map => false).resolve
|
143
|
-
end
|
144
|
-
|
145
142
|
def check_database_version!
|
146
143
|
database_version = Boombera.database_version(database)
|
147
144
|
unless Boombera.version == database_version
|
@@ -2,41 +2,26 @@
|
|
2
2
|
# content-mapping semantics and method-based access to the attributes that
|
3
3
|
# Boombera knows about.
|
4
4
|
class Boombera::ContentItem < CouchRest::Document
|
5
|
-
class MapResolver #:nodoc: all
|
6
|
-
def initialize(path, database, options = {})
|
7
|
-
@path = path
|
8
|
-
@database = database
|
9
|
-
@final_attempt = options[:resolve_map] == false
|
10
|
-
end
|
11
|
-
|
12
|
-
def resolve
|
13
|
-
id, maps_to = content_map
|
14
|
-
return if id.nil?
|
15
|
-
if @final_attempt || maps_to == @path
|
16
|
-
Boombera::ContentItem.new(@database.get(id))
|
17
|
-
else
|
18
|
-
@path = maps_to
|
19
|
-
resolve
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def content_map
|
26
|
-
rows = @database.view('boombera/content_map', :key => @path)['rows']
|
27
|
-
return if rows.empty?
|
28
|
-
match = rows.first
|
29
|
-
[match['id'], match['value']]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
5
|
# The actual content that is being stored
|
34
6
|
attr_accessor :body
|
35
7
|
|
36
|
-
# The path used to access the ContentItem
|
8
|
+
# The path used to access the ContentItem, it is stored as the '_id' attribute
|
9
|
+
# in CouchDB
|
37
10
|
attr_reader :path
|
38
11
|
|
39
|
-
|
12
|
+
def self.get(path, db)
|
13
|
+
doc = get_pointer(path, db)
|
14
|
+
until doc.nil? || doc.resolved?
|
15
|
+
doc = get_pointer(doc.maps_to, db)
|
16
|
+
end
|
17
|
+
doc
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.get_pointer(path, db)
|
21
|
+
Boombera::ContentItem.new(db.get(path))
|
22
|
+
rescue RestClient::ResourceNotFound
|
23
|
+
nil
|
24
|
+
end
|
40
25
|
|
41
26
|
def initialize(doc_or_path, body = nil, database = nil) #:nodoc:
|
42
27
|
case doc_or_path
|
@@ -45,20 +30,20 @@ class Boombera::ContentItem < CouchRest::Document
|
|
45
30
|
super(doc_or_path)
|
46
31
|
when String
|
47
32
|
@database = database
|
48
|
-
super(
|
33
|
+
super('_id' => doc_or_path, 'body' => body)
|
49
34
|
else
|
50
35
|
raise ArgumentError, "doc_or_path must either be an instance of CouchRest::Document or a String"
|
51
36
|
end
|
52
37
|
end
|
53
38
|
|
54
39
|
def map_to(source_path) #:nodoc:
|
55
|
-
rows = @database.view('boombera/
|
40
|
+
rows = @database.view('boombera/content_paths', :key => source_path)['rows']
|
56
41
|
if rows.empty?
|
57
42
|
raise Boombera::InvalidMapping,
|
58
43
|
"Tried to map #{path} to #{source_path}, but #{source_path} doesn't exist."
|
59
44
|
else
|
60
45
|
self.body = nil
|
61
|
-
self[
|
46
|
+
self['maps_to'] = source_path
|
62
47
|
end
|
63
48
|
end
|
64
49
|
|
@@ -68,20 +53,30 @@ class Boombera::ContentItem < CouchRest::Document
|
|
68
53
|
rows.map{ |row| row['value'] }.sort
|
69
54
|
end
|
70
55
|
|
56
|
+
def save(*args)
|
57
|
+
self['maps_to'] = maps_to
|
58
|
+
self['type'] = 'content_item'
|
59
|
+
super
|
60
|
+
end
|
61
|
+
|
62
|
+
def resolved?
|
63
|
+
path == maps_to
|
64
|
+
end
|
65
|
+
|
66
|
+
def maps_to #:nodoc:
|
67
|
+
return path unless body.nil?
|
68
|
+
self['maps_to'] || path
|
69
|
+
end
|
70
|
+
|
71
71
|
def path #:nodoc:
|
72
|
-
self[
|
72
|
+
self['_id']
|
73
73
|
end
|
74
74
|
|
75
75
|
def body #:nodoc:
|
76
|
-
self[
|
76
|
+
self['body']
|
77
77
|
end
|
78
78
|
|
79
79
|
def body=(new_body) #:nodoc:
|
80
|
-
self[
|
81
|
-
self[:maps_to] = path unless new_body.nil?
|
82
|
-
end
|
83
|
-
|
84
|
-
def maps_to #:nodoc:
|
85
|
-
self[:maps_to]
|
80
|
+
self['body'] = new_body
|
86
81
|
end
|
87
82
|
end
|
data/lib/boombera/information.rb
CHANGED
@@ -14,14 +14,14 @@ module Boombera::Information #:nodoc: all
|
|
14
14
|
'language' => 'javascript',
|
15
15
|
'gem_version' => version,
|
16
16
|
'views' => {
|
17
|
-
'
|
17
|
+
'content_paths' => {
|
18
18
|
'map' => <<-EOF
|
19
19
|
function(doc) {
|
20
|
-
if (doc['
|
20
|
+
if (doc['type'] && doc.type == 'content_item') {
|
21
21
|
if (doc['maps_to']) {
|
22
|
-
emit(doc.
|
22
|
+
emit(doc._id, doc.maps_to);
|
23
23
|
} else {
|
24
|
-
emit(doc.
|
24
|
+
emit(doc._id, doc._id);
|
25
25
|
}
|
26
26
|
}
|
27
27
|
}
|
@@ -30,8 +30,8 @@ module Boombera::Information #:nodoc: all
|
|
30
30
|
'map_references' => {
|
31
31
|
'map' => <<-EOF
|
32
32
|
function(doc) {
|
33
|
-
if(doc['maps_to'] && doc.maps_to != doc.
|
34
|
-
emit(doc.maps_to, doc.
|
33
|
+
if(doc['maps_to'] && doc.maps_to != doc._id) {
|
34
|
+
emit(doc.maps_to, doc._id);
|
35
35
|
}
|
36
36
|
}
|
37
37
|
EOF
|
@@ -65,20 +65,16 @@ describe 'The Boombera library:' do
|
|
65
65
|
describe 'putting content in the database' do
|
66
66
|
it 'saves content to a new path' do
|
67
67
|
boombera.put('/foo', 'foo bar baz')
|
68
|
-
|
69
|
-
|
70
|
-
document = db.get(results.first['id'])
|
71
|
-
document['path'].should == '/foo'
|
68
|
+
document = db.get('/foo')
|
69
|
+
document['_id'].should == '/foo'
|
72
70
|
document['body'].should == 'foo bar baz'
|
73
71
|
end
|
74
72
|
|
75
73
|
it 'saves content to an existing path' do
|
76
74
|
boombera.put('/foo', 'foo bar baz')
|
77
75
|
boombera.put('/foo', 'the new content')
|
78
|
-
|
79
|
-
|
80
|
-
document = db.get(results.first['id'])
|
81
|
-
document['path'].should == '/foo'
|
76
|
+
document = db.get('/foo')
|
77
|
+
document['_id'].should == '/foo'
|
82
78
|
document['body'].should == 'the new content'
|
83
79
|
end
|
84
80
|
|
@@ -86,12 +82,10 @@ describe 'The Boombera library:' do
|
|
86
82
|
boombera.put('/foo', 'foo bar baz')
|
87
83
|
boombera.map('/bar', '/foo')
|
88
84
|
boombera.put('/bar', 'the new content')
|
89
|
-
|
90
|
-
|
91
|
-
document = db.get(results.first['id'])
|
92
|
-
document['path'].should == '/bar'
|
85
|
+
document = db.get('/bar')
|
86
|
+
document['_id'].should == '/bar'
|
93
87
|
document['body'].should == 'the new content'
|
94
|
-
document['
|
88
|
+
document['maps_to'].should == '/bar'
|
95
89
|
end
|
96
90
|
end
|
97
91
|
|
@@ -99,10 +93,9 @@ describe 'The Boombera library:' do
|
|
99
93
|
it 'creates a pointer from a path to another path' do
|
100
94
|
boombera.put('/foo', 'foo bar baz')
|
101
95
|
boombera.map('/bar', '/foo')
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
map_item['value'].should == '/foo'
|
96
|
+
result = boombera.get('/bar')
|
97
|
+
result.path.should == '/foo'
|
98
|
+
result.body.should == 'foo bar baz'
|
106
99
|
end
|
107
100
|
|
108
101
|
it 'updates a pointer from a path to another path' do
|
@@ -110,22 +103,18 @@ describe 'The Boombera library:' do
|
|
110
103
|
boombera.put('/spam', 'ham spam can')
|
111
104
|
boombera.map('/bar', '/foo')
|
112
105
|
boombera.map('/bar', '/spam')
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
map_item['value'].should == '/spam'
|
106
|
+
result = boombera.get('/bar')
|
107
|
+
result.path.should == '/spam'
|
108
|
+
result.body.should == 'ham spam can'
|
117
109
|
end
|
118
110
|
|
119
111
|
it 'turns a content item into a pointer' do
|
120
112
|
boombera.put('/foo', 'foo bar baz')
|
121
113
|
boombera.put('/bar', 'some old bar content')
|
122
114
|
boombera.map('/bar', '/foo')
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
map_item['value'].should == '/foo'
|
127
|
-
doc = db.get(map_item['id'])
|
128
|
-
doc['body'].should be_nil
|
115
|
+
result = boombera.get('/bar')
|
116
|
+
result.path.should == '/foo'
|
117
|
+
result.body.should == 'foo bar baz'
|
129
118
|
end
|
130
119
|
end
|
131
120
|
|
@@ -135,7 +124,7 @@ describe 'The Boombera library:' do
|
|
135
124
|
end
|
136
125
|
|
137
126
|
it 'gives you a ContentItem if the content is there' do
|
138
|
-
|
127
|
+
boombera.put('/index', 'Hello, World!')
|
139
128
|
result = boombera.get('/index')
|
140
129
|
result.path.should == '/index'
|
141
130
|
result.body.should == 'Hello, World!'
|
@@ -1,6 +1,12 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
2
2
|
|
3
3
|
describe Boombera::ContentItem do
|
4
|
+
let(:db) do
|
5
|
+
db = stub(CouchRest::Database)
|
6
|
+
CouchRest.stub!(:database! => db)
|
7
|
+
db
|
8
|
+
end
|
9
|
+
|
4
10
|
describe '.new' do
|
5
11
|
context 'when passed a path, body and database' do
|
6
12
|
it 'sets the database from the database argument' do
|
@@ -20,10 +26,16 @@ describe Boombera::ContentItem do
|
|
20
26
|
end
|
21
27
|
|
22
28
|
describe '#path' do
|
23
|
-
it 'returns the path from the
|
29
|
+
it 'returns the path from the arguments' do
|
24
30
|
content = Boombera::ContentItem.new('/index.html')
|
25
31
|
content.path.should == '/index.html'
|
26
32
|
end
|
33
|
+
|
34
|
+
it 'returns the _id when initialized with a Document' do
|
35
|
+
doc = CouchRest::Document.new('_id' => '/foobar')
|
36
|
+
content = Boombera::ContentItem.new(doc)
|
37
|
+
content.path.should == '/foobar'
|
38
|
+
end
|
27
39
|
end
|
28
40
|
|
29
41
|
describe '#body' do
|
@@ -34,27 +46,12 @@ describe Boombera::ContentItem do
|
|
34
46
|
end
|
35
47
|
|
36
48
|
describe '#body=' do
|
37
|
-
let(:db) { stub(CouchRest::Database) }
|
38
49
|
let(:content) { Boombera::ContentItem.new('/foo', 'not bar', db) }
|
39
50
|
|
40
51
|
it 'overwrites the current contents of the document body' do
|
41
52
|
content.body = 'bar'
|
42
53
|
content.body.should == 'bar'
|
43
54
|
end
|
44
|
-
|
45
|
-
it 'sets the maps_to attribute equal to the path attribute if argument is not nil' do
|
46
|
-
db.stub!(:view => {'rows' => [{'value' => '/foo'}]})
|
47
|
-
content.map_to '/bar'
|
48
|
-
content.body = 'something'
|
49
|
-
content.maps_to.should == '/foo'
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'does not change the maps_to attribute if the argument is nil' do
|
53
|
-
db.stub!(:view => {'rows' => [{'value' => '/foo'}]})
|
54
|
-
content.map_to '/bar'
|
55
|
-
content.body = nil
|
56
|
-
content.maps_to.should == '/bar'
|
57
|
-
end
|
58
55
|
end
|
59
56
|
|
60
57
|
describe '#map_to' do
|
@@ -74,8 +71,8 @@ describe Boombera::ContentItem do
|
|
74
71
|
|
75
72
|
before(:each) do
|
76
73
|
db.should_receive(:view) \
|
77
|
-
.with('boombera/
|
78
|
-
.and_return({'rows' => [{'
|
74
|
+
.with('boombera/content_paths', :key => '/foo') \
|
75
|
+
.and_return({'rows' => [{'id' => '/foo'}]})
|
79
76
|
content.map_to '/foo'
|
80
77
|
end
|
81
78
|
|
@@ -88,4 +85,68 @@ describe Boombera::ContentItem do
|
|
88
85
|
end
|
89
86
|
end
|
90
87
|
end
|
88
|
+
|
89
|
+
describe '#save' do
|
90
|
+
it 'ensures that the type attribute is set to "content_item"' do
|
91
|
+
content = Boombera::ContentItem.new('/foo', 'bar', db)
|
92
|
+
db.should_receive(:save_doc) \
|
93
|
+
.with({'_id' => '/foo', 'body' => 'bar', 'type' => 'content_item',
|
94
|
+
'maps_to' => '/foo'}, false) \
|
95
|
+
.and_return({'ok' => true})
|
96
|
+
content.save
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'when the body is not nil' do
|
100
|
+
it 'sets the maps_to attribute equal to the path' do
|
101
|
+
content = Boombera::ContentItem.new('/foo', 'bar', db)
|
102
|
+
db.should_receive(:save_doc) \
|
103
|
+
.with({'_id' => '/foo', 'body' => 'bar', 'type' => 'content_item',
|
104
|
+
'maps_to' => '/foo'}, false) \
|
105
|
+
.and_return({'ok' => true})
|
106
|
+
content.save
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'but the maps_to attribute points to another document' do
|
110
|
+
it 'sets the maps_to attribute equal to the path' do
|
111
|
+
db.stub!(:view => {'rows' => [{'id' => '/bar'}]})
|
112
|
+
content = Boombera::ContentItem.new('/foo', nil, db)
|
113
|
+
content.map_to('/bar')
|
114
|
+
content.body = 'bar'
|
115
|
+
db.should_receive(:save_doc) \
|
116
|
+
.with({'_id' => '/foo', 'body' => 'bar', 'type' => 'content_item',
|
117
|
+
'maps_to' => '/foo'}, false) \
|
118
|
+
.and_return({'ok' => true})
|
119
|
+
content.save
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'when the body is nil' do
|
125
|
+
it 'does not change the maps_to attribute if it is already set' do
|
126
|
+
# stub result from boombera/content_paths view
|
127
|
+
db.stub(:view => {'rows' => [{'id' => '/bar'}]})
|
128
|
+
content = Boombera::ContentItem.new('/foo', nil, db)
|
129
|
+
content.map_to('/bar')
|
130
|
+
db.should_receive(:save_doc) \
|
131
|
+
.with({'_id' => '/foo', 'body' => nil, 'type' => 'content_item',
|
132
|
+
'maps_to' => '/bar'}, false) \
|
133
|
+
.and_return({'ok' => true})
|
134
|
+
content.save
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#resolved' do
|
140
|
+
it 'returns true if maps_to == path' do
|
141
|
+
content = Boombera::ContentItem.new('/foo', 'bar', db)
|
142
|
+
content.should be_resolved
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'returns false if maps_to != path' do
|
146
|
+
db.stub!(:view => {'rows' => [{'id' => '/bar'}]})
|
147
|
+
content = Boombera::ContentItem.new('/foo', nil, db)
|
148
|
+
content.map_to '/bar'
|
149
|
+
content.should_not be_resolved
|
150
|
+
end
|
151
|
+
end
|
91
152
|
end
|
data/spec/lib/boombera_spec.rb
CHANGED
@@ -40,10 +40,9 @@ describe Boombera do
|
|
40
40
|
describe '#put' do
|
41
41
|
context "to an existing path" do
|
42
42
|
it 'updates and saves the existing content item' do
|
43
|
-
|
44
|
-
|
45
|
-
.
|
46
|
-
.and_return(resolver)
|
43
|
+
Boombera::ContentItem.should_receive(:get_pointer) \
|
44
|
+
.with('/foo', db) \
|
45
|
+
.and_return(content_item)
|
47
46
|
content_item.should_receive(:body=).with('bar')
|
48
47
|
content_item.should_receive(:save).and_return(true)
|
49
48
|
boombera.put('/foo', 'bar').should == true
|
@@ -52,7 +51,7 @@ describe Boombera do
|
|
52
51
|
|
53
52
|
context "to a new path" do
|
54
53
|
it 'creates and saves the content item' do
|
55
|
-
Boombera::ContentItem
|
54
|
+
Boombera::ContentItem.stub!(:get_pointer => nil)
|
56
55
|
Boombera::ContentItem.should_receive(:new) \
|
57
56
|
.with('/foo', 'bar', db) \
|
58
57
|
.and_return(content_item)
|
@@ -64,20 +63,20 @@ describe Boombera do
|
|
64
63
|
|
65
64
|
describe '#get' do
|
66
65
|
it 'gets the content item at the specified path from the current database' do
|
67
|
-
|
68
|
-
Boombera::ContentItem::MapResolver.should_receive(:new) \
|
66
|
+
Boombera::ContentItem.should_receive(:get) \
|
69
67
|
.with('/foo', db) \
|
70
|
-
.and_return(
|
71
|
-
boombera.get('/foo').should ==
|
68
|
+
.and_return(content_item)
|
69
|
+
boombera.get('/foo').should == content_item
|
72
70
|
end
|
73
71
|
end
|
74
72
|
|
75
73
|
describe '#map' do
|
76
74
|
context 'to a new path' do
|
77
75
|
before(:each) do
|
78
|
-
|
79
|
-
Boombera::ContentItem
|
80
|
-
|
76
|
+
Boombera::ContentItem.stub!(:get_pointer => nil)
|
77
|
+
Boombera::ContentItem.should_receive(:new) \
|
78
|
+
.with('/bar', nil, db) \
|
79
|
+
.and_return(content_item)
|
81
80
|
end
|
82
81
|
|
83
82
|
it 'creates and saves ContentItem as pointer' do
|
@@ -95,10 +94,9 @@ describe Boombera do
|
|
95
94
|
|
96
95
|
context 'to an existing path' do
|
97
96
|
before(:each) do
|
98
|
-
|
99
|
-
|
100
|
-
.
|
101
|
-
.and_return(resolver)
|
97
|
+
Boombera::ContentItem.should_receive(:get_pointer) \
|
98
|
+
.with('/bar', db) \
|
99
|
+
.and_return(content_item)
|
102
100
|
end
|
103
101
|
|
104
102
|
it 'updates ContentItem as pointer' do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: boombera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- John Wilger
|
@@ -123,6 +123,17 @@ dependencies:
|
|
123
123
|
type: :development
|
124
124
|
prerelease: false
|
125
125
|
version_requirements: *id010
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: ruby-debug19
|
128
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ~>
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 0.11.6
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: *id011
|
126
137
|
description: CouchDB-backed content repository for multi-tenant, multi-stage applications
|
127
138
|
email: johnwilger@gmail.com
|
128
139
|
executables: []
|
@@ -148,7 +159,6 @@ files:
|
|
148
159
|
- lib/boombera/content_item.rb
|
149
160
|
- lib/boombera/information.rb
|
150
161
|
- spec/integration/boombera_spec.rb
|
151
|
-
- spec/lib/boombera/content_item_map_resolver_spec.rb
|
152
162
|
- spec/lib/boombera/content_item_spec.rb
|
153
163
|
- spec/lib/boombera_spec.rb
|
154
164
|
- spec/spec_helper.rb
|
@@ -166,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
166
176
|
requirements:
|
167
177
|
- - ">="
|
168
178
|
- !ruby/object:Gem::Version
|
169
|
-
hash:
|
179
|
+
hash: -4409328939730188519
|
170
180
|
segments:
|
171
181
|
- 0
|
172
182
|
version: "0"
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
2
|
-
|
3
|
-
describe Boombera::ContentItem::MapResolver do
|
4
|
-
describe '#resolve' do
|
5
|
-
context 'with an existing content item' do
|
6
|
-
it 'returns a ContentItem instance for the found document' do
|
7
|
-
view_result = {'rows' => [{'id' => '123', 'value' => '/foo'}]}
|
8
|
-
db = mock(CouchRest::Database)
|
9
|
-
db.should_receive(:view) \
|
10
|
-
.with('boombera/content_map', :key => '/foo') \
|
11
|
-
.and_return(view_result)
|
12
|
-
db.should_receive(:get) \
|
13
|
-
.with('123') \
|
14
|
-
.and_return(CouchRest::Document.new('path' => '/foo', 'body' => 'bar'))
|
15
|
-
result = Boombera::ContentItem::MapResolver.new('/foo', db).resolve
|
16
|
-
result.path.should == '/foo'
|
17
|
-
result.body.should == 'bar'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'with a non-existant content item' do
|
22
|
-
it 'returns nil' do
|
23
|
-
view_result = {'rows' => []}
|
24
|
-
db = mock(CouchRest::Database)
|
25
|
-
db.should_receive(:view) \
|
26
|
-
.with('boombera/content_map', :key => '/foo') \
|
27
|
-
.and_return(view_result)
|
28
|
-
Boombera::ContentItem::MapResolver.new('/foo', db).resolve.should == nil
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'with a path that maps to another content item' do
|
33
|
-
it 'returns the mapped content item' do
|
34
|
-
map_view_result = {'rows' => [{'id' => '123', 'value' => '/bar'}]}
|
35
|
-
content_view_result = {'rows' => [{'id' => '456', 'value' => '/bar'}]}
|
36
|
-
db = mock(CouchRest::Database)
|
37
|
-
db.should_receive(:view) \
|
38
|
-
.with('boombera/content_map', :key => '/foo') \
|
39
|
-
.and_return(map_view_result)
|
40
|
-
db.should_receive(:view) \
|
41
|
-
.with('boombera/content_map', :key => '/bar') \
|
42
|
-
.and_return(content_view_result)
|
43
|
-
db.should_receive(:get) \
|
44
|
-
.with('456') \
|
45
|
-
.and_return(CouchRest::Document.new('path' => '/bar', 'body' => 'bar'))
|
46
|
-
result = Boombera::ContentItem::MapResolver.new('/foo', db).resolve
|
47
|
-
result.path.should == '/bar'
|
48
|
-
result.body.should == 'bar'
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'returns the pointer content item when passed the :resolve_map option as false' do
|
52
|
-
map_view_result = {'rows' => [{'id' => '123', 'value' => '/bar'}]}
|
53
|
-
db = mock(CouchRest::Database)
|
54
|
-
db.should_receive(:view) \
|
55
|
-
.with('boombera/content_map', :key => '/foo') \
|
56
|
-
.and_return(map_view_result)
|
57
|
-
db.should_receive(:get) \
|
58
|
-
.with('123') \
|
59
|
-
.and_return(CouchRest::Document.new('path' => '/foo', 'maps_to' => '/bar'))
|
60
|
-
result = Boombera::ContentItem::MapResolver.new('/foo', db, :resolve_map => false).resolve
|
61
|
-
result.path.should == '/foo'
|
62
|
-
result.maps_to.should == '/bar'
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|