Skip to content

Commit

Permalink
Merge pull request #519 from senid231/517-fix-outgoing-registrations-1-9
Browse files Browse the repository at this point in the history
fix outgoing registrations 1.9 #517
  • Loading branch information
dmitry-sinina authored Aug 27, 2019
2 parents c815b1d + 9d85219 commit 9cc069d
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ GEM
net_tcp_client (2.0.1)
netstring (0.0.3)
nio4r (2.3.1)
nokogiri (1.10.3)
nokogiri (1.10.4)
mini_portile2 (~> 2.4.0)
oj (2.18.5)
orm_adapter (0.5.0)
Expand Down
1 change: 1 addition & 0 deletions app/admin/realtime_data/active_calls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
flash[:notice] = "#{params[:id]} was terminated"
redirect_to action: :index
rescue StandardError => e
Rails.logger.error { "<#{e.class}>: #{e.message}\n#{e.backtrace.join("\n")}" }
flash[:warning] = e.message
redirect_to action: :index
end
Expand Down
1 change: 1 addition & 0 deletions app/admin/realtime_data/outgoing_registrations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def find_collection
registrations = Kaminari.paginate_array(registrations).page(1).per(registrations.count)
flash.now[:warning] = searcher.errors if searcher.errors.any?
rescue StandardError => e
Rails.logger.error { "<#{e.class}>: #{e.message}\n#{e.backtrace.join("\n")}" }
flash.now[:warning] = e.message
end
@skip_drop_down_pagination = true
Expand Down
1 change: 1 addition & 0 deletions app/models/yeti/outgoing_registrations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def raw_registrations(options = {})
rescue StandardError => e
raise e unless options[:empty_on_error]

Rails.logger.error { "<#{e.class}>: #{e.message}\n#{e.backtrace.join("\n")}" }
@errors << e.message
end
Rails.logger.info { " loading #{registrations.count} registrations" }
Expand Down
4 changes: 4 additions & 0 deletions app/models/yeti_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def column_names
def human_attribute_name(attribute_key_name, _options = {})
attribute_key_name
end

def collection(rows)
rows.map(&method(:new))
end
end

def to_param
Expand Down
26 changes: 26 additions & 0 deletions spec/factories/outgoing_registrations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

FactoryGirl.define do
factory :outgoing_registration, class: RealtimeData::OutgoingRegistration do
trait :filled do
sequence(:id, 1_000)
domain 'qwe.asd.com'
user 'user_name'
state 'some_state'
auth_user 'auth.user'
display_name 'display.name'
contact 'some.contact'
proxy ''
expires { 5.minutes.from_now.utc.to_s(:db) }
expires_left '5 minutes'
last_error_code ''
last_error_initiator ''
last_error_reason ''
last_request_time { Time.now.utc.to_s(:db) }
last_succ_reg_time { Time.now.utc.to_s(:db) }
attempt 1
max_attempts 5
retry_delay 2
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'Index Active Calls', type: :feature do
include_context :login_as_admin

let!(:node) { FactoryGirl.create(:node) }
let(:record_attributes) { FactoryGirl.attributes_for(:active_call, :filled) }
before do
stub_jrpc_request('show.calls', node.rpc_endpoint).and_return([record_attributes.stringify_keys])
visit active_calls_path(q: { node_id_eq: node.id })
end

it 'has record' do
expect(page).to have_css('.col-duration', text: record_attributes[:duration].to_i)
expect(page).to_not have_css('flash-warning')
expect(page).to_not have_css('flash-error')
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'Index Incoming Registrations', type: :feature do
include_context :login_as_admin

let!(:node) { FactoryGirl.create(:node) }
let(:record_attributes) { FactoryGirl.attributes_for(:incoming_registration, :filled) }
before do
stub_jrpc_request('show.aors', node.rpc_endpoint).and_return([record_attributes.stringify_keys])
allow(Node).to receive(:all).and_return([node])
visit incoming_registrations_path
end

it 'has record' do
expect(page).to have_css('.col-path', text: record_attributes[:path])
expect(page).to_not have_css('flash-warning')
expect(page).to_not have_css('flash-error')
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'Index Outgoing Registrations', type: :feature do
include_context :login_as_admin

let!(:node) { FactoryGirl.create(:node) }
let(:record_attributes) { FactoryGirl.attributes_for(:outgoing_registration, :filled) }
before do
stub_jrpc_request('show.registrations', node.rpc_endpoint).and_return([record_attributes.stringify_keys])
visit outgoing_registrations_path(q: { node_id_eq: node.id })
end

it 'has record' do
expect(page).to have_css('.col-id', text: record_attributes[:id])
expect(page).to_not have_css('flash-warning')
expect(page).to_not have_css('flash-error')
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
config.extend Helpers::ActiveAdminForms::ExampleGroups, type: :feature
config.include Helpers::ActiveAdminForms::Examples, type: :feature
config.include FeatureTestHelper, type: :feature
config.include JRPCMockHelper

config.around(:each, freeze_time: proc { |val| val == true || val.is_a?(Time) }) do |example|
val = example.metadata[:freeze_time]
Expand Down
4 changes: 2 additions & 2 deletions spec/support/examples/test_index_table_exist.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.shared_examples :test_index_table_exist do
RSpec.shared_examples :test_index_table_exist do |id_css = '.resource_id_link'|
it 'has record' do
expect(page).to have_css('.resource_id_link', text: @item.id)
expect(page).to have_css(id_css, text: @item.id)
end
end
44 changes: 44 additions & 0 deletions spec/support/helpers/jrpc_mock_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

module JRPCMockHelper
# DSL allows stub JRPC in test environment.
# Example:
#
# let!(:node) { FactoryGirl.create(:node) }
# before do
# stub_jrpc_request(:registrations, node.rpc_endpoint).with(123).and_return({ bar: 'baz' })
# end
#
# it 'calls correctly' do
# expect(node.api.registration(123)).to match({ bar: 'baz' })
# end

class StubHelper
def initialize(stub:, ctx:, meth:)
@stub = stub
@ctx = ctx
@meth = meth
end

def with(*params)
stub_with_params(params)
end

def and_return(*args)
stub_with_params([]).and_return(*args)
end

private

def stub_with_params(params)
@ctx.expect(@stub).to @ctx.receive(:perform_request).with(@meth, params: params).once
end
end

def stub_jrpc_request(meth, uri, options = nil)
options ||= hash_including(namespace: 'yeti.')
jrpc_tcp_stub = instance_double(::JRPC::TcpClient, closed?: false, close: nil)
expect(::JRPC::TcpClient).to receive(:new).with(uri, options).and_return(jrpc_tcp_stub)
StubHelper.new(stub: jrpc_tcp_stub, ctx: self, meth: meth)
end
end

0 comments on commit 9cc069d

Please sign in to comment.