Skip to content

Commit

Permalink
Create failing test case for boolean field for Issue #203.
Browse files Browse the repository at this point in the history
This works:

	.where("booleanField = ?", 0)

This doesn't work:

	.where("booleanField = ?", false)
  • Loading branch information
joshuapinter committed Apr 6, 2014
1 parent 72d4a4c commit 75f3562
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/src/com/activeandroid/test/ModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.activeandroid.Model;
import com.activeandroid.TableInfo;
import com.activeandroid.annotation.Table;
import com.activeandroid.query.Select;

import java.lang.reflect.Field;
import java.util.HashSet;
Expand Down Expand Up @@ -142,6 +143,32 @@ public void testColumnNamesDefaulToFieldNames() {
}
}

/**
* Boolean should handle integer (0/1) and boolean (false/true) values.
*/
public void testBooleanColumnType() {
MockModel mockModel = new MockModel();
mockModel.booleanField = false;
Long id = mockModel.save();

boolean databaseBooleanValue = MockModel.load( MockModel.class, id ).booleanField;

assertEquals( false, databaseBooleanValue );

// Test passing both a integer and a boolean into the where conditional.
assertEquals(
mockModel,
new Select().from(MockModel.class).where("booleanField = ?", 0).executeSingle() );

assertEquals(
mockModel,
new Select().from(MockModel.class).where("booleanField = ?", false).executeSingle() );

assertNull( new Select().from(MockModel.class).where("booleanField = ?", 1).executeSingle() );

assertNull( new Select().from(MockModel.class).where("booleanField = ?", true).executeSingle() );
}

/**
* Mock model as we need 2 different model classes.
*/
Expand Down

0 comments on commit 75f3562

Please sign in to comment.