couchrest 0.33 → 0.34
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -127
- data/Rakefile +20 -36
- data/THANKS.md +2 -1
- data/history.txt +25 -0
- data/lib/couchrest.rb +5 -4
- data/lib/couchrest/core/database.rb +26 -21
- data/lib/couchrest/core/document.rb +4 -3
- data/lib/couchrest/helper/streamer.rb +11 -4
- data/lib/couchrest/mixins/attribute_protection.rb +74 -0
- data/lib/couchrest/mixins/callbacks.rb +187 -138
- data/lib/couchrest/mixins/collection.rb +3 -16
- data/lib/couchrest/mixins/extended_attachments.rb +1 -1
- data/lib/couchrest/mixins/extended_document_mixins.rb +1 -0
- data/lib/couchrest/mixins/properties.rb +71 -44
- data/lib/couchrest/mixins/validation.rb +18 -29
- data/lib/couchrest/more/casted_model.rb +29 -1
- data/lib/couchrest/more/extended_document.rb +73 -25
- data/lib/couchrest/more/property.rb +20 -1
- data/lib/couchrest/support/class.rb +81 -67
- data/lib/couchrest/support/rails.rb +12 -5
- data/lib/couchrest/validation/auto_validate.rb +5 -9
- data/lib/couchrest/validation/validators/confirmation_validator.rb +11 -3
- data/lib/couchrest/validation/validators/format_validator.rb +8 -3
- data/lib/couchrest/validation/validators/length_validator.rb +10 -5
- data/lib/couchrest/validation/validators/numeric_validator.rb +6 -1
- data/lib/couchrest/validation/validators/required_field_validator.rb +8 -3
- data/spec/couchrest/core/couchrest_spec.rb +48 -2
- data/spec/couchrest/core/database_spec.rb +22 -10
- data/spec/couchrest/core/document_spec.rb +9 -1
- data/spec/couchrest/helpers/streamer_spec.rb +31 -2
- data/spec/couchrest/more/attribute_protection_spec.rb +94 -0
- data/spec/couchrest/more/casted_extended_doc_spec.rb +2 -4
- data/spec/couchrest/more/casted_model_spec.rb +230 -1
- data/spec/couchrest/more/extended_doc_attachment_spec.rb +2 -2
- data/spec/couchrest/more/extended_doc_spec.rb +173 -15
- data/spec/couchrest/more/extended_doc_view_spec.rb +17 -10
- data/spec/couchrest/more/property_spec.rb +97 -3
- data/spec/fixtures/more/article.rb +4 -3
- data/spec/fixtures/more/card.rb +1 -1
- data/spec/fixtures/more/cat.rb +5 -3
- data/spec/fixtures/more/event.rb +4 -1
- data/spec/fixtures/more/invoice.rb +2 -2
- data/spec/fixtures/more/person.rb +1 -0
- data/spec/fixtures/more/user.rb +22 -0
- metadata +46 -13
@@ -32,9 +32,28 @@ module CouchRest
|
|
32
32
|
@alias = options.delete(:alias) if options[:alias]
|
33
33
|
@default = options.delete(:default) unless options[:default].nil?
|
34
34
|
@casted = options[:casted] ? true : false
|
35
|
-
@init_method = options[:
|
35
|
+
@init_method = options[:init_method] ? options.delete(:init_method) : 'new'
|
36
36
|
@options = options
|
37
37
|
end
|
38
38
|
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
class CastedArray < Array
|
43
|
+
attr_accessor :casted_by
|
44
|
+
|
45
|
+
def << obj
|
46
|
+
obj.casted_by = self.casted_by if obj.respond_to?(:casted_by)
|
47
|
+
super(obj)
|
48
|
+
end
|
49
|
+
|
50
|
+
def push(obj)
|
51
|
+
obj.casted_by = self.casted_by if obj.respond_to?(:casted_by)
|
52
|
+
super(obj)
|
53
|
+
end
|
54
|
+
|
55
|
+
def []= index, obj
|
56
|
+
obj.casted_by = self.casted_by if obj.respond_to?(:casted_by)
|
57
|
+
super(index, obj)
|
58
|
+
end
|
59
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# Copyright (c)
|
2
|
-
#
|
1
|
+
# Copyright (c) 2006-2009 David Heinemeier Hansson
|
2
|
+
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
# a copy of this software and associated documentation files (the
|
5
5
|
# "Software"), to deal in the Software without restriction, including
|
@@ -7,10 +7,10 @@
|
|
7
7
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
8
|
# permit persons to whom the Software is furnished to do so, subject to
|
9
9
|
# the following conditions:
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# The above copyright notice and this permission notice shall be
|
12
12
|
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
16
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -18,79 +18,59 @@
|
|
18
18
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
-
|
22
|
-
#
|
23
|
-
#
|
24
|
-
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
21
|
+
#
|
22
|
+
# Extracted From
|
23
|
+
# http://github.com/rails/rails/commit/971e2438d98326c994ec6d3ef8e37b7e868ed6e2
|
24
|
+
|
25
|
+
# Extends the class object with class and instance accessors for class attributes,
|
26
|
+
# just like the native attr* accessors for instance attributes.
|
27
|
+
#
|
28
|
+
# class Person
|
29
|
+
# cattr_accessor :hair_colors
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# Person.hair_colors = [:brown, :black, :blonde, :red]
|
28
33
|
class Class
|
29
|
-
# Defines class-level and instance-level attribute reader.
|
30
|
-
#
|
31
|
-
# @param *syms<Array> Array of attributes to define reader for.
|
32
|
-
# @return <Array[#to_s]> List of attributes that were made into cattr_readers
|
33
|
-
#
|
34
|
-
# @api public
|
35
|
-
#
|
36
|
-
# @todo Is this inconsistent in that it does not allow you to prevent
|
37
|
-
# an instance_reader via :instance_reader => false
|
38
34
|
def cattr_reader(*syms)
|
39
35
|
syms.flatten.each do |sym|
|
40
36
|
next if sym.is_a?(Hash)
|
41
|
-
class_eval(<<-
|
42
|
-
unless defined? @@#{sym}
|
43
|
-
@@#{sym} = nil
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.#{sym}
|
47
|
-
@@#{sym}
|
48
|
-
end
|
49
|
-
|
50
|
-
def #{sym}
|
51
|
-
@@#{sym}
|
52
|
-
end
|
53
|
-
|
37
|
+
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
38
|
+
unless defined? @@#{sym} # unless defined? @@hair_colors
|
39
|
+
@@#{sym} = nil # @@hair_colors = nil
|
40
|
+
end # end
|
41
|
+
#
|
42
|
+
def self.#{sym} # def self.hair_colors
|
43
|
+
@@#{sym} # @@hair_colors
|
44
|
+
end # end
|
45
|
+
#
|
46
|
+
def #{sym} # def hair_colors
|
47
|
+
@@#{sym} # @@hair_colors
|
48
|
+
end # end
|
49
|
+
EOS
|
54
50
|
end
|
55
51
|
end unless Class.respond_to?(:cattr_reader)
|
56
52
|
|
57
|
-
# Defines class-level (and optionally instance-level) attribute writer.
|
58
|
-
#
|
59
|
-
# @param <Array[*#to_s, Hash{:instance_writer => Boolean}]> Array of attributes to define writer for.
|
60
|
-
# @option syms :instance_writer<Boolean> if true, instance-level attribute writer is defined.
|
61
|
-
# @return <Array[#to_s]> List of attributes that were made into cattr_writers
|
62
|
-
#
|
63
|
-
# @api public
|
64
53
|
def cattr_writer(*syms)
|
65
|
-
options = syms.
|
54
|
+
options = syms.extract_options!
|
66
55
|
syms.flatten.each do |sym|
|
67
|
-
class_eval(<<-
|
68
|
-
unless defined? @@#{sym}
|
69
|
-
@@#{sym} = nil
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.#{sym}=(obj)
|
73
|
-
@@#{sym} = obj
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
RUBY
|
83
|
-
end
|
56
|
+
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
57
|
+
unless defined? @@#{sym} # unless defined? @@hair_colors
|
58
|
+
@@#{sym} = nil # @@hair_colors = nil
|
59
|
+
end # end
|
60
|
+
#
|
61
|
+
def self.#{sym}=(obj) # def self.hair_colors=(obj)
|
62
|
+
@@#{sym} = obj # @@hair_colors = obj
|
63
|
+
end # end
|
64
|
+
#
|
65
|
+
#{" #
|
66
|
+
def #{sym}=(obj) # def hair_colors=(obj)
|
67
|
+
@@#{sym} = obj # @@hair_colors = obj
|
68
|
+
end # end
|
69
|
+
" unless options[:instance_writer] == false } # # instance writer above is generated unless options[:instance_writer] == false
|
70
|
+
EOS
|
84
71
|
end
|
85
72
|
end unless Class.respond_to?(:cattr_writer)
|
86
73
|
|
87
|
-
# Defines class-level (and optionally instance-level) attribute accessor.
|
88
|
-
#
|
89
|
-
# @param *syms<Array[*#to_s, Hash{:instance_writer => Boolean}]> Array of attributes to define accessor for.
|
90
|
-
# @option syms :instance_writer<Boolean> if true, instance-level attribute writer is defined.
|
91
|
-
# @return <Array[#to_s]> List of attributes that were made into accessors
|
92
|
-
#
|
93
|
-
# @api public
|
94
74
|
def cattr_accessor(*syms)
|
95
75
|
cattr_reader(*syms)
|
96
76
|
cattr_writer(*syms)
|
@@ -156,6 +136,8 @@ class Class
|
|
156
136
|
def #{ivar}=(obj) self.class.#{ivar} = obj end
|
157
137
|
RUBY
|
158
138
|
end
|
139
|
+
|
140
|
+
self.send("#{ivar}=", yield) if block_given?
|
159
141
|
end
|
160
142
|
end unless Class.respond_to?(:extlib_inheritable_writer)
|
161
143
|
|
@@ -168,9 +150,41 @@ class Class
|
|
168
150
|
# @return <Array[#to_s]> An Array of attributes turned into inheritable accessors.
|
169
151
|
#
|
170
152
|
# @api public
|
171
|
-
def extlib_inheritable_accessor(*syms)
|
153
|
+
def extlib_inheritable_accessor(*syms, &block)
|
172
154
|
extlib_inheritable_reader(*syms)
|
173
|
-
extlib_inheritable_writer(*syms)
|
155
|
+
extlib_inheritable_writer(*syms, &block)
|
174
156
|
end unless Class.respond_to?(:extlib_inheritable_accessor)
|
175
157
|
end
|
176
158
|
|
159
|
+
class Array
|
160
|
+
# Extracts options from a set of arguments. Removes and returns the last
|
161
|
+
# element in the array if it's a hash, otherwise returns a blank hash.
|
162
|
+
#
|
163
|
+
# def options(*args)
|
164
|
+
# args.extract_options!
|
165
|
+
# end
|
166
|
+
#
|
167
|
+
# options(1, 2) # => {}
|
168
|
+
# options(1, 2, :a => :b) # => {:a=>:b}
|
169
|
+
def extract_options!
|
170
|
+
last.is_a?(::Hash) ? pop : {}
|
171
|
+
end unless Array.new.respond_to?(:extract_options!)
|
172
|
+
|
173
|
+
# Wraps the object in an Array unless it's an Array. Converts the
|
174
|
+
# object to an Array using #to_ary if it implements that.
|
175
|
+
def self.wrap(object)
|
176
|
+
case object
|
177
|
+
when nil
|
178
|
+
[]
|
179
|
+
when self
|
180
|
+
object
|
181
|
+
else
|
182
|
+
if object.respond_to?(:to_ary)
|
183
|
+
object.to_ary
|
184
|
+
else
|
185
|
+
[object]
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end unless Array.respond_to?(:wrap)
|
189
|
+
end
|
190
|
+
|
@@ -1,8 +1,4 @@
|
|
1
1
|
# This file contains various hacks for Rails compatibility.
|
2
|
-
# To use, just require in environment.rb, like so:
|
3
|
-
#
|
4
|
-
# require 'couchrest/support/rails'
|
5
|
-
|
6
2
|
class Hash
|
7
3
|
# Hack so that CouchRest::Document, which descends from Hash,
|
8
4
|
# doesn't appear to Rails routing as a Hash of options
|
@@ -12,8 +8,10 @@ class Hash
|
|
12
8
|
end
|
13
9
|
end
|
14
10
|
|
15
|
-
|
16
11
|
CouchRest::Document.class_eval do
|
12
|
+
# Need this when passing doc to a resourceful route
|
13
|
+
alias_method :to_param, :id
|
14
|
+
|
17
15
|
# Hack so that CouchRest::Document, which descends from Hash,
|
18
16
|
# doesn't appear to Rails routing as a Hash of options
|
19
17
|
def is_a?(o)
|
@@ -23,6 +21,15 @@ CouchRest::Document.class_eval do
|
|
23
21
|
alias_method :kind_of?, :is_a?
|
24
22
|
end
|
25
23
|
|
24
|
+
CouchRest::CastedModel.class_eval do
|
25
|
+
# The to_param method is needed for rails to generate resourceful routes.
|
26
|
+
# In your controller, remember that it's actually the id of the document.
|
27
|
+
def id
|
28
|
+
return nil if base_doc.nil?
|
29
|
+
base_doc.id
|
30
|
+
end
|
31
|
+
alias_method :to_param, :id
|
32
|
+
end
|
26
33
|
|
27
34
|
require Pathname.new(File.dirname(__FILE__)).join('..', 'validation', 'validation_errors')
|
28
35
|
|
@@ -65,7 +65,7 @@ module CouchRest
|
|
65
65
|
# validator to be automatically created on the property
|
66
66
|
#
|
67
67
|
# Integer type
|
68
|
-
# Using a Integer type causes a
|
68
|
+
# Using a Integer type causes a validates_numericality_of
|
69
69
|
# validator to be created for the property. integer_only
|
70
70
|
# is set to true
|
71
71
|
#
|
@@ -97,8 +97,7 @@ module CouchRest
|
|
97
97
|
|
98
98
|
# presence
|
99
99
|
if opts[:allow_nil] == false
|
100
|
-
|
101
|
-
validates_present property.name, options_with_message(opts, property, :presence)
|
100
|
+
validates_presence_of property.name, options_with_message(opts, property, :presence)
|
102
101
|
end
|
103
102
|
|
104
103
|
# length
|
@@ -111,8 +110,7 @@ module CouchRest
|
|
111
110
|
else
|
112
111
|
opts[:maximum] = len
|
113
112
|
end
|
114
|
-
|
115
|
-
validates_length property.name, options_with_message(opts, property, :length)
|
113
|
+
validates_length_of property.name, options_with_message(opts, property, :length)
|
116
114
|
end
|
117
115
|
|
118
116
|
# format
|
@@ -142,13 +140,11 @@ module CouchRest
|
|
142
140
|
# numeric validator
|
143
141
|
if "Integer" == property.type
|
144
142
|
opts[:integer_only] = true
|
145
|
-
|
146
|
-
validates_is_number property.name, options_with_message(opts, property, :is_number)
|
143
|
+
validates_numericality_of property.name, options_with_message(opts, property, :is_number)
|
147
144
|
elsif Float == property.type
|
148
145
|
opts[:precision] = property.precision
|
149
146
|
opts[:scale] = property.scale
|
150
|
-
|
151
|
-
validates_is_number property.name, options_with_message(opts, property, :is_number)
|
147
|
+
validates_numericality_of property.name, options_with_message(opts, property, :is_number)
|
152
148
|
end
|
153
149
|
|
154
150
|
# marked the property has checked
|
@@ -81,18 +81,26 @@ module CouchRest
|
|
81
81
|
# attr_accessor :password_confirmation
|
82
82
|
# attr_accessor :email_repeated
|
83
83
|
#
|
84
|
-
#
|
85
|
-
#
|
84
|
+
# validates_confirmation_of :password
|
85
|
+
# validates_confirmation_of :email, :confirm => :email_repeated
|
86
86
|
#
|
87
87
|
# # a call to valid? will return false unless:
|
88
88
|
# # password == password_confirmation
|
89
89
|
# # and
|
90
90
|
# # email == email_repeated
|
91
91
|
#
|
92
|
-
def
|
92
|
+
def validates_confirmation_of(*fields)
|
93
93
|
opts = opts_from_validator_args(fields)
|
94
94
|
add_validator_to_context(opts, fields, CouchRest::Validation::ConfirmationValidator)
|
95
95
|
end
|
96
|
+
|
97
|
+
def validates_is_confirmed(*fields)
|
98
|
+
warn "[DEPRECATION] `validates_is_confirmed` is deprecated. Please use `validates_confirmation_of` instead."
|
99
|
+
validates_confirmation_of(*fields)
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
|
96
104
|
|
97
105
|
end # module ValidatesIsConfirmed
|
98
106
|
end # module Validation
|
@@ -99,18 +99,23 @@ module CouchRest
|
|
99
99
|
# property :email, String
|
100
100
|
# property :zip_code, String
|
101
101
|
#
|
102
|
-
#
|
103
|
-
#
|
102
|
+
# validates_format_of :email, :as => :email_address
|
103
|
+
# validates_format_of :zip_code, :with => /^\d{5}$/
|
104
104
|
#
|
105
105
|
# # a call to valid? will return false unless:
|
106
106
|
# # email is formatted like an email address
|
107
107
|
# # and
|
108
108
|
# # zip_code is a string of 5 digits
|
109
109
|
#
|
110
|
-
def
|
110
|
+
def validates_format_of(*fields)
|
111
111
|
opts = opts_from_validator_args(fields)
|
112
112
|
add_validator_to_context(opts, fields, CouchRest::Validation::FormatValidator)
|
113
113
|
end
|
114
|
+
|
115
|
+
def validates_format(*fields)
|
116
|
+
warn "[DEPRECATION] `validates_format` is deprecated. Please use `validates_format_of` instead."
|
117
|
+
validates_format_of(*fields)
|
118
|
+
end
|
114
119
|
|
115
120
|
end # module ValidatesFormat
|
116
121
|
end # module Validation
|
@@ -115,20 +115,25 @@ module CouchRest
|
|
115
115
|
# property low, Integer
|
116
116
|
# property just_right, Integer
|
117
117
|
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
118
|
+
# validates_length_of :high, :min => 100000000000
|
119
|
+
# validates_length_of :low, :equals => 0
|
120
|
+
# validates_length_of :just_right, :within => 1..10
|
121
121
|
#
|
122
122
|
# # a call to valid? will return false unless:
|
123
123
|
# # high is greater than or equal to 100000000000
|
124
124
|
# # low is equal to 0
|
125
125
|
# # just_right is between 1 and 10 (inclusive of both 1 and 10)
|
126
126
|
#
|
127
|
-
def
|
127
|
+
def validates_length_of(*fields)
|
128
128
|
opts = opts_from_validator_args(fields)
|
129
129
|
add_validator_to_context(opts, fields, CouchRest::Validation::LengthValidator)
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
|
+
def validates_length(*fields)
|
133
|
+
warn "[DEPRECATION] `validates_length` is deprecated. Please use `validates_length_of` instead."
|
134
|
+
validates_length_of(*fields)
|
135
|
+
end
|
136
|
+
|
132
137
|
end # module ValidatesLength
|
133
138
|
end # module Validation
|
134
139
|
end # module CouchRest
|
@@ -94,10 +94,15 @@ module CouchRest
|
|
94
94
|
|
95
95
|
# Validate whether a field is numeric
|
96
96
|
#
|
97
|
-
def
|
97
|
+
def validates_numericality_of(*fields)
|
98
98
|
opts = opts_from_validator_args(fields)
|
99
99
|
add_validator_to_context(opts, fields, CouchRest::Validation::NumericValidator)
|
100
100
|
end
|
101
|
+
|
102
|
+
def validates_is_number(*fields)
|
103
|
+
warn "[DEPRECATION] `validates_is_number` is deprecated. Please use `validates_numericality_of` instead."
|
104
|
+
validates_numericality_of(*fields)
|
105
|
+
end
|
101
106
|
|
102
107
|
end # module ValidatesIsNumber
|
103
108
|
end # module Validation
|
@@ -93,16 +93,21 @@ module CouchRest
|
|
93
93
|
# property :another_required, String
|
94
94
|
# property :yet_again, String
|
95
95
|
#
|
96
|
-
#
|
97
|
-
#
|
96
|
+
# validates_presence_of :required_attribute
|
97
|
+
# validates_presence_of :another_required, :yet_again
|
98
98
|
#
|
99
99
|
# # a call to valid? will return false unless
|
100
100
|
# # all three attributes are !blank?
|
101
101
|
# end
|
102
|
-
def
|
102
|
+
def validates_presence_of(*fields)
|
103
103
|
opts = opts_from_validator_args(fields)
|
104
104
|
add_validator_to_context(opts, fields, CouchRest::Validation::RequiredFieldValidator)
|
105
105
|
end
|
106
|
+
|
107
|
+
def validates_present(*fields)
|
108
|
+
warn "[DEPRECATION] `validates_present` is deprecated. Please use `validates_presence_of` instead."
|
109
|
+
validates_presence_of(*fields)
|
110
|
+
end
|
106
111
|
|
107
112
|
end # module ValidatesPresent
|
108
113
|
end # module Validation
|
@@ -54,7 +54,7 @@ describe CouchRest do
|
|
54
54
|
db[:host].should == "127.0.0.1"
|
55
55
|
end
|
56
56
|
it "should parse a host and db with http" do
|
57
|
-
db = CouchRest.parse "
|
57
|
+
db = CouchRest.parse "https://127.0.0.1/my-db"
|
58
58
|
db[:database].should == "my-db"
|
59
59
|
db[:host].should == "127.0.0.1"
|
60
60
|
end
|
@@ -68,16 +68,31 @@ describe CouchRest do
|
|
68
68
|
db[:database].should == "my-db"
|
69
69
|
db[:host].should == "127.0.0.1:5555"
|
70
70
|
end
|
71
|
+
it "should parse a host with a port and db with https" do
|
72
|
+
db = CouchRest.parse "https://127.0.0.1:5555/my-db"
|
73
|
+
db[:database].should == "my-db"
|
74
|
+
db[:host].should == "127.0.0.1:5555"
|
75
|
+
end
|
71
76
|
it "should parse just a host" do
|
72
77
|
db = CouchRest.parse "http://127.0.0.1:5555/"
|
73
78
|
db[:database].should be_nil
|
74
79
|
db[:host].should == "127.0.0.1:5555"
|
75
80
|
end
|
81
|
+
it "should parse just a host with https" do
|
82
|
+
db = CouchRest.parse "https://127.0.0.1:5555/"
|
83
|
+
db[:database].should be_nil
|
84
|
+
db[:host].should == "127.0.0.1:5555"
|
85
|
+
end
|
76
86
|
it "should parse just a host no slash" do
|
77
87
|
db = CouchRest.parse "http://127.0.0.1:5555"
|
78
88
|
db[:host].should == "127.0.0.1:5555"
|
79
89
|
db[:database].should be_nil
|
80
90
|
end
|
91
|
+
it "should parse just a host no slash and https" do
|
92
|
+
db = CouchRest.parse "https://127.0.0.1:5555"
|
93
|
+
db[:host].should == "127.0.0.1:5555"
|
94
|
+
db[:database].should be_nil
|
95
|
+
end
|
81
96
|
it "should get docid" do
|
82
97
|
db = CouchRest.parse "127.0.0.1:5555/my-db/my-doc"
|
83
98
|
db[:database].should == "my-db"
|
@@ -90,7 +105,12 @@ describe CouchRest do
|
|
90
105
|
db[:host].should == "127.0.0.1:5555"
|
91
106
|
db[:doc].should == "my-doc"
|
92
107
|
end
|
93
|
-
|
108
|
+
it "should get docid with https" do
|
109
|
+
db = CouchRest.parse "https://127.0.0.1:5555/my-db/my-doc"
|
110
|
+
db[:database].should == "my-db"
|
111
|
+
db[:host].should == "127.0.0.1:5555"
|
112
|
+
db[:doc].should == "my-doc"
|
113
|
+
end
|
94
114
|
it "should parse a host and db" do
|
95
115
|
db = CouchRest.parse "127.0.0.1/my-db"
|
96
116
|
db[:database].should == "my-db"
|
@@ -101,6 +121,11 @@ describe CouchRest do
|
|
101
121
|
db[:database].should == "my-db"
|
102
122
|
db[:host].should == "127.0.0.1"
|
103
123
|
end
|
124
|
+
it "should parse a host and db with https" do
|
125
|
+
db = CouchRest.parse "https://127.0.0.1/my-db"
|
126
|
+
db[:database].should == "my-db"
|
127
|
+
db[:host].should == "127.0.0.1"
|
128
|
+
end
|
104
129
|
it "should parse a host with a port and db" do
|
105
130
|
db = CouchRest.parse "127.0.0.1:5555/my-db"
|
106
131
|
db[:database].should == "my-db"
|
@@ -111,16 +136,31 @@ describe CouchRest do
|
|
111
136
|
db[:database].should == "my-db"
|
112
137
|
db[:host].should == "127.0.0.1:5555"
|
113
138
|
end
|
139
|
+
it "should parse a host with a port and db with https" do
|
140
|
+
db = CouchRest.parse "http://127.0.0.1:5555/my-db"
|
141
|
+
db[:database].should == "my-db"
|
142
|
+
db[:host].should == "127.0.0.1:5555"
|
143
|
+
end
|
114
144
|
it "should parse just a host" do
|
115
145
|
db = CouchRest.parse "http://127.0.0.1:5555/"
|
116
146
|
db[:database].should be_nil
|
117
147
|
db[:host].should == "127.0.0.1:5555"
|
118
148
|
end
|
149
|
+
it "should parse just a host with https" do
|
150
|
+
db = CouchRest.parse "https://127.0.0.1:5555/"
|
151
|
+
db[:database].should be_nil
|
152
|
+
db[:host].should == "127.0.0.1:5555"
|
153
|
+
end
|
119
154
|
it "should parse just a host no slash" do
|
120
155
|
db = CouchRest.parse "http://127.0.0.1:5555"
|
121
156
|
db[:host].should == "127.0.0.1:5555"
|
122
157
|
db[:database].should be_nil
|
123
158
|
end
|
159
|
+
it "should parse just a host no slash and https" do
|
160
|
+
db = CouchRest.parse "https://127.0.0.1:5555"
|
161
|
+
db[:host].should == "127.0.0.1:5555"
|
162
|
+
db[:database].should be_nil
|
163
|
+
end
|
124
164
|
it "should get docid" do
|
125
165
|
db = CouchRest.parse "127.0.0.1:5555/my-db/my-doc"
|
126
166
|
db[:database].should == "my-db"
|
@@ -133,6 +173,12 @@ describe CouchRest do
|
|
133
173
|
db[:host].should == "127.0.0.1:5555"
|
134
174
|
db[:doc].should == "my-doc"
|
135
175
|
end
|
176
|
+
it "should get docid with https" do
|
177
|
+
db = CouchRest.parse "https://127.0.0.1:5555/my-db/my-doc"
|
178
|
+
db[:database].should == "my-db"
|
179
|
+
db[:host].should == "127.0.0.1:5555"
|
180
|
+
db[:doc].should == "my-doc"
|
181
|
+
end
|
136
182
|
end
|
137
183
|
|
138
184
|
describe "easy initializing a database adapter" do
|