HAVING clause API code-coverage
diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php
index dd248ae..7d8abc3 100644
--- a/tests/codeigniter/database/query_builder/group_test.php
+++ b/tests/codeigniter/database/query_builder/group_test.php
@@ -22,16 +22,32 @@
*/
public function test_group_by()
{
- $jobs = $this->db->select('job.name as job_name, job.id as job_id')
+ $jobs = $this->db->select('name')
->from('job')
- ->group_by('job_name HAVING SUM(job_id) > 2')
+ ->group_by('name')
+ ->get()
+ ->result_array();
+
+ // Check the result
+ $this->assertEquals(4, count($jobs));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_having_by()
+ {
+ $jobs = $this->db->select('name')
+ ->from('job')
+ ->group_by('name')
+ ->having('SUM(id) > 2')
->get()
->result_array();
// Check the result
$this->assertEquals(2, count($jobs));
- $this->assertEquals('Accountant', $jobs[0]['job_name']);
- $this->assertEquals('Musician', $jobs[1]['job_name']);
}
}
\ No newline at end of file
diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite
index e4128b2..d48e331 100755
--- a/tests/mocks/database/ci_test.sqlite
+++ b/tests/mocks/database/ci_test.sqlite
Binary files differ
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
index 9ebd6e8..671336c 100644
--- a/tests/mocks/database/schema/skeleton.php
+++ b/tests/mocks/database/schema/skeleton.php
@@ -64,6 +64,10 @@
'type' => 'VARCHAR',
'constraint' => 100,
),
+ 'country' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40,
+ ),
));
static::$forge->add_key('id', TRUE);
static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE));
@@ -96,10 +100,10 @@
// Job Data
$data = array(
'user' => array(
- array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com'),
- array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com'),
- array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com'),
- array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com'),
+ array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com', 'country' => 'US'),
+ array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com', 'country' => 'Iran'),
+ array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com', 'country' => 'US'),
+ array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com', 'country' => 'UK'),
),
'job' => array(
array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'),