couchrest_model 1.1.1 → 1.1.2

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/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.1.2
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["J. Chris Anderson", "Matt Aimonetti", "Marcos Tapajos", "Will Leinweber", "Sam Lown"]
9
- s.date = %q{2011-04-29}
9
+ s.date = File.mtime('VERSION')
10
10
  s.description = %q{CouchRest Model provides aditional features to the standard CouchRest Document class such as properties, view designs, associations, callbacks, typecasting and validations.}
11
11
  s.email = %q{jchris@apache.org}
12
12
  s.extra_rdoc_files = [
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
24
  s.require_paths = ["lib"]
25
25
 
26
- s.add_dependency(%q<couchrest>, "1.1.1")
26
+ s.add_dependency(%q<couchrest>, "~> 1.1.2")
27
27
  s.add_dependency(%q<mime-types>, "~> 1.15")
28
28
  s.add_dependency(%q<activemodel>, "~> 3.0")
29
29
  s.add_dependency(%q<tzinfo>, "~> 0.3.22")
data/history.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # CouchRest Model Change History
2
2
 
3
+ ## 1.1.2 - 2011-07-23
4
+
5
+ * Minor fixes
6
+ * Upgrade to couchrest 1.1.2
7
+ * Override as_couch_json to ensure nil values not stored
8
+ * Removing restriction that prohibited objects that cast as an array to be loaded.
9
+
3
10
  ## 1.1.1 - 2011-07-04
4
11
 
5
12
  * Minor fix
@@ -12,8 +12,10 @@ module CouchRest
12
12
  raise "You can only mixin Properties in a class responding to [] and []=, if you tried to mixin CastedModel, make sure your class inherits from Hash or responds to the proper methods" unless (method_defined?(:[]) && method_defined?(:[]=))
13
13
  end
14
14
 
15
- def as_json(options = nil)
16
- Hash[self].reject{|k,v| v.nil?}.as_json(options)
15
+ # Provide an attribute hash ready to be sent to CouchDB but with
16
+ # all the nil attributes removed.
17
+ def as_couch_json
18
+ super.delete_if{|k,v| v.nil?}
17
19
  end
18
20
 
19
21
  # Returns the Class properties with their values
@@ -43,9 +43,8 @@ module CouchRest::Model
43
43
  end
44
44
  end
45
45
 
46
- # Cast an individual value, not an array
46
+ # Cast an individual value
47
47
  def cast_value(parent, value)
48
- raise "An array inside an array cannot be casted, use Embeddable module" if value.is_a?(Array)
49
48
  value = typecast_value(value, self)
50
49
  associate_casted_value_to_parent(parent, value)
51
50
  end
@@ -62,15 +62,23 @@ describe CouchRest::Model::Property do
62
62
  @card.updated_at.should_not be_nil
63
63
  end
64
64
 
65
- describe "#as_json" do
65
+ describe "#as_couch_json" do
66
66
 
67
67
  it "should provide a simple hash from model" do
68
- @card.as_json.class.should eql(Hash)
68
+ @card.as_couch_json.class.should eql(Hash)
69
69
  end
70
70
 
71
71
  it "should remove properties from Hash if value is nil" do
72
72
  @card.last_name = nil
73
- @card.as_json.keys.include?('last_name').should be_false
73
+ @card.as_couch_json.keys.include?('last_name').should be_false
74
+ end
75
+
76
+ end
77
+
78
+ describe "#as_json" do
79
+
80
+ it "should provide a simple hash from model" do
81
+ @card.as_json.class.should eql(Hash)
74
82
  end
75
83
 
76
84
  it "should pass options to Active Support's as_json" do
@@ -442,15 +450,18 @@ describe "Property Class" do
442
450
  ary.last.should eql(Date.new(2011, 05, 22))
443
451
  end
444
452
 
445
- it "should raise and error if value is array when type is not" do
446
- property = CouchRest::Model::Property.new(:test, Date)
453
+ it "should cast an object that provides an array" do
454
+ prop = Class.new do
455
+ attr_accessor :ary
456
+ def initialize(val); self.ary = val; end
457
+ def as_json; ary; end
458
+ end
459
+ property = CouchRest::Model::Property.new(:test, prop)
447
460
  parent = mock("FooClass")
448
- lambda {
449
- cast = property.cast(parent, [Date.new(2010, 6, 1)])
450
- }.should raise_error
461
+ cast = property.cast(parent, [1, 2])
462
+ cast.ary.should eql([1, 2])
451
463
  end
452
464
 
453
-
454
465
  it "should set parent as casted_by object in CastedArray" do
455
466
  property = CouchRest::Model::Property.new(:test, [Object])
456
467
  parent = mock("FooObject")
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchrest_model
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 23
4
5
  prerelease:
5
- version: 1.1.1
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 2
10
+ version: 1.1.2
6
11
  platform: ruby
7
12
  authors:
8
13
  - J. Chris Anderson
@@ -14,7 +19,7 @@ autorequire:
14
19
  bindir: bin
15
20
  cert_chain: []
16
21
 
17
- date: 2011-04-29 00:00:00 +02:00
22
+ date: 2011-07-23 00:00:00 +02:00
18
23
  default_executable:
19
24
  dependencies:
20
25
  - !ruby/object:Gem::Dependency
@@ -23,9 +28,14 @@ dependencies:
23
28
  requirement: &id001 !ruby/object:Gem::Requirement
24
29
  none: false
25
30
  requirements:
26
- - - "="
31
+ - - ~>
27
32
  - !ruby/object:Gem::Version
28
- version: 1.1.1
33
+ hash: 23
34
+ segments:
35
+ - 1
36
+ - 1
37
+ - 2
38
+ version: 1.1.2
29
39
  type: :runtime
30
40
  version_requirements: *id001
31
41
  - !ruby/object:Gem::Dependency
@@ -36,6 +46,10 @@ dependencies:
36
46
  requirements:
37
47
  - - ~>
38
48
  - !ruby/object:Gem::Version
49
+ hash: 17
50
+ segments:
51
+ - 1
52
+ - 15
39
53
  version: "1.15"
40
54
  type: :runtime
41
55
  version_requirements: *id002
@@ -47,6 +61,10 @@ dependencies:
47
61
  requirements:
48
62
  - - ~>
49
63
  - !ruby/object:Gem::Version
64
+ hash: 7
65
+ segments:
66
+ - 3
67
+ - 0
50
68
  version: "3.0"
51
69
  type: :runtime
52
70
  version_requirements: *id003
@@ -58,6 +76,11 @@ dependencies:
58
76
  requirements:
59
77
  - - ~>
60
78
  - !ruby/object:Gem::Version
79
+ hash: 63
80
+ segments:
81
+ - 0
82
+ - 3
83
+ - 22
61
84
  version: 0.3.22
62
85
  type: :runtime
63
86
  version_requirements: *id004
@@ -69,6 +92,11 @@ dependencies:
69
92
  requirements:
70
93
  - - ~>
71
94
  - !ruby/object:Gem::Version
95
+ hash: 23
96
+ segments:
97
+ - 2
98
+ - 6
99
+ - 0
72
100
  version: 2.6.0
73
101
  type: :development
74
102
  version_requirements: *id005
@@ -80,6 +108,11 @@ dependencies:
80
108
  requirements:
81
109
  - - ~>
82
110
  - !ruby/object:Gem::Version
111
+ hash: 1
112
+ segments:
113
+ - 1
114
+ - 5
115
+ - 1
83
116
  version: 1.5.1
84
117
  type: :development
85
118
  version_requirements: *id006
@@ -91,6 +124,11 @@ dependencies:
91
124
  requirements:
92
125
  - - ">="
93
126
  - !ruby/object:Gem::Version
127
+ hash: 5
128
+ segments:
129
+ - 0
130
+ - 5
131
+ - 7
94
132
  version: 0.5.7
95
133
  type: :development
96
134
  version_requirements: *id007
@@ -225,17 +263,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
263
  requirements:
226
264
  - - ">="
227
265
  - !ruby/object:Gem::Version
266
+ hash: 3
267
+ segments:
268
+ - 0
228
269
  version: "0"
229
270
  required_rubygems_version: !ruby/object:Gem::Requirement
230
271
  none: false
231
272
  requirements:
232
273
  - - ">"
233
274
  - !ruby/object:Gem::Version
275
+ hash: 25
276
+ segments:
277
+ - 1
278
+ - 3
279
+ - 1
234
280
  version: 1.3.1
235
281
  requirements: []
236
282
 
237
283
  rubyforge_project:
238
- rubygems_version: 1.3.9.1
284
+ rubygems_version: 1.6.2
239
285
  signing_key:
240
286
  specification_version: 3
241
287
  summary: Extends the CouchRest Document for advanced modelling.