示例#1
0
func TestTag(t *testing.T) {
	fmt.Println("Start")
	models.RegistDB()
	Convey("should be test Tag", t, func() {

		Convey("get hot tags", func() {
			tags := models.GetHotTags(3)
			So(len(tags), ShouldEqual, 3)
		})
		Convey("get blog count", func() {
			tags := models.GetHotTags(3)
			count := tags[0].GetBlogCount()
			So(count, ShouldBeGreaterThan, 0)
		})
		Convey("get blogs", func() {

			tags := models.GetHotTags(3)
			tag := &models.Tag{Id: tags[0].Id}
			So(len(tag.Blogs), ShouldEqual, 0)
			tag.Get()
			So(len(tag.Blogs), ShouldBeGreaterThan, 0)
		})
		// tag := models.NewTag("TEST", -1)
		// Convey("`tag` should not be nil", func() {
		// 	So(tag, ShouldNotBeNil)
		// })
		// Convey("update tag to database", func() {
		// 	tag.Name = "Test"
		// 	tag.ParentId = -2
		// 	e := tag.Update()
		// 	So(e, ShouldEqual, nil)
		// })
		// Convey("get tag by name", func() {
		// 	t := models.GetTag("linux")
		// 	fmt.Println("new tag", t)
		// 	So(t.Id, ShouldNotEqual, 0)
		// })
		// Convey("delete tag to database", func() {
		// 	e := tag.Delete()
		// 	So(e, ShouldEqual, nil)
		// })
	})
}
示例#2
0
func (this *BaseController) Prepare() {
	this.Ctx.Request.Header.Add("Access-Control-Allow-Origin", "*")

	// 验证是否来自合法域名访问
	if !this.isAllowHost() {
		this.Ctx.WriteString(`<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=` +
			website.HostUrl + string([]byte(this.Ctx.Input.Url())[4:]) + `" /></head></html>`)
		this.StopRun()
	}

	this.Data["WebSite"] = website
	this.SetPateTitle("Home")
	this.SetDescript("Ckeyer blog")
	this.AddKeyWord("ckeyer")
	this.Data["Metes"] = ""
	this.AddCssStyle("style.css")
	this.AddJsScript("jquery-2.1.3.min.js", "default.js", "modernizr.js", "dat.gui.min.js", "toxiclibs.min.js", "animitter.min.js", "bg_index.js")
	this.Data["Tail"] = `Download your use my life`

	this.Data["BlogsMonth"] = models.GetBlogsMonth(5)
	this.Data["BlogsTag"] = models.GetHotTags(5)

	this.Layout = "layout/layout.html"
}