couchrest_model 2.1.0.rc1 → 2.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +15 -4
  4. data/Gemfile.activesupport-4.x +4 -0
  5. data/Gemfile.activesupport-5.x +4 -0
  6. data/README.md +2 -0
  7. data/VERSION +1 -1
  8. data/couchrest_model.gemspec +3 -2
  9. data/history.md +14 -1
  10. data/lib/couchrest/model/associations.rb +3 -8
  11. data/lib/couchrest/model/base.rb +15 -7
  12. data/lib/couchrest/model/casted_array.rb +22 -34
  13. data/lib/couchrest/model/configuration.rb +2 -0
  14. data/lib/couchrest/model/design.rb +4 -3
  15. data/lib/couchrest/model/designs/view.rb +37 -32
  16. data/lib/couchrest/model/dirty.rb +93 -19
  17. data/lib/couchrest/model/embeddable.rb +2 -14
  18. data/lib/couchrest/model/extended_attachments.rb +2 -4
  19. data/lib/couchrest/model/persistence.rb +14 -17
  20. data/lib/couchrest/model/properties.rb +46 -54
  21. data/lib/couchrest/model/property.rb +0 -3
  22. data/lib/couchrest/model/proxyable.rb +20 -4
  23. data/lib/couchrest/model/validations/uniqueness.rb +4 -1
  24. data/lib/couchrest_model.rb +2 -2
  25. data/spec/fixtures/models/article.rb +1 -1
  26. data/spec/fixtures/models/card.rb +2 -1
  27. data/spec/fixtures/models/person.rb +1 -0
  28. data/spec/fixtures/models/project.rb +3 -0
  29. data/spec/unit/assocations_spec.rb +73 -73
  30. data/spec/unit/attachment_spec.rb +34 -34
  31. data/spec/unit/base_spec.rb +102 -102
  32. data/spec/unit/casted_array_spec.rb +7 -7
  33. data/spec/unit/casted_spec.rb +7 -7
  34. data/spec/unit/configuration_spec.rb +11 -11
  35. data/spec/unit/connection_spec.rb +30 -30
  36. data/spec/unit/core_extensions/{time_parsing.rb → time_parsing_spec.rb} +21 -21
  37. data/spec/unit/design_spec.rb +38 -38
  38. data/spec/unit/designs/design_mapper_spec.rb +26 -26
  39. data/spec/unit/designs/migrations_spec.rb +13 -13
  40. data/spec/unit/designs/view_spec.rb +319 -274
  41. data/spec/unit/designs_spec.rb +39 -39
  42. data/spec/unit/dirty_spec.rb +188 -103
  43. data/spec/unit/embeddable_spec.rb +119 -117
  44. data/spec/unit/inherited_spec.rb +4 -4
  45. data/spec/unit/persistence_spec.rb +122 -122
  46. data/spec/unit/properties_spec.rb +466 -16
  47. data/spec/unit/property_protection_spec.rb +32 -32
  48. data/spec/unit/property_spec.rb +45 -436
  49. data/spec/unit/proxyable_spec.rb +140 -82
  50. data/spec/unit/subclass_spec.rb +14 -14
  51. data/spec/unit/translations_spec.rb +5 -5
  52. data/spec/unit/typecast_spec.rb +131 -131
  53. data/spec/unit/utils/migrate_spec.rb +2 -2
  54. data/spec/unit/validations_spec.rb +31 -31
  55. metadata +27 -12
  56. data/lib/couchrest/model/casted_hash.rb +0 -84
@@ -13,8 +13,8 @@ describe CouchRest::Model::Utils::Migrate do
13
13
  end
14
14
  it "should detect if Rails is available and require models" do
15
15
  Rails = double()
16
- Rails.stub(:root).and_return("")
17
- Dir.should_receive(:[]).with("app/models/**/*.rb").and_return(['failed_require'])
16
+ allow(Rails).to receive(:root).and_return("")
17
+ expect(Dir).to receive(:[]).with("app/models/**/*.rb").and_return(['failed_require'])
18
18
  # we can't double require, so just expect an error
19
19
  expect {
20
20
  @module.load_all_models
@@ -10,25 +10,25 @@ describe CouchRest::Model::Validations do
10
10
  end
11
11
 
12
12
  it "should create a new view if none defined before performing" do
13
- WithUniqueValidation.design_doc.has_view?(:by_title).should be_true
13
+ expect(WithUniqueValidation.design_doc.has_view?(:by_title)).to be_truthy
14
14
  end
15
15
 
16
16
  it "should validate a new unique document" do
17
17
  @obj = WithUniqueValidation.create(:title => 'title 4')
18
- @obj.new?.should_not be_true
19
- @obj.should be_valid
18
+ expect(@obj.new?).not_to be_truthy
19
+ expect(@obj).to be_valid
20
20
  end
21
21
 
22
22
  it "should not validate a non-unique document" do
23
23
  @obj = WithUniqueValidation.create(:title => 'title 1')
24
- @obj.should_not be_valid
25
- @obj.errors[:title].should == ["has already been taken"]
24
+ expect(@obj).not_to be_valid
25
+ expect(@obj.errors[:title]).to eq(["has already been taken"])
26
26
  end
27
27
 
28
28
  it "should save already created document" do
29
29
  @obj = @objs.first
30
- @obj.save.should_not be_false
31
- @obj.should be_valid
30
+ expect(@obj.save).not_to be_falsey
31
+ expect(@obj).to be_valid
32
32
  end
33
33
 
34
34
 
@@ -36,27 +36,27 @@ describe CouchRest::Model::Validations do
36
36
  # validates_uniqueness_of :code, :view => 'all'
37
37
  WithUniqueValidationView.create(:title => 'title 1', :code => '1234')
38
38
  @obj = WithUniqueValidationView.new(:title => 'title 5', :code => '1234')
39
- @obj.should_not be_valid
39
+ expect(@obj).not_to be_valid
40
40
  end
41
41
 
42
42
  it "should raise an error if specified view does not exist" do
43
43
  WithUniqueValidationView.validates_uniqueness_of :title, :view => 'fooobar'
44
44
  @obj = WithUniqueValidationView.new(:title => 'title 2', :code => '12345')
45
- lambda {
45
+ expect {
46
46
  @obj.valid?
47
- }.should raise_error
47
+ }.to raise_error(/WithUniqueValidationView.fooobar does not exist for validation/)
48
48
  end
49
49
 
50
50
  it "should not try to create a defined view" do
51
51
  WithUniqueValidationView.validates_uniqueness_of :title, :view => 'fooobar'
52
- WithUniqueValidationView.design_doc.has_view?('fooobar').should be_false
53
- WithUniqueValidationView.design_doc.has_view?('by_title').should be_false
52
+ expect(WithUniqueValidationView.design_doc.has_view?('fooobar')).to be_falsey
53
+ expect(WithUniqueValidationView.design_doc.has_view?('by_title')).to be_falsey
54
54
  end
55
55
 
56
56
 
57
57
  it "should not try to create new view when already defined" do
58
58
  @obj = @objs[1]
59
- @obj.class.design_doc.should_not_receive('create_view')
59
+ expect(@obj.class.design_doc).not_to receive('create_view')
60
60
  @obj.valid?
61
61
  end
62
62
  end
@@ -64,24 +64,24 @@ describe CouchRest::Model::Validations do
64
64
  context "with a proxy parameter" do
65
65
 
66
66
  it "should create a new view despite proxy" do
67
- WithUniqueValidationProxy.design_doc.has_view?(:by_title).should be_true
67
+ expect(WithUniqueValidationProxy.design_doc.has_view?(:by_title)).to be_truthy
68
68
  end
69
69
 
70
70
  it "should be used" do
71
71
  @obj = WithUniqueValidationProxy.new(:title => 'test 6')
72
- proxy = @obj.should_receive('proxy').and_return(@obj.class)
73
- @obj.valid?.should be_true
72
+ proxy = expect(@obj).to receive('proxy').and_return(@obj.class)
73
+ expect(@obj.valid?).to be_truthy
74
74
  end
75
75
 
76
76
  it "should allow specific view" do
77
77
  @obj = WithUniqueValidationProxy.new(:title => 'test 7')
78
- @obj.class.should_not_receive('by_title')
78
+ expect(@obj.class).not_to receive('by_title')
79
79
  view = double('View')
80
- view.stub(:rows).and_return([])
80
+ allow(view).to receive(:rows).and_return([])
81
81
  proxy = double('Proxy')
82
- proxy.should_receive('by_title').and_return(view)
83
- proxy.should_receive('respond_to?').with('by_title').and_return(true)
84
- @obj.should_receive('proxy').and_return(proxy)
82
+ expect(proxy).to receive('by_title').and_return(view)
83
+ expect(proxy).to receive('respond_to?').with('by_title').and_return(true)
84
+ expect(@obj).to receive('proxy').and_return(proxy)
85
85
  @obj.valid?
86
86
  end
87
87
  end
@@ -89,11 +89,11 @@ describe CouchRest::Model::Validations do
89
89
  context "when proxied" do
90
90
  it "should lookup the model_proxy" do
91
91
  view = double('View')
92
- view.stub(:rows).and_return([])
92
+ allow(view).to receive(:rows).and_return([])
93
93
  mp = double(:ModelProxy)
94
- mp.should_receive(:by_title).and_return(view)
94
+ expect(mp).to receive(:by_title).and_return(view)
95
95
  @obj = WithUniqueValidation.new(:title => 'test 8')
96
- @obj.stub(:model_proxy).twice.and_return(mp)
96
+ allow(@obj).to receive(:model_proxy).twice.and_return(mp)
97
97
  @obj.valid?
98
98
  end
99
99
  end
@@ -110,29 +110,29 @@ describe CouchRest::Model::Validations do
110
110
 
111
111
  it "should validate unique document" do
112
112
  @obj = WithScopedUniqueValidation.create(:title => 'title 4', :parent_id => 1)
113
- @obj.should be_valid
113
+ expect(@obj).to be_valid
114
114
  end
115
115
 
116
116
  it "should validate unique document outside of scope" do
117
117
  @obj = WithScopedUniqueValidation.create(:title => 'title 1', :parent_id => 2)
118
- @obj.should be_valid
118
+ expect(@obj).to be_valid
119
119
  end
120
120
 
121
121
  it "should validate non-unique document" do
122
122
  @obj = WithScopedUniqueValidation.create(:title => 'title 1', :parent_id => 1)
123
- @obj.should_not be_valid
124
- @obj.errors[:title].should == ["has already been taken"]
123
+ expect(@obj).not_to be_valid
124
+ expect(@obj.errors[:title]).to eq(["has already been taken"])
125
125
  end
126
126
 
127
127
  it "should validate unique document will nil scope" do
128
128
  @obj = WithScopedUniqueValidation.create(:title => 'title 4', :parent_id => nil)
129
- @obj.should be_valid
129
+ expect(@obj).to be_valid
130
130
  end
131
131
 
132
132
  it "should validate non-unique document with nil scope" do
133
133
  @obj = WithScopedUniqueValidation.create(:title => 'title 1', :parent_id => nil)
134
- @obj.should_not be_valid
135
- @obj.errors[:title].should == ["has already been taken"]
134
+ expect(@obj).not_to be_valid
135
+ expect(@obj.errors[:title]).to eq(["has already been taken"])
136
136
  end
137
137
 
138
138
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchrest_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.rc1
4
+ version: 2.2.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - J. Chris Anderson
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2016-07-06 00:00:00.000000000 Z
15
+ date: 2016-08-20 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: couchrest
@@ -32,16 +32,16 @@ dependencies:
32
32
  name: activemodel
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  requirements:
35
- - - "~>"
35
+ - - ">="
36
36
  - !ruby/object:Gem::Version
37
- version: '4.0'
37
+ version: 4.0.2
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
- - - "~>"
42
+ - - ">="
43
43
  - !ruby/object:Gem::Version
44
- version: '4.0'
44
+ version: 4.0.2
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: tzinfo
47
47
  requirement: !ruby/object:Gem::Requirement
@@ -56,20 +56,34 @@ dependencies:
56
56
  - - ">="
57
57
  - !ruby/object:Gem::Version
58
58
  version: 0.3.22
59
+ - !ruby/object:Gem::Dependency
60
+ name: hashdiff
61
+ requirement: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - "~>"
64
+ - !ruby/object:Gem::Version
65
+ version: '0.3'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '0.3'
59
73
  - !ruby/object:Gem::Dependency
60
74
  name: rspec
61
75
  requirement: !ruby/object:Gem::Requirement
62
76
  requirements:
63
77
  - - "~>"
64
78
  - !ruby/object:Gem::Version
65
- version: 2.14.1
79
+ version: 3.5.0
66
80
  type: :development
67
81
  prerelease: false
68
82
  version_requirements: !ruby/object:Gem::Requirement
69
83
  requirements:
70
84
  - - "~>"
71
85
  - !ruby/object:Gem::Version
72
- version: 2.14.1
86
+ version: 3.5.0
73
87
  - !ruby/object:Gem::Dependency
74
88
  name: rack-test
75
89
  requirement: !ruby/object:Gem::Requirement
@@ -175,6 +189,8 @@ files:
175
189
  - ".rspec"
176
190
  - ".travis.yml"
177
191
  - Gemfile
192
+ - Gemfile.activesupport-4.x
193
+ - Gemfile.activesupport-5.x
178
194
  - LICENSE
179
195
  - README.md
180
196
  - Rakefile
@@ -192,7 +208,6 @@ files:
192
208
  - lib/couchrest/model/callbacks.rb
193
209
  - lib/couchrest/model/casted_array.rb
194
210
  - lib/couchrest/model/casted_by.rb
195
- - lib/couchrest/model/casted_hash.rb
196
211
  - lib/couchrest/model/configuration.rb
197
212
  - lib/couchrest/model/connection.rb
198
213
  - lib/couchrest/model/core_extensions/hash.rb
@@ -267,7 +282,7 @@ files:
267
282
  - spec/unit/casted_spec.rb
268
283
  - spec/unit/configuration_spec.rb
269
284
  - spec/unit/connection_spec.rb
270
- - spec/unit/core_extensions/time_parsing.rb
285
+ - spec/unit/core_extensions/time_parsing_spec.rb
271
286
  - spec/unit/design_spec.rb
272
287
  - spec/unit/designs/design_mapper_spec.rb
273
288
  - spec/unit/designs/migrations_spec.rb
@@ -306,7 +321,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
306
321
  version: 1.3.1
307
322
  requirements: []
308
323
  rubyforge_project:
309
- rubygems_version: 2.4.6
324
+ rubygems_version: 2.4.8
310
325
  signing_key:
311
326
  specification_version: 4
312
327
  summary: Extends the CouchRest Document class for advanced modelling.
@@ -349,7 +364,7 @@ test_files:
349
364
  - spec/unit/casted_spec.rb
350
365
  - spec/unit/configuration_spec.rb
351
366
  - spec/unit/connection_spec.rb
352
- - spec/unit/core_extensions/time_parsing.rb
367
+ - spec/unit/core_extensions/time_parsing_spec.rb
353
368
  - spec/unit/design_spec.rb
354
369
  - spec/unit/designs/design_mapper_spec.rb
355
370
  - spec/unit/designs/migrations_spec.rb
@@ -1,84 +0,0 @@
1
- #
2
- # Wrapper around Hash so that the casted_by attribute is set.
3
-
4
- module CouchRest::Model
5
- class CastedHash < Hash
6
- include CouchRest::Model::CastedBy
7
- include CouchRest::Model::Dirty
8
- attr_accessor :casted_by_property
9
-
10
- def self.[](hash, property, parent = nil)
11
- obj = super(hash)
12
- obj.casted_by_property = property
13
- obj.casted_by = parent unless parent.nil?
14
- obj
15
- end
16
-
17
- # needed for dirty
18
- def attributes
19
- self
20
- end
21
-
22
- def []= key, obj
23
- couchrest_attribute_will_change!(key) if use_dirty? && obj != self[key]
24
- super(key, obj)
25
- end
26
-
27
- def delete(key)
28
- couchrest_attribute_will_change!(key) if use_dirty? && include?(key)
29
- super(key)
30
- end
31
-
32
- def merge!(other_hash)
33
- if use_dirty? && other_hash && other_hash.kind_of?(Hash)
34
- other_hash.keys.each do |key|
35
- if self[key] != other_hash[key] || !include?(key)
36
- couchrest_attribute_will_change!(key)
37
- end
38
- end
39
- end
40
- super(other_hash)
41
- end
42
-
43
- def replace(other_hash)
44
- if use_dirty? && other_hash && other_hash.kind_of?(Hash)
45
- # new keys and changed keys
46
- other_hash.keys.each do |key|
47
- if self[key] != other_hash[key] || !include?(key)
48
- couchrest_attribute_will_change!(key)
49
- end
50
- end
51
- # old keys
52
- old_keys = self.keys.reject { |key| other_hash.include?(key) }
53
- old_keys.each { |key| couchrest_attribute_will_change!(key) }
54
- end
55
-
56
- super(other_hash)
57
- end
58
-
59
- def clear
60
- self.keys.each { |key| couchrest_attribute_will_change!(key) } if use_dirty?
61
- super
62
- end
63
-
64
- def delete_if
65
- if use_dirty? && block_given?
66
- self.keys.each do |key|
67
- couchrest_attribute_will_change!(key) if yield key, self[key]
68
- end
69
- end
70
- super
71
- end
72
-
73
- # ruby 1.9
74
- def keep_if
75
- if use_dirty? && block_given?
76
- self.keys.each do |key|
77
- couchrest_attribute_will_change!(key) if !yield key, self[key]
78
- end
79
- end
80
- super
81
- end
82
-
83
- end
84
- end