Skip to content

Instantly share code, notes, and snippets.

@fabriziomachado
fabriziomachado / phone_carrier_model.php
Created September 6, 2011 12:00
my-ci-app/application/models/phone_carrier_model.php
<?php
class Phone_carrier_model extends CI_Model {
function __construct()
{
parent::__construct();
}
public function getCarriers($attributes)
{
@fabriziomachado
fabriziomachado / phone_carrier_model.php
Created September 6, 2011 12:01
my-ci-app/application/models/phone_carrier_model.php
<?php
class Phone_carrier_model extends CI_Model {
function __construct()
{
parent::__construct();
}
public function getCarriers($attributes)
{
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->spark('php-activerecord/0.0.1');
}
public function index() {
@fabriziomachado
fabriziomachado / PersonTest.php
Created September 6, 2011 18:11
tests/models/PersonTest.php
<?php
include_once dirname(__FILE__) . '/../support/enviromment.php';
/**
* @group models
*/
class PersonTest extends CIUnit_TestCase {
public function setUp() {
$this->CI->load->spark('php-activerecord/0.0.1');
parent::setUp();
@fabriziomachado
fabriziomachado / .watchr.rb
Created September 26, 2011 19:03
autotest
require "open3"
watch("application/(models|controllers)/(.*).php") do |match|
test_changed_application(match[0])
end
watch("tests/(.*/.*)\.php") do |match|
phpunit match[0]
end
@fabriziomachado
fabriziomachado / Student.php
Created September 26, 2011 20:10
application/models/Student.php
<?php
class Student extends Person {
static $primary_key = 'id';
static $has_many = array(array('enrollments'));
public function __construct(array $attributes = array()) {
parent::__construct(array_merge($attributes,array('type'=> __CLASS__ )));
}
}
<?php
/**
* @group Helper
*/
class PartialsHelperTest extends CIUnit_TestCase
{
public function setUp()
{
@fabriziomachado
fabriziomachado / Account.php
Created October 20, 2011 12:22
application/models/Account.php
<?php
class Account extends ActiveRecord\Model {
static $belongs_to = array(
array('person')
);
static $validates_inclusion_of = array(
array('provider', 'in' => array('twitter','facebook'),
@fabriziomachado
fabriziomachado / AccountTest.php
Created October 20, 2011 12:25
tests/models/AccountTest.php
<?php
include_once dirname(__FILE__) . '/../support/enviromment.php';
/**
* @group models
*/
class AccountTest extends CIUnit_TestCase
{
protected $tables = array(
@fabriziomachado
fabriziomachado / gist:1305832
Created October 22, 2011 09:59
nested_forms_test_passing
context "create questions and answers for the exam" do
let(:build_object) { mock().as_null_object }
it "should instantiate at least 3 questions" do
exam_questions = mock("questions for an exam").as_null_object
Exam.any_instance.stub(:questions).and_return(exam_questions)
exam_questions.stub(:build).and_return(build_object)
exam_questions.should_receive(:build).exactly(3).times
get :new