couchbase-orm 0.0.11 → 0.0.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fd4a43082ca5d80291db012e1434dc09830a8e5
4
- data.tar.gz: ae0fd140002527cd633658d5ad52479d9f4a2a6a
3
+ metadata.gz: 44135e0c3811a53e9244b2abb2a85246b32aad72
4
+ data.tar.gz: 62706edfbb74806112f634d835134eefcc063b79
5
5
  SHA512:
6
- metadata.gz: 9e75b6386a260d835ee1af1a193fe2445fe81761def69396321314b666fb5d10db0239869563f9fa6accc7c8cf3315f88e5a2bb5a1093b930473d77204b9ecd9
7
- data.tar.gz: 9bbaa54b9b611e1268a78bef595e96e355c8e0880c4bc9da4e69c5e86c8c23a9fe3a0a07e5efa69790225b4bd493f67ff6c28da37b17251c1a2587f11102a1b2
6
+ metadata.gz: 748a1c214023270fd9510b2a448c066afc3fbbd371abfa2d01260a5517b48860486412957596558f7486fd09d03a7588c8faa0234246f1650037f8147b8bfe01
7
+ data.tar.gz: 8c68a6a0e04ae8abd51bbee6321b23a7d53fc6adf84cea12df091a6791eaf3a57190fc218fc32e2fd6e3d51193f51200a3ff211a51f70be346491acd4d5faff4
@@ -162,6 +162,33 @@ module CouchbaseOrm
162
162
  end
163
163
  alias_method :update_attributes!, :update!
164
164
 
165
+ # Updates the record without validating or running callbacks
166
+ def update_columns(with_cas: false, **hash)
167
+ _id = @__metadata__.key
168
+ raise "unable to update columns, model not persisted" unless _id
169
+
170
+ assign_attributes(hash)
171
+
172
+ # Ensure the type is set
173
+ @__attributes__[:type] = self.class.design_document
174
+ @__attributes__.delete(:id)
175
+
176
+ options = {}
177
+ options[:cas] = @__metadata__.cas if with_cas
178
+
179
+ resp = nil
180
+ ::ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
181
+ resp = self.class.bucket.replace(_id, @__attributes__, **options)
182
+ end
183
+
184
+ # Ensure the model is up to date
185
+ @__metadata__.key = resp.key
186
+ @__metadata__.cas = resp.cas
187
+
188
+ clear_changes_information
189
+ self
190
+ end
191
+
165
192
  # Reloads the record from the database.
166
193
  #
167
194
  # This method finds record by its key and modifies the receiver in-place:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true, encoding: ASCII-8BIT
2
2
 
3
3
  module CouchbaseOrm
4
- VERSION = '0.0.11'
4
+ VERSION = '0.0.12'
5
5
  end
@@ -133,6 +133,41 @@ describe CouchbaseOrm::Persistence do
133
133
  expect(model.name).to eq('joe')
134
134
  end
135
135
 
136
+ it "should skip callbacks when updating columns" do
137
+ model = ModelWithCallbacks.new
138
+
139
+ # Test initialize
140
+ expect(model.name).to be(nil)
141
+ expect(model.age).to be(10)
142
+ expect(model.address).to be(nil)
143
+
144
+ expect(model.new_record?).to be(true)
145
+ expect(model.destroyed?).to be(false)
146
+ expect(model.persisted?).to be(false)
147
+
148
+ # Test create
149
+ result = model.save
150
+ expect(result).to be(true)
151
+
152
+ expect(model.name).to eq('bob')
153
+ expect(model.age).to be(10)
154
+ expect(model.address).to eq('23')
155
+
156
+ # Test Update
157
+ model.update_columns(address: 'other')
158
+ expect(model.address).to eq('other')
159
+ loaded = ModelWithCallbacks.find model.id
160
+ expect(loaded.address).to eq('other')
161
+
162
+ # Test delete skipping callbacks
163
+ model.delete
164
+ expect(model.new_record?).to be(false)
165
+ expect(model.destroyed?).to be(true)
166
+ expect(model.persisted?).to be(false)
167
+
168
+ expect(model.name).to eq('bob')
169
+ end
170
+
136
171
  it "should perform validations" do
137
172
  model = ModelWithValidations.new
138
173
 
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: 0.0.11
4
+ version: 0.0.12
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: 2016-11-28 00:00:00.000000000 Z
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libcouchbase