fix a sql bug

This commit is contained in:
wemeya 2016-05-19 14:40:09 +08:00
parent 91ef155da5
commit 973ee40fdf
2 changed files with 15 additions and 2 deletions

View File

@ -624,6 +624,19 @@ func TestGetAllProjects(t *testing.T) {
}
}
func TestGetPublicProjects(t *testing.T) {
projects, err := GetPublicProjects("")
if err != nil {
t.Errorf("Error occurred in getProjects: %v", err)
}
if len(projects) != 1 {
t.Errorf("Expected length of projects is 1, but actual: %d, the projects: %+v", len(projects), projects)
}
if projects[0].Name != "library" {
t.Errorf("Expected project name in the list: %s, actual: %s", "library", projects[0].Name)
}
}
func TestAddProjectMember(t *testing.T) {
err := AddProjectMember(currentProject.ProjectID, 1, models.DEVELOPER)
if err != nil {

View File

@ -221,7 +221,6 @@ func GetPublicProjects(projectName string) ([]models.Project, error) {
publicProjects, err := getProjects(1, projectName)
if err != nil {
return nil, err
}
return publicProjects, nil
}
@ -242,7 +241,7 @@ func getProjects(public int, projectName string) ([]models.Project, error) {
where deleted = 0`
queryParam := make([]interface{}, 1)
if public == 1 {
sql += "and public = ?"
sql += " and public = ? "
queryParam = append(queryParam, public)
}
if len(projectName) > 0 {
@ -251,6 +250,7 @@ func getProjects(public int, projectName string) ([]models.Project, error) {
}
sql += " order by name "
var projects []models.Project
log.Debugf("sql xxx", sql)
if _, err := o.Raw(sql, queryParam).QueryRows(&projects); err != nil {
return nil, err
}