source: Dev/branches/play-2.0.1/samples/scala/computer-database/test/ModelSpec.scala @ 322

Last change on this file since 322 was 322, checked in by hendrikvanantwerpen, 13 years ago

Added Play! framework and application with Jena dependency. Working on
the basic things now (login/register), after that start implementing
our data model.

File size: 1.4 KB
Line 
1package test
2
3import org.specs2.mutable._
4
5import play.api.test._
6import play.api.test.Helpers._
7
8class ModelSpec extends Specification {
9 
10  import models._
11
12  // -- Date helpers
13 
14  def dateIs(date: java.util.Date, str: String) = new java.text.SimpleDateFormat("yyyy-MM-dd").format(date) == str
15 
16  // --
17 
18  "Computer model" should {
19   
20    "be retrieved by id" in {
21      running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
22       
23        val Some(macintosh) = Computer.findById(21)
24     
25        macintosh.name must equalTo("Macintosh")
26        macintosh.introduced must beSome.which(dateIs(_, "1984-01-24")) 
27       
28      }
29    }
30   
31    "be listed along its companies" in {
32      running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
33       
34        val computers = Computer.list()
35
36        computers.total must equalTo(574)
37        computers.items must have length(10)
38
39      }
40    }
41   
42    "be updated if needed" in {
43      running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
44       
45        Computer.update(21, Computer(name="The Macintosh", introduced=None, discontinued=None, companyId=Some(1)))
46       
47        val Some(macintosh) = Computer.findById(21)
48       
49        macintosh.name must equalTo("The Macintosh")
50        macintosh.introduced must beNone
51       
52      }
53    }
54   
55  }
56 
57}
Note: See TracBrowser for help on using the repository browser.