Skip to content

Commit

Permalink
Update dummy app
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoroth committed Jun 6, 2024
1 parent 94ccc9c commit 1f0223a
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 33 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Setup database
run: bundle exec rake db:create db:migrate
working-directory: test/dummy

- name: Run tests
run: bundle exec rake test
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ gem "rake", "~> 13.0"
gem "rubocop", "~> 1.21"

group :test do
gem "sprockets-rails"
gem "sqlite3"
gem "rails"
gem "simplecov"
gem "sprockets-rails"
gem "sqlite3", "~> 1.3"
end
5 changes: 5 additions & 0 deletions test/dummy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.log
*.sqlite3
*.sqlite3-shm
*.sqlite3-wal
tmp/*
8 changes: 8 additions & 0 deletions test/dummy/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative "config/application"

Rails.application.load_tasks
6 changes: 6 additions & 0 deletions test/dummy/app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
6 changes: 6 additions & 0 deletions test/dummy/app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end
2 changes: 2 additions & 0 deletions test/dummy/app/models/message.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

class Message < ActiveRecord::Base
end
10 changes: 5 additions & 5 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
require_relative "boot"

require "action_controller/railtie"
# require "action_cable/engine"
require "action_cable/engine"
# require "active_job/railtie"
# require "active_model/railtie"
# require "active_record/railtie"
require "sprockets/railtie"
require "active_model/railtie"
require "active_record/railtie"
# require "sprockets/railtie"

Bundler.require(*Rails.groups)

module Dummy
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.0
config.load_defaults 7.1

# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
Expand Down
10 changes: 10 additions & 0 deletions test/dummy/config/cable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
development:
adapter: async

test:
adapter: inline

production:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: dummy_production
13 changes: 11 additions & 2 deletions test/dummy/config/database.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000

test:
adapter: sqlite3
database: db/combustion_test.sqlite
<<: *default
database: db/test.sqlite3

development:
<<: *default
database: db/development.sqlite3
2 changes: 2 additions & 0 deletions test/dummy/db/migrate/20240606204215_create_messages.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateMessages < ActiveRecord::Migration[6.1]
def change
create_table :messages do |t|
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Configure Rails Environment
ENV["RAILS_ENV"] = "test"

require 'simplecov'
require "simplecov"

SimpleCov.start do
add_filter "/test/"
Expand Down
50 changes: 27 additions & 23 deletions test/turbo_power/broadcastable_test.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
# frozen_string_literal: true

require "test_helper"

class TurboPower::BroadcastableTest < ActionCable::Channel::TestCase
include ::Turbo::Broadcastable::TestHelper
module TurboPower
class BroadcastableTest < ActionCable::Channel::TestCase
include ::Turbo::Broadcastable::TestHelper

test "broadcast_dispatch_event" do
message = Message.new(id: 1)
test "broadcast_dispatch_event" do
message = Message.new(id: 1)

detail = { id: message.id, action: "save" }
message.broadcast_dispatch_event(target: dom_id(message), name: "saved", detail: detail)
detail = { id: message.id, action: "save" }
message.broadcast_dispatch_event(target: dom_id(message), name: "saved", detail: detail)

streams = capture_turbo_stream_broadcasts(message)
streams = capture_turbo_stream_broadcasts(message)

assert_equal 1, streams.length
assert_equal "message_1", streams.first["target"]
assert_equal "dispatch_event", streams.first["action"]
assert_equal 1, streams.length
assert_equal "message_1", streams.first["target"]
assert_equal "dispatch_event", streams.first["action"]

template_content = detail.to_json
assert_equal template_content, streams.first.at_css("template").content
end
template_content = detail.to_json
assert_equal template_content, streams.first.at_css("template").content
end

test "broadcast_dispatch_event_to" do
message = Message.new(id: 1)
test "broadcast_dispatch_event_to" do
message = Message.new(id: 1)

detail = { id: message.id, action: "save" }
message.broadcast_dispatch_event_to("messages", target: dom_id(message), name: "saved", detail: detail)
detail = { id: message.id, action: "save" }
message.broadcast_dispatch_event_to("messages", target: dom_id(message), name: "saved", detail: detail)

streams = capture_turbo_stream_broadcasts("messages")
streams = capture_turbo_stream_broadcasts("messages")

assert_equal 1, streams.length
assert_equal "message_1", streams.first["target"]
assert_equal "dispatch_event", streams.first["action"]
assert_equal 1, streams.length
assert_equal "message_1", streams.first["target"]
assert_equal "dispatch_event", streams.first["action"]

template_content = detail.to_json
assert_equal template_content, streams.first.at_css("template").content
template_content = detail.to_json
assert_equal template_content, streams.first.at_css("template").content
end
end
end

0 comments on commit 1f0223a

Please sign in to comment.