desc: Regression tests for issue #733 (make group_by take both kinds of object)
tests:
  - cd: r.db('test').table_create('733')
    def: tbl = r.db('test').table('733')

  - rb: tbl.insert([{:a => 0, :id => 1}, {:a => 1, :id => 2},{:a => 0, :id => 3}])
    ot: ({'unchanged':0,'skipped':0,'replaced':0,'inserted':3,'errors':0,'deleted':0})

  # To adequately test this issue we need to send a literal datum object in place of
  # the usual MAK_OBJ term when invoking group_by. Since the Ruby driver don't do
  # this by default we hack it here by directly constructing the protobuf object.
  - rb: |
      tbl.groupby(:a,
        (t = RethinkDB::RQL.new;
         t.body = Term.new;
         t.body.type = Term::TermType::DATUM;
         t.body.datum = (attr = Datum.new;
             attr.type = Datum::DatumType::R_STR;
             attr.r_str = "id";
             ap = Datum::AssocPair.new;
             ap.key = "SUM";
             ap.val = attr;
             d = Datum.new;
             d.type = Datum::DatumType::R_OBJECT;
             d.r_object << ap;
             d);
         t
        )
      ).orderby(:group)
    ot: [{"group":{"a":0}, "reduction":4}, {"group":{"a":1}, "reduction":2}]

  - cd: r.db('test').table_drop('733')
