couchrest_model 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +72 -49
- data/VERSION +1 -1
- data/couchrest_model.gemspec +1 -0
- data/history.md +6 -0
- data/lib/couchrest/model/base.rb +1 -1
- data/lib/couchrest/model/connection.rb +10 -4
- data/lib/couchrest/model/designs/view.rb +13 -5
- data/lib/couchrest/model/persistence.rb +7 -0
- data/spec/unit/base_spec.rb +0 -47
- data/spec/unit/connection_spec.rb +22 -3
- data/spec/unit/designs/view_spec.rb +12 -3
- data/spec/unit/persistence_spec.rb +6 -0
- data/spec/unit/properties_spec.rb +77 -0
- metadata +23 -42
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e473840521261d3dfe005eea56cd1585b4b245f4
|
4
|
+
data.tar.gz: 1df0369dc5e7a80c4d681eb9efdbb939f0df77f5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b8d8ded40ab8343e7f2e13969af3e319d1989724024b50ec00b3736d0b88eb0b118f807cf6e92a74d508b19581ff14a5e33b05a5d80cb14285c00e25794948e3
|
7
|
+
data.tar.gz: 31b1ecc35ec710094bec15bfa04fb2fa0eb3c208b966d787988fbfdd0bcd3c643684242f4508f98f6111d8f4075081e540b9969ab65050129054c4e85859721d
|
data/README.md
CHANGED
@@ -1,25 +1,21 @@
|
|
1
|
-
# CouchRest Model
|
1
|
+
# CouchRest Model
|
2
2
|
|
3
|
-
|
4
|
-
setting properties, callbacks, typecasting, and validations.
|
3
|
+
[![Build Status](https://travis-ci.org/couchrest/couchrest_model.png)](https://travis-ci.org/couchrest/couchrest_model)
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
Please visit the documentation project at [http://www.couchrest.info](http://www.couchrest.info). You're [contributions](https://github.com/couchrest/couchrest.github.com) to the documentation would be greatly appreciated!
|
5
|
+
CouchRest Model helps you define models that are stored as documents in your CouchDB database.
|
9
6
|
|
10
|
-
|
7
|
+
It supports useful features such as setting properties with typecasting, callbacks, validations, associations, and helps
|
8
|
+
with creating CouchDB views to access your data.
|
11
9
|
|
12
|
-
|
10
|
+
CouchRest Model uses ActiveModel for a lot of the magic, so if you're using Rails, you'll need at least version 3.0. The latest release (since 2.0.0) is Rails 4.0 compatible, and we recommend Ruby 2.0+.
|
13
11
|
|
14
|
-
##
|
12
|
+
## Documentation
|
15
13
|
|
16
|
-
|
17
|
-
for validations and callbacks.
|
14
|
+
Please visit the documentation project at [http://www.couchrest.info](http://www.couchrest.info). Your [contributions](https://github.com/couchrest/couchrest.github.com) would be greatly appreciated!
|
18
15
|
|
19
|
-
|
20
|
-
it is not possible to load ActiveModel into programs that do not use ActiveSupport 3.0.
|
16
|
+
General API: [http://rdoc.info/projects/couchrest/couchrest_model](http://rdoc.info/projects/couchrest/couchrest_model)
|
21
17
|
|
22
|
-
|
18
|
+
See the [update history](https://github.com/couchrest/couchrest_model/blob/master/history.md) for an up to date list of all the changes we've been working on recently.
|
23
19
|
|
24
20
|
### Upgrading from an earlier version?
|
25
21
|
|
@@ -27,23 +23,27 @@ CouchRest Model is only properly tested on CouchDB version 1.0 or newer.
|
|
27
23
|
|
28
24
|
*Pre 1.1:* As of April 2011 and the release of version 1.1.0, the default model type key is 'type' instead of 'couchrest-type'. Simply updating your project will not work unless you migrate your data or set the configuration option in your initializers:
|
29
25
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
```ruby
|
27
|
+
CouchRest::Model::Base.configure do |config|
|
28
|
+
config.model_type_key = 'couchrest-type'
|
29
|
+
end
|
30
|
+
```
|
35
31
|
|
36
32
|
## Install
|
37
33
|
|
38
34
|
### Gem
|
39
35
|
|
40
|
-
|
36
|
+
```bash
|
37
|
+
$ sudo gem install couchrest_model
|
38
|
+
```
|
41
39
|
|
42
40
|
### Bundler
|
43
41
|
|
44
42
|
If you're using bundler, define a line similar to the following in your project's Gemfile:
|
45
43
|
|
46
|
-
|
44
|
+
```ruby
|
45
|
+
gem 'couchrest_model'
|
46
|
+
```
|
47
47
|
|
48
48
|
### Configuration
|
49
49
|
|
@@ -64,56 +64,77 @@ Note that the name of the database is either just the prefix and suffix combined
|
|
64
64
|
|
65
65
|
The example config above for example would use a database called "project_test". Heres an example using the `use_database` call:
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
```ruby
|
68
|
+
class Project < CouchRest::Model::Base
|
69
|
+
use_database 'sample'
|
70
|
+
end
|
71
|
+
|
72
|
+
# The database object would be provided as:
|
73
|
+
Project.database #=> "https://test:user@sample.cloudant.com:443/project_sample_test"
|
74
|
+
```
|
75
|
+
|
76
|
+
### Using instead of ActiveRecord in Rails
|
77
|
+
|
78
|
+
A common use case for a new project is to replace ActiveRecord with CouchRest Model, although they should work perfectly well together. If you no longer want to depend on ActiveRecord or any of its sub-dependencies such as sqlite, update your `config/application.rb` so the top looks something like:
|
70
79
|
|
71
|
-
|
72
|
-
|
80
|
+
```ruby
|
81
|
+
# We don't need active record, so load everything but:
|
82
|
+
# require 'rails/all'
|
83
|
+
require 'action_controller/railtie'
|
84
|
+
require 'action_mailer/railtie'
|
85
|
+
require 'rails/test_unit/railtie'
|
86
|
+
```
|
73
87
|
|
88
|
+
You'll then need to make sure any references to `config.active_record` are removed from your environment files.
|
74
89
|
|
75
90
|
## Generators
|
76
91
|
|
77
92
|
### Configuration
|
78
93
|
|
79
|
-
|
94
|
+
```bash
|
95
|
+
$ rails generate couchrest_model:config
|
96
|
+
```
|
80
97
|
|
81
98
|
### Model
|
82
99
|
|
83
|
-
|
100
|
+
```bash
|
101
|
+
$ rails generate model person --orm=couchrest_model
|
102
|
+
```
|
84
103
|
|
85
104
|
## General Usage
|
86
105
|
|
87
|
-
|
106
|
+
```ruby
|
107
|
+
require 'couchrest_model'
|
88
108
|
|
89
|
-
|
109
|
+
class Cat < CouchRest::Model::Base
|
90
110
|
|
91
|
-
|
92
|
-
|
111
|
+
property :name, String
|
112
|
+
property :lives, Integer, :default => 9
|
93
113
|
|
94
|
-
|
114
|
+
property :nicknames, [String]
|
95
115
|
|
96
|
-
|
116
|
+
timestamps!
|
97
117
|
|
98
|
-
|
99
|
-
|
100
|
-
|
118
|
+
design do
|
119
|
+
view :by_name
|
120
|
+
end
|
101
121
|
|
102
|
-
|
122
|
+
end
|
103
123
|
|
104
|
-
|
124
|
+
@cat = Cat.new(:name => 'Felix', :nicknames => ['so cute', 'sweet kitty'])
|
105
125
|
|
106
|
-
|
107
|
-
|
126
|
+
@cat.new? # true
|
127
|
+
@cat.save
|
108
128
|
|
109
|
-
|
129
|
+
@cat['name'] # "Felix"
|
110
130
|
|
111
|
-
|
131
|
+
@cat.nicknames << 'getoffdamntable'
|
112
132
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
133
|
+
@cat = Cat.new
|
134
|
+
@cat.update_attributes(:name => 'Felix', :random_text => 'feline')
|
135
|
+
@cat.new? # false
|
136
|
+
@cat.random_text # Raises error!
|
137
|
+
```
|
117
138
|
|
118
139
|
## Development
|
119
140
|
|
@@ -121,7 +142,9 @@ The example config above for example would use a database called "project_test".
|
|
121
142
|
|
122
143
|
CouchRest Model now comes with a Gemfile to help with development. If you want to make changes to the code, download a copy then run:
|
123
144
|
|
124
|
-
|
145
|
+
```bash
|
146
|
+
bundle install
|
147
|
+
```
|
125
148
|
|
126
149
|
That should set everything up for `rake spec` to be run correctly. Update the couchrest_model.gemspec if your alterations
|
127
150
|
use different gems.
|
@@ -138,6 +161,6 @@ Please post bugs, suggestions and patches to the bug tracker at [http://github.c
|
|
138
161
|
|
139
162
|
Follow us on Twitter: [http://twitter.com/couchrest](http://twitter.com/couchrest)
|
140
163
|
|
141
|
-
Also, check [
|
164
|
+
Also, check [https://twitter.com/search?q=couchrest](https://twitter.com/search?q=couchrest)
|
142
165
|
|
143
166
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.1
|
data/couchrest_model.gemspec
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{couchrest_model}
|
5
5
|
s.version = `cat VERSION`.strip
|
6
|
+
s.license = "Apache License 2.0"
|
6
7
|
|
7
8
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
8
9
|
s.authors = ["J. Chris Anderson", "Matt Aimonetti", "Marcos Tapajos", "Will Leinweber", "Sam Lown"]
|
data/history.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# CouchRest Model Change History
|
2
2
|
|
3
|
+
## 2.0.1 - 2013-12-03
|
4
|
+
|
5
|
+
* nil keys in view requests are now sent to server, avoiding returning first document issue. (Thanks to @svoboda-jan for pointer.)
|
6
|
+
* lazy create database if using `use_database`
|
7
|
+
* added .model_type_value to persistence layer, so that model name can be overwrriten if required (issue #163)
|
8
|
+
|
3
9
|
## 2.0.0 - 2013-10-04
|
4
10
|
|
5
11
|
* Added design doc migration support, including for proxied models
|
data/lib/couchrest/model/base.rb
CHANGED
@@ -56,7 +56,7 @@ module CouchRest
|
|
56
56
|
# set the instance's database, if provided
|
57
57
|
self.database = options[:database] unless options[:database].nil?
|
58
58
|
unless self['_id'] && self['_rev']
|
59
|
-
self[self.model_type_key] = self.class.
|
59
|
+
self[self.model_type_key] = self.class.model_type_value
|
60
60
|
end
|
61
61
|
|
62
62
|
yield self if block_given?
|
@@ -11,14 +11,19 @@ module CouchRest
|
|
11
11
|
|
12
12
|
# Overwrite the normal use_database method so that a database
|
13
13
|
# name can be provided instead of a full connection.
|
14
|
+
# The actual database will be validated when it is requested for use.
|
15
|
+
# Note that this should not be used with proxied models!
|
14
16
|
def use_database(db)
|
15
|
-
@
|
17
|
+
@_use_database = db
|
16
18
|
end
|
17
19
|
|
18
20
|
# Overwrite the default database method so that it always
|
19
|
-
# provides something from the configuration
|
21
|
+
# provides something from the configuration.
|
22
|
+
# It will try to inherit the database from an ancester
|
23
|
+
# unless the use_database method has been used, in which
|
24
|
+
# case a new connection will be started.
|
20
25
|
def database
|
21
|
-
|
26
|
+
@database ||= prepare_database(super)
|
22
27
|
end
|
23
28
|
|
24
29
|
def server
|
@@ -26,7 +31,8 @@ module CouchRest
|
|
26
31
|
end
|
27
32
|
|
28
33
|
def prepare_database(db = nil)
|
29
|
-
unless
|
34
|
+
db = @_use_database unless @_use_database.nil?
|
35
|
+
if db.nil? || db.is_a?(String) || db.is_a?(Symbol)
|
30
36
|
conf = connection_configuration
|
31
37
|
db = [conf[:prefix], db.to_s, conf[:suffix]].reject{|s| s.to_s.empty?}.join(conf[:join])
|
32
38
|
self.server.database!(db)
|
@@ -20,7 +20,11 @@ module CouchRest
|
|
20
20
|
# outside CouchRest Model.
|
21
21
|
def initialize(design_doc, parent, new_query = {}, name = nil)
|
22
22
|
self.design_doc = design_doc
|
23
|
-
|
23
|
+
|
24
|
+
# Extrace important non-regular query values
|
25
|
+
proxy = new_query.delete(:proxy)
|
26
|
+
delete = new_query.delete(:delete)
|
27
|
+
|
24
28
|
if parent.is_a?(Class) && parent < CouchRest::Model::Base
|
25
29
|
raise "Name must be provided for view to be initialized" if name.nil?
|
26
30
|
self.model = (proxy || parent)
|
@@ -36,7 +40,11 @@ module CouchRest
|
|
36
40
|
else
|
37
41
|
raise "View cannot be initialized without a parent Model or View"
|
38
42
|
end
|
43
|
+
|
44
|
+
# Update the local query hash
|
39
45
|
query.update(new_query)
|
46
|
+
delete.each{|k| query.delete(k)} if delete
|
47
|
+
|
40
48
|
super()
|
41
49
|
end
|
42
50
|
|
@@ -276,7 +284,7 @@ module CouchRest
|
|
276
284
|
# will fail.
|
277
285
|
def reduce
|
278
286
|
raise "Cannot reduce a view without a reduce method" unless can_reduce?
|
279
|
-
update_query(:reduce => true, :
|
287
|
+
update_query(:reduce => true, :delete => [:include_docs])
|
280
288
|
end
|
281
289
|
|
282
290
|
# Control whether the reduce function reduces to a set of distinct keys
|
@@ -414,7 +422,7 @@ module CouchRest
|
|
414
422
|
|
415
423
|
design_doc.sync(use_database)
|
416
424
|
|
417
|
-
self.result = design_doc.view_on(use_database, name, query
|
425
|
+
self.result = design_doc.view_on(use_database, name, query)
|
418
426
|
end
|
419
427
|
|
420
428
|
# Class Methods
|
@@ -460,7 +468,7 @@ module CouchRest
|
|
460
468
|
if name.to_s == 'all'
|
461
469
|
opts[:map] = <<-EOF
|
462
470
|
function(doc) {
|
463
|
-
if (doc['#{model.model_type_key}'] == '#{model.
|
471
|
+
if (doc['#{model.model_type_key}'] == '#{model.model_type_value}') {
|
464
472
|
emit(doc._id, null);
|
465
473
|
}
|
466
474
|
}
|
@@ -473,7 +481,7 @@ module CouchRest
|
|
473
481
|
|
474
482
|
opts[:allow_blank] = opts[:allow_blank].nil? ? true : opts[:allow_blank]
|
475
483
|
opts[:guards] ||= []
|
476
|
-
opts[:guards].push "(doc['#{model.model_type_key}'] == '#{model.
|
484
|
+
opts[:guards].push "(doc['#{model.model_type_key}'] == '#{model.model_type_value}')"
|
477
485
|
|
478
486
|
keys = opts[:by].map{|o| "doc['#{o}']"}
|
479
487
|
emit = keys.length == 1 ? keys.first : "[#{keys.join(', ')}]"
|
@@ -166,6 +166,13 @@ module CouchRest
|
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
|
+
# The value to use for this model's model_type_key.
|
170
|
+
# By default, this shouls always be the string representation of the class,
|
171
|
+
# but if you need anything special, overwrite this method.
|
172
|
+
def model_type_value
|
173
|
+
to_s
|
174
|
+
end
|
175
|
+
|
169
176
|
# Raise an error if validation failed.
|
170
177
|
def fail_validate!(document)
|
171
178
|
raise Errors::Validations.new(document)
|
data/spec/unit/base_spec.rb
CHANGED
@@ -81,53 +81,6 @@ describe "Model Base" do
|
|
81
81
|
@doc.name.should eql("foobar")
|
82
82
|
end
|
83
83
|
end
|
84
|
-
describe "multipart attributes" do
|
85
|
-
context "with valid params" do
|
86
|
-
it "should parse a legal date" do
|
87
|
-
valid_date_params = { "exec_date(1i)"=>"2011",
|
88
|
-
"exec_date(2i)"=>"10",
|
89
|
-
"exec_date(3i)"=>"18"}
|
90
|
-
@obj = WithDateAndTime.new valid_date_params
|
91
|
-
@obj.exec_date.should_not be_nil
|
92
|
-
@obj.exec_date.should be_kind_of(Date)
|
93
|
-
@obj.exec_date.should == Date.new(2011, 10 ,18)
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should parse a legal time" do
|
97
|
-
valid_time_params = { "exec_time(1i)"=>"2011",
|
98
|
-
"exec_time(2i)"=>"10",
|
99
|
-
"exec_time(3i)"=>"18",
|
100
|
-
"exec_time(4i)"=>"15",
|
101
|
-
"exec_time(5i)"=>"15",
|
102
|
-
"exec_time(6i)"=>"15",}
|
103
|
-
@obj = WithDateAndTime.new valid_time_params
|
104
|
-
@obj.exec_time.should_not be_nil
|
105
|
-
@obj.exec_time.should be_kind_of(Time)
|
106
|
-
@obj.exec_time.should == Time.utc(2011, 10 ,18, 15, 15, 15)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
context "with invalid params" do
|
111
|
-
before(:each) do
|
112
|
-
@invalid_date_params = { "exec_date(1i)"=>"2011",
|
113
|
-
"exec_date(2i)"=>"foo",
|
114
|
-
"exec_date(3i)"=>"18"}
|
115
|
-
end
|
116
|
-
it "should still create a model if there are invalid attributes" do
|
117
|
-
@obj = WithDateAndTime.new @invalid_date_params
|
118
|
-
@obj.should_not be_nil
|
119
|
-
@obj.should be_kind_of(WithDateAndTime)
|
120
|
-
end
|
121
|
-
it "should not crash because of an empty value" do
|
122
|
-
@invalid_date_params["exec_date(2i)"] = ""
|
123
|
-
@obj = WithDateAndTime.new @invalid_date_params
|
124
|
-
@obj.should_not be_nil
|
125
|
-
@obj.exec_date.should_not be_kind_of(Date)
|
126
|
-
@obj.should be_kind_of(WithDateAndTime)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
84
|
|
132
85
|
describe "ActiveModel compatability Basic" do
|
133
86
|
|
@@ -53,6 +53,21 @@ describe CouchRest::Model::Connection do
|
|
53
53
|
it "should respond to" do
|
54
54
|
@class.should respond_to(:use_database)
|
55
55
|
end
|
56
|
+
it "should set the database if object provided" do
|
57
|
+
db = @class.server.database('test')
|
58
|
+
@class.use_database(db)
|
59
|
+
@class.database.should eql(db)
|
60
|
+
end
|
61
|
+
it "should never prepare the database before it is needed" do
|
62
|
+
db = @class.server.database('test')
|
63
|
+
@class.should_not_receive(:prepare_database)
|
64
|
+
@class.use_database('test')
|
65
|
+
@class.use_database(db)
|
66
|
+
end
|
67
|
+
it "should use the database specified" do
|
68
|
+
@class.use_database(:test)
|
69
|
+
@class.database.name.should eql('couchrest_test')
|
70
|
+
end
|
56
71
|
end
|
57
72
|
|
58
73
|
describe ".database" do
|
@@ -63,9 +78,8 @@ describe CouchRest::Model::Connection do
|
|
63
78
|
@class.database.should be_a(CouchRest::Database)
|
64
79
|
end
|
65
80
|
it "should provide a database with default name" do
|
66
|
-
|
81
|
+
@class.database.name.should eql('couchrest')
|
67
82
|
end
|
68
|
-
|
69
83
|
end
|
70
84
|
|
71
85
|
describe ".server" do
|
@@ -94,7 +108,6 @@ describe CouchRest::Model::Connection do
|
|
94
108
|
end
|
95
109
|
|
96
110
|
describe ".prepare_database" do
|
97
|
-
|
98
111
|
it "should respond to" do
|
99
112
|
@class.should respond_to(:prepare_database)
|
100
113
|
end
|
@@ -110,6 +123,12 @@ describe CouchRest::Model::Connection do
|
|
110
123
|
db = @class.prepare_database('test')
|
111
124
|
db.name.should eql('couchrest_test')
|
112
125
|
end
|
126
|
+
|
127
|
+
it "should use the .use_database value" do
|
128
|
+
@class.use_database('testing')
|
129
|
+
db = @class.prepare_database
|
130
|
+
db.name.should eql('couchrest_testing')
|
131
|
+
end
|
113
132
|
end
|
114
133
|
|
115
134
|
describe "protected methods" do
|
@@ -57,6 +57,11 @@ describe "Design View" do
|
|
57
57
|
@obj.query.should eql({:foo => :bar})
|
58
58
|
end
|
59
59
|
|
60
|
+
it "should delete query keys if :delete defined" do
|
61
|
+
@obj2 = @klass.new(@mod.design_doc, @obj, {:delete => [:foo]})
|
62
|
+
@obj2.query.should_not include(:foo)
|
63
|
+
end
|
64
|
+
|
60
65
|
end
|
61
66
|
|
62
67
|
describe "with proxy in query for first initialization" do
|
@@ -517,7 +522,7 @@ describe "Design View" do
|
|
517
522
|
describe "#reduce" do
|
518
523
|
it "should update query" do
|
519
524
|
@obj.should_receive(:can_reduce?).and_return(true)
|
520
|
-
@obj.should_receive(:update_query).with({:reduce => true, :
|
525
|
+
@obj.should_receive(:update_query).with({:reduce => true, :delete => [:include_docs]})
|
521
526
|
@obj.reduce
|
522
527
|
end
|
523
528
|
it "should raise error if query cannot be reduced" do
|
@@ -690,11 +695,11 @@ describe "Design View" do
|
|
690
695
|
@obj.result.should eql('foos')
|
691
696
|
end
|
692
697
|
|
693
|
-
it "should remove nil values from query" do
|
698
|
+
it "should not remove nil values from query" do
|
694
699
|
@obj.should_receive(:can_reduce?).and_return(true)
|
695
700
|
@obj.stub!(:use_database).and_return(@mod.database)
|
696
701
|
@obj.query = {:reduce => true, :limit => nil, :skip => nil}
|
697
|
-
@design_doc.should_receive(:view_on).with(@mod.database, 'test_view', {:reduce => true})
|
702
|
+
@design_doc.should_receive(:view_on).with(@mod.database, 'test_view', {:reduce => true, :limit => nil, :skip => nil})
|
698
703
|
@obj.send(:execute)
|
699
704
|
end
|
700
705
|
|
@@ -871,6 +876,10 @@ describe "Design View" do
|
|
871
876
|
view.last.name.should eql("Peter")
|
872
877
|
view.all.length.should eql(3)
|
873
878
|
end
|
879
|
+
|
880
|
+
it "should not return document if nil key provided" do
|
881
|
+
DesignViewModel.by_name.key(nil).first.should be_nil
|
882
|
+
end
|
874
883
|
end
|
875
884
|
|
876
885
|
describe "index information" do
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe CouchRest::Model::Properties do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@obj = WithDefaultValues.new
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "multipart attributes" do
|
11
|
+
context "with valid params" do
|
12
|
+
it "should parse a legal date" do
|
13
|
+
valid_date_params = { "exec_date(1i)"=>"2011",
|
14
|
+
"exec_date(2i)"=>"10",
|
15
|
+
"exec_date(3i)"=>"18"}
|
16
|
+
@obj = WithDateAndTime.new valid_date_params
|
17
|
+
@obj.exec_date.should_not be_nil
|
18
|
+
@obj.exec_date.should be_kind_of(Date)
|
19
|
+
@obj.exec_date.should == Date.new(2011, 10 ,18)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should parse a legal time" do
|
23
|
+
valid_time_params = { "exec_time(1i)"=>"2011",
|
24
|
+
"exec_time(2i)"=>"10",
|
25
|
+
"exec_time(3i)"=>"18",
|
26
|
+
"exec_time(4i)"=>"15",
|
27
|
+
"exec_time(5i)"=>"15",
|
28
|
+
"exec_time(6i)"=>"15",}
|
29
|
+
@obj = WithDateAndTime.new valid_time_params
|
30
|
+
@obj.exec_time.should_not be_nil
|
31
|
+
@obj.exec_time.should be_kind_of(Time)
|
32
|
+
@obj.exec_time.should == Time.utc(2011, 10 ,18, 15, 15, 15)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "with invalid params" do
|
37
|
+
before(:each) do
|
38
|
+
@invalid_date_params = { "exec_date(1i)"=>"2011",
|
39
|
+
"exec_date(2i)"=>"foo",
|
40
|
+
"exec_date(3i)"=>"18"}
|
41
|
+
end
|
42
|
+
it "should still create a model if there are invalid attributes" do
|
43
|
+
@obj = WithDateAndTime.new @invalid_date_params
|
44
|
+
@obj.should_not be_nil
|
45
|
+
@obj.should be_kind_of(WithDateAndTime)
|
46
|
+
end
|
47
|
+
it "should not crash because of an empty value" do
|
48
|
+
@invalid_date_params["exec_date(2i)"] = ""
|
49
|
+
@obj = WithDateAndTime.new @invalid_date_params
|
50
|
+
@obj.should_not be_nil
|
51
|
+
@obj.exec_date.should_not be_kind_of(Date)
|
52
|
+
@obj.should be_kind_of(WithDateAndTime)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Specific use case for Ruby 2.0.0
|
57
|
+
context "with brackets in value" do
|
58
|
+
let :klass do
|
59
|
+
klass = Class.new(CouchRest::Model::Base)
|
60
|
+
klass.class_eval do
|
61
|
+
property :name, String
|
62
|
+
end
|
63
|
+
klass
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should be accepted" do
|
67
|
+
lambda {
|
68
|
+
@obj = klass.new(:name => 'test (object)')
|
69
|
+
}.should_not raise_error
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couchrest_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- J. Chris Anderson
|
@@ -13,12 +12,11 @@ authors:
|
|
13
12
|
autorequire:
|
14
13
|
bindir: bin
|
15
14
|
cert_chain: []
|
16
|
-
date: 2013-
|
15
|
+
date: 2013-12-03 00:00:00.000000000 Z
|
17
16
|
dependencies:
|
18
17
|
- !ruby/object:Gem::Dependency
|
19
18
|
name: couchrest
|
20
19
|
requirement: !ruby/object:Gem::Requirement
|
21
|
-
none: false
|
22
20
|
requirements:
|
23
21
|
- - ~>
|
24
22
|
- !ruby/object:Gem::Version
|
@@ -26,7 +24,6 @@ dependencies:
|
|
26
24
|
type: :runtime
|
27
25
|
prerelease: false
|
28
26
|
version_requirements: !ruby/object:Gem::Requirement
|
29
|
-
none: false
|
30
27
|
requirements:
|
31
28
|
- - ~>
|
32
29
|
- !ruby/object:Gem::Version
|
@@ -34,55 +31,48 @@ dependencies:
|
|
34
31
|
- !ruby/object:Gem::Dependency
|
35
32
|
name: mime-types
|
36
33
|
requirement: !ruby/object:Gem::Requirement
|
37
|
-
none: false
|
38
34
|
requirements:
|
39
|
-
- -
|
35
|
+
- - '>='
|
40
36
|
- !ruby/object:Gem::Version
|
41
37
|
version: '1.15'
|
42
38
|
type: :runtime
|
43
39
|
prerelease: false
|
44
40
|
version_requirements: !ruby/object:Gem::Requirement
|
45
|
-
none: false
|
46
41
|
requirements:
|
47
|
-
- -
|
42
|
+
- - '>='
|
48
43
|
- !ruby/object:Gem::Version
|
49
44
|
version: '1.15'
|
50
45
|
- !ruby/object:Gem::Dependency
|
51
46
|
name: activemodel
|
52
47
|
requirement: !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
48
|
requirements:
|
55
|
-
- -
|
49
|
+
- - '>='
|
56
50
|
- !ruby/object:Gem::Version
|
57
51
|
version: '3.0'
|
58
52
|
type: :runtime
|
59
53
|
prerelease: false
|
60
54
|
version_requirements: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
55
|
requirements:
|
63
|
-
- -
|
56
|
+
- - '>='
|
64
57
|
- !ruby/object:Gem::Version
|
65
58
|
version: '3.0'
|
66
59
|
- !ruby/object:Gem::Dependency
|
67
60
|
name: tzinfo
|
68
61
|
requirement: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
62
|
requirements:
|
71
|
-
- -
|
63
|
+
- - '>='
|
72
64
|
- !ruby/object:Gem::Version
|
73
65
|
version: 0.3.22
|
74
66
|
type: :runtime
|
75
67
|
prerelease: false
|
76
68
|
version_requirements: !ruby/object:Gem::Requirement
|
77
|
-
none: false
|
78
69
|
requirements:
|
79
|
-
- -
|
70
|
+
- - '>='
|
80
71
|
- !ruby/object:Gem::Version
|
81
72
|
version: 0.3.22
|
82
73
|
- !ruby/object:Gem::Dependency
|
83
74
|
name: rspec
|
84
75
|
requirement: !ruby/object:Gem::Requirement
|
85
|
-
none: false
|
86
76
|
requirements:
|
87
77
|
- - ~>
|
88
78
|
- !ruby/object:Gem::Version
|
@@ -90,7 +80,6 @@ dependencies:
|
|
90
80
|
type: :development
|
91
81
|
prerelease: false
|
92
82
|
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
none: false
|
94
83
|
requirements:
|
95
84
|
- - ~>
|
96
85
|
- !ruby/object:Gem::Version
|
@@ -98,7 +87,6 @@ dependencies:
|
|
98
87
|
- !ruby/object:Gem::Dependency
|
99
88
|
name: json
|
100
89
|
requirement: !ruby/object:Gem::Requirement
|
101
|
-
none: false
|
102
90
|
requirements:
|
103
91
|
- - ~>
|
104
92
|
- !ruby/object:Gem::Version
|
@@ -106,7 +94,6 @@ dependencies:
|
|
106
94
|
type: :development
|
107
95
|
prerelease: false
|
108
96
|
version_requirements: !ruby/object:Gem::Requirement
|
109
|
-
none: false
|
110
97
|
requirements:
|
111
98
|
- - ~>
|
112
99
|
- !ruby/object:Gem::Version
|
@@ -114,55 +101,48 @@ dependencies:
|
|
114
101
|
- !ruby/object:Gem::Dependency
|
115
102
|
name: rack-test
|
116
103
|
requirement: !ruby/object:Gem::Requirement
|
117
|
-
none: false
|
118
104
|
requirements:
|
119
|
-
- -
|
105
|
+
- - '>='
|
120
106
|
- !ruby/object:Gem::Version
|
121
107
|
version: 0.5.7
|
122
108
|
type: :development
|
123
109
|
prerelease: false
|
124
110
|
version_requirements: !ruby/object:Gem::Requirement
|
125
|
-
none: false
|
126
111
|
requirements:
|
127
|
-
- -
|
112
|
+
- - '>='
|
128
113
|
- !ruby/object:Gem::Version
|
129
114
|
version: 0.5.7
|
130
115
|
- !ruby/object:Gem::Dependency
|
131
116
|
name: rake
|
132
117
|
requirement: !ruby/object:Gem::Requirement
|
133
|
-
none: false
|
134
118
|
requirements:
|
135
|
-
- -
|
119
|
+
- - '>='
|
136
120
|
- !ruby/object:Gem::Version
|
137
121
|
version: 0.8.0
|
138
122
|
type: :development
|
139
123
|
prerelease: false
|
140
124
|
version_requirements: !ruby/object:Gem::Requirement
|
141
|
-
none: false
|
142
125
|
requirements:
|
143
|
-
- -
|
126
|
+
- - '>='
|
144
127
|
- !ruby/object:Gem::Version
|
145
128
|
version: 0.8.0
|
146
129
|
- !ruby/object:Gem::Dependency
|
147
130
|
name: activemodel
|
148
131
|
requirement: !ruby/object:Gem::Requirement
|
149
|
-
none: false
|
150
132
|
requirements:
|
151
|
-
- -
|
133
|
+
- - '>='
|
152
134
|
- !ruby/object:Gem::Version
|
153
135
|
version: '4.0'
|
154
136
|
type: :development
|
155
137
|
prerelease: false
|
156
138
|
version_requirements: !ruby/object:Gem::Requirement
|
157
|
-
none: false
|
158
139
|
requirements:
|
159
|
-
- -
|
140
|
+
- - '>='
|
160
141
|
- !ruby/object:Gem::Version
|
161
142
|
version: '4.0'
|
162
143
|
- !ruby/object:Gem::Dependency
|
163
144
|
name: kaminari
|
164
145
|
requirement: !ruby/object:Gem::Requirement
|
165
|
-
none: false
|
166
146
|
requirements:
|
167
147
|
- - ~>
|
168
148
|
- !ruby/object:Gem::Version
|
@@ -170,7 +150,6 @@ dependencies:
|
|
170
150
|
type: :development
|
171
151
|
prerelease: false
|
172
152
|
version_requirements: !ruby/object:Gem::Requirement
|
173
|
-
none: false
|
174
153
|
requirements:
|
175
154
|
- - ~>
|
176
155
|
- !ruby/object:Gem::Version
|
@@ -287,6 +266,7 @@ files:
|
|
287
266
|
- spec/unit/embeddable_spec.rb
|
288
267
|
- spec/unit/inherited_spec.rb
|
289
268
|
- spec/unit/persistence_spec.rb
|
269
|
+
- spec/unit/properties_spec.rb
|
290
270
|
- spec/unit/property_protection_spec.rb
|
291
271
|
- spec/unit/property_spec.rb
|
292
272
|
- spec/unit/proxyable_spec.rb
|
@@ -296,28 +276,28 @@ files:
|
|
296
276
|
- spec/unit/utils/migrate_spec.rb
|
297
277
|
- spec/unit/validations_spec.rb
|
298
278
|
homepage: http://github.com/couchrest/couchrest_model
|
299
|
-
licenses:
|
279
|
+
licenses:
|
280
|
+
- Apache License 2.0
|
281
|
+
metadata: {}
|
300
282
|
post_install_message:
|
301
283
|
rdoc_options: []
|
302
284
|
require_paths:
|
303
285
|
- lib
|
304
286
|
required_ruby_version: !ruby/object:Gem::Requirement
|
305
|
-
none: false
|
306
287
|
requirements:
|
307
|
-
- -
|
288
|
+
- - '>='
|
308
289
|
- !ruby/object:Gem::Version
|
309
290
|
version: '0'
|
310
291
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
311
|
-
none: false
|
312
292
|
requirements:
|
313
|
-
- -
|
293
|
+
- - '>'
|
314
294
|
- !ruby/object:Gem::Version
|
315
295
|
version: 1.3.1
|
316
296
|
requirements: []
|
317
297
|
rubyforge_project:
|
318
|
-
rubygems_version:
|
298
|
+
rubygems_version: 2.0.3
|
319
299
|
signing_key:
|
320
|
-
specification_version:
|
300
|
+
specification_version: 4
|
321
301
|
summary: Extends the CouchRest Document for advanced modelling.
|
322
302
|
test_files:
|
323
303
|
- spec/fixtures/attachments/README
|
@@ -366,6 +346,7 @@ test_files:
|
|
366
346
|
- spec/unit/embeddable_spec.rb
|
367
347
|
- spec/unit/inherited_spec.rb
|
368
348
|
- spec/unit/persistence_spec.rb
|
349
|
+
- spec/unit/properties_spec.rb
|
369
350
|
- spec/unit/property_protection_spec.rb
|
370
351
|
- spec/unit/property_spec.rb
|
371
352
|
- spec/unit/proxyable_spec.rb
|