cable_ready 5.0.0.pre2 → 5.0.0.pre6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +45 -0
- data/Gemfile.lock +75 -71
- data/README.md +6 -2
- data/app/helpers/cable_ready_helper.rb +15 -2
- data/app/models/concerns/cable_ready/updatable/collection_updatable_callbacks.rb +19 -0
- data/app/models/concerns/cable_ready/updatable/collections_registry.rb +33 -0
- data/app/models/concerns/cable_ready/updatable/model_updatable_callbacks.rb +28 -0
- data/app/models/concerns/cable_ready/updatable.rb +98 -0
- data/app/models/concerns/extend_has_many.rb +13 -0
- data/lib/cable_ready/channels.rb +1 -1
- data/lib/cable_ready/compoundable.rb +1 -1
- data/lib/cable_ready/config.rb +2 -0
- data/lib/cable_ready/operation_builder.rb +6 -9
- data/lib/cable_ready/version.rb +1 -1
- data/lib/generators/cable_ready/{stream_from_generator.rb → helpers_generator.rb} +1 -1
- data/test/dummy/app/channels/application_cable/channel.rb +4 -0
- data/test/dummy/app/channels/application_cable/connection.rb +4 -0
- data/test/dummy/app/controllers/application_controller.rb +2 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +7 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/application_record.rb +3 -0
- data/test/dummy/app/models/global_idable_entity.rb +16 -0
- data/test/dummy/app/models/post.rb +4 -0
- data/test/dummy/app/models/section.rb +6 -0
- data/test/dummy/app/models/team.rb +6 -0
- data/test/dummy/app/models/topic.rb +4 -0
- data/test/dummy/app/models/user.rb +7 -0
- data/test/dummy/config/application.rb +22 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +76 -0
- data/test/dummy/config/environments/production.rb +120 -0
- data/test/dummy/config/environments/test.rb +59 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/test/dummy/config/initializers/assets.rb +12 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +8 -0
- data/test/dummy/config/initializers/cable_ready.rb +18 -0
- data/test/dummy/config/initializers/content_security_policy.rb +28 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +6 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/permissions_policy.rb +11 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/puma.rb +43 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/db/migrate/20210902154139_create_users.rb +9 -0
- data/test/dummy/db/migrate/20210902154153_create_posts.rb +10 -0
- data/test/dummy/db/migrate/20210904081930_create_topics.rb +9 -0
- data/test/dummy/db/migrate/20210904093607_create_sections.rb +9 -0
- data/test/dummy/db/migrate/20210913191735_create_teams.rb +8 -0
- data/test/dummy/db/migrate/20210913191759_add_team_reference_to_users.rb +5 -0
- data/test/dummy/db/schema.rb +49 -0
- data/test/dummy/test/models/post_test.rb +7 -0
- data/test/dummy/test/models/section_test.rb +7 -0
- data/test/dummy/test/models/team_test.rb +7 -0
- data/test/dummy/test/models/topic_test.rb +7 -0
- data/test/dummy/test/models/user_test.rb +7 -0
- data/test/lib/cable_ready/cable_car_test.rb +5 -5
- data/test/lib/cable_ready/compoundable_test.rb +26 -0
- data/test/lib/cable_ready/helper_test.rb +25 -0
- data/test/lib/cable_ready/identifiable_test.rb +0 -6
- data/test/lib/cable_ready/operation_builder_test.rb +26 -48
- data/test/lib/cable_ready/updatable_test.rb +112 -0
- data/test/test_helper.rb +4 -1
- metadata +117 -8
- data/cable_ready.gemspec +0 -27
- data/package.json +0 -41
- data/tags +0 -80
- data/yarn.lock +0 -2562
@@ -0,0 +1,49 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# This file is the source Rails uses to define your schema when running `bin/rails
|
6
|
+
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
|
7
|
+
# be faster and is potentially less error prone than running all of your
|
8
|
+
# migrations from scratch. Old migrations may fail to apply correctly if those
|
9
|
+
# migrations use external dependencies or application code.
|
10
|
+
#
|
11
|
+
# It's strongly recommended that you check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(version: 2021_09_13_191759) do
|
14
|
+
|
15
|
+
create_table "posts", force: :cascade do |t|
|
16
|
+
t.string "title"
|
17
|
+
t.integer "user_id", null: false
|
18
|
+
t.datetime "created_at", precision: 6, null: false
|
19
|
+
t.datetime "updated_at", precision: 6, null: false
|
20
|
+
t.index ["user_id"], name: "index_posts_on_user_id"
|
21
|
+
end
|
22
|
+
|
23
|
+
create_table "sections", force: :cascade do |t|
|
24
|
+
t.string "title"
|
25
|
+
t.datetime "created_at", precision: 6, null: false
|
26
|
+
t.datetime "updated_at", precision: 6, null: false
|
27
|
+
end
|
28
|
+
|
29
|
+
create_table "teams", force: :cascade do |t|
|
30
|
+
t.datetime "created_at", precision: 6, null: false
|
31
|
+
t.datetime "updated_at", precision: 6, null: false
|
32
|
+
end
|
33
|
+
|
34
|
+
create_table "topics", force: :cascade do |t|
|
35
|
+
t.string "title"
|
36
|
+
t.datetime "created_at", precision: 6, null: false
|
37
|
+
t.datetime "updated_at", precision: 6, null: false
|
38
|
+
end
|
39
|
+
|
40
|
+
create_table "users", force: :cascade do |t|
|
41
|
+
t.string "name"
|
42
|
+
t.datetime "created_at", precision: 6, null: false
|
43
|
+
t.datetime "updated_at", precision: 6, null: false
|
44
|
+
t.integer "team_id"
|
45
|
+
t.index ["team_id"], name: "index_users_on_team_id"
|
46
|
+
end
|
47
|
+
|
48
|
+
add_foreign_key "posts", "users"
|
49
|
+
end
|
@@ -11,19 +11,19 @@ class CableReady::CableCarTest < ActiveSupport::TestCase
|
|
11
11
|
test "dispatch should return json-ifiable payload" do
|
12
12
|
CableReady::CableCar.instance.reset!
|
13
13
|
dispatch = CableReady::CableCar.instance.inner_html(selector: "#users", html: "<span>winning</span>").dispatch
|
14
|
-
assert_equal({"
|
14
|
+
assert_equal([{"operation" => "innerHtml", "selector" => "#users", "html" => "<span>winning</span>"}], dispatch)
|
15
15
|
end
|
16
16
|
|
17
17
|
test "dispatch should clear operations" do
|
18
18
|
CableReady::CableCar.instance.reset!
|
19
19
|
CableReady::CableCar.instance.inner_html(selector: "#users", html: "<span>winning</span>").dispatch
|
20
|
-
assert_equal(
|
20
|
+
assert_equal([], CableReady::CableCar.instance.instance_variable_get(:@enqueued_operations))
|
21
21
|
end
|
22
22
|
|
23
23
|
test "dispatch should maintain operations if clear is false" do
|
24
24
|
CableReady::CableCar.instance.reset!
|
25
25
|
CableReady::CableCar.instance.inner_html(selector: "#users", html: "<span>winning</span>").dispatch(clear: false)
|
26
|
-
assert_equal({"
|
26
|
+
assert_equal([{"operation" => "innerHtml", "selector" => "#users", "html" => "<span>winning</span>"}], CableReady::CableCar.instance.instance_variable_get(:@enqueued_operations))
|
27
27
|
end
|
28
28
|
|
29
29
|
test "selectors should accept any object which respond_to? to_dom_selector" do
|
@@ -34,7 +34,7 @@ class CableReady::CableCarTest < ActiveSupport::TestCase
|
|
34
34
|
end
|
35
35
|
end.new("users")
|
36
36
|
dispatch = CableReady::CableCar.instance.inner_html(selector: my_object, html: "<span>winning</span>").dispatch
|
37
|
-
assert_equal({"
|
37
|
+
assert_equal([{"operation" => "innerHtml", "selector" => ".users", "html" => "<span>winning</span>"}], dispatch)
|
38
38
|
end
|
39
39
|
|
40
40
|
test "selectors should accept any object which respond_to? to_dom_id" do
|
@@ -45,6 +45,6 @@ class CableReady::CableCarTest < ActiveSupport::TestCase
|
|
45
45
|
end
|
46
46
|
end.new("users")
|
47
47
|
dispatch = CableReady::CableCar.instance.inner_html(selector: my_object, html: "<span>winning</span>").dispatch
|
48
|
-
assert_equal({"
|
48
|
+
assert_equal([{"operation" => "innerHtml", "selector" => "#users", "html" => "<span>winning</span>"}], dispatch)
|
49
49
|
end
|
50
50
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
require_relative "../../../lib/cable_ready"
|
5
|
+
|
6
|
+
class CableReady::CompoundableTest < ActiveSupport::TestCase
|
7
|
+
include CableReady::Compoundable
|
8
|
+
|
9
|
+
test "compounds an ActiveRecord::Base" do
|
10
|
+
user = User.create(name: "Alan Turing")
|
11
|
+
|
12
|
+
assert_equal "gid://dummy/User/1", compound([user])
|
13
|
+
end
|
14
|
+
|
15
|
+
test "compounds any GlobalId-able entity" do
|
16
|
+
entity = GlobalIdableEntity.new
|
17
|
+
|
18
|
+
assert_equal "gid://dummy/GlobalIdableEntity/fake-id", compound([entity])
|
19
|
+
end
|
20
|
+
|
21
|
+
test "compounds any combination of globalid-able and strings" do
|
22
|
+
user = User.create(name: "Alan Turing")
|
23
|
+
|
24
|
+
assert_equal "gid://dummy/User/1:enigma", compound([user, :enigma])
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
class CableReady::HelperTest < ActionView::TestCase
|
6
|
+
include CableReadyHelper
|
7
|
+
|
8
|
+
# stream_from
|
9
|
+
|
10
|
+
test "stream_from renders html options" do
|
11
|
+
element = Nokogiri::HTML.fragment(stream_from("key", html_options: {class: "block", data: {controller: "modal"}}) {})
|
12
|
+
|
13
|
+
assert_equal "block", element.children.first["class"]
|
14
|
+
assert_equal "modal", element.children.first["data-controller"]
|
15
|
+
end
|
16
|
+
|
17
|
+
# updates_for
|
18
|
+
|
19
|
+
test "updates_for renders html options" do
|
20
|
+
element = Nokogiri::HTML.fragment(updates_for("key", html_options: {class: "block", data: {controller: "modal"}}) {})
|
21
|
+
|
22
|
+
assert_equal "block", element.children.first["class"]
|
23
|
+
assert_equal "modal", element.children.first["data-controller"]
|
24
|
+
end
|
25
|
+
end
|
@@ -55,42 +55,42 @@ class CableReady::OperationBuilderTest < ActiveSupport::TestCase
|
|
55
55
|
|
56
56
|
operations = @operation_builder.instance_variable_get(:@enqueued_operations)
|
57
57
|
|
58
|
-
assert_equal 1, operations
|
59
|
-
assert_equal({"name" => "passed_option"
|
58
|
+
assert_equal 1, operations.size
|
59
|
+
assert_equal({"name" => "passed_option", "operation" => "foobar"}, operations.first)
|
60
60
|
end
|
61
61
|
|
62
62
|
test "should json-ify operations" do
|
63
63
|
@operation_builder.add_operation_method("foobar")
|
64
64
|
@operation_builder.foobar({name: "passed_option"})
|
65
|
-
assert_equal("{\"
|
65
|
+
assert_equal("[{\"name\":\"passed_option\",\"operation\":\"foobar\"}]", @operation_builder.to_json)
|
66
66
|
end
|
67
67
|
|
68
68
|
test "should apply! many operations" do
|
69
|
-
@operation_builder.apply!(
|
69
|
+
@operation_builder.apply!({name: "passed_option"})
|
70
70
|
|
71
71
|
operations = @operation_builder.instance_variable_get(:@enqueued_operations)
|
72
|
-
assert_equal 1, operations
|
73
|
-
assert_equal({"name" => "passed_option"}, operations
|
72
|
+
assert_equal 1, operations.size
|
73
|
+
assert_equal({"name" => "passed_option"}, operations.first)
|
74
74
|
end
|
75
75
|
|
76
76
|
test "should apply! many operations from a string" do
|
77
|
-
@operation_builder.apply!(JSON.generate({
|
77
|
+
@operation_builder.apply!(JSON.generate({name: "passed_option"}))
|
78
78
|
|
79
79
|
operations = @operation_builder.instance_variable_get(:@enqueued_operations)
|
80
|
-
assert_equal 1, operations
|
81
|
-
assert_equal({"name" => "passed_option"}, operations
|
80
|
+
assert_equal 1, operations.size
|
81
|
+
assert_equal({"name" => "passed_option"}, operations.first)
|
82
82
|
end
|
83
83
|
|
84
84
|
test "operations payload should omit empty operations" do
|
85
85
|
@operation_builder.add_operation_method("foobar")
|
86
86
|
payload = @operation_builder.operations_payload
|
87
|
-
assert_equal(
|
87
|
+
assert_equal([], payload)
|
88
88
|
end
|
89
89
|
|
90
90
|
test "operations payload should camelize keys" do
|
91
91
|
@operation_builder.add_operation_method("foo_bar")
|
92
92
|
@operation_builder.foo_bar({beep_boop: "passed_option"})
|
93
|
-
assert_equal({"
|
93
|
+
assert_equal([{"operation" => "fooBar", "beepBoop" => "passed_option"}], @operation_builder.operations_payload)
|
94
94
|
end
|
95
95
|
|
96
96
|
test "should take first argument as selector" do
|
@@ -98,9 +98,7 @@ class CableReady::OperationBuilderTest < ActiveSupport::TestCase
|
|
98
98
|
|
99
99
|
@operation_builder.inner_html("#smelly", html: "<span>I rock</span>")
|
100
100
|
|
101
|
-
operations = {
|
102
|
-
"innerHtml" => [{"html" => "<span>I rock</span>", "selector" => "#smelly"}]
|
103
|
-
}
|
101
|
+
operations = [{"operation" => "innerHtml", "html" => "<span>I rock</span>", "selector" => "#smelly"}]
|
104
102
|
|
105
103
|
assert_equal(operations, @operation_builder.operations_payload)
|
106
104
|
end
|
@@ -111,10 +109,10 @@ class CableReady::OperationBuilderTest < ActiveSupport::TestCase
|
|
111
109
|
|
112
110
|
@operation_builder.set_focus("#smelly").inner_html(html: "<span>I rock</span>")
|
113
111
|
|
114
|
-
operations =
|
115
|
-
"
|
116
|
-
"
|
117
|
-
|
112
|
+
operations = [
|
113
|
+
{"operation" => "setFocus", "selector" => "#smelly"},
|
114
|
+
{"operation" => "innerHtml", "html" => "<span>I rock</span>", "selector" => "#smelly"}
|
115
|
+
]
|
118
116
|
|
119
117
|
assert_equal(operations, @operation_builder.operations_payload)
|
120
118
|
end
|
@@ -127,7 +125,7 @@ class CableReady::OperationBuilderTest < ActiveSupport::TestCase
|
|
127
125
|
|
128
126
|
@operation_builder.inner_html(html: "<span>winning</span>")
|
129
127
|
|
130
|
-
assert_equal({"
|
128
|
+
assert_equal([{"operation" => "innerHtml", "html" => "<span>winning</span>"}], @operation_builder.operations_payload)
|
131
129
|
end
|
132
130
|
|
133
131
|
test "should use previous_selector if present and should use `selector` if explicitly provided" do
|
@@ -136,15 +134,11 @@ class CableReady::OperationBuilderTest < ActiveSupport::TestCase
|
|
136
134
|
|
137
135
|
@operation_builder.set_focus("#smelly").inner_html(html: "<span>I rock</span>").inner_html(html: "<span>I rock too</span>", selector: "#smelly2")
|
138
136
|
|
139
|
-
operations =
|
140
|
-
"setFocus" =>
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
{"html" => "<span>I rock</span>", "selector" => "#smelly"},
|
145
|
-
{"html" => "<span>I rock too</span>", "selector" => "#smelly2"}
|
146
|
-
]
|
147
|
-
}
|
137
|
+
operations = [
|
138
|
+
{"operation" => "setFocus", "selector" => "#smelly"},
|
139
|
+
{"operation" => "innerHtml", "html" => "<span>I rock</span>", "selector" => "#smelly"},
|
140
|
+
{"operation" => "innerHtml", "html" => "<span>I rock too</span>", "selector" => "#smelly2"}
|
141
|
+
]
|
148
142
|
|
149
143
|
assert_equal(operations, @operation_builder.operations_payload)
|
150
144
|
end
|
@@ -155,11 +149,7 @@ class CableReady::OperationBuilderTest < ActiveSupport::TestCase
|
|
155
149
|
|
156
150
|
@operation_builder.inner_html(html: death)
|
157
151
|
|
158
|
-
operations = {
|
159
|
-
"innerHtml" => [
|
160
|
-
{"html" => "I rock"}
|
161
|
-
]
|
162
|
-
}
|
152
|
+
operations = [{"operation" => "innerHtml", "html" => "I rock"}]
|
163
153
|
|
164
154
|
assert_equal(operations, @operation_builder.operations_payload)
|
165
155
|
end
|
@@ -170,11 +160,7 @@ class CableReady::OperationBuilderTest < ActiveSupport::TestCase
|
|
170
160
|
|
171
161
|
@operation_builder.inner_html(death, html: death)
|
172
162
|
|
173
|
-
operations = {
|
174
|
-
"innerHtml" => [
|
175
|
-
{"html" => "I rock", "selector" => "#death"}
|
176
|
-
]
|
177
|
-
}
|
163
|
+
operations = [{"operation" => "innerHtml", "html" => "I rock", "selector" => "#death"}]
|
178
164
|
|
179
165
|
assert_equal(operations, @operation_builder.operations_payload)
|
180
166
|
end
|
@@ -185,11 +171,7 @@ class CableReady::OperationBuilderTest < ActiveSupport::TestCase
|
|
185
171
|
|
186
172
|
@operation_builder.inner_html(death)
|
187
173
|
|
188
|
-
operations = {
|
189
|
-
"innerHtml" => [
|
190
|
-
{"html" => "I rock", "domId" => "death"}
|
191
|
-
]
|
192
|
-
}
|
174
|
+
operations = [{"operation" => "innerHtml", "html" => "I rock", "domId" => "death"}]
|
193
175
|
|
194
176
|
assert_equal(operations, @operation_builder.operations_payload)
|
195
177
|
end
|
@@ -200,11 +182,7 @@ class CableReady::OperationBuilderTest < ActiveSupport::TestCase
|
|
200
182
|
|
201
183
|
@operation_builder.inner_html(life)
|
202
184
|
|
203
|
-
operations = {
|
204
|
-
"innerHtml" => [
|
205
|
-
{"html" => "You go, girl", "domId" => "life"}
|
206
|
-
]
|
207
|
-
}
|
185
|
+
operations = [{"operation" => "innerHtml", "html" => "You go, girl", "domId" => "life"}]
|
208
186
|
|
209
187
|
assert_equal(operations, @operation_builder.operations_payload)
|
210
188
|
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
class CableReady::UpdatableTest < ActiveSupport::TestCase
|
6
|
+
test "includes the module automatically in associated models" do
|
7
|
+
user = User.create(name: "John Doe")
|
8
|
+
|
9
|
+
post = user.posts.build
|
10
|
+
assert post.class < CableReady::Updatable
|
11
|
+
end
|
12
|
+
|
13
|
+
test "updates the collection when an item is added" do
|
14
|
+
mock_server = mock("server")
|
15
|
+
mock_server.expects(:broadcast).with(User, {}).once
|
16
|
+
mock_server.expects(:broadcast).with("gid://dummy/User/1:posts", {}).once
|
17
|
+
|
18
|
+
ActionCable.stubs(:server).returns(mock_server)
|
19
|
+
user = User.create(name: "John Doe")
|
20
|
+
|
21
|
+
user.posts.create(title: "Lorem")
|
22
|
+
end
|
23
|
+
|
24
|
+
test "updates the collection when an item is destroyed" do
|
25
|
+
user = User.create(name: "John Doe")
|
26
|
+
post = user.posts.create(title: "Lorem")
|
27
|
+
|
28
|
+
mock_server = mock("server")
|
29
|
+
mock_server.expects(:broadcast).with("gid://dummy/User/1:posts", {}).once
|
30
|
+
|
31
|
+
ActionCable.stubs(:server).returns(mock_server)
|
32
|
+
|
33
|
+
post.destroy
|
34
|
+
end
|
35
|
+
|
36
|
+
test "updates the collection when an item is updated" do
|
37
|
+
user = User.create(name: "John Doe")
|
38
|
+
post = user.posts.create(title: "Lorem")
|
39
|
+
|
40
|
+
mock_server = mock("server")
|
41
|
+
mock_server.expects(:broadcast).with("gid://dummy/User/1:posts", {}).once
|
42
|
+
|
43
|
+
ActionCable.stubs(:server).returns(mock_server)
|
44
|
+
|
45
|
+
post.update(title: "Ipsum")
|
46
|
+
end
|
47
|
+
|
48
|
+
test "updates the model when it is updated" do
|
49
|
+
user = User.create(name: "John Doe")
|
50
|
+
|
51
|
+
mock_server = mock("server")
|
52
|
+
mock_server.expects(:broadcast).with(User, {}).once
|
53
|
+
mock_server.expects(:broadcast).with(user.to_global_id, {}).once
|
54
|
+
|
55
|
+
ActionCable.stubs(:server).returns(mock_server)
|
56
|
+
|
57
|
+
user.update(name: "Jane Doe")
|
58
|
+
end
|
59
|
+
|
60
|
+
test "updates the parent when it is touched" do
|
61
|
+
team = Team.create
|
62
|
+
user = team.users.create(name: "Ada Lovelace")
|
63
|
+
|
64
|
+
mock_server = mock("server")
|
65
|
+
mock_server.expects(:broadcast).with(User, {}).once
|
66
|
+
mock_server.expects(:broadcast).with(user.to_global_id, {}).once
|
67
|
+
mock_server.expects(:broadcast).with("gid://dummy/Team/1:users", {}).once
|
68
|
+
mock_server.expects(:broadcast).with(Team, {}).once
|
69
|
+
mock_server.expects(:broadcast).with(team.to_global_id, {}).once
|
70
|
+
|
71
|
+
ActionCable.stubs(:server).returns(mock_server)
|
72
|
+
|
73
|
+
user.update(name: "Jane Doe")
|
74
|
+
end
|
75
|
+
|
76
|
+
test "respects :on to specify persistence methods" do
|
77
|
+
mock_server = mock("server")
|
78
|
+
|
79
|
+
ActionCable.stubs(:server).returns(mock_server)
|
80
|
+
|
81
|
+
mock_server.expects(:broadcast).with(Topic, {}).once
|
82
|
+
topic = Topic.create(title: "Reactive Rails with Hotwire")
|
83
|
+
|
84
|
+
mock_server.expects(:broadcast).with(topic.to_global_id, {}).never
|
85
|
+
topic.update(title: "Reactive Rails with CableReady")
|
86
|
+
end
|
87
|
+
|
88
|
+
test "respects :if on enable_updates" do
|
89
|
+
mock_server = mock("server")
|
90
|
+
|
91
|
+
ActionCable.stubs(:server).returns(mock_server)
|
92
|
+
|
93
|
+
section = Section.create
|
94
|
+
section.updates_enabled = true
|
95
|
+
|
96
|
+
mock_server.expects(:broadcast).with(Section, {}).once
|
97
|
+
mock_server.expects(:broadcast).with(section.to_global_id, {}).once
|
98
|
+
section.update(title: "First Section")
|
99
|
+
end
|
100
|
+
|
101
|
+
test "updates any GlobalID-able entity" do
|
102
|
+
entity = GlobalIdableEntity.new
|
103
|
+
|
104
|
+
mock_server = mock("server")
|
105
|
+
mock_server.expects(:broadcast).with(GlobalIdableEntity, {}).once
|
106
|
+
mock_server.expects(:broadcast).with(entity.to_global_id, {}).once
|
107
|
+
|
108
|
+
ActionCable.stubs(:server).returns(mock_server)
|
109
|
+
|
110
|
+
entity.fake_update
|
111
|
+
end
|
112
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -3,10 +3,13 @@
|
|
3
3
|
# Configure Rails Environment
|
4
4
|
ENV["RAILS_ENV"] = "test"
|
5
5
|
|
6
|
+
require_relative "../test/dummy/config/environment"
|
7
|
+
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
|
8
|
+
|
6
9
|
require "mocha"
|
7
10
|
require "rails"
|
8
|
-
require "rails/generators"
|
9
11
|
require "rails/test_help"
|
12
|
+
require "rails/generators"
|
10
13
|
require "minitest/mock"
|
11
14
|
require "mocha/minitest"
|
12
15
|
require "pry"
|