Exemplo n.º 1
0
  @Test
  public void shouldIncludeOnlyProvidedAttributes() {
    deleteAndPopulateTables("users", "addresses");

    User u = User.findById(1);
    String json = u.toJson(true, "email", "last_name");
    JsonHelper.readTree(json); // validate
    the(json)
        .shouldBeEqual(
            "{\n" + "  \"email\":\"[email protected]\",\n" + "  \"last_name\":\"Monroe\"\n" + "}");
  }
Exemplo n.º 2
0
  @Test
  public void shouldIncludeUglyChildren() {
    deleteAndPopulateTables("users", "addresses");
    List<User> personList = User.findAll().orderBy("id").include(Address.class);
    User u = personList.get(0);
    String json = u.toJson(false);
    Map m = JsonHelper.toMap(json);

    a(m.get("first_name")).shouldBeEqual("Marilyn");
    a(m.get("last_name")).shouldBeEqual("Monroe");

    Map children = (Map) m.get("children");
    List<Map> addresses = (List<Map>) children.get("addresses");

    the(addresses.size()).shouldBeEqual(3);
    // at this point, no need to verify, since the order of addresses is not guaranteed.. or is it??
  }