db connection and fixtures

11 views
Skip to first unread message

Josh Kamau

unread,
May 8, 2015, 12:33:18 PM5/8/15
to acti...@googlegroups.com
Hi. 

I am really enjoying working with javalite stack.  

I have 2 questions: 
1.  Which is the best place to put code to load fixtures 
2.  I have the database.properties file. How do i use it in dbConfig#init method? 

Thanks

Josh Kamau

unread,
May 8, 2015, 1:00:50 PM5/8/15
to acti...@googlegroups.com
I figured how  issue number (2),  Now all i need to do is find out how to load (or where  to put the code) for loading fixtures.

Igor Polevoy

unread,
May 8, 2015, 3:38:02 PM5/8/15
to acti...@googlegroups.com
Josh, JavaLite does not really have fixtures implemented as they exist in Ruby on Rails. This is one feature we thought unnecessary. 

Usually we write tests like this:


123456789101112131415
 
@Test
public void shouldFindPerson(){
//create data in DB
Person.createId("first_name", "John", "last_name", "Doe");
Person.createId("first_name", "Jane", "last_name", "Doe");
 
//perform tests that need data:
 
List<Person> people = Person.where("first_name = ?", "John");
the(people.size()).shouldBe(1);
a(people.get(0).get("last_name")).shouldBe("Doe");
}

As you can see, on lines 6 and 7 I create data. I personally like to view data creation in the sane file. Sometimes you would use JUnit @Before to run this before any test. 

Also, keep in mind that ActiveWeb automatically runs every test in a transaction that rolls back after each test. This leaves all tables in a test database clean at all times. 

I hope this helps!

Igor

Josh Kamau

unread,
May 8, 2015, 8:43:27 PM5/8/15
to acti...@googlegroups.com
That helps. I am studying the code and looking forward to contributing some day.  Great work.

Thanks.
Josh

--
--
You received this message because you are subscribed to the Google
Groups "ActiveWeb Group" group.
To post to this group, send email to acti...@googlegroups.com
To unsubscribe from this group, send email to
activeweb+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/activeweb?hl=en?hl=en

---
You received this message because you are subscribed to the Google Groups "ActiveWeb Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to activeweb+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Igor Polevoy

unread,
May 9, 2015, 11:11:34 AM5/9/15
to acti...@googlegroups.com
awesome!
Reply all
Reply to author
Forward
0 new messages