readded "junk removal" from usernames before output
This commit is contained in:
@@ -12,6 +12,8 @@ class WpUsers < WpItems
|
|||||||
headings = ['Id', 'Login', 'Name']
|
headings = ['Id', 'Login', 'Name']
|
||||||
headings << 'Password' if options[:show_password]
|
headings << 'Password' if options[:show_password]
|
||||||
|
|
||||||
|
remove_junk_from_display_names
|
||||||
|
|
||||||
self.each do |wp_user|
|
self.each do |wp_user|
|
||||||
row = [wp_user.id, wp_user.login, wp_user.display_name]
|
row = [wp_user.id, wp_user.login, wp_user.display_name]
|
||||||
row << wp_user.password if options[:show_password]
|
row << wp_user.password if options[:show_password]
|
||||||
@@ -25,5 +27,21 @@ class WpUsers < WpItems
|
|||||||
puts table
|
puts table
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remove_junk_from_display_names
|
||||||
|
display_names = []
|
||||||
|
self.each do |u|
|
||||||
|
display_name = u.display_name
|
||||||
|
unless display_name == 'empty'
|
||||||
|
display_names << display_name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
junk = get_equal_string_end(display_names)
|
||||||
|
unless junk.nil? or junk.empty?
|
||||||
|
self.each do |u|
|
||||||
|
u.display_name = u.display_name.sub(/#{Regexp.escape(junk)}$/, '')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -112,3 +112,28 @@ def redefine_constant(constant, value)
|
|||||||
Object.send(:remove_const, constant)
|
Object.send(:remove_const, constant)
|
||||||
Object.const_set(constant, value)
|
Object.const_set(constant, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Gets the string all elements in stringarray ends with
|
||||||
|
def get_equal_string_end(stringarray = [''])
|
||||||
|
already_found = ''
|
||||||
|
looping = true
|
||||||
|
counter = -1
|
||||||
|
if stringarray.kind_of? Array and stringarray.length > 1
|
||||||
|
base = stringarray[0]
|
||||||
|
while looping
|
||||||
|
character = base[counter, 1]
|
||||||
|
stringarray.each do |s|
|
||||||
|
if s[counter, 1] != character
|
||||||
|
looping = false
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if looping == false or (counter * -1) > base.length
|
||||||
|
break
|
||||||
|
end
|
||||||
|
already_found = "#{character if character}#{already_found}"
|
||||||
|
counter -= 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
already_found
|
||||||
|
end
|
||||||
72
spec/lib/common/collections/wp_users/output_spec.rb
Normal file
72
spec/lib/common/collections/wp_users/output_spec.rb
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
# encoding: UTF-8
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'WpUsers::Output' do
|
||||||
|
subject(:wp_users) { WpUsers.new(0) }
|
||||||
|
let(:wp_content_dir) { 'wp-content' }
|
||||||
|
let(:wp_plugins_dir) { wp_content_dir + '/plugins' }
|
||||||
|
let(:wp_target) { WpTarget.new(url, wp_content_dir: wp_content_dir, wp_plugins_dir: wp_plugins_dir) }
|
||||||
|
let(:url) { 'http://example.com/' }
|
||||||
|
let(:uri) { URI.parse(url) }
|
||||||
|
|
||||||
|
describe '#remove_junk_from_display_names' do
|
||||||
|
it 'does not throw an exception' do
|
||||||
|
expect { subject.remove_junk_from_display_names }.to_not raise_error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#remove_junk_from_display_names' do
|
||||||
|
before :each do
|
||||||
|
@input = WpUsers.new(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
after :each do
|
||||||
|
subject.push(@input)
|
||||||
|
subject.flatten!
|
||||||
|
subject.remove_junk_from_display_names
|
||||||
|
subject.should === @expected
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return an empty array' do
|
||||||
|
@expected = @input
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return input object' do
|
||||||
|
@input.push(WpUser.new(nil))
|
||||||
|
@expected = @input
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return input object' do
|
||||||
|
@input.push(WpUser.new(''))
|
||||||
|
@expected = @input
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should remove asdf' do
|
||||||
|
@input.push(WpUser.new('', login: '', id: 1, display_name: 'lkjh asdf'))
|
||||||
|
@input.push(WpUser.new('', login: '', id: 2, display_name: 'ijrjd asdf'))
|
||||||
|
@expected = WpUsers.new(0)
|
||||||
|
@expected.push(WpUser.new('', login: '', id: 1, display_name: 'lkjh'))
|
||||||
|
@expected.push(WpUser.new('', login: '', id: 2, display_name: 'ijrjd'))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return unmodified input object' do
|
||||||
|
@input.push(WpUser.new('', login: '', id: 1, display_name: 'lkjh asdfa'))
|
||||||
|
@input.push(WpUser.new('', login: '', id: 2, display_name: 'ijrjd asdf'))
|
||||||
|
@expected = @input
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return input object' do
|
||||||
|
@input.push(WpUser.new('', login: '', id: 1, display_name: 'lkjh asdf'))
|
||||||
|
@expected = @input
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return an empty display_name' do
|
||||||
|
@input.push(WpUser.new('', login: '', id: 1, display_name: 'lkhj asdf'))
|
||||||
|
@input.push(WpUser.new('', login: '', id: 2, display_name: 'lkhj asdf'))
|
||||||
|
@expected = WpUsers.new(0)
|
||||||
|
@expected.push(WpUser.new('', login: '', id: 1, display_name: ''))
|
||||||
|
@expected.push(WpUser.new('', login: '', id: 2, display_name: ''))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
59
spec/lib/common/common_helper_spec.rb
Normal file
59
spec/lib/common/common_helper_spec.rb
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
# encoding: UTF-8
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'common_helper' do
|
||||||
|
describe '#get_equal_string' do
|
||||||
|
after :each do
|
||||||
|
output = get_equal_string_end(@input)
|
||||||
|
|
||||||
|
output.should == @expected
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns an empty string' do
|
||||||
|
@input = %w()
|
||||||
|
@expected = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns an empty string' do
|
||||||
|
@input = []
|
||||||
|
@expected = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns asdf' do
|
||||||
|
@input = ['kjh asdf', 'oijr asdf']
|
||||||
|
@expected = ' asdf'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns « BlogName' do
|
||||||
|
@input = ['user1 « BlogName',
|
||||||
|
'user2 « BlogName',
|
||||||
|
'user3 « BlogName',
|
||||||
|
'user4 « BlogName']
|
||||||
|
@expected = ' « BlogName'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns an empty string' do
|
||||||
|
@input = %w{user1 user2 user3 user4}
|
||||||
|
@expected = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns an empty string' do
|
||||||
|
@input = ['user1 « BlogName',
|
||||||
|
'user2 « BlogName',
|
||||||
|
'user3 « BlogName',
|
||||||
|
'user4 « BlogNamea']
|
||||||
|
@expected = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns an empty string' do
|
||||||
|
@input = %w{ user1 }
|
||||||
|
@expected = ''
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns | test' do
|
||||||
|
@input = ['admin | test', 'test | test']
|
||||||
|
@expected = ' | test'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user