Renaming

Saturday, December 5th, 2009 09:15 pm
afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)
[personal profile] afuna
I'm doing Bug 216: Renaming, and maaaaaan.

It's kind of funny -- I studiously ignored most of the renaming support requests back on LJ, because it seemed complicated and I didn't want to dig into the code, and now here I am, writing similar logic from scratch *snickers*

I'm having great fun. This seemed like one of the projects where tests would have a great effect, so I spent some time figuring out how to write tests from scratch, rather than just trying to tweak existing tests.

My tests look kinda like this:

# user-to-other-user, no redirect
{
    my $fromu = temp_user();
    my $tou = temp_user();

    my $fromuid = $fromu->userid;
    my $touid = $tou->userid;
    my $tousername = $tou->user;

    $fromu->rename( $tousername );

    is( $fromu->user, $tousername, "Rename fromu to tou, which is under the control of fromu" );
    my $ex_user = substr( $tou->user, 0, 10 );
    like( $tou->user, qr/^ex_$ex_user/ , "Moved out of the way." );
    is( $fromu->userid, $fromuid, "Id of fromu remains the same after rename." );
    is( $tou->userid, $touid, "Id of tou remains the same after rename." );

}

# user-to-other-user, with redirect
TODO: {
    local $TODO = "rename unimplemented";
}

TODO: {
    local $TODO = "rename to an expunged user";
}

TODO: {
    local $TODO = "rename to a deleted user; should not work";
}



I'm coding by first writing a bunch of tests, then writing code to make the tests pass. Every time I think of something new I should check for, I dash off a quick TODO block and then go back to writing either my test or my module. That helps me not lose my train of thought, but also means that I don't lose my ideas.

I'm starting with a small set of limited functionality, and then gradually expanding the scope. I actually started by disallowing everything except user-to-unregistered, and now I'm relaxing the rules as I add more. So far, I have personal-user-to-unregistered, with redirect and without redirect, and lots of checking for whether $fromu can rename to $tousername.

I'm in the middle of user-to-other-user, where the second user is just moved out of the way.
I estimate that I'm only about 10% of the way through -- I still need community-to-unregistered, community-to-other-community (or journal??), two-username-swap, keeping or removing various links -- subscriptions and the like, then catching edge cases (loops, openid attempts to rename, etc). And then I need to integrate it into the shop. And after that, I need to build a frontend so people can buy it from the shop *g*

At some point, I'll probably need to catch someone in chat to ask certain questions about the renaming process -- what should happen to usernames that were renamed away from, is swapping usernames one token or two, should you be able to rename a comm to a journal and vice versa, blah blah blah, buuut that can all wait a bit, because I'm sure I'll end up with still yet more questions.

Date: 2009-12-05 01:33 pm (UTC)
pne: A picture of a plush toy, halfway between a duck and a platypus, with a green body and a yellow bill and feet. (Default)
From: [personal profile] pne
is swapping usernames one token or two,

Three, as far as I know: you start off with three journals, A and B and SPARE.

Then you rename SPARE to A, ex_A123 to B, and ex_B789 to A.

End result: the journal formerly known as A -> ex_A123 -> B; the journal formal known as B -> ex_B789 -> A; the journal formerly known as SPARE -> ex_A456.

(If you don't start off with the spare, then renaming A to B will leave the username A unavailable for renaming to under normal circumstances.)

should you be able to rename a comm to a journal

That's how it works on LiveJournal, at any rate: you can rename a comm to a journal but not vice versa.

Date: 2009-12-05 01:43 pm (UTC)
yvi: Kaylee half-smiling, looking very pretty (Default)
From: [personal profile] yvi
I think explaining to users why switching names from 2 journals would cost 3 tokens would be a nightmare.

Date: 2009-12-05 02:03 pm (UTC)
yvi: Kaylee half-smiling, looking very pretty (Default)
From: [personal profile] yvi
You are made of awesome.

And also cute when you geek out about things like tests :)

Date: 2009-12-05 03:13 pm (UTC)
pne: A picture of a plush toy, halfway between a duck and a platypus, with a green body and a yellow bill and feet. (Default)
From: [personal profile] pne
IIRC, on LiveJournal, the personal account to rename to must have the same email address and password as the maintainer of the community who is doing the renaming.

Date: 2009-12-05 05:13 pm (UTC)
owl: Motherboard and CD (computer)
From: [personal profile] owl
Hey, test-driven development :)

Date: 2009-12-05 08:27 pm (UTC)
niqaeli: cat with arizona flag in the background (Default)
From: [personal profile] niqaeli
I dunno what actually the business-types might or have had to say, but I personally see it as two rename actions in practice rather than one: two journals are being renamed to something else -- in this case, each other, but, yeah. You're renaming two journals. So, two tokens.