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 +4 -4
- data/lib/couchbase-orm/persistence.rb +27 -0
- data/lib/couchbase-orm/version.rb +1 -1
- data/spec/persistence_spec.rb +35 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44135e0c3811a53e9244b2abb2a85246b32aad72
|
4
|
+
data.tar.gz: 62706edfbb74806112f634d835134eefcc063b79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
data/spec/persistence_spec.rb
CHANGED
@@ -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.
|
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
|
+
date: 2016-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: libcouchbase
|