Module: RenderTurboStream::Test::Request::ChannelHelpers

Defined in:
lib/render_turbo_stream/test/request/channel_helpers.rb

Instance Method Summary collapse

Instance Method Details

#assert_action_to_all(action, count: 1, &block) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/render_turbo_stream/test/request/channel_helpers.rb', line 80

def assert_action_to_all(action, count: 1, &block)

  libs = RenderTurboStream::Test::Request::Libs.new(response)

  r = libs.select_actions('all', action, &block)

  assert(
    r[:responses].length == count,
    libs.class.assert_error_message(count, r[:responses].length, r[:log])
  )
end

#assert_action_to_authenticated_group(group, action, count: 1, &block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/render_turbo_stream/test/request/channel_helpers.rb', line 52

def assert_action_to_authenticated_group(group, action, count: 1, &block)

  channel = "authenticated_group_#{group}"

  libs = RenderTurboStream::Test::Request::Libs.new(response)

  r = libs.select_actions(channel, action, &block)

  assert(
    r[:responses].length == count,
    libs.class.assert_error_message(count, r[:responses].length, r[:log])
  )
end

#assert_action_to_me(user, action, count: 1, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/render_turbo_stream/test/request/channel_helpers.rb', line 22

def assert_action_to_me(user, action, count: 1, &block)

  channel = "authenticated_user_#{user.id}"

  libs = RenderTurboStream::Test::Request::Libs.new(response)

  r = libs.select_actions(channel, action, &block)

  assert(
    r[:responses].length == count,
    libs.class.assert_error_message(count, r[:responses].length, r[:log])
  )
end

#assert_channel_to_all(target_id, action: nil, count: 1, &block) ⇒ Object

Assert a action by turbo streams channel to all visitors of the page



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/render_turbo_stream/test/request/channel_helpers.rb', line 68

def assert_channel_to_all(target_id, action: nil, count: 1, &block)

  libs = RenderTurboStream::Test::Request::Libs.new(response)

  r = libs.select_responses('all', RenderTurboStream::Libs.target_id_to_target(target_id), action, &block)

  assert(
    r[:responses].length == count,
    libs.class.assert_error_message(count, r[:responses].length, r[:log])
  )
end

#assert_channel_to_authenticated_group(group, target_id, count: 1, &block) ⇒ Object

Assert a action by turbo streams channel to a group of authenticated users



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/render_turbo_stream/test/request/channel_helpers.rb', line 38

def assert_channel_to_authenticated_group(group, target_id, count: 1, &block)

  channel = "authenticated_group_#{group}"

  libs = RenderTurboStream::Test::Request::Libs.new(response)

  r = libs.select_responses(channel, target_id, action, &block)

  assert(
    r[:responses].length == count,
    libs.class.assert_error_message(count, r[:responses].length, r[:log])
  )
end

#assert_channel_to_me(user, target_id, action: nil, count: 1, &block) ⇒ Object

Assert a action by turbo streams channel to the current_user



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/render_turbo_stream/test/request/channel_helpers.rb', line 8

def assert_channel_to_me(user, target_id, action: nil, count: 1, &block)

  channel = "authenticated_user_#{user.id}"

  libs = RenderTurboStream::Test::Request::Libs.new(response)

  r = libs.select_responses(channel, RenderTurboStream::Libs.target_id_to_target(target_id), action, &block)

  assert(
    r[:responses].length == count,
    libs.class.assert_error_message(count, r[:responses].length, r[:log])
  )
end