cubism 0.2.0 → 0.2.2

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +6 -11
  3. data/Gemfile.lock +332 -155
  4. data/README.md +9 -0
  5. data/README.md~ +32 -12
  6. data/Rakefile +0 -2
  7. data/app/channels/cubism/presence_channel.rb +4 -0
  8. data/app/helpers/cubism_helper.rb +11 -0
  9. data/cubism.gemspec +5 -5
  10. data/lib/cubism/broadcaster.rb +6 -0
  11. data/lib/cubism/cubicle_store.rb +9 -2
  12. data/lib/cubism/preprocessor.rb +4 -1
  13. data/lib/cubism/version.rb +1 -1
  14. data/lib/cubism.rb +6 -0
  15. data/package.json +1 -1
  16. metadata +25 -102
  17. data/test/block_container_test.rb +0 -105
  18. data/test/block_source_test.rb +0 -102
  19. data/test/broadcaster_test.rb +0 -66
  20. data/test/channels/cubism/presence_channel_test.rb +0 -72
  21. data/test/cubicle_store_test.rb +0 -34
  22. data/test/cubism_test.rb +0 -7
  23. data/test/dummy/app/channels/application_cable/channel.rb +0 -4
  24. data/test/dummy/app/channels/application_cable/connection.rb +0 -4
  25. data/test/dummy/app/controllers/application_controller.rb +0 -2
  26. data/test/dummy/app/helpers/application_helper.rb +0 -2
  27. data/test/dummy/app/jobs/application_job.rb +0 -7
  28. data/test/dummy/app/mailers/application_mailer.rb +0 -4
  29. data/test/dummy/app/models/application_record.rb +0 -3
  30. data/test/dummy/app/models/post.rb +0 -3
  31. data/test/dummy/app/models/user.rb +0 -3
  32. data/test/dummy/config/application.rb +0 -22
  33. data/test/dummy/config/boot.rb +0 -5
  34. data/test/dummy/config/environment.rb +0 -5
  35. data/test/dummy/config/environments/development.rb +0 -76
  36. data/test/dummy/config/environments/production.rb +0 -120
  37. data/test/dummy/config/environments/test.rb +0 -59
  38. data/test/dummy/config/initializers/application_controller_renderer.rb +0 -8
  39. data/test/dummy/config/initializers/assets.rb +0 -12
  40. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -8
  41. data/test/dummy/config/initializers/content_security_policy.rb +0 -28
  42. data/test/dummy/config/initializers/cookies_serializer.rb +0 -5
  43. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -6
  44. data/test/dummy/config/initializers/inflections.rb +0 -16
  45. data/test/dummy/config/initializers/mime_types.rb +0 -4
  46. data/test/dummy/config/initializers/permissions_policy.rb +0 -11
  47. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  48. data/test/dummy/config/puma.rb +0 -43
  49. data/test/dummy/config/routes.rb +0 -3
  50. data/test/dummy/db/migrate/20220102072929_create_posts.rb +0 -10
  51. data/test/dummy/db/migrate/20220102073003_create_users.rb +0 -9
  52. data/test/dummy/db/schema.rb +0 -26
  53. data/test/dummy/test/models/post_test.rb +0 -7
  54. data/test/dummy/test/models/user_test.rb +0 -7
  55. data/test/helpers/cubism_helper_test.rb +0 -39
  56. data/test/integration/navigation_test.rb +0 -7
  57. data/test/models/concerns/presence_test.rb +0 -25
  58. data/test/models/concerns/user_test.rb +0 -9
  59. data/test/rendering/preprocessor_test.rb +0 -61
  60. data/test/test_helper.rb +0 -16
@@ -1,43 +0,0 @@
1
- # Puma can serve each request in a thread from an internal thread pool.
2
- # The `threads` method setting takes two numbers: a minimum and maximum.
3
- # Any libraries that use thread pools should be configured to match
4
- # the maximum value specified for Puma. Default is set to 5 threads for minimum
5
- # and maximum; this matches the default thread size of Active Record.
6
- #
7
- max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5)
8
- min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
9
- threads min_threads_count, max_threads_count
10
-
11
- # Specifies the `worker_timeout` threshold that Puma will use to wait before
12
- # terminating a worker in development environments.
13
- #
14
- worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"
15
-
16
- # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
17
- #
18
- port ENV.fetch("PORT", 3000)
19
-
20
- # Specifies the `environment` that Puma will run in.
21
- #
22
- environment ENV.fetch("RAILS_ENV") { "development" }
23
-
24
- # Specifies the `pidfile` that Puma will use.
25
- pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
26
-
27
- # Specifies the number of `workers` to boot in clustered mode.
28
- # Workers are forked web server processes. If using threads and workers together
29
- # the concurrency of the application would be max `threads` * `workers`.
30
- # Workers do not work on JRuby or Windows (both of which do not support
31
- # processes).
32
- #
33
- # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
34
-
35
- # Use the `preload_app!` method when specifying a `workers` number.
36
- # This directive tells Puma to first boot the application and load code
37
- # before forking the application. This takes advantage of Copy On Write
38
- # process behavior so workers use less memory.
39
- #
40
- # preload_app!
41
-
42
- # Allow puma to be restarted by `rails restart` command.
43
- plugin :tmp_restart
@@ -1,3 +0,0 @@
1
- Rails.application.routes.draw do
2
- # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
3
- end
@@ -1,10 +0,0 @@
1
- class CreatePosts < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :posts do |t|
4
- t.string :title
5
- t.text :body
6
-
7
- t.timestamps
8
- end
9
- end
10
- end
@@ -1,9 +0,0 @@
1
- class CreateUsers < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :users do |t|
4
- t.string :username
5
-
6
- t.timestamps
7
- end
8
- end
9
- end
@@ -1,26 +0,0 @@
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: 2022_01_02_073003) do
14
- create_table "posts", force: :cascade do |t|
15
- t.string "title"
16
- t.text "body"
17
- t.datetime "created_at", precision: 6, null: false
18
- t.datetime "updated_at", precision: 6, null: false
19
- end
20
-
21
- create_table "users", force: :cascade do |t|
22
- t.string "username"
23
- t.datetime "created_at", precision: 6, null: false
24
- t.datetime "updated_at", precision: 6, null: false
25
- end
26
- end
@@ -1,7 +0,0 @@
1
- require "test_helper"
2
-
3
- class PostTest < ActiveSupport::TestCase
4
- # test "the truth" do
5
- # assert true
6
- # end
7
- end
@@ -1,7 +0,0 @@
1
- require "test_helper"
2
-
3
- class UserTest < ActiveSupport::TestCase
4
- # test "the truth" do
5
- # assert true
6
- # end
7
- end
@@ -1,39 +0,0 @@
1
- class CubismHelperTest < ActionView::TestCase
2
- include CubismHelper
3
-
4
- setup do
5
- @post = posts(:one)
6
- @user = users(:one)
7
- end
8
-
9
- teardown do
10
- Cubism.block_store.clear
11
- end
12
-
13
- test "it displays a cubicle element for a resource" do
14
- element = Nokogiri::HTML.fragment(cubicle_for(@post, @user) { |users| })
15
-
16
- cubicle_element = element.children.first
17
-
18
- assert_equal "cubicle-element", cubicle_element.name
19
- assert_equal "connect", cubicle_element["appear-trigger"]
20
- assert_nil cubicle_element["disappear-trigger"]
21
- assert_nil cubicle_element["trigger-root"]
22
- assert cubicle_element["exclude-current-user"]
23
-
24
- refute_nil cubicle_element["id"]
25
- end
26
-
27
- test "it passes html_options" do
28
- element = Nokogiri::HTML.fragment(cubicle_for(@post, @user, html_options: {class: "my-class1 my-class2"}) { |users| })
29
- cubicle_element = element.children.first
30
-
31
- assert_equal "my-class1 my-class2", cubicle_element["class"]
32
- end
33
-
34
- test "it stores the passed block in the global store" do
35
- Nokogiri::HTML.fragment(cubicle_for(@post, @user) { |present_users| })
36
-
37
- assert_equal 1, Cubism.block_store.size
38
- end
39
- end
@@ -1,7 +0,0 @@
1
- require "test_helper"
2
-
3
- class NavigationTest < ActionDispatch::IntegrationTest
4
- # test "the truth" do
5
- # assert true
6
- # end
7
- end
@@ -1,25 +0,0 @@
1
- require "test_helper"
2
-
3
- class Cubism::PresenceTest < ActiveSupport::TestCase
4
- setup do
5
- scoped_present_users = {
6
- "" => Marshal.dump(Set.new([users(:one).id, users(:two).id])),
7
- :edit => Marshal.dump(Set.new([users(:one).id])),
8
- :show => Marshal.dump(Set.new([users(:two).id]))
9
- }
10
-
11
- @post = posts(:one)
12
- @post.stubs(:present_users).returns(scoped_present_users)
13
- @post.stubs(:excluded_user_id_for_element_id).returns({"foo" => users(:one).id, "bar" => users(:two).id})
14
- end
15
-
16
- test "Cubism::Presence respects excluded users per element" do
17
- assert_equal [users(:two)], @post.present_users_for_element_id_and_scope("foo")
18
- assert_equal [users(:one)], @post.present_users_for_element_id_and_scope("bar")
19
- end
20
-
21
- test "Cubism::Presence respects scopes along with excluded users" do
22
- assert_equal [users(:one)], @post.present_users_for_element_id_and_scope("bar", :edit)
23
- assert_equal [], @post.present_users_for_element_id_and_scope("bar", :show)
24
- end
25
- end
@@ -1,9 +0,0 @@
1
- require "test_helper"
2
-
3
- class Cubism::UserTest < ActiveSupport::TestCase
4
- test "Cubism::User registers global Cubism.user_class upon inclusion" do
5
- user = users(:one)
6
-
7
- assert_equal Cubism.user_class, user.class
8
- end
9
- end
@@ -1,61 +0,0 @@
1
- class PreprocessorTest < ActionView::TestCase
2
- test "it extracts a simple cubicle_for block" do
3
- source = <<-ERB
4
- <%= cubicle_for post, user do |users| %>
5
- <span class="presence">
6
- <%= users.map(&:username).to_sentence %>
7
- <span>
8
- <% end %>
9
- ERB
10
-
11
- result = <<~ERB
12
- <span class="presence">
13
- <%= users.map(&:username).to_sentence %>
14
- <span>
15
- ERB
16
-
17
- preprocessor = Cubism::Preprocessor.new(source: source, view_context: self)
18
-
19
- assert_equal result.squish, preprocessor.process.squish
20
- end
21
-
22
- test "it respects ERB tags nested in the block" do
23
- source = <<-ERB
24
- <%= cubicle_for post, user do |users| %>
25
- <% if users.size > 0 %>
26
- <span class="presence">
27
- <%= users.map(&:username).to_sentence %>
28
- <span>
29
- <% end %>
30
- <% end %>
31
- ERB
32
-
33
- result = <<~ERB
34
- <% if users.size > 0 %>
35
- <span class="presence">
36
- <%= users.map(&:username).to_sentence %>
37
- <span>
38
- <% end %>
39
- ERB
40
-
41
- preprocessor = Cubism::Preprocessor.new(source: source, view_context: self)
42
-
43
- assert_equal result.squish, preprocessor.process.squish
44
- end
45
-
46
- test "it respects render calls nested in the block" do
47
- source = <<-ERB
48
- <%= cubicle_for post, user do |users| %>
49
- <%= render "presence_partial", users: users %>
50
- <% end %>
51
- ERB
52
-
53
- result = <<~ERB
54
- <%= render "presence_partial", users: users %>
55
- ERB
56
-
57
- preprocessor = Cubism::Preprocessor.new(source: source, view_context: self)
58
-
59
- assert_equal result.squish, preprocessor.process.squish
60
- end
61
- end
data/test/test_helper.rb DELETED
@@ -1,16 +0,0 @@
1
- # Configure Rails Environment
2
- ENV["RAILS_ENV"] = "test"
3
-
4
- require_relative "../test/dummy/config/environment"
5
- ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
6
- require "rails/test_help"
7
- require "minitest/unit"
8
- require "mocha/minitest"
9
-
10
- # Load fixtures from the engine
11
- if ActiveSupport::TestCase.respond_to?(:fixture_path=)
12
- ActiveSupport::TestCase.fixture_path = File.expand_path("dummy/test/fixtures", __dir__)
13
- ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
14
- ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files"
15
- ActiveSupport::TestCase.fixtures :all
16
- end