ruby_rabbitmq_janus 3.0.0.pre.352 → 3.0.0.pre.382

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -2
  3. data/lib/generators/ruby_rabbitmq_janus/migration_generator.rb +2 -0
  4. data/lib/rrj/errors/error.rb +1 -1
  5. data/lib/rrj/janus/responses/admin.rb +13 -9
  6. data/lib/rrj/janus/responses/error.rb +0 -2
  7. data/lib/rrj/janus/responses/rspec.rb +2 -0
  8. data/lib/rrj/janus/responses/standard.rb +1 -0
  9. data/lib/rrj/janus/transactions/handle.rb +2 -0
  10. data/lib/rrj/janus/transactions/rspec.rb +2 -0
  11. data/lib/rrj/janus/transactions/session.rb +1 -0
  12. data/lib/rrj/models/active_record.rb +3 -0
  13. data/lib/rrj/models/concerns/instances.rb +11 -6
  14. data/lib/rrj/process/concurrency.rb +9 -3
  15. data/lib/rrj/process/event.rb +8 -26
  16. data/lib/rrj/process/event_admin.rb +8 -26
  17. data/lib/rrj/process/thread_runner_concern.rb +56 -0
  18. data/lib/rrj/rabbit/base_event.rb +2 -2
  19. data/lib/rrj/rabbit/connect.rb +12 -4
  20. data/lib/rrj/rabbit/listener/base.rb +17 -1
  21. data/lib/rrj/rabbit/listener/from.rb +2 -15
  22. data/lib/rrj/rabbit/listener/from_admin.rb +2 -15
  23. data/lib/rrj/rabbit/publisher/non_exclusive.rb +3 -0
  24. data/lib/rrj/rails.rb +9 -5
  25. data/lib/rrj/rspec.rb +5 -0
  26. data/lib/rrj/task.rb +2 -0
  27. data/lib/rrj/tools/gem/config/gem.rb +1 -1
  28. data/lib/rrj/tools/gem/logger.rb +1 -2
  29. data/lib/rrj/tools/gem/requests.rb +2 -2
  30. data/spec/config/database.rb +1 -0
  31. data/spec/factories/janus_instance.rb +2 -0
  32. data/spec/ruby_rabbitmq_janus/janus/responses/errors_spec.rb +175 -0
  33. data/spec/ruby_rabbitmq_janus/janus/responses/response_spec.rb +1 -1
  34. data/spec/ruby_rabbitmq_janus/models/{janus_instance_definition_spec.rb → janus_instance_field_spec.rb} +0 -0
  35. data/spec/ruby_rabbitmq_janus/models/janus_instance_instance_spec.rb +47 -0
  36. data/spec/ruby_rabbitmq_janus/models/{janus_instance_spec.rb → janus_instance_validation_spec.rb} +10 -2
  37. data/spec/ruby_rabbitmq_janus/process/concurrencies/concurrency_spec.rb +1 -5
  38. data/spec/ruby_rabbitmq_janus/process/concurrencies/event_admin_spec.rb +3 -2
  39. data/spec/ruby_rabbitmq_janus/process/concurrencies/event_spec.rb +3 -2
  40. data/spec/ruby_rabbitmq_janus/rabbit/listener/from_spec.rb +1 -0
  41. data/spec/ruby_rabbitmq_janus/rabbit/publisher/admin_spec.rb +1 -0
  42. data/spec/ruby_rabbitmq_janus/rabbit/publisher/exclusive_spec.rb +4 -3
  43. data/spec/ruby_rabbitmq_janus/rabbit/publisher/non_exclusive_spec.rb +4 -4
  44. data/spec/ruby_rabbitmq_janus/tools/logger_spec.rb +34 -0
  45. data/spec/ruby_rabbitmq_janus/tools/replaces/admin_spec.rb +2 -2
  46. data/spec/ruby_rabbitmq_janus/tools/replaces/handle_spec.rb +1 -1
  47. data/spec/ruby_rabbitmq_janus/tools/type_spec.rb +1 -1
  48. data/spec/spec_helper.rb +27 -3
  49. data/spec/support/examples_model.rb +45 -0
  50. data/spec/support/examples_thread.rb +18 -12
  51. data/tmp/coverage/assets/0.10.2/application.css +799 -0
  52. data/tmp/coverage/assets/0.10.2/application.js +1707 -0
  53. data/tmp/coverage/assets/0.10.2/colorbox/border.png +0 -0
  54. data/tmp/coverage/assets/0.10.2/colorbox/controls.png +0 -0
  55. data/tmp/coverage/assets/0.10.2/colorbox/loading.gif +0 -0
  56. data/tmp/coverage/assets/0.10.2/colorbox/loading_background.png +0 -0
  57. data/tmp/coverage/assets/0.10.2/favicon_green.png +0 -0
  58. data/tmp/coverage/assets/0.10.2/favicon_red.png +0 -0
  59. data/tmp/coverage/assets/0.10.2/favicon_yellow.png +0 -0
  60. data/tmp/coverage/assets/0.10.2/loading.gif +0 -0
  61. data/tmp/coverage/assets/0.10.2/magnify.png +0 -0
  62. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  63. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  64. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  65. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  66. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  67. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  68. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  69. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  70. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-icons_222222_256x240.png +0 -0
  71. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  72. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-icons_454545_256x240.png +0 -0
  73. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-icons_888888_256x240.png +0 -0
  74. data/tmp/coverage/assets/0.10.2/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  75. data/tmp/coverage/index.html +21249 -0
  76. metadata +74 -10
@@ -14,10 +14,10 @@ module RubyRabbitmqJanus
14
14
  end
15
15
 
16
16
  # Create an transaction with rabbitmq and close after response is received
17
- def transaction_short
18
- raise Errors::Rabbit::Connect::MissingAction unless block_given?
17
+ def transaction_short(&block)
18
+ raise Errors::Rabbit::Connect::MissingAction unless block
19
19
 
20
- response = transaction_long { yield }
20
+ response = transaction_long(&block)
21
21
  close
22
22
  response
23
23
  end
@@ -50,7 +50,15 @@ module RubyRabbitmqJanus
50
50
  private
51
51
 
52
52
  def bunny_conf
53
- Tools::Config.instance.server_settings.merge(connection_timeout: 5)
53
+ Tools::Config.instance.server_settings.merge(bunny_conf_static)
54
+ end
55
+
56
+ def bunny_conf_static
57
+ {
58
+ connection_timeout: 5,
59
+ connection_name: "[#{rand(999)}] backend",
60
+ recover_from_connection_close: false
61
+ }
54
62
  end
55
63
  end
56
64
  end
@@ -36,7 +36,7 @@ module RubyRabbitmqJanus
36
36
  end
37
37
 
38
38
  def opts_subs
39
- { block: false, manual_ack: true, arguments: { 'x-priority': 2 } }
39
+ { block: false, manual_ack: false, arguments: { 'x-priority': 2 } }
40
40
  end
41
41
 
42
42
  def info_subscribe(info, _prop, payload)
@@ -51,6 +51,22 @@ module RubyRabbitmqJanus
51
51
  raise Errors::Rabbit::Listener::ResponseEmpty, response \
52
52
  if response.to_hash.size.zero?
53
53
  end
54
+
55
+ def subscribe_queue
56
+ rabbit.prefetch(1)
57
+ reply.bind(binding).subscribe(opts_subs) do |info, prop, payload|
58
+ info_subscribe(info, prop, payload)
59
+ synchronize_response(payload)
60
+ end
61
+ end
62
+
63
+ def synchronize_response(payload)
64
+ lock.synchronize do
65
+ response = response_class(payload)
66
+ responses.push(response)
67
+ end
68
+ semaphore.signal
69
+ end
54
70
  end
55
71
  end
56
72
  end
@@ -15,21 +15,8 @@ module RubyRabbitmqJanus
15
15
  rabbit.queue(Tools::Config.instance.queue_from)
16
16
  end
17
17
 
18
- def subscribe_queue
19
- rabbit.prefetch(1)
20
- reply.bind(binding).subscribe(opts_subs) do |info, prop, payload|
21
- info_subscribe(info, prop, payload)
22
- synchronize_response(info, payload)
23
- end
24
- end
25
-
26
- def synchronize_response(info, payload)
27
- lock.synchronize do
28
- response = Janus::Responses::Event.new(JSON.parse(payload))
29
- responses.push(response)
30
- end
31
- rabbit.acknowledge(info.delivery_tag, false)
32
- semaphore.signal
18
+ def response_class(payload)
19
+ Janus::Responses::Event.new(JSON.parse(payload))
33
20
  end
34
21
  end
35
22
  end
@@ -15,21 +15,8 @@ module RubyRabbitmqJanus
15
15
  rabbit.queue(Tools::Config.instance.queue_admin_from)
16
16
  end
17
17
 
18
- def subscribe_queue
19
- rabbit.prefetch(1)
20
- reply.bind(binding).subscribe(opts_subs) do |info, prop, payload|
21
- info_subscribe(info, prop, payload)
22
- synchronize_response(info, payload)
23
- end
24
- end
25
-
26
- def synchronize_response(info, payload)
27
- lock.synchronize do
28
- response = Janus::Responses::Admin.new(JSON.parse(payload))
29
- responses.push(response)
30
- end
31
- rabbit.acknowledge(info.delivery_tag, false)
32
- semaphore.signal
18
+ def response_class(payload)
19
+ Janus::Responses::Admin.new(JSON.parse(payload))
33
20
  end
34
21
  end
35
22
  end
@@ -17,9 +17,12 @@ module RubyRabbitmqJanus
17
17
  # Send an message to queue
18
18
  #
19
19
  # @param [String] request JSON request sending to rabbitmq queue
20
+ #
21
+ # rubocop:disable Lint/UselessMethodDefinition
20
22
  def publish(request)
21
23
  super(request)
22
24
  end
25
+ # rubocop:enable Lint/UselessMethodDefinition
23
26
  end
24
27
  end
25
28
  end
data/lib/rrj/rails.rb CHANGED
@@ -25,11 +25,15 @@ module RubyRabbitmqJanus
25
25
  actions = RubyRabbitmqJanus::ActionEvents.new.actions
26
26
  admin_actions = RubyRabbitmqJanus::ActionAdminEvents.new.actions
27
27
 
28
- Parallel.map([
29
- process::Event.new.run(&actions),
30
- process::EventAdmin.new.run(&admin_actions)
31
- ], in_processes: number) do |listener|
32
- "Item: #{listener}, Worker: #{Parallel.worker_number}"
28
+ listeners = []
29
+ (1..number).each do
30
+ listeners.push process::Event.new.run(&actions)
31
+ listeners.push process::EventAdmin.new.run(&admin_actions)
32
+ end
33
+
34
+ Parallel.each(listeners, in_processes: number) do |listener|
35
+ item = "[Item##{listener}]"
36
+ Log.warn "#{item}, Worker : #{Parallel.worker_number + 1} / #{number}"
33
37
  end
34
38
  end
35
39
  end
data/lib/rrj/rspec.rb CHANGED
@@ -9,20 +9,25 @@ module RubyRabbitmqJanus
9
9
  #
10
10
  # Initializer to use with RSpec execution
11
11
  class RRJRSpec < RRJTaskAdmin
12
+ # rubocop:disable Lint/MissingSuper
12
13
  def initialize
13
14
  RubyRabbitmqJanus::Tools::Config.instance
14
15
  end
16
+ # rubocop:enable Lint/MissingSuper
15
17
 
18
+ # @see RubyRabbitmqJanus::RRJ::session_endpoint_public
16
19
  def session_endpoint_public(_options)
17
20
  yield(RubyRabbitmqJanus::Janus::Transactions::RSpec.new)
18
21
  end
19
22
 
23
+ # @see RubyRabbitmqJanus::RRJ::session_endpoint_private
20
24
  def handle_endpoint_public(_options)
21
25
  transaction = RubyRabbitmqJanus::Janus::Transactions::RSpec.new
22
26
  yield(transaction)
23
27
  transaction.response
24
28
  end
25
29
 
30
+ # @see RubyRabbitmqJanus::RRJAdmin::admin_endpoint
26
31
  def admin_endpoint(_options)
27
32
  yield(RubyRabbitmqJanus::Janus::Transactions::RSpec.new)
28
33
  end
data/lib/rrj/task.rb CHANGED
@@ -9,10 +9,12 @@ module RubyRabbitmqJanus
9
9
  #
10
10
  # This class is used with rake task.
11
11
  class RRJTask < RRJ
12
+ # rubocop:disable Lint/MissingSuper
12
13
  def initialize
13
14
  Tools::Config.instance
14
15
  Tools::Requests.instance
15
16
  end
17
+ # rubocop:enable Lint/MissingSuper
16
18
 
17
19
  # Create a transaction between Apps and Janus in queue private
18
20
  #
@@ -12,7 +12,7 @@ module RubyRabbitmqJanus
12
12
  module ConfigGem
13
13
  # @return [Boolean] Read option file for a janus cluster section
14
14
  def cluster
15
- @options['gem']['cluster']['enabled'].to_s.match?('true') ? true : false
15
+ @options['gem']['cluster']['enabled'].to_s.match?('true')
16
16
  end
17
17
 
18
18
  # @return [Symbol] read configuration for log level used in this gem
@@ -41,7 +41,6 @@ module RubyRabbitmqJanus
41
41
  # Choose type logger used in application instance
42
42
  def self.initialize_logger
43
43
  case @config.log_type
44
- when :stdout then logger_stdout
45
44
  when :file then logger_file
46
45
  when :remote then logger_remote
47
46
  else
@@ -51,7 +50,7 @@ module RubyRabbitmqJanus
51
50
 
52
51
  # Configure logger with output SDTOUT
53
52
  def self.logger_stdout
54
- ::Logger.new(STDOUT)
53
+ ::Logger.new($stdout)
55
54
  end
56
55
 
57
56
  # Configure logger with output file
@@ -32,9 +32,9 @@ module RubyRabbitmqJanus
32
32
  def each_folder(subfolder)
33
33
  Dir[File.join(PATH_REQUEST + subfolder, '*')].count do |file|
34
34
  if File.file?(file)
35
- read_folder(subfolder.gsub('/', '::') + '::', file)
35
+ read_folder("#{subfolder.gsub('/', '::')}::", file)
36
36
  elsif File.directory?(file)
37
- each_folder(subfolder + '/' + File.basename(file))
37
+ each_folder("#{subfolder}/#{File.basename(file)}")
38
38
  end
39
39
  end
40
40
  end
@@ -16,6 +16,7 @@ def migrate
16
16
  ActiveRecord::Base.connection.create_table(:janus_instances) do |table|
17
17
  table.integer :session, limit: 8
18
18
  table.boolean :enable
19
+ table.string :name
19
20
  end
20
21
  end
21
22
 
@@ -3,5 +3,7 @@
3
3
  FactoryBot.define do
4
4
  factory :janus_instance, class: 'RubyRabbitmqJanus::Models::JanusInstance' do
5
5
  enable { true }
6
+ session_id { (rand * 10_000_000_000).to_i }
7
+ name { [*('a'..'z'), *('0'..'9')].sample(12).join }
6
8
  end
7
9
  end
@@ -0,0 +1,175 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe RubyRabbitmqJanus::Janus::Responses::Errors, type: :responses,
6
+ name: :errors do
7
+ let(:message) do
8
+ {
9
+ 'janus' => 'error',
10
+ 'error' => {
11
+ 'code' => number,
12
+ 'reason' => reason
13
+ }
14
+ }
15
+ end
16
+ let(:response) { RubyRabbitmqJanus::Janus::Responses::Response.new(message) }
17
+ let(:error) { described_class.new }
18
+ let(:reason) { [*('a'..'z'), *('0'..'9')].sample(12).join }
19
+
20
+ context 'when 403' do
21
+ let(:number) { 403 }
22
+
23
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::Unauthorized) }
24
+ end
25
+
26
+ context 'when 405' do
27
+ let(:number) { 405 }
28
+
29
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::UnauthorizedPlugin) }
30
+ end
31
+
32
+ context 'when 450' do
33
+ let(:number) { 450 }
34
+
35
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::TransportSpecific) }
36
+ end
37
+
38
+ context 'when 452' do
39
+ let(:number) { 452 }
40
+
41
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::MissingRequest) }
42
+ end
43
+
44
+ context 'when 453' do
45
+ let(:number) { 453 }
46
+
47
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::UnknownRequest) }
48
+ end
49
+
50
+ context 'when 454' do
51
+ let(:number) { 454 }
52
+
53
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::InvalidJSON) }
54
+ end
55
+
56
+ context 'when 455' do
57
+ let(:number) { 455 }
58
+
59
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::InvalidJSONObject) }
60
+ end
61
+
62
+ context 'when 456' do
63
+ let(:number) { 456 }
64
+
65
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::MissingMandatoryElement) }
66
+ end
67
+
68
+ context 'when 457' do
69
+ let(:number) { 457 }
70
+
71
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::InvalidRequestPath) }
72
+ end
73
+
74
+ context 'when 458' do
75
+ let(:number) { 458 }
76
+
77
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::SessionNotFound) }
78
+ end
79
+
80
+ context 'when 459' do
81
+ let(:number) { 459 }
82
+
83
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::HandleNotFound) }
84
+ end
85
+
86
+ context 'when 460' do
87
+ let(:number) { 460 }
88
+
89
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::PluginNotFound) }
90
+ end
91
+
92
+ context 'when 461' do
93
+ let(:number) { 461 }
94
+
95
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::PluginAttach) }
96
+ end
97
+
98
+ context 'when 462' do
99
+ let(:number) { 462 }
100
+
101
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::PluginMessage) }
102
+ end
103
+
104
+ context 'when 463' do
105
+ let(:number) { 463 }
106
+
107
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::PluginDetach) }
108
+ end
109
+
110
+ context 'when 464' do
111
+ let(:number) { 464 }
112
+
113
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::JSEPUnknownType) }
114
+ end
115
+
116
+ context 'when 465' do
117
+ let(:number) { 465 }
118
+
119
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::JSEPInvalidSDP) }
120
+ end
121
+
122
+ context 'when 466' do
123
+ let(:number) { 466 }
124
+
125
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::TrickleInvalidStream) }
126
+ end
127
+
128
+ context 'when 467' do
129
+ let(:number) { 467 }
130
+
131
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::InvalidElementType) }
132
+ end
133
+
134
+ context 'when 468' do
135
+ let(:number) { 468 }
136
+
137
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::SessionConflit) }
138
+ end
139
+
140
+ context 'when 469' do
141
+ let(:number) { 469 }
142
+
143
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::UnexpectedAnswer) }
144
+ end
145
+
146
+ context 'when 470' do
147
+ let(:number) { 470 }
148
+
149
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::TokenNotFound) }
150
+ end
151
+
152
+ context 'when 471' do
153
+ let(:number) { 471 }
154
+
155
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::WebRTCState) }
156
+ end
157
+
158
+ context 'when 472' do
159
+ let(:number) { 472 }
160
+
161
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::NotAcceptingSession) }
162
+ end
163
+
164
+ context 'when 490' do
165
+ let(:number) { 490 }
166
+
167
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::Unknown) }
168
+ end
169
+
170
+ context 'when error missing' do
171
+ let(:number) { 418 }
172
+
173
+ it { expect { error.send(:"_#{number}", response) }.to raise_error(RubyRabbitmqJanus::Errors::Janus::Responses::Nok) }
174
+ end
175
+ end
@@ -14,7 +14,7 @@ describe RubyRabbitmqJanus::Janus::Responses::Response, type: :responses,
14
14
  context 'when ask nice json response' do
15
15
  let(:message) { { 'data' => { 'id' => (rand * 10_000).to_i } } }
16
16
 
17
- it { expect(response.to_json).to be_kind_of(String) }
17
+ it { expect(response.to_nice_json).to be_kind_of(String) }
18
18
  end
19
19
 
20
20
  context 'when ask hash response' do
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe RubyRabbitmqJanus::Models::JanusInstance, type: :model,
6
+ name: :janus_instance do
7
+ before do
8
+ instances
9
+ first
10
+ end
11
+
12
+ let(:model) { described_class }
13
+ let(:size) { (rand * 5).to_i + 1 }
14
+ let(:first) { model.first }
15
+ let(:session_id) { first.session_id }
16
+ let(:id) { first.id }
17
+
18
+ context 'when Janus instances are activated.' do
19
+ let(:instances) { FactoryBot.create_list(:janus_instance, size) }
20
+ let(:count_enabled) { size }
21
+ let(:count_destroyed) { 0 }
22
+ let(:count_disabled) { 0 }
23
+
24
+ include_examples 'when disable an instance'
25
+ include_examples 'when enable an instance not change'
26
+ include_examples 'when destroys all disable instance'
27
+ include_examples 'when search by instance'
28
+ include_examples 'when search by session'
29
+ include_examples 'when search instance enabled'
30
+ include_examples 'when search instance disabled'
31
+ end
32
+
33
+ context 'when Janus instances are disabled.' do
34
+ let(:instances) { FactoryBot.create_list(:janus_instance, size, enable: false) }
35
+ let(:count_enabled) { 0 }
36
+ let(:count_destroyed) { size }
37
+ let(:count_disabled) { size }
38
+
39
+ include_examples 'when disable an instance not change'
40
+ include_examples 'when enable an instance'
41
+ include_examples 'when destroys all disable instance'
42
+ include_examples 'when search by instance'
43
+ include_examples 'when search by session'
44
+ include_examples 'when search instance enabled'
45
+ include_examples 'when search instance disabled'
46
+ end
47
+ end