bugfixing and better output
This commit is contained in:
@@ -45,13 +45,10 @@ module WpUsernames
|
||||
real_name = get_real_name_from_response(response)
|
||||
end
|
||||
|
||||
if username == nil and real_name != nil
|
||||
username = real_name
|
||||
real_name = nil
|
||||
end
|
||||
|
||||
unless username == nil
|
||||
usernames << "id: #{author_id}, name: #{username}#{', real name: ' + real_name if real_name}"
|
||||
unless username == nil and real_name == nil
|
||||
usernames << { :id => author_id,
|
||||
:name => username ? username : "empty",
|
||||
:real_name => real_name ? real_name : "empty"}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -50,7 +50,9 @@ shared_examples_for "WpUsernames" do
|
||||
usernames = @module.usernames
|
||||
usernames.should_not be_empty
|
||||
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
|
||||
|
||||
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.should_not be_empty
|
||||
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"]
|
||||
usernames.should === [{ :id => 2, :name => "admin", :real_name => "admin | Wordpress 3.3.2"}]
|
||||
end
|
||||
|
||||
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.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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user