couch 0.2.0 → 0.2.1
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/README.rdoc +6 -88
- data/Rakefile +3 -54
- data/bin/couch +1 -7
- data/couch.gemspec +6 -72
- data/lib/couch.rb +0 -41
- metadata +9 -127
- data/.gitmodules +0 -3
- data/LICENSE +0 -20
- data/lib/couch/actions/base.rb +0 -15
- data/lib/couch/actions/pull.rb +0 -28
- data/lib/couch/actions/push.rb +0 -53
- data/lib/couch/actions/routes.rb +0 -41
- data/lib/couch/commands.rb +0 -41
- data/lib/couch/commands/destroy.rb +0 -9
- data/lib/couch/commands/generate.rb +0 -9
- data/lib/couch/commands/pull.rb +0 -4
- data/lib/couch/commands/push.rb +0 -4
- data/lib/couch/commands/routes.rb +0 -4
- data/lib/couch/design_document.rb +0 -314
- data/lib/couch/generators.rb +0 -63
- data/lib/couch/generators/application/USAGE +0 -10
- data/lib/couch/generators/application/application_generator.rb +0 -51
- data/lib/couch/generators/application/templates/README +0 -1
- data/lib/couch/generators/application/templates/_attachments/index.html +0 -11
- data/lib/couch/generators/application/templates/_attachments/stylesheets/application.css +0 -25
- data/lib/couch/generators/application/templates/_id +0 -1
- data/lib/couch/generators/application/templates/couchrc +0 -1
- data/lib/couch/generators/application/templates/gitignore +0 -0
- data/lib/couch/generators/application/templates/lib/mustache.js +0 -305
- data/lib/couch/generators/application/templates/validate_doc_update.js +0 -3
- data/lib/couch/generators/base.rb +0 -66
- data/lib/couch/generators/list/USAGE +0 -8
- data/lib/couch/generators/list/list_generator.rb +0 -9
- data/lib/couch/generators/list/templates/list.js +0 -29
- data/lib/couch/generators/named_base.rb +0 -22
- data/lib/couch/generators/scaffold/USAGE +0 -10
- data/lib/couch/generators/scaffold/scaffold_generator.rb +0 -28
- data/lib/couch/generators/show/USAGE +0 -8
- data/lib/couch/generators/show/show_generator.rb +0 -9
- data/lib/couch/generators/show/templates/show.js +0 -20
- data/lib/couch/generators/validation/USAGE +0 -9
- data/lib/couch/generators/validation/templates/validate_doc_update.js +0 -3
- data/lib/couch/generators/validation/validation_generator.rb +0 -34
- data/lib/couch/generators/view/USAGE +0 -8
- data/lib/couch/generators/view/templates/map.js +0 -5
- data/lib/couch/generators/view/view_generator.rb +0 -17
- data/lib/couch/version.rb +0 -3
- data/spec/couch/design_document_spec.rb +0 -313
- data/spec/couch_spec.rb +0 -7
- data/spec/spec.opts +0 -1
- data/spec/spec_helper.rb +0 -9
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'thor/group'
|
2
|
-
require 'active_support/inflector'
|
3
|
-
|
4
|
-
module Couch
|
5
|
-
module Generators
|
6
|
-
class Error < Thor::Error
|
7
|
-
end
|
8
|
-
|
9
|
-
class Base < Thor::Group
|
10
|
-
include Thor::Actions
|
11
|
-
|
12
|
-
add_runtime_options!
|
13
|
-
|
14
|
-
class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
|
15
|
-
:desc => "Skip Git ignores and keeps"
|
16
|
-
|
17
|
-
# Automatically sets the source root based on the class name.
|
18
|
-
#
|
19
|
-
def self.source_root
|
20
|
-
@_couch_source_root ||= begin
|
21
|
-
if generator_name
|
22
|
-
File.expand_path(File.join("../generators", generator_name, 'templates'), File.dirname(__FILE__))
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# Tries to get the description from a USAGE file one folder above the source
|
28
|
-
# root otherwise uses a default description.
|
29
|
-
#
|
30
|
-
def self.desc(description=nil)
|
31
|
-
return super if description
|
32
|
-
usage = File.expand_path(File.join(source_root, "..", "USAGE"))
|
33
|
-
|
34
|
-
@desc ||= if File.exist?(usage)
|
35
|
-
File.read(usage)
|
36
|
-
else
|
37
|
-
"Description:\n Create files for #{generator_name} generator."
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.info
|
42
|
-
desc.split(/\n+/)[1].strip
|
43
|
-
end
|
44
|
-
|
45
|
-
protected
|
46
|
-
|
47
|
-
# Use Couch default banner.
|
48
|
-
#
|
49
|
-
def self.banner
|
50
|
-
"couch generate|destroy #{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
|
51
|
-
end
|
52
|
-
|
53
|
-
# Removes the namespaces and get the generator name. For example,
|
54
|
-
# Couch::Generators::MetalGenerator will return "metal" as generator name.
|
55
|
-
#
|
56
|
-
def self.generator_name
|
57
|
-
@generator_name ||= begin
|
58
|
-
if generator = name.to_s.split('::').last
|
59
|
-
generator.sub!(/Generator$/, '')
|
60
|
-
generator.underscore
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
function(head, req) {
|
2
|
-
provides("html", function() {
|
3
|
-
var header = '<html><head><link rel="stylesheet" href="../../stylesheets/application.css" type="text/css" media="screen" charset="utf-8"></head><body><h1>Listing <%= pluralized_model_name.humanize %></h1>';
|
4
|
-
|
5
|
-
header += '<p><a href="../../_show/<%= model_name %>/">New <%= model_name.humanize %></a></p>';
|
6
|
-
|
7
|
-
header += '<table><tr>';
|
8
|
-
<% attributes.each do |attribute| -%>
|
9
|
-
header += '<th><%= attribute.humanize %></th>';
|
10
|
-
<% end -%>
|
11
|
-
header += '<th></th>';
|
12
|
-
header += '</tr>';
|
13
|
-
send(header);
|
14
|
-
|
15
|
-
var row;
|
16
|
-
while (row = getRow()) {
|
17
|
-
var body = '<tr>';
|
18
|
-
<% attributes.each do |attribute| -%>
|
19
|
-
body += '<td>' + row.value['<%= attribute %>'] + '</td>';
|
20
|
-
<% end -%>
|
21
|
-
body += '<td><a href="../../_show/<%= model_name %>/' + row.id + '" alt="Show <%= model_name.humanize %>">Show</a></td>';
|
22
|
-
body += '</tr>';
|
23
|
-
send(body);
|
24
|
-
}
|
25
|
-
|
26
|
-
var tail = '</table></body></html>';
|
27
|
-
return tail;
|
28
|
-
});
|
29
|
-
}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'thor/group'
|
2
|
-
require 'active_support/inflector'
|
3
|
-
|
4
|
-
module Couch
|
5
|
-
module Generators
|
6
|
-
class NamedBase < Base
|
7
|
-
argument :name, :type => :string
|
8
|
-
argument :attributes, :type => :array, :default => []
|
9
|
-
|
10
|
-
protected
|
11
|
-
|
12
|
-
# force underscored and singularized model name
|
13
|
-
def model_name
|
14
|
-
@model_name ||= name.underscore.singularize
|
15
|
-
end
|
16
|
-
|
17
|
-
def pluralized_model_name
|
18
|
-
model_name.pluralize
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
Description:
|
2
|
-
The 'scaffold' generator creates a scaffold skelet
|
3
|
-
with a default show function, list function
|
4
|
-
of the name and attributes you specify
|
5
|
-
|
6
|
-
Example:
|
7
|
-
couch generate scaffold post title body
|
8
|
-
|
9
|
-
This generates a skeletal model post with a posts list view,
|
10
|
-
post show function and validation.
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'couch/generators/named_base'
|
2
|
-
|
3
|
-
module Couch::Generators
|
4
|
-
class ScaffoldGenerator < NamedBase
|
5
|
-
def create_view_function
|
6
|
-
Couch::Generators.invoke :view, *invokation_options
|
7
|
-
end
|
8
|
-
|
9
|
-
def inject_validations
|
10
|
-
Couch::Generators.invoke :validation, *invokation_options
|
11
|
-
end
|
12
|
-
|
13
|
-
def create_list_function
|
14
|
-
Couch::Generators.invoke :list, *invokation_options
|
15
|
-
end
|
16
|
-
|
17
|
-
def create_show_function
|
18
|
-
Couch::Generators.invoke :show, *invokation_options
|
19
|
-
end
|
20
|
-
|
21
|
-
protected
|
22
|
-
|
23
|
-
# TODO: add default options, like --help, --force etc
|
24
|
-
def invokation_options
|
25
|
-
[[name] + attributes, { :behavior => behavior }]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
function(doc, req) {
|
2
|
-
var head = '<html><head><link rel="stylesheet" href="../../stylesheets/application.css" type="text/css" media="screen" charset="utf-8"></head><body>';
|
3
|
-
var body = '';
|
4
|
-
var tail = '</body></html>';
|
5
|
-
if(doc) {
|
6
|
-
body += '<p><a href="../../_list/<%= pluralized_model_name %>/<%= pluralized_model_name %>">List <%= pluralized_model_name.humanize %></a></p>';
|
7
|
-
<% attributes.each do |attribute| -%>
|
8
|
-
if(doc['<%= attribute %>']) {
|
9
|
-
body += '<p><strong><%= attribute.humanize %></strong>: ' + doc['<%= attribute %>'] + '</p>';
|
10
|
-
}
|
11
|
-
<% end -%>
|
12
|
-
return head + '<h1>Showing <%= model_name.humanize %></h1>' + body + tail;
|
13
|
-
} else {
|
14
|
-
<% attributes.each do |attribute| -%>
|
15
|
-
body += '<p><label><%= attribute.humanize %></label>: <input type="text" name="<%= model_name %>[<%= attribute %>]" id="<%= model_name %>_<%= attribute %>" /></p>';
|
16
|
-
<% end -%>
|
17
|
-
body += '<p><input type="submit" /> <a href="../../_list/<%= pluralized_model_name %>/<%= pluralized_model_name %>">Cancel</a></p>';
|
18
|
-
return head + '<h1>New <%= model_name.humanize %></h1>' + body + tail;
|
19
|
-
}
|
20
|
-
}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
Description:
|
2
|
-
The 'validation' generator creates a validation function
|
3
|
-
for the model name and attributes you specify
|
4
|
-
|
5
|
-
Example:
|
6
|
-
couch generate validation post title body
|
7
|
-
|
8
|
-
This generates a skeletal model validation for post
|
9
|
-
with validations of presence for title and body
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'couch/generators/named_base'
|
2
|
-
|
3
|
-
module Couch::Generators
|
4
|
-
class ValidationGenerator < NamedBase
|
5
|
-
def create_validate_doc_update
|
6
|
-
return if File.exists?(File.join(destination_root, "validate_doc_update.js"))
|
7
|
-
template "validate_doc_update.js"
|
8
|
-
end
|
9
|
-
|
10
|
-
def inject_validations
|
11
|
-
inject_into_file "validate_doc_update.js", model_validations, :after => "function (newDoc, oldDoc, userCtx) {\n"
|
12
|
-
end
|
13
|
-
|
14
|
-
protected
|
15
|
-
|
16
|
-
def model_validations
|
17
|
-
str = <<-STR
|
18
|
-
if(newDoc.type == '#{model_name}') {
|
19
|
-
// validations for #{model_name}
|
20
|
-
STR
|
21
|
-
|
22
|
-
attributes.each do |attribute|
|
23
|
-
str << <<-STR
|
24
|
-
if (typeof(newDoc['#{attribute}']) === 'undefined') {
|
25
|
-
throw({ forbidden: '#{attribute} is required' });
|
26
|
-
}
|
27
|
-
STR
|
28
|
-
end
|
29
|
-
|
30
|
-
str << " }\n"
|
31
|
-
str
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'couch/generators/named_base'
|
2
|
-
|
3
|
-
module Couch::Generators
|
4
|
-
class ViewGenerator < NamedBase
|
5
|
-
def create_view_function
|
6
|
-
path = "views/#{pluralized_model_name}"
|
7
|
-
empty_directory path
|
8
|
-
template "map.js", "#{path}/map.js"
|
9
|
-
end
|
10
|
-
|
11
|
-
protected
|
12
|
-
|
13
|
-
def mydoc
|
14
|
-
"{ %s }" % attributes.map { |a| '"%s": doc["%s"]' % [a,a] }.join(", ")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/couch/version.rb
DELETED
@@ -1,313 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
require 'couch/design_document'
|
3
|
-
|
4
|
-
describe "DesignDocument" do
|
5
|
-
before do
|
6
|
-
@doc = Couch::DesignDocument.new
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "read" do
|
10
|
-
it "should assign key-value pair" do
|
11
|
-
@doc.read("key") do |filename|
|
12
|
-
"value"
|
13
|
-
end
|
14
|
-
@doc.hash.should == { "key" => "value" }
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should assign two key-value pairs" do
|
18
|
-
@doc.read("key1", "key2") do |filename|
|
19
|
-
"value"
|
20
|
-
end
|
21
|
-
@doc.hash.should == { "key1" => "value", "key2" => "value" }
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should assign an array of two key-value pairs" do
|
25
|
-
@doc.read(["key1", "key2"]) do |filename|
|
26
|
-
"value"
|
27
|
-
end
|
28
|
-
@doc.hash.should == { "key1" => "value", "key2" => "value" }
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should assign nested hash" do
|
32
|
-
@doc.read("hash/key") do |filename|
|
33
|
-
"value"
|
34
|
-
end
|
35
|
-
@doc.hash.should == { "hash" => { "key" => "value" } }
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should assign deep nested hash" do
|
39
|
-
@doc.read("hash/hash/key") do |filename|
|
40
|
-
"value"
|
41
|
-
end
|
42
|
-
@doc.hash.should == { "hash" => { "hash" => { "key" => "value" } } }
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "_attachments encoding and content_type" do
|
46
|
-
it "should proper encode and add plain text content type" do
|
47
|
-
@doc.read("_attachments/key") do |filename|
|
48
|
-
"value"
|
49
|
-
end
|
50
|
-
@doc.hash.should == { "_attachments" => { "key" => { "data" => "dmFsdWU=", "content_type" => "text/plain" } } }
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should proper encode and add html content type" do
|
54
|
-
@doc.read("_attachments/key.html") do |filename|
|
55
|
-
"value"
|
56
|
-
end
|
57
|
-
@doc.hash.should == { "_attachments" => { "key.html" => { "data" => "dmFsdWU=", "content_type" => "text/html" } } }
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should proper encode nested keys" do
|
61
|
-
@doc.read("_attachments/hash/key") do |filename|
|
62
|
-
"value"
|
63
|
-
end
|
64
|
-
@doc.hash.should == { "_attachments" => { "hash/key" => { "data" => "dmFsdWU=", "content_type" => "text/plain" } } }
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "exclude files should not be mapped" do
|
69
|
-
it "should not map README" do
|
70
|
-
@doc.read("README") do |filename|
|
71
|
-
"value"
|
72
|
-
end
|
73
|
-
@doc.hash.should == {}
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "javascript files should be stripped off extension" do
|
78
|
-
it "should strip validate_doc_update extension" do
|
79
|
-
@doc.read("validate_doc_update.js") do |filename|
|
80
|
-
"value"
|
81
|
-
end
|
82
|
-
@doc.hash.should == { "validate_doc_update" => "value" }
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should strip lists/my_list.js" do
|
86
|
-
@doc.read("lists/my_list.js") do |filename|
|
87
|
-
"value"
|
88
|
-
end
|
89
|
-
@doc.hash.should == { "lists" => { "my_list" => "value" } }
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should strip views/my_view/map.js" do
|
93
|
-
@doc.read("views/my_view/map.js") do |filename|
|
94
|
-
"value"
|
95
|
-
end
|
96
|
-
@doc.hash.should == { "views" => { "my_view" => { "map" => "value" } } }
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe "code makro" do
|
101
|
-
it "should expand code" do
|
102
|
-
idx = 0
|
103
|
-
@doc.read("key", "lib/code.js") do |filename|
|
104
|
-
case idx += 1
|
105
|
-
when 1
|
106
|
-
"// !code code.js"
|
107
|
-
when 2
|
108
|
-
"value"
|
109
|
-
end
|
110
|
-
end
|
111
|
-
@doc.hash.should == { "key" => "value", "lib" => { "code.js" => "value" } }
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe "json makro" do
|
116
|
-
it "should expand json" do
|
117
|
-
idx = 0
|
118
|
-
@doc.read("key", "lib/json.json") do |filename|
|
119
|
-
case idx += 1
|
120
|
-
when 1
|
121
|
-
"// !json json.json"
|
122
|
-
when 2
|
123
|
-
"value"
|
124
|
-
end
|
125
|
-
end
|
126
|
-
@doc.hash.should == { "key" => "var json = \"value\";", "lib" => { "json.json" => "value" } }
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe "write" do
|
132
|
-
it "should return key-value pair" do
|
133
|
-
@doc.hash = { "key" => "value" }
|
134
|
-
filename, content = nil, nil
|
135
|
-
@doc.write do |key, value|
|
136
|
-
filename, content = key, value
|
137
|
-
end
|
138
|
-
filename.should == "key"
|
139
|
-
content.should == "value"
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should return subdirectory for nested hash" do
|
143
|
-
@doc.hash = { "hash" => { "key" => "value" } }
|
144
|
-
filename, content = nil, nil
|
145
|
-
@doc.write do |key, value|
|
146
|
-
filename, content = key, value
|
147
|
-
end
|
148
|
-
filename.should == "hash/key"
|
149
|
-
content.should == "value"
|
150
|
-
end
|
151
|
-
|
152
|
-
it "should return subdirectory for nested hash" do
|
153
|
-
@doc.hash = { "hash" => { "hash" => { "key" => "value" } } }
|
154
|
-
filename, content = nil, nil
|
155
|
-
@doc.write do |key, value|
|
156
|
-
filename, content = key, value
|
157
|
-
end
|
158
|
-
filename.should == "hash/hash/key"
|
159
|
-
content.should == "value"
|
160
|
-
end
|
161
|
-
|
162
|
-
it "should return decoded _attachments data" do
|
163
|
-
@doc.hash = { "_attachments" => { "key" => { "data" => "dmFsdWU=" } } }
|
164
|
-
filename, content = nil, nil
|
165
|
-
@doc.write do |key, value|
|
166
|
-
filename, content = key, value
|
167
|
-
end
|
168
|
-
filename.should == "_attachments/key"
|
169
|
-
content.should == "value"
|
170
|
-
end
|
171
|
-
|
172
|
-
describe "javascript extensions" do
|
173
|
-
it "should append validate_doc_update" do
|
174
|
-
@doc.hash = { "validate_doc_update" => "value" }
|
175
|
-
filename = nil
|
176
|
-
@doc.write do |key, value|
|
177
|
-
filename = key
|
178
|
-
end
|
179
|
-
filename.should == "validate_doc_update.js"
|
180
|
-
end
|
181
|
-
|
182
|
-
it "should append lists/my_list" do
|
183
|
-
@doc.hash = { "lists" => { "my_list" => "value" } }
|
184
|
-
filename = nil
|
185
|
-
@doc.write do |key, value|
|
186
|
-
filename = key
|
187
|
-
end
|
188
|
-
filename.should == "lists/my_list.js"
|
189
|
-
end
|
190
|
-
|
191
|
-
it "should append views/my_view/map" do
|
192
|
-
@doc.hash = { "views" => { "my_view" => { "map" => "value" } } }
|
193
|
-
filename = nil
|
194
|
-
@doc.write do |key, value|
|
195
|
-
filename = key
|
196
|
-
end
|
197
|
-
filename.should == "views/my_view/map.js"
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
describe "code makro" do
|
202
|
-
it "should reject code" do
|
203
|
-
@doc.hash = { "key" => "value", "lib" => { "code.js" => "value" } }
|
204
|
-
content = nil
|
205
|
-
@doc.write do |key, value|
|
206
|
-
content = value
|
207
|
-
end
|
208
|
-
@doc.hash.should == { "key" => "// !code code.js", "lib" => { "code.js" => "value" } }
|
209
|
-
content.should == "// !code code.js"
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
describe "json makro" do
|
214
|
-
it "should reject json" do
|
215
|
-
@doc.hash = { "key" => "var json = \"value\";", "lib" => { "json.json" => "value" } }
|
216
|
-
content = nil
|
217
|
-
@doc.write do |key, value|
|
218
|
-
content = value
|
219
|
-
end
|
220
|
-
@doc.hash.should == { "key" => "// !json json.json", "lib" => { "json.json" => "value" } }
|
221
|
-
content.should == "// !json json.json"
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
describe "json" do
|
227
|
-
it "should convert key-value pair" do
|
228
|
-
@doc.hash = { "key" => "value" }
|
229
|
-
@doc.json.should == '{"key":"value"}'
|
230
|
-
end
|
231
|
-
|
232
|
-
it "should convert nested hash" do
|
233
|
-
@doc.hash = { "hash" => { "key" => "value" } }
|
234
|
-
@doc.json.should == '{"hash":{"key":"value"}}'
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
describe "json=" do
|
239
|
-
it "should read key-value pair" do
|
240
|
-
@doc.json = '{"key":"value"}'
|
241
|
-
@doc.hash.should == { "key" => "value" }
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should read nested hash" do
|
245
|
-
@doc.json = '{"hash":{"key":"value"}}'
|
246
|
-
@doc.hash.should == { "hash" => { "key" => "value" } }
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
describe "id accessor" do
|
251
|
-
it "should return id from hash" do
|
252
|
-
@doc.hash = { "_id" => "my_id" }
|
253
|
-
@doc.id.should == "my_id"
|
254
|
-
end
|
255
|
-
|
256
|
-
it "should return id from couch" do
|
257
|
-
Couch.stub!(:id).and_return("my_id")
|
258
|
-
@doc.hash = {}
|
259
|
-
@doc.id.should == "my_id"
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
describe "rev accessor" do
|
264
|
-
it "should return rev from hash" do
|
265
|
-
@doc.hash = { "_rev" => "my_rev" }
|
266
|
-
@doc.rev.should == "my_rev"
|
267
|
-
end
|
268
|
-
|
269
|
-
it "should return rev from couch" do
|
270
|
-
Couch.stub!(:rev).and_return("my_rev")
|
271
|
-
@doc.hash = {}
|
272
|
-
@doc.rev.should == "my_rev"
|
273
|
-
end
|
274
|
-
|
275
|
-
it "should update rev in hash" do
|
276
|
-
@doc.hash = {}
|
277
|
-
@doc.rev = "my_rev"
|
278
|
-
@doc.hash.should == { "_rev" => "my_rev" }
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
describe "database accessor" do
|
283
|
-
it "should return database couch" do
|
284
|
-
Couch.stub!(:database).and_return("my_db")
|
285
|
-
@doc.database.should == "my_db"
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
describe "base url" do
|
290
|
-
it "should combine database and id" do
|
291
|
-
@doc.should_receive(:id).and_return("my_id")
|
292
|
-
@doc.should_receive(:database).and_return("my_db")
|
293
|
-
@doc.base_url.should == "my_db/my_id"
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
describe "url" do
|
298
|
-
it "should return base_url without options" do
|
299
|
-
@doc.should_receive(:base_url).and_return("my_base_url")
|
300
|
-
@doc.url.should == "my_base_url"
|
301
|
-
end
|
302
|
-
|
303
|
-
it "should return base_url with options string" do
|
304
|
-
@doc.should_receive(:base_url).and_return("my_base_url")
|
305
|
-
@doc.url(:key => :value).should == "my_base_url?key=value"
|
306
|
-
end
|
307
|
-
|
308
|
-
it "should return base_url with properly escaped options string" do
|
309
|
-
@doc.should_receive(:base_url).and_return("my_base_url")
|
310
|
-
@doc.url(:key => "value value").should == "my_base_url?key=value%20value"
|
311
|
-
end
|
312
|
-
end
|
313
|
-
end
|