volt 0.8.27.beta5 → 0.8.27.beta6

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: 42348e0223848e865c4d02adcc27da2db50d0551
4
- data.tar.gz: bdf2f78a331fdec437d1a82571bc897ef24a865c
3
+ metadata.gz: 664d87e842c6c03b483345d4771a71d72ad1567e
4
+ data.tar.gz: 8e82d85deddbc176c6cda90317b5a005f63f918d
5
5
  SHA512:
6
- metadata.gz: 7674f328725d1e5adf5e73aae1658d4793f63bfa8dd475a104e82de0ee47e7e00f672a28631aaf6266723cdf3baa22bdd30cc4e6fcf0a4a66e335606e972f355
7
- data.tar.gz: edac11f20bbdca8fb750adfebdfae961870ca1b4b54e681ca76f06d59873bc4bc6dceca6310dae1322db23e082af60d80f6953e4f5cb663ac8ee682e3421ed15
6
+ metadata.gz: a8e1ffac496bf1ead1564de04a4dac9a48ccbc68776d5db3fa0b9bb8ed2fcb7b10a31c9e5869f1f521f6b0d0796c37937a041a4efbe398d674e0884cbf93e3c2
7
+ data.tar.gz: 5e54e036809c3d61f75de5a80f01658d46ef572aacc0193c45498a97b92c41dc665e2b761dcc848f7206a21240b18698557cc2df90be43cdf36b39b4594cce9c
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.27.beta5
1
+ 0.8.27.beta6
@@ -25,8 +25,8 @@ class StoreTasks < Volt::TaskHandler
25
25
  # Create a buffer
26
26
  buffer = model.buffer
27
27
 
28
- # Assign the data
29
- buffer.assign_attributes(data, true)
28
+ # Assign the changed data to the buffer
29
+ buffer.assign_attributes(data, false, true)
30
30
 
31
31
  buffer
32
32
  end
@@ -38,6 +38,23 @@ module Volt
38
38
 
39
39
  # Sets the current model on this controller
40
40
  def model=(val)
41
+ if val.is_a?(Promise)
42
+ # Resolve the promise before setting
43
+ @last_promise = val
44
+
45
+ val.then do |result|
46
+ # Only assign if nothing else has been assigned since we started the resolve
47
+ self.model = result if @last_promise == val
48
+ end.fail do |err|
49
+ Volt.logger.error("Unable to resolve promise assigned to model on #{inspect}")
50
+ end
51
+
52
+ return
53
+ end
54
+
55
+ # Clear
56
+ @last_promise = nil
57
+
41
58
  # Start with a nil reactive value.
42
59
  self.current_model ||= Model.new
43
60
 
@@ -1,7 +1,11 @@
1
1
  module Volt
2
2
  module Buffer
3
3
  def save!
4
- # Compute the erros once
4
+ # TODO: this shouldn't need to be run, but if no attributes are assigned, then
5
+ # if needs to be run. Maybe there's a better way to handle it.
6
+ validate!
7
+
8
+ # Get errors from validate
5
9
  errors = self.errors.to_h
6
10
 
7
11
  if errors.size == 0
@@ -12,7 +16,7 @@ module Volt
12
16
  promise = save_to.append(attributes)
13
17
  else
14
18
  # We have a saved model
15
- promise = save_to.assign_attributes(attributes, true)
19
+ promise = save_to.assign_attributes(attributes)
16
20
  end
17
21
 
18
22
  return promise.then do |new_model|
@@ -64,20 +68,12 @@ module Volt
64
68
  model_klass = self.class
65
69
 
66
70
  new_options = options.merge(path: model_path, save_to: self, buffer: true).reject { |k, _| k.to_sym == :persistor }
67
- model = model_klass.new({}, new_options, :loading)
68
71
 
69
- if loaded?
70
- setup_buffer(model)
71
- else
72
- parent.then do
73
- setup_buffer(model)
74
- end.fail do |err|
75
- # TODO: right now this error gets ignored a lot, so lets log.
76
- Volt.logger.error("error setting up buffer: #{err.inspect}")
77
- Volt.logger.error(err.backtrace)
78
-
79
- raise err
80
- end
72
+ model = nil
73
+ Volt::Model.no_validate do
74
+ model = model_klass.new(attributes, new_options, :loaded)
75
+
76
+ model.instance_variable_set('@new', @new)
81
77
  end
82
78
 
83
79
  model
@@ -124,16 +124,16 @@ module Volt
124
124
  end
125
125
 
126
126
  # Assign multiple attributes as a hash, directly.
127
- def assign_attributes(attrs, initial_setup = false)
128
- @attributes = {}
127
+ def assign_attributes(attrs, initial_setup=false, skip_changes=false)
128
+ @attributes ||= {}
129
129
 
130
130
  attrs = wrap_values(attrs)
131
131
 
132
132
  if attrs
133
133
  # When doing a mass-assign, we don't validate or save until the end.
134
- if initial_setup
134
+ if initial_setup || skip_changes
135
135
  Model.no_change_tracking do
136
- assign_all_attributes(attrs)
136
+ assign_all_attributes(attrs, skip_changes)
137
137
  end
138
138
  else
139
139
  assign_all_attributes(attrs)
@@ -403,13 +403,14 @@ module Volt
403
403
  end
404
404
 
405
405
  # Used internally from other methods that assign all attributes
406
- def assign_all_attributes(attrs)
406
+ def assign_all_attributes(attrs, track_changes=false)
407
407
  # Assign each attribute using setters
408
408
  attrs.each_pair do |key, value|
409
409
  key = key.to_sym
410
410
 
411
411
  # Track the change, since assign_all_attributes runs with no_change_tracking
412
- # attribute_will_change!(key, @attributes[key])
412
+ old_val = @attributes[key]
413
+ attribute_will_change!(key, old_val) if track_changes && old_val != value
413
414
 
414
415
  if self.respond_to?(:"#{key}=")
415
416
  # If a method without an underscore is defined, call that.
@@ -12,7 +12,8 @@ module Volt
12
12
  def own_by_user(key=:user_id)
13
13
  # When the model is created, assign it the user_id (if the user is logged in)
14
14
  on(:new) do
15
- if !(user_id = Volt.user_id).nil?
15
+ # Only assign the user_id if there isn't already one and the user is logged in.
16
+ if _user_id.nil? && !(user_id = Volt.user_id).nil?
16
17
  send(:"_#{key}=", user_id)
17
18
  end
18
19
  end
@@ -92,6 +92,7 @@ module Volt
92
92
 
93
93
  queue_client_save
94
94
  else
95
+ # puts "SAVE TO DB: #{@model.inspect} - #{self_attributes.inspect} - #{@model.changed_attributes.inspect}"
95
96
  errors = save_to_db!(self_attributes)
96
97
  if errors.size == 0
97
98
  promise.resolve(nil)
@@ -98,6 +98,7 @@ module Volt
98
98
  # @return [Boolean] true if one of the changed fields has an error.
99
99
  def error_in_changed_attributes?
100
100
  errs = errors
101
+
101
102
  changed_attributes.each_pair do |key, _|
102
103
  # If any of the fields with errors are also the ones that were
103
104
  return true if errs[key]
@@ -499,5 +499,9 @@ describe Volt::Model do
499
499
 
500
500
  expect(count).to eq(1)
501
501
  end
502
+
503
+ it 'should skip read permissions when checking create/update' do
504
+
505
+ end
502
506
  end
503
507
  end
@@ -29,6 +29,7 @@ describe Volt::Model do
29
29
 
30
30
  it 'should show all fields in marked errors once saved' do
31
31
  buffer = model.buffer
32
+
32
33
  buffer.save!
33
34
 
34
35
  expect(buffer.marked_errors.keys).to eq(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: volt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.27.beta5
4
+ version: 0.8.27.beta6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Stout
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-03 00:00:00.000000000 Z
11
+ date: 2015-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor