コード例 #1
0
ファイル: factory.go プロジェクト: nicholasray/sandstone
func (c Climb) Create(db *sqlx.DB, m *climb.Model) error {
	if m.RockID == 0 {
		r := Rock{}
		rm := rock.Model{}
		err := r.Create(db, &rm)
		if err != nil {
			log.Fatal(err)
		}

		m.RockID = rm.ID
	}

	stmt, err := db.PrepareNamed(`INSERT INTO climbs (rock_id, name, rating, description) VALUES (:rock_id, :name, :rating, :description) RETURNING *`)
	if err != nil {
		log.Fatal(err)
	}

	err = stmt.Get(m, m)

	return err
}
コード例 #2
0
ファイル: climb_test.go プロジェクト: nicholasray/sandstone
import (
	"fmt"
	"strconv"

	"github.com/nicholasray/sandstone/resource/climb"
	"github.com/nicholasray/sandstone/resource/rock"
	"github.com/nicholasray/sandstone/test"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Climb", func() {
	var (
		request      Request
		climbFactory factory.Climb
		rockFactory  factory.Rock
		m            climb.Model
	)

	BeforeEach(func() {
		factory.ClearDB(db)
		request = Request{}
		climbFactory = factory.Climb{}
		m = climb.Model{Name: "Zion", Rating: 3, Description: "Awesome!"}
	})

	Describe("Show", func() {
		BeforeEach(func() {
			err := climbFactory.Create(db, &m)
			Expect(err).To(BeNil())
コード例 #3
0
	model  climb.Model
}

func (r ClimbReader) Model() interface{} {
	return r.model
}

func (r ClimbReader) Fields() []string {
	return r.fields
}

var _ = Describe("Climb", func() {
	var (
		m            climb.Model
		rm           rock.Model
		climbFactory factory.Climb
		rockFactory  factory.Rock
		climbRepo    climb.Repository
		reader       decode.DecoderReader
	)

	BeforeEach(func() {
		factory.ClearDB(db)

		m = climb.Model{Name: "test", Rating: 3, Description: "Awesome climbing!"}
		rm = rock.Model{Latitude: 5, Longitude: 10}
		climbFactory = factory.Climb{}
		rockFactory = factory.Rock{}
		climbRepo = climb.Repository{db}
	})

	JustBeforeEach(func() {