cubism 0.1.0.pre12 → 0.1.0.pre13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +16 -0
- data/Appraisals~ +16 -0
- data/CHANGELOG.md +87 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +220 -0
- data/Gemfile~ +9 -0
- data/README.md +32 -12
- data/README.md~ +191 -0
- data/app/assets/javascripts/cubism.js +141 -0
- data/app/assets/javascripts/cubism.min.js +2 -0
- data/app/assets/javascripts/cubism.min.js.map +1 -0
- data/app/assets/javascripts/cubism.umd.js +149 -0
- data/app/assets/javascripts/cubism.umd.min.js +2 -0
- data/app/assets/javascripts/cubism.umd.min.js.map +1 -0
- data/bin/rails +14 -0
- data/bin/standardize +4 -0
- data/bin/test +5 -0
- data/cubism.gemspec +36 -0
- data/cubism.gemspec~ +28 -0
- data/lib/cubism/engine.rb +20 -0
- data/lib/cubism/importmap.rb +2 -0
- data/lib/cubism/version.rb +1 -1
- data/package.json +43 -0
- data/package.json~ +33 -0
- data/rollup.config.js +77 -0
- data/{lib/cubism/cubicle_source_store.rb~ → rollup.config.js~} +0 -0
- data/test/block_container_test.rb +105 -0
- data/test/block_source_test.rb +102 -0
- data/test/broadcaster_test.rb +66 -0
- data/test/channels/cubism/presence_channel_test.rb +72 -0
- data/test/cubicle_store_test.rb +34 -0
- data/test/cubism_test.rb +7 -0
- 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/post.rb +3 -0
- data/test/dummy/app/models/user.rb +3 -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/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/20220102072929_create_posts.rb +10 -0
- data/test/dummy/db/migrate/20220102073003_create_users.rb +9 -0
- data/test/dummy/db/schema.rb +26 -0
- data/test/dummy/test/models/post_test.rb +7 -0
- data/test/dummy/test/models/user_test.rb +7 -0
- data/test/helpers/cubism_helper_test.rb +39 -0
- data/test/integration/navigation_test.rb +7 -0
- data/test/models/concerns/presence_test.rb +25 -0
- data/test/models/concerns/user_test.rb +9 -0
- data/test/rendering/preprocessor_test.rb +61 -0
- data/test/test_helper.rb +16 -0
- data/yarn.lock +2814 -0
- metadata +117 -19
- data/app/channels/cubism/presence_channel.rb~ +0 -61
- data/app/helpers/cubism_helper.rb~ +0 -36
- data/app/models/concerns/cubism/presence.rb~ +0 -20
- data/config/routes.rb +0 -2
- data/lib/cubism/broadcaster.rb~ +0 -37
- data/lib/cubism/cubicle_block_store.rb~ +0 -56
- data/lib/cubism/cubicle_store.rb~ +0 -141
- data/lib/cubism/engine.rb~ +0 -7
- data/lib/cubism/parser.rb~ +0 -0
- data/lib/cubism/preprocessor.rb~ +0 -30
- data/lib/cubism/version.rb~ +0 -3
- data/lib/cubism.rb~ +0 -18
- data/lib/tasks/cubism_tasks.rake +0 -4
data/rollup.config.js
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
import resolve from '@rollup/plugin-node-resolve'
|
2
|
+
import commonjs from '@rollup/plugin-commonjs'
|
3
|
+
import json from '@rollup/plugin-json'
|
4
|
+
import { terser } from 'rollup-plugin-terser'
|
5
|
+
|
6
|
+
const pretty = () => {
|
7
|
+
return terser({
|
8
|
+
mangle: false,
|
9
|
+
compress: false,
|
10
|
+
format: {
|
11
|
+
beautify: true,
|
12
|
+
indent_level: 2
|
13
|
+
}
|
14
|
+
})
|
15
|
+
}
|
16
|
+
|
17
|
+
const minify = () => {
|
18
|
+
return terser({
|
19
|
+
mangle: true,
|
20
|
+
compress: true
|
21
|
+
})
|
22
|
+
}
|
23
|
+
|
24
|
+
const esConfig = {
|
25
|
+
format: 'es',
|
26
|
+
inlineDynamicImports: true
|
27
|
+
}
|
28
|
+
|
29
|
+
const umdConfig = {
|
30
|
+
name: 'Cubism',
|
31
|
+
format: 'umd',
|
32
|
+
exports: 'named',
|
33
|
+
globals: {
|
34
|
+
cable_ready: 'CableReady'
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
const distFolders = ['dist/', 'app/assets/javascripts/']
|
39
|
+
|
40
|
+
const output = distFolders
|
41
|
+
.map(distFolder => [
|
42
|
+
{
|
43
|
+
...esConfig,
|
44
|
+
file: `${distFolder}/cubism.js`,
|
45
|
+
plugins: [pretty()]
|
46
|
+
},
|
47
|
+
{
|
48
|
+
...esConfig,
|
49
|
+
file: `${distFolder}/cubism.min.js`,
|
50
|
+
sourcemap: true,
|
51
|
+
plugins: [minify()]
|
52
|
+
},
|
53
|
+
{
|
54
|
+
...umdConfig,
|
55
|
+
file: `${distFolder}/cubism.umd.js`,
|
56
|
+
plugins: [pretty()]
|
57
|
+
},
|
58
|
+
{
|
59
|
+
...umdConfig,
|
60
|
+
file: `${distFolder}/cubism.umd.min.js`,
|
61
|
+
sourcemap: true,
|
62
|
+
plugins: [minify()]
|
63
|
+
}
|
64
|
+
])
|
65
|
+
.flat()
|
66
|
+
|
67
|
+
export default [
|
68
|
+
{
|
69
|
+
external: ['cable_ready'],
|
70
|
+
input: 'javascript/index.js',
|
71
|
+
output,
|
72
|
+
plugins: [commonjs(), resolve(), json()],
|
73
|
+
watch: {
|
74
|
+
include: 'javascript/**'
|
75
|
+
}
|
76
|
+
}
|
77
|
+
]
|
File without changes
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class BlockContainerTest < ActiveSupport::TestCase
|
4
|
+
FIXTURES_DIR = File.expand_path("./fixtures", __dir__)
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@cwd = Dir.pwd
|
8
|
+
@tmp_dir = Dir.mktmpdir
|
9
|
+
|
10
|
+
FileUtils.cp_r FIXTURES_DIR, @tmp_dir
|
11
|
+
Dir.chdir @tmp_dir
|
12
|
+
|
13
|
+
@post = posts(:one)
|
14
|
+
@user = users(:one)
|
15
|
+
end
|
16
|
+
|
17
|
+
teardown do
|
18
|
+
Dir.chdir @cwd
|
19
|
+
FileUtils.rm_r @tmp_dir
|
20
|
+
end
|
21
|
+
|
22
|
+
test "block container digest changes when file contents change" do
|
23
|
+
template = "fixtures/_cubicle_partial"
|
24
|
+
|
25
|
+
digest1 = Cubism::BlockContainer.new(
|
26
|
+
block_location: "#{template_tmp_path(template)}.html.erb:1",
|
27
|
+
resource_gid: @post.to_gid.to_s,
|
28
|
+
user_gid: @user.to_gid.to_s
|
29
|
+
).digest
|
30
|
+
|
31
|
+
change_template(template)
|
32
|
+
|
33
|
+
digest2 = Cubism::BlockContainer.new(
|
34
|
+
block_location: "#{template_tmp_path(template)}.html.erb:1",
|
35
|
+
resource_gid: @post.to_gid.to_s,
|
36
|
+
user_gid: @user.to_gid.to_s
|
37
|
+
).digest
|
38
|
+
|
39
|
+
refute_equal digest1, digest2
|
40
|
+
end
|
41
|
+
|
42
|
+
test "block container digest changes when user changes" do
|
43
|
+
template = "fixtures/_cubicle_partial"
|
44
|
+
|
45
|
+
digest1 = Cubism::BlockContainer.new(
|
46
|
+
block_location: "#{template_tmp_path(template)}.html.erb:1",
|
47
|
+
resource_gid: @post.to_gid.to_s,
|
48
|
+
user_gid: @user.to_gid.to_s
|
49
|
+
).digest
|
50
|
+
|
51
|
+
digest2 = Cubism::BlockContainer.new(
|
52
|
+
block_location: "#{template_tmp_path(template)}.html.erb:1",
|
53
|
+
resource_gid: @post.to_gid.to_s,
|
54
|
+
user_gid: users(:two).to_gid.to_s
|
55
|
+
).digest
|
56
|
+
|
57
|
+
refute_equal digest1, digest2
|
58
|
+
end
|
59
|
+
|
60
|
+
test "block container digest changes when resource changes" do
|
61
|
+
template = "fixtures/_cubicle_partial"
|
62
|
+
|
63
|
+
digest1 = Cubism::BlockContainer.new(
|
64
|
+
block_location: "#{template_tmp_path(template)}.html.erb:1",
|
65
|
+
resource_gid: @post.to_gid.to_s,
|
66
|
+
user_gid: @user.to_gid.to_s
|
67
|
+
).digest
|
68
|
+
|
69
|
+
digest2 = Cubism::BlockContainer.new(
|
70
|
+
block_location: "#{template_tmp_path(template)}.html.erb:1",
|
71
|
+
resource_gid: posts(:two).to_gid.to_s,
|
72
|
+
user_gid: @user.to_gid.to_s
|
73
|
+
).digest
|
74
|
+
|
75
|
+
refute_equal digest1, digest2
|
76
|
+
end
|
77
|
+
|
78
|
+
test "block container digest changes when block_location changes" do
|
79
|
+
template = "fixtures/_cubicle_partial"
|
80
|
+
|
81
|
+
digest1 = Cubism::BlockContainer.new(
|
82
|
+
block_location: "#{template_tmp_path(template)}.html.erb:1",
|
83
|
+
resource_gid: @post.to_gid.to_s,
|
84
|
+
user_gid: @user.to_gid.to_s
|
85
|
+
).digest
|
86
|
+
|
87
|
+
digest2 = Cubism::BlockContainer.new(
|
88
|
+
block_location: "#{template_tmp_path(template)}.html.erb:2",
|
89
|
+
resource_gid: @post.to_gid.to_s,
|
90
|
+
user_gid: @user.to_gid.to_s
|
91
|
+
).digest
|
92
|
+
|
93
|
+
refute_equal digest1, digest2
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def template_tmp_path(template)
|
99
|
+
Pathname.new(@tmp_dir).join(template).to_path
|
100
|
+
end
|
101
|
+
|
102
|
+
def change_template(template)
|
103
|
+
File.write("#{template}.html.erb", "\nTHIS WAS CHANGED!")
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class BlockSourceTest < ActionView::TestCase
|
4
|
+
FIXTURES_DIR = File.expand_path("./fixtures", __dir__)
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@cwd = Dir.pwd
|
8
|
+
@tmp_dir = Dir.mktmpdir
|
9
|
+
|
10
|
+
FileUtils.cp_r FIXTURES_DIR, @tmp_dir
|
11
|
+
Dir.chdir @tmp_dir
|
12
|
+
|
13
|
+
@post = posts(:one)
|
14
|
+
@user = users(:one)
|
15
|
+
end
|
16
|
+
|
17
|
+
teardown do
|
18
|
+
Dir.chdir @cwd
|
19
|
+
FileUtils.rm_r @tmp_dir
|
20
|
+
end
|
21
|
+
|
22
|
+
test "block source digest changes when file contents change" do
|
23
|
+
template = "fixtures/_cubicle_partial"
|
24
|
+
|
25
|
+
digest1 = Cubism::BlockSource.new(
|
26
|
+
location: "#{template_tmp_path(template)}.html.erb:1",
|
27
|
+
view_context: self
|
28
|
+
).digest
|
29
|
+
|
30
|
+
change_template(template)
|
31
|
+
|
32
|
+
digest2 = Cubism::BlockSource.new(
|
33
|
+
location: "#{template_tmp_path(template)}.html.erb:1",
|
34
|
+
view_context: self
|
35
|
+
).digest
|
36
|
+
|
37
|
+
refute_equal digest1, digest2
|
38
|
+
end
|
39
|
+
|
40
|
+
test "block source digest changes when block_location changes" do
|
41
|
+
template = "fixtures/_cubicle_partial"
|
42
|
+
|
43
|
+
digest1 = Cubism::BlockSource.new(
|
44
|
+
location: "#{template_tmp_path(template)}.html.erb:1",
|
45
|
+
view_context: self
|
46
|
+
).digest
|
47
|
+
|
48
|
+
digest2 = Cubism::BlockSource.new(
|
49
|
+
location: "#{template_tmp_path(template)}.html.erb:2",
|
50
|
+
view_context: self
|
51
|
+
).digest
|
52
|
+
|
53
|
+
refute_equal digest1, digest2
|
54
|
+
end
|
55
|
+
|
56
|
+
test "can be created in the store by source location" do
|
57
|
+
template = "fixtures/_cubicle_partial"
|
58
|
+
|
59
|
+
assert_equal 0, Cubism.source_store.size
|
60
|
+
|
61
|
+
Cubism::BlockSource.any_instance.expects(:parse!).once
|
62
|
+
|
63
|
+
Cubism::BlockSource.find_or_create(
|
64
|
+
location: "#{template_tmp_path(template)}.html.erb:1",
|
65
|
+
view_context: self
|
66
|
+
)
|
67
|
+
|
68
|
+
assert_equal 1, Cubism.source_store.size
|
69
|
+
end
|
70
|
+
|
71
|
+
test "existing block source is returned and not parsed" do
|
72
|
+
template = "fixtures/_cubicle_partial"
|
73
|
+
|
74
|
+
instance = Cubism::BlockSource.new(
|
75
|
+
location: "#{template_tmp_path(template)}.html.erb:1",
|
76
|
+
view_context: self
|
77
|
+
)
|
78
|
+
|
79
|
+
Cubism.source_store[instance.digest] = instance
|
80
|
+
|
81
|
+
assert_equal 1, Cubism.source_store.size
|
82
|
+
|
83
|
+
Cubism::BlockSource.any_instance.expects(:parse!).never
|
84
|
+
|
85
|
+
Cubism::BlockSource.find_or_create(
|
86
|
+
location: "#{template_tmp_path(template)}.html.erb:1",
|
87
|
+
view_context: self
|
88
|
+
)
|
89
|
+
|
90
|
+
assert_equal 1, Cubism.source_store.size
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def template_tmp_path(template)
|
96
|
+
Pathname.new(@tmp_dir).join(template).to_path
|
97
|
+
end
|
98
|
+
|
99
|
+
def change_template(template)
|
100
|
+
File.write("#{template}.html.erb", "\nTHIS WAS CHANGED!")
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class BroadcasterTest < ActionView::TestCase
|
4
|
+
include CableReady::StreamIdentifier
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@post = posts(:one)
|
8
|
+
@post.stubs(:cubicle_element_ids).returns(%w[foo bar])
|
9
|
+
@post.stubs(:present_users_for_element_id_and_scope).with("foo", "").returns([users(:one)])
|
10
|
+
@post.stubs(:present_users_for_element_id_and_scope).with("bar", "").returns([users(:two)])
|
11
|
+
|
12
|
+
@post_2 = posts(:two)
|
13
|
+
@post_2.stubs(:cubicle_element_ids).returns(%w[baz])
|
14
|
+
@post_2.stubs(:present_users_for_element_id_and_scope).with("baz", :edit).returns([users(:one)])
|
15
|
+
@post_2.stubs(:present_users_for_element_id_and_scope).with("baz", :show).returns([])
|
16
|
+
|
17
|
+
block_source_foo = Cubism::BlockSource.new(location: "test:1", variable_name: "users", source: "<div><%= users.map(&:username).to_sentence %></div>", view_context: self)
|
18
|
+
block_source_bar = Cubism::BlockSource.new(location: "test:1", variable_name: "present_users", source: "<div><%= present_users.map(&:username).to_sentence %></div>", view_context: self)
|
19
|
+
|
20
|
+
Cubism.stubs(:block_store).returns({
|
21
|
+
"foo" => Cubism::BlockContainer.new(block_location: "test:1", block_source: block_source_foo, user_gid: users(:one).to_gid.to_s, resource_gid: posts(:one).to_gid.to_s),
|
22
|
+
"bar" => Cubism::BlockContainer.new(block_location: "test:1", block_source: block_source_bar, user_gid: users(:two).to_gid.to_s, resource_gid: posts(:one).to_gid.to_s),
|
23
|
+
"baz" => Cubism::BlockContainer.new(block_location: "test:1", block_source: block_source_foo, user_gid: users(:one).to_gid.to_s, resource_gid: posts(:two).to_gid.to_s, scope: :edit)
|
24
|
+
})
|
25
|
+
end
|
26
|
+
|
27
|
+
test "it broadcasts to all registered element ids with default scopes" do
|
28
|
+
with_mocked_cable_ready({"foo" => {"" => users(:one)}, "bar" => {"" => users(:two)}}, @post) do |cable_ready_mock|
|
29
|
+
@broadcaster = Cubism::Broadcaster.new(resource: @post)
|
30
|
+
|
31
|
+
@broadcaster.expects(:cable_ready).returns(cable_ready_mock).times(3)
|
32
|
+
|
33
|
+
@broadcaster.broadcast
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
test "it broadcasts to all registered element ids and respects scopes" do
|
38
|
+
with_mocked_cable_ready({"baz" => {"edit" => users(:one)}}, @post_2) do |cable_ready_mock|
|
39
|
+
@broadcaster = Cubism::Broadcaster.new(resource: @post_2)
|
40
|
+
|
41
|
+
@broadcaster.expects(:cable_ready).returns(cable_ready_mock).twice
|
42
|
+
|
43
|
+
@broadcaster.broadcast
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def with_mocked_cable_ready(elements_with_users_and_scopes, resource)
|
49
|
+
cable_ready_mock = mock
|
50
|
+
cable_ready_mock.expects(:broadcast).once
|
51
|
+
|
52
|
+
elements_with_users_and_scopes.each do |element_id, scoped_users|
|
53
|
+
cable_ready_channel = mock
|
54
|
+
scoped_users.each do |scope, user|
|
55
|
+
cable_ready_channel
|
56
|
+
.expects(:inner_html)
|
57
|
+
.with({
|
58
|
+
selector: "cubicle-element#cubicle-#{element_id}[identifier='#{signed_stream_identifier(resource.to_global_id.to_s)}']",
|
59
|
+
html: "<div>#{user.username}</div>"
|
60
|
+
})
|
61
|
+
end
|
62
|
+
cable_ready_mock.expects(:[]).with(element_id).returns(cable_ready_channel)
|
63
|
+
end
|
64
|
+
|
65
|
+
yield cable_ready_mock
|
66
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class Cubism::PresenceChannelTest < ActionCable::Channel::TestCase
|
4
|
+
include CableReady::StreamIdentifier
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@post = posts(:one)
|
8
|
+
@user = users(:one)
|
9
|
+
|
10
|
+
Post.any_instance.stubs(:cubicle_element_ids).returns([])
|
11
|
+
Post.any_instance.stubs(:excluded_user_id_for_element_id).returns({})
|
12
|
+
Post.any_instance.stubs(:present_users).returns({})
|
13
|
+
|
14
|
+
Cubism.stubs(:block_store).returns({
|
15
|
+
"foo" => Cubism::BlockContainer.new(block_location: "test:1", user_gid: @user.to_gid.to_s, resource_gid: @post.to_gid.to_s, scope: ""),
|
16
|
+
"bar" => Cubism::BlockContainer.new(block_location: "test:1", user_gid: @user.to_gid.to_s, resource_gid: @post.to_gid.to_s, scope: "edit")
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
test "rejects a subscription for invalid identifiers" do
|
21
|
+
subscribe identifier: "foo", element_id: "cubicle-bar"
|
22
|
+
|
23
|
+
assert subscription.rejected?
|
24
|
+
end
|
25
|
+
|
26
|
+
test "confirms a subscription for valid identifiers" do
|
27
|
+
subscribe identifier: signed_stream_identifier(@post.to_gid.to_s), element_id: "cubicle-bar"
|
28
|
+
|
29
|
+
assert subscription.confirmed?
|
30
|
+
|
31
|
+
assert_has_stream "bar"
|
32
|
+
assert_equal 1, @post.cubicle_element_ids.size
|
33
|
+
end
|
34
|
+
|
35
|
+
test "adds user_id to the excluded users hash if the exclude_current_user param is passed" do
|
36
|
+
subscribe identifier: signed_stream_identifier(@post.to_gid.to_s), element_id: "cubicle-bar", exclude_current_user: true
|
37
|
+
|
38
|
+
assert_equal({"bar" => @user.id}, @post.excluded_user_id_for_element_id)
|
39
|
+
end
|
40
|
+
|
41
|
+
test "adds a user to the present users list when appear is called" do
|
42
|
+
subscribe identifier: signed_stream_identifier(@post.to_gid.to_s), element_id: "cubicle-foo"
|
43
|
+
perform :appear
|
44
|
+
|
45
|
+
assert_equal [@user.id], @post.present_users_for_scope("").to_a
|
46
|
+
end
|
47
|
+
|
48
|
+
test "adds a user to a scope in the present users list when appear is called with a scope parameter" do
|
49
|
+
assert_equal [], @post.present_users_for_scope("edit").to_a
|
50
|
+
assert_equal [], @post.present_users_for_scope("show").to_a
|
51
|
+
|
52
|
+
subscribe identifier: signed_stream_identifier(@post.to_gid.to_s), element_id: "cubicle-bar", scope: "edit"
|
53
|
+
perform :appear
|
54
|
+
|
55
|
+
subscribe identifier: signed_stream_identifier(@post.to_gid.to_s), element_id: "bar", scope: "show"
|
56
|
+
|
57
|
+
assert_equal [@user.id], @post.present_users_for_scope("edit").to_a
|
58
|
+
assert_equal [], @post.present_users_for_scope("show").to_a
|
59
|
+
end
|
60
|
+
|
61
|
+
test "removes a user from the present users list when disappear is called" do
|
62
|
+
subscribe identifier: signed_stream_identifier(@post.to_gid.to_s), element_id: "cubicle-foo"
|
63
|
+
|
64
|
+
perform :appear
|
65
|
+
|
66
|
+
assert_equal [@user.id], @post.present_users_for_scope("").to_a
|
67
|
+
|
68
|
+
perform :disappear
|
69
|
+
|
70
|
+
assert_equal [], @post.present_users_for_scope("").to_a
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CubicleStoreTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@store = Cubism::CubicleStore.new("cubism-test")
|
6
|
+
end
|
7
|
+
|
8
|
+
test "empty value just retrieves the key" do
|
9
|
+
@store["foo"] = "bar"
|
10
|
+
|
11
|
+
value = @store.fetch("foo")
|
12
|
+
|
13
|
+
refute_nil @store["foo"]
|
14
|
+
assert_equal "bar", value
|
15
|
+
end
|
16
|
+
|
17
|
+
test "fetch assigns value to empty key" do
|
18
|
+
assert_nil @store["foo"]
|
19
|
+
|
20
|
+
value = @store.fetch("foo", "bar")
|
21
|
+
|
22
|
+
refute_nil @store["foo"]
|
23
|
+
assert_equal "bar", value
|
24
|
+
end
|
25
|
+
|
26
|
+
test "fetch retrieves value for existing key, and does not overwrite it" do
|
27
|
+
@store["foo"] = "baz"
|
28
|
+
|
29
|
+
value = @store.fetch("foo", "bar")
|
30
|
+
|
31
|
+
refute_nil @store["foo"]
|
32
|
+
assert_equal "baz", value
|
33
|
+
end
|
34
|
+
end
|
data/test/cubism_test.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
class ApplicationJob < ActiveJob::Base
|
2
|
+
# Automatically retry jobs that encountered a deadlock
|
3
|
+
# retry_on ActiveRecord::Deadlocked
|
4
|
+
|
5
|
+
# Most jobs are safe to ignore if the underlying records are no longer available
|
6
|
+
# discard_on ActiveJob::DeserializationError
|
7
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "boot"
|
2
|
+
|
3
|
+
require "rails/all"
|
4
|
+
|
5
|
+
# Require the gems listed in Gemfile, including any gems
|
6
|
+
# you've limited to :test, :development, or :production.
|
7
|
+
Bundler.require(*Rails.groups)
|
8
|
+
require "cubism"
|
9
|
+
|
10
|
+
module Dummy
|
11
|
+
class Application < Rails::Application
|
12
|
+
config.load_defaults Rails::VERSION::STRING.to_f
|
13
|
+
|
14
|
+
# Configuration for the application, engines, and railties goes here.
|
15
|
+
#
|
16
|
+
# These settings can be overridden in specific environments using the files
|
17
|
+
# in config/environments, which are processed later.
|
18
|
+
#
|
19
|
+
# config.time_zone = "Central Time (US & Canada)"
|
20
|
+
# config.eager_load_paths << Rails.root.join("extras")
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "active_support/core_ext/integer/time"
|
2
|
+
|
3
|
+
Rails.application.configure do
|
4
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
5
|
+
|
6
|
+
# In the development environment your application's code is reloaded any time
|
7
|
+
# it changes. This slows down response time but is perfect for development
|
8
|
+
# since you don't have to restart the web server when you make code changes.
|
9
|
+
config.cache_classes = false
|
10
|
+
|
11
|
+
# Do not eager load code on boot.
|
12
|
+
config.eager_load = false
|
13
|
+
|
14
|
+
# Show full error reports.
|
15
|
+
config.consider_all_requests_local = true
|
16
|
+
|
17
|
+
# Enable/disable caching. By default caching is disabled.
|
18
|
+
# Run rails dev:cache to toggle caching.
|
19
|
+
if Rails.root.join("tmp", "caching-dev.txt").exist?
|
20
|
+
config.action_controller.perform_caching = true
|
21
|
+
config.action_controller.enable_fragment_cache_logging = true
|
22
|
+
|
23
|
+
config.cache_store = :memory_store
|
24
|
+
config.public_file_server.headers = {
|
25
|
+
"Cache-Control" => "public, max-age=#{2.days.to_i}"
|
26
|
+
}
|
27
|
+
else
|
28
|
+
config.action_controller.perform_caching = false
|
29
|
+
|
30
|
+
config.cache_store = :null_store
|
31
|
+
end
|
32
|
+
|
33
|
+
# Store uploaded files on the local file system (see config/storage.yml for options).
|
34
|
+
config.active_storage.service = :local
|
35
|
+
|
36
|
+
# Don't care if the mailer can't send.
|
37
|
+
config.action_mailer.raise_delivery_errors = false
|
38
|
+
|
39
|
+
config.action_mailer.perform_caching = false
|
40
|
+
|
41
|
+
# Print deprecation notices to the Rails logger.
|
42
|
+
config.active_support.deprecation = :log
|
43
|
+
|
44
|
+
# Raise exceptions for disallowed deprecations.
|
45
|
+
config.active_support.disallowed_deprecation = :raise
|
46
|
+
|
47
|
+
# Tell Active Support which deprecation messages to disallow.
|
48
|
+
config.active_support.disallowed_deprecation_warnings = []
|
49
|
+
|
50
|
+
# Raise an error on page load if there are pending migrations.
|
51
|
+
config.active_record.migration_error = :page_load
|
52
|
+
|
53
|
+
# Highlight code that triggered database queries in logs.
|
54
|
+
config.active_record.verbose_query_logs = true
|
55
|
+
|
56
|
+
# Debug mode disables concatenation and preprocessing of assets.
|
57
|
+
# This option may cause significant delays in view rendering with a large
|
58
|
+
# number of complex assets.
|
59
|
+
config.assets.debug = true
|
60
|
+
|
61
|
+
# Suppress logger output for asset requests.
|
62
|
+
config.assets.quiet = true
|
63
|
+
|
64
|
+
# Raises error for missing translations.
|
65
|
+
# config.i18n.raise_on_missing_translations = true
|
66
|
+
|
67
|
+
# Annotate rendered view with file names.
|
68
|
+
# config.action_view.annotate_rendered_view_with_filenames = true
|
69
|
+
|
70
|
+
# Use an evented file watcher to asynchronously detect changes in source code,
|
71
|
+
# routes, locales, etc. This feature depends on the listen gem.
|
72
|
+
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
73
|
+
|
74
|
+
# Uncomment if you wish to allow Action Cable access from any origin.
|
75
|
+
# config.action_cable.disable_request_forgery_protection = true
|
76
|
+
end
|