Željko Filipin's Blog on Software and Testing

Test like you do not need the money.

Archive for February, 2007

Akismet Bug

without comments

Akismet Bug

I started to get a lot of spam comments, and yesterday I installed Askimet. This morning, I found a bug in Askimet. Don’t you just love to start a day with a bug? :)

This is bug report I sent.

I think I found a bug.

I have WordPress 2.1 and Akismet 2.0.

At “/wp-admin/edit-comments.php?page=akismet-admin” page (Comments > Akismet Spam) I have 51 spam comment, just enough for two pages.

There I can click “2″ or “Next Page »” link that leads me to “wp-admin/edit-comments.php?page=akismet-admin&apage=2″ page.

There are links “« Previous Page” and “1″ that lead to “wp-admin/edit-comments.php?page=akismet-admin&apage=” page (please notice that the number “1″ is missing at the end of the url).

At that page I get this error message:

“WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-50, 0' at line 1]
SELECT * FROM wp_comments WHERE comment_approved = ‘spam’ ORDER BY comment_date DESC LIMIT -50, 0″

I guess that is because I am at page “[...]&apage=” and it should be “[...]&apage=1″ (again, the number “1″ is missing at the end of the url).

Links “2″ or “Next Page »” point to “[...]&apage=2″ and links “« Previous Page” and “1″ point to “[...]&apage=” instead of “[...]&apage=1″ (once more, just to be sure, the number “1″ is missing at the end of the url).

Written by Željko Filipin

February 21st, 2007 at 10:52 am

Posted in Bugs

Ruby Hashes (2)

without comments

Yesterday I wrote about Ruby hashes. Use it and you can write nice looking code.

edit({“security” => “low”})

def edit(properties)
prepare_for_edit
edit_title(properties["title"]) if properties["title"]
# …
edit_security(properties["security"]) if properties["security"]
check_after_edit
end

Instead of ugly code.

edit(nil, nil, nil, nil, nil, nil, security)

def edit(title = nil, url = nil, mail = nil,
description = nil, membership = nil,
status = nil, security = nil)
prepare_for_edit
edit_title(title) if title
# …
edit_security(security) if security
check_after_edit
end

I got interested when I saw this at wtr-general

ie.div(:name => ‘foo’, :index => 2).click

This will find the second div with the name ‘foo’.

I tried to do something like that, but this was the best I could think of.

div(:name => ‘foo’, :index => 2)

def div(first, second)
hash = {first, second}
puts hash[:name]
puts hash[:index]
end

And, of course, it did not work.

ArgumentError: wrong number of arguments (1 for 2)

I posted my problem to wtr-general and Charley Baker was kind enough to help me. A link to Collecting Hash Arguments (at the bottom of the page) from Programming Ruby said it all.

div(:name => ‘foo’, :index => 2)

def div(properties)
puts properties[:name]
puts properties[:index]
end

Written by Željko Filipin

February 9th, 2007 at 12:31 pm

Posted in Ruby

Ruby Hashes

with one comment

I have seen Ruby hashes in use, but I never needed them. Until today. I was testing edit community feature. I started with editing title.

edit(title)

I created class Community and method edit.

def edit(title)
prepare_for_edit
edit_title(title)
check_after_edit
end

Then I tested editing other community properties. Sometimes I need to edit just one property, sometimes a few of them and sometimes all properties. The only way I could think of how to do it is to make all arguments of edit method optional.

def edit(title = nil, url = nil, mail = nil,
description = nil, membership = nil,
status = nil, security = nil)
prepare_for_edit
edit_title(title) if title
edit_url(url) if url
edit_mail(mail) if mail
edit_description(description) if description
edit_membership(membership) if membership
edit_status(status) if status
edit_security(security) if security
check_after_edit
end

But that caused ugly code when calling edit method if, for example, I only wanted to change security property.

edit(nil, nil, nil, nil, nil, nil, security)

I could make edit_security (and edit_title, edit_url…).

edit_security(security)

def edit_security(security)
prepare_for_edit
set_security(security)
check_after_edit
end

Better, but I wanted to try hashes, and it worked great.

edit({“security” => “low”})
edit({“security” => “low”, “status” => “offline”})

def edit(properties)
prepare_for_edit
edit_title(properties["title"]) if properties["title"]
edit_url(properties["url"]) if properties["url"]
edit_mail(properties["mail"]) if properties["mail"]
edit_description(properties["description"]) if properties["description"]
edit_membership(properties["membership"]) if properties["membership"]
edit_status(properties["status"]) if properties["status"]
edit_security(properties["security"]) if properties["security"]
check_after_edit
end

Written by Željko Filipin

February 8th, 2007 at 3:25 pm

Posted in Ruby