"There's only Loony Lovegood in here-" -Ginny on Luna, before the two became friends.
Ginevra Molly Weasley was a witch in Luna's year, but she's in Gryffindor.
Before their fourth yearEdit
It is unknown how Ginny and Luna got along before their fourth year, but it is known, that they weren't the best of friends, that's why she called her her stupid childhood nickname "Loony".
The two became friends, when they both joined Dumbledore's Army . It is possible that Ginny only befriended Luna because Harry likes Luna as a friend. This doesn't seem likely, though, as Ginny's a good-natured young girl.
Ginny encouraged Harry to go to Slughorn's party with Luna. They got along again and Luna praised the fact, that Ginny stood up for her when some boys called her Loony, saying she was "very nice".
Ginny and Luna - with Neville - kept Dumbledore's army going. They fought together in the battle of Hogwarts.
It's very likely, they remained friends and that being the reason, why Ginny's daughter has Luna as a middle name.