couchbase-orm 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f2b06085f930736b6220efb0e13013cc287a7891
4
- data.tar.gz: b078737e87c3d752b317471fdf36b750b3a0d37d
2
+ SHA256:
3
+ metadata.gz: 8d5a44e4dcc24a7d2e0d4dfdac8ea6cf2657cbf8cd2edf6499ab8ac002b82192
4
+ data.tar.gz: ff4554e430770fc9d69f83247e6089ed8ec2874afd2f5cc3543bd21ef7c9ae5c
5
5
  SHA512:
6
- metadata.gz: e9e09cdc7885a995e5abff1dcd8282f1fda44060bda39d9690a1fc3a7ca909bc074816fecfde8e31cbbfd58ee582ef56de44f13b4d94991dc89fb9aa21a82d3e
7
- data.tar.gz: d4bbe1ca233678304c2e1f811140f970ee796031483d5bdcfe50d228994d5158d6053223b25278ea0bc270acb0f39d4aced787dc6f3b4280230ed24a2bfefce6
6
+ metadata.gz: 50bf631a6df22796e99a6fc7a6d1c49b1a00dd19fbbab58e4035286b2388fb597168b2cdbfd335f8a6f89028526ac7f47c005d30d49aac19064b6d7bd67d87b4
7
+ data.tar.gz: 1b2c61ce24033f54779fa56e5ef51e3c12a9f8c3e603fa8b00c4b7837db5289d032a2041b4e72d45dc032383fe6d8d710c822a1814bac75ad3be03269c36dc87
@@ -14,8 +14,8 @@ before_install:
14
14
  - git submodule update --init --recursive
15
15
  - gem install ffi
16
16
  - sudo apt-get install libev-dev python-httplib2
17
- - sudo wget https://packages.couchbase.com/releases/5.0.0/couchbase-server-enterprise_5.0.0-ubuntu14.04_amd64.deb
18
- - sudo dpkg -i couchbase-server-enterprise_5.0.0-ubuntu14.04_amd64.deb
17
+ - sudo wget https://packages.couchbase.com/releases/5.1.0/couchbase-server-enterprise_5.1.0-ubuntu14.04_amd64.deb
18
+ - sudo dpkg -i couchbase-server-enterprise_5.1.0-ubuntu14.04_amd64.deb
19
19
  - sleep 8
20
20
  - sudo service couchbase-server status
21
21
  - /opt/couchbase/bin/couchbase-cli cluster-init -c 127.0.0.1:8091 --cluster-username=admin --cluster-password=password --cluster-ramsize=320 --cluster-index-ramsize=256 --cluster-fts-ramsize=256 --services=data,index,query,fts
@@ -165,14 +165,22 @@ module CouchbaseOrm
165
165
 
166
166
  assign_attributes(hash)
167
167
 
168
- # Ensure the type is set
169
- @__attributes__[:type] = self.class.design_document
170
- @__attributes__.delete(:id)
171
-
172
- options = {}
168
+ options = {extended: true}
173
169
  options[:cas] = @__metadata__.cas if with_cas
174
170
 
175
- resp = self.class.bucket.replace(_id, @__attributes__, **options)
171
+ # There is a limit of 16 subdoc operations per request
172
+ resp = if hash.length <= 16
173
+ subdoc = self.class.bucket.subdoc(_id)
174
+ hash.each do |key, value|
175
+ subdoc.dict_upsert(key, value)
176
+ end
177
+ subdoc.execute!(options)
178
+ else
179
+ # Fallback to writing the whole document
180
+ @__attributes__[:type] = self.class.design_document
181
+ @__attributes__.delete(:id)
182
+ self.class.bucket.replace(_id, @__attributes__, **options)
183
+ end
176
184
 
177
185
  # Ensure the model is up to date
178
186
  @__metadata__.key = resp.key
@@ -98,7 +98,17 @@ module CouchbaseOrm
98
98
  # new one. the id of the current record is used as the key's value.
99
99
  after_save do |record|
100
100
  original_key = instance_variable_get(original_bucket_key_var)
101
- record.class.bucket.delete(original_key, quiet: true) if original_key
101
+
102
+ if original_key
103
+ check_ref_id = record.class.bucket.get(original_key, extended: true, quiet: true)
104
+ if check_ref_id && check_ref_id.value == record.id
105
+ begin
106
+ record.class.bucket.delete(original_key, cas: check_ref_id.cas)
107
+ rescue ::Libcouchbase::Error::KeyExists
108
+ # Errors here can be ignored. Just means the key was updated elswhere
109
+ end
110
+ end
111
+ end
102
112
 
103
113
  unless presence == false && attrs.length == 1 && record[attrs[0]].nil?
104
114
  record.class.bucket.set(record.send(bucket_key_method), record.id, plain: true)
@@ -109,7 +119,14 @@ module CouchbaseOrm
109
119
  # cleanup by removing the bucket key before the record is deleted
110
120
  # TODO: handle unpersisted, modified component values
111
121
  before_destroy do |record|
112
- record.class.bucket.delete(record.send(bucket_key_method), quiet: true)
122
+ check_ref_id = record.class.bucket.get(record.send(bucket_key_method), extended: true, quiet: true)
123
+ if check_ref_id && check_ref_id.value == record.id
124
+ begin
125
+ record.class.bucket.delete(record.send(bucket_key_method), cas: check_ref_id.cas)
126
+ rescue ::Libcouchbase::Error::KeyExists
127
+ # Errors here can be ignored. Just means the key was updated elswhere
128
+ end
129
+ end
113
130
  true
114
131
  end
115
132
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true, encoding: ASCII-8BIT
2
2
 
3
3
  module CouchbaseOrm
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.1'
5
5
  end
@@ -9,6 +9,13 @@ class IndexTest < CouchbaseOrm::Base
9
9
  ensure_unique :email, presence: false
10
10
  end
11
11
 
12
+ class NoUniqueIndexTest < CouchbaseOrm::Base
13
+ attribute :email, type: String
14
+ attribute :name, type: String, default: :joe
15
+
16
+ index :email, presence: false
17
+ end
18
+
12
19
  class EnumTest < CouchbaseOrm::Base
13
20
  enum visibility: [:group, :authority, :public], default: :authority
14
21
  end
@@ -92,4 +99,40 @@ describe CouchbaseOrm::Index do
92
99
  expect(enum.visibility).to eq(2)
93
100
  enum.destroy
94
101
  end
102
+
103
+ it "should not overwrite index's that do not belong to the current model" do
104
+ joe = NoUniqueIndexTest.create!
105
+ expect(NoUniqueIndexTest.find_by_email(nil)).to eq(nil)
106
+
107
+ joe.email = 'joe@aca.com'
108
+ joe.save!
109
+ expect(NoUniqueIndexTest.find_by_email('joe@aca.com')).to eq(joe)
110
+
111
+ joe2 = NoUniqueIndexTest.create!
112
+ joe2.email = 'joe@aca.com' # joe here is deliberate
113
+ joe2.save!
114
+
115
+ expect(NoUniqueIndexTest.find_by_email('joe@aca.com')).to eq(joe2)
116
+
117
+ # Joe's indexing should not remove joe2 index
118
+ joe.email = nil
119
+ joe.save!
120
+ expect(NoUniqueIndexTest.find_by_email('joe@aca.com')).to eq(joe2)
121
+
122
+ # Test destroy
123
+ joe.email = 'joe@aca.com'
124
+ joe.save!
125
+ expect(NoUniqueIndexTest.find_by_email('joe@aca.com')).to eq(joe)
126
+
127
+ # Index should not be updated
128
+ joe2.destroy
129
+ expect(NoUniqueIndexTest.find_by_email('joe@aca.com')).to eq(joe)
130
+
131
+ # index should be updated
132
+ joe.email = nil
133
+ joe.save!
134
+ expect(NoUniqueIndexTest.find_by_email('joe@aca.com')).to eq(nil)
135
+
136
+ joe.destroy
137
+ end
95
138
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true, encoding: ASCII-8BIT
2
2
 
3
3
  require File.expand_path("../support", __FILE__)
4
-
4
+ require 'set'
5
5
 
6
6
  class ViewTest < CouchbaseOrm::Base
7
7
  attribute :name, type: String
@@ -68,6 +68,6 @@ describe CouchbaseOrm::Views do
68
68
  ob.destroy
69
69
  }
70
70
 
71
- expect(docs).to eq(['bob', 'jane'])
71
+ expect(Set.new(docs)).to eq(Set.new(['bob', 'jane']))
72
72
  end
73
73
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchbase-orm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen von Takach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-31 00:00:00.000000000 Z
11
+ date: 2018-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libcouchbase
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
175
  version: '0'
176
176
  requirements: []
177
177
  rubyforge_project:
178
- rubygems_version: 2.6.14
178
+ rubygems_version: 2.7.7
179
179
  signing_key:
180
180
  specification_version: 4
181
181
  summary: Couchbase ORM for Rails