Skip to content

Commit

Permalink
add routing tags count filter (#949)
Browse files Browse the repository at this point in the history
  • Loading branch information
BigG1947 authored Apr 26, 2021
1 parent dadb7f4 commit fa8374e
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/admin/routing/destinations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
filter :acd_limit
filter :short_calls_limit

acts_as_filter_by_routing_tag_ids
acts_as_filter_by_routing_tag_ids routing_tag_ids_count: true

permit_params :enabled, :prefix, :dst_number_min_length, :dst_number_max_length, :rate_group_id, :next_rate, :connect_fee,
:initial_interval, :next_interval, :dp_margin_fixed,
Expand Down
2 changes: 1 addition & 1 deletion app/admin/routing/dialpeers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def update
filter :external_id
filter :exclusive_route, as: :select, collection: [['Yes', true], ['No', false]]

acts_as_filter_by_routing_tag_ids
acts_as_filter_by_routing_tag_ids routing_tag_ids_count: true

form do |f|
f.semantic_errors *f.object.errors.keys
Expand Down
2 changes: 2 additions & 0 deletions app/models/concerns/routing_tag_ids_scopeable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ module RoutingTagIdsScopeable
where("routing_tag_ids = '{}'") # no tags
end
}

scope :routing_tag_ids_count_equals, ->(count) { where('array_length(routing_tag_ids, 1) = ?', count) if count.to_i >= 0 }
end
end
1 change: 1 addition & 0 deletions app/models/dialpeer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def self.ransackable_scopes(_auth_object = nil)
routing_for_contains
routing_tag_ids_covers
tagged
routing_tag_ids_count_equals
]
end
end
1 change: 1 addition & 0 deletions app/models/routing/destination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def self.ransackable_scopes(_auth_object = nil)
routing_for_contains
routing_tag_ids_covers
tagged
routing_tag_ids_count_equals
]
end
end
4 changes: 3 additions & 1 deletion lib/resource_dsl/acts_as_filter_by_routing_tag_ids.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module ResourceDSL
module ActsAsFilterByRoutingTagIds
def acts_as_filter_by_routing_tag_ids(routing_tag_ids_covers: true)
def acts_as_filter_by_routing_tag_ids(routing_tag_ids_covers: true, routing_tag_ids_count: false)
if routing_tag_ids_covers
filter :routing_tag_ids_covers, as: :select,
collection: -> { Routing::RoutingTag.pluck(:name, :id) },
Expand All @@ -14,6 +14,8 @@ def acts_as_filter_by_routing_tag_ids(routing_tag_ids_covers: true)
input_html: { class: 'chosen', multiple: true }

filter :tagged, as: :select, collection: [['Yes', true], ['No', false]], input_html: { class: 'chosen' }

filter :routing_tag_ids_count, as: :numeric, filters: [:equals] if routing_tag_ids_count
end
end
end
81 changes: 81 additions & 0 deletions spec/features/routing/destinations/filters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,85 @@
end
end
end

describe 'filter by routing tags count' do
let!(:other_destinations) { create_list :destination, 2 }
let!(:tags) { create_list :routing_tag, 3 }
let!(:destination_tagged) { create :destination, routing_tag_ids: tags.map(&:id) }

context 'when user set negative tags count' do
let(:filter_records) do
within_filters do
fill_in name: 'q[routing_tag_ids_count_equals]', with: negative_value
expect(page).to have_field(name: 'q[routing_tag_ids_count_equals]', with: negative_value)
end
end

let(:negative_value) { -2 }

it 'shoul be return all destinations' do
subject

expect(page).to have_table
expect(page).to have_table_row count: (other_destinations << destination_tagged).size
expect(page).to have_table_cell column: 'Id', text: destination_tagged.id
end
end

context 'when user set correct tags count' do
let(:filter_records) do
within_filters do
fill_in name: 'q[routing_tag_ids_count_equals]', with: tags.size
expect(page).to have_field(name: 'q[routing_tag_ids_count_equals]', with: tags.size)
end
end

it 'shoul be return destinations with correct routing tags count' do
subject

expect(page).to have_table
expect(page).to have_table_row count: 1
expect(page).to have_table_cell column: 'Id', text: destination_tagged.id
end

context 'when set specific routing tag cover and routing tag count' do
let(:filter_records) do
within_filters do
fill_in name: 'q[routing_tag_ids_count_equals]', with: 1
fill_in_chosen 'Routing tag ids covers', with: specific_tag.name, multiple: true
expect(page).to have_field(name: 'q[routing_tag_ids_count_equals]', with: 1)
expect(page).to have_field_chosen('Routing tag ids covers', with: specific_tag.name, exact: false)
end
end
let!(:specific_tag) { tags.first }
let!(:destination_with_one_tag) { create :destination, routing_tag_ids: [specific_tag.id] }

it 'should return only destinations with specific tag' do
subject

expect(page).to have_table
expect(page).to have_table_row count: 1
within_table_row(id: destination_with_one_tag.id) do
expect(page).to have_table_cell(column: 'Routing Tags', text: specific_tag.name)
end
end
end

context 'when there are no destinations wtih specified routing tags count' do
let(:filter_records) do
within_filters do
fill_in name: 'q[routing_tag_ids_count_equals]', with: tags.size + 1
expect(page).to have_field(name: 'q[routing_tag_ids_count_equals]', with: tags.size + 1)
end
end

it 'shouldn`t return any rows' do
subject

expect(page).to_not have_table
expect(page).to have_text('No Destinations found')
end
end
end
end
end
80 changes: 80 additions & 0 deletions spec/features/routing/dialpeers/filters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,84 @@
end
end
end

describe 'filter by routing tags count' do
let!(:tags) { create_list :routing_tag, 3 }
let!(:dialpeer_tagged) { create :dialpeer, routing_tag_ids: tags.map(&:id) }

context 'when user set negative tags count' do
let(:filter_records) do
within_filters do
fill_in name: 'q[routing_tag_ids_count_equals]', with: negative_value
expect(page).to have_field(name: 'q[routing_tag_ids_count_equals]', with: negative_value)
end
end

let(:negative_value) { -2 }

it 'shoul be return all dialpeers' do
subject

expect(page).to have_table
expect(page).to have_table_row count: (other_dialpeers << dialpeer_tagged).size
expect(page).to have_table_cell column: 'Id', text: dialpeer_tagged.id
end
end

context 'when user set correct tags count' do
let(:filter_records) do
within_filters do
fill_in name: 'q[routing_tag_ids_count_equals]', with: tags.size
expect(page).to have_field(name: 'q[routing_tag_ids_count_equals]', with: tags.size)
end
end

it 'shoul be return dialpeers with correct routing tags count' do
subject

expect(page).to have_table
expect(page).to have_table_row count: 1
expect(page).to have_table_cell column: 'Id', text: dialpeer_tagged.id
end

context 'when set specific routing tag cover and routing tag count' do
let(:filter_records) do
within_filters do
fill_in name: 'q[routing_tag_ids_count_equals]', with: 1
fill_in_chosen 'Routing tag ids covers', with: specific_tag.name, multiple: true
expect(page).to have_field(name: 'q[routing_tag_ids_count_equals]', with: 1)
expect(page).to have_field_chosen('Routing tag ids covers', with: specific_tag.name, exact: false)
end
end
let!(:specific_tag) { tags.first }
let!(:dialpeers_with_one_tag) { create :dialpeer, routing_tag_ids: [specific_tag.id] }

it 'should return only dialpeers with specific tag' do
subject

expect(page).to have_table
expect(page).to have_table_row count: 1
within_table_row(id: dialpeers_with_one_tag.id) do
expect(page).to have_table_cell(column: 'Routing Tags', text: specific_tag.name)
end
end
end

context 'when there are no dialpeers wtih specified routing tags count' do
let(:filter_records) do
within_filters do
fill_in name: 'q[routing_tag_ids_count_equals]', with: tags.size + 1
expect(page).to have_field(name: 'q[routing_tag_ids_count_equals]', with: tags.size + 1)
end
end

it 'shouldn`t return any rows' do
subject

expect(page).to_not have_table
expect(page).to have_text('No Dialpeers found')
end
end
end
end
end

0 comments on commit fa8374e

Please sign in to comment.