bugfixing and better output
This commit is contained in:
@@ -45,13 +45,10 @@ module WpUsernames
|
|||||||
real_name = get_real_name_from_response(response)
|
real_name = get_real_name_from_response(response)
|
||||||
end
|
end
|
||||||
|
|
||||||
if username == nil and real_name != nil
|
unless username == nil and real_name == nil
|
||||||
username = real_name
|
usernames << { :id => author_id,
|
||||||
real_name = nil
|
:name => username ? username : "empty",
|
||||||
end
|
:real_name => real_name ? real_name : "empty"}
|
||||||
|
|
||||||
unless username == nil
|
|
||||||
usernames << "id: #{author_id}, name: #{username}#{', real name: ' + real_name if real_name}"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,9 @@ shared_examples_for "WpUsernames" do
|
|||||||
usernames = @module.usernames
|
usernames = @module.usernames
|
||||||
usernames.should_not be_empty
|
usernames.should_not be_empty
|
||||||
usernames.length.should == 1
|
usernames.length.should == 1
|
||||||
usernames[0].should == "id: 3, name: Youhou"
|
usernames[0][:id].should == 3
|
||||||
|
usernames[0][:name].should == "Youhou"
|
||||||
|
usernames[0][:real_name].should == "empty"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return an array with 1 username (from in the body response)" do
|
it "should return an array with 1 username (from in the body response)" do
|
||||||
@@ -59,16 +61,7 @@ shared_examples_for "WpUsernames" do
|
|||||||
|
|
||||||
usernames = @module.usernames(:range => (1..2))
|
usernames = @module.usernames(:range => (1..2))
|
||||||
usernames.should_not be_empty
|
usernames.should_not be_empty
|
||||||
usernames.should === ["id: 2, name: admin, real name: admin | Wordpress 3.3.2"]
|
usernames.should === [{ :id => 2, :name => "admin", :real_name => "admin | Wordpress 3.3.2"}]
|
||||||
end
|
|
||||||
|
|
||||||
it "should return an array with 1 username (testing duplicates)" do
|
|
||||||
(2..3).each do |id|
|
|
||||||
stub_request(:get, @module.author_url(id)).
|
|
||||||
to_return(:status => 200, :body => File.new(@fixtures_dir + '/admin.htm'))
|
|
||||||
end
|
|
||||||
|
|
||||||
@module.usernames(:range => (1..3)).should === ["admin"]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return an array with 2 usernames (one is a duplicate and should not be present twice)" do
|
it "should return an array with 2 usernames (one is a duplicate and should not be present twice)" do
|
||||||
@@ -80,7 +73,9 @@ shared_examples_for "WpUsernames" do
|
|||||||
|
|
||||||
usernames = @module.usernames(:range => (1..5))
|
usernames = @module.usernames(:range => (1..5))
|
||||||
usernames.should_not be_empty
|
usernames.should_not be_empty
|
||||||
usernames.sort.should === ["admin", "Youhou"].sort
|
expected = [{:id => 2, :name =>"admin", :real_name => "admin | Wordpress 3.3.2"},
|
||||||
|
{:id => 4, :name => "Youhou", :real_name => "empty"}]
|
||||||
|
usernames.sort_by { |u| u[:name]}.should === expected.sort_by { |u| u[:name]}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -322,7 +322,9 @@ begin
|
|||||||
puts "We found the following #{usernames.length.to_s} username/s :"
|
puts "We found the following #{usernames.length.to_s} username/s :"
|
||||||
puts
|
puts
|
||||||
|
|
||||||
usernames.each {|username| puts " #{username}"}
|
usernames.each do |u|
|
||||||
|
puts " id: #{u[:id]}, name: #{u[:name]}#{', real name: ' + u[:real_name] if u[:real_name]}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user