Test mass actions in admin

This commit is contained in:
Karl Erik Õunapuu 2020-11-05 14:16:37 +02:00
parent d80007d83c
commit 1a0becf785
No known key found for this signature in database
GPG key ID: C9DD647298A34764
7 changed files with 40 additions and 9 deletions

View file

@ -1,3 +0,0 @@
$('input:file').on("change", function() {
$('input:submit').prop('disabled', !$(this).val());
});

View file

@ -2,10 +2,11 @@
module Admin
class MassActionsController < BaseController
authorize_resource
before_action :authorize_admin
# GET /admin/mass_actions
def index; end
def index
end
# POST /admin/mass_actions
def create
@ -19,5 +20,9 @@ module Admin
redirect_to(admin_mass_actions_path, notice: notice)
end
def authorize_admin
authorize! :manage, :mass_actions
end
end
end

View file

@ -109,7 +109,7 @@ class Ability
can :destroy, :pending
can :create, :zonefile
can :access, :settings_menu
can :manage, MassAction
can :manage, :mass_actions
end
def static_registrant

View file

@ -7,11 +7,13 @@
<div class="panel-body">
<p>Triggers <b>soft</b> force delete procedure for uploaded domain list. List must be in <b>CSV</b> format. Each domain entry must be on separate line. Line must include <b>domain_name</b> (puny) followed with <b>delete_reason</b>, separated by comma.</p>
<p>Allowed delete reasons: <b>ENTITY_BURIED</b> | <b>PHONE</b> | <b>EMAIL</b></p>
<%= form_tag admin_mass_actions_path, multipart: true do %>
<%= file_field_tag :entry_list, accept: 'text/csv' %>
<%= form_tag admin_mass_actions_path, multipart: true, method: :post do %>
<%= label_tag :entry_list %>
<%= file_field_tag :entry_list, required: true, accept: 'text/csv' %>
<%= hidden_field_tag :mass_action, 'force_delete' %>
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
<br>
<%= submit_tag "Start force delete process", class: 'btn btn-danger', disabled: true %>
<%= submit_tag "Start force delete process", class: 'btn btn-danger', id: 'fd_submit' %>
<% end %>
</div>
</div>

View file

@ -0,0 +1,2 @@
domain_name, delete_reason
sh\á;[]c'
1 domain_name, delete_reason
2 sh\á;[]c'

View file

@ -0,0 +1,2 @@
domain_name, delete_reason
shop.test,ENTITY_BURIED
1 domain_name delete_reason
2 shop.test ENTITY_BURIED

View file

@ -0,0 +1,23 @@
require 'application_system_test_case'
require 'test_helper'
class AdminAreaMassActionsForceDeleteTest < ApplicationSystemTestCase
def setup
sign_in users(:admin)
end
def test_processes_uploaded_valid_csv
visit admin_mass_actions_path
attach_file('entry_list', Rails.root.join('test', 'fixtures', 'files', 'valid_mass_force_delete_list.csv').to_s)
click_link_or_button 'Start force delete process'
assert_text 'force_delete completed for ["shop.test"]. Failed: objects: []'
end
def test_processes_uploaded_invalid_csv
visit admin_mass_actions_path
attach_file(:entry_list, Rails.root.join('test', 'fixtures', 'files', 'invalid_mass_force_delete_list.csv').to_s)
click_link_or_button 'Start force delete process'
assert_text 'Dataset integrity validation failed for force_delete'
end
end