Skip to content

Commit b0d5e65

Browse files
committed
closes #119 #123
1 parent 33659fc commit b0d5e65

File tree

4 files changed

+47
-14
lines changed

4 files changed

+47
-14
lines changed

release-notes/1.0.alpha1.7.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
## 1.0alpha1.7 - 2021-03-29
1+
## 1.0alpha1.7 - 2021-04-05
22

33
| Release<br/>Date | Version | Open<br/>Issues | Documentation<br/>Sections<br/>Draft Ready | Documentation<br/>Sections<br/>WIP |
44
|--------------|---------|-------------|-------|------|
5-
| April 5, 2021 | 1.0.alpha1.6 | 167 | 35 | 10 |
6-
5+
| April 5, 2021 | 1.0.alpha1.7 | ??? | ?? | ?? |
6+
| March 29, 2021 | 1.0.alpha1.6 | 167 | 35 | 10 |
77
> Open issues includes enhancements, documentation, and discussion issues as well as few bugs.
88
>
99
> The documentation WIP (work in progress) numbers are approx, as more sections may be added.
1010
1111
### New Major Features
12-
+
1312

1413

1514
### Breaking Changes
@@ -25,6 +24,9 @@
2524
+ [#399](https://github.com/hyperstack-org/hyperstack/issues/399) Pluck now takes multiple keys
2625
+ [#358](https://github.com/hyperstack-org/hyperstack/issues/358) Fixed: (again) changing primary_key causes some failures
2726
+ [#127](https://github.com/hyperstack-org/hyperstack/issues/127) Complex expressions work better in on_client (due to upgrade in Parser gem)
27+
+ [#123](https://github.com/hyperstack-org/hyperstack/issues/123) `public_columns_hash` now thread safe.
28+
+ [#119](https://github.com/hyperstack-org/hyperstack/issues/119) `destroy` now updates errors properly and will not mark the record as destroyed unless destroy was successful
29+
2830

2931

3032
### Not Reproducible

ruby/hyper-model/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,14 @@ def destroy(&block)
557557
if !data_loading? && (id || vector)
558558
Operations::Destroy.run(model: ar_instance.model_name.to_s, id: id, vector: vector)
559559
.then do |response|
560-
Broadcast.to_self ar_instance
561-
@destroyed = true
560+
#[reactive_record_id, model.class.name, attributes, messages] model.errors.messages
561+
562+
if response[:success]
563+
@destroyed = true
564+
Broadcast.to_self ar_instance
565+
else
566+
errors! response[:messages]
567+
end
562568
yield response[:success], response[:message] if block
563569
promise.resolve response
564570
end
@@ -590,10 +596,9 @@ def self.destroy_record(model, id, vector, acting_user)
590596
ServerDataCache.new(acting_user, {})[*vector].value
591597
end
592598

593-
record.check_permission_with_acting_user(acting_user, :destroy_permitted?).destroy
594-
{ success: true, attributes: {} }
599+
success = record.check_permission_with_acting_user(acting_user, :destroy_permitted?).destroy
600+
{ success: success, attributes: {}, messages: record.errors.messages }
595601
rescue Exception => e
596-
# ReactiveRecord::Pry.rescued(e)
597602
{ success: false, record: record, message: e }
598603
end
599604
end

ruby/hyper-model/spec/batch3/aaa_edge_cases_spec.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,28 @@ class TestComponent77 < HyperComponent
106106
end
107107
end
108108

109+
it "destroy receives any errors added by the server" do
110+
class Todo < ActiveRecord::Base
111+
before_destroy do
112+
return true unless title == "don't destroy me"
113+
errors.add :base, "Can't destroy me"
114+
throw(:abort)
115+
end
116+
end
117+
id = Todo.create(title: "don't destroy me").id
118+
expect do
119+
Hyperstack::Model.load do
120+
@todo = Todo.find(id)
121+
end.then do |todo|
122+
todo.destroy.then do |response|
123+
todo.errors.messages unless response[:success]
124+
end
125+
end
126+
end.on_client_to eq("base" => ["Can't destroy me"])
127+
expect { @todo.destroyed?}.on_client_to be_falsy
128+
end
129+
130+
109131
it "the limit and offset predefined scopes work" do
110132
5.times do |i|
111133
FactoryBot.create(:todo, title: "Todo #{i}")
@@ -200,7 +222,7 @@ def synchromesh_after_create
200222
orig_synchromesh_after_create
201223
end
202224
end
203-
225+
204226
has_many1 = HasManyModel.create(name: "has_many1")
205227
2.times { |i| BelongsToModel.create(name: "belongs_to_#{i}", has_many_model: has_many1) }
206228
expect { HasManyModel.first.belongs_to_models.count }.on_client_to eq(1)

ruby/hyper-model/spec/batch6/aaa_update_associations_spec.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,20 @@
135135
expect(TodoItem.find_by_title("Jon's first todo!").user.first_name).to eq('Jan')
136136
end
137137

138-
it "and a model in a belongs_to relationship can be deleted" do
139-
expect_promise do
138+
it "and a model in a belongs_to relationship can be destroyed" do
139+
expect do
140140
ReactiveRecord.load do
141141
User.find_by_first_name("Jan").todo_items.collect { |item| item.itself }.first
142142
end.then do | first |
143143
first.destroy.then do |response|
144144
User.find_by_first_name("Jan").todo_items.all
145-
end
145+
end.tap { @was_destroyed_already = first.destroyed? }
146146
end
147-
end.to be_empty
147+
end.on_client_to
148+
# added to check that issue #119 got fixed. Item is not
149+
# considered destroyed until we get the status back from server
150+
# that it was destroyed
151+
expect { @was_destroyed_already }.on_client_to be_falsy
148152
end
149153

150154
it "will update the server properly" do

0 commit comments

Comments
 (0)