- Renamed List model to Segment

This commit is contained in:
MrCasual
2015-09-02 09:29:54 -04:00
parent 78a2a50af7
commit 64756c865d
8 changed files with 109 additions and 109 deletions

View File

@ -34,13 +34,13 @@ class Initializer {
$settings = Env::$db_prefix . 'settings';
$newsletters = Env::$db_prefix . 'newsletters';
$lists = Env::$db_prefix . 'lists';
$subscriber_list = Env::$db_prefix . 'subscriber_list';
$subscriber_segment = Env::$db_prefix . 'subscriber_segment';
define('MP_SUBSCRIBERS_TABLE', $subscribers);
define('MP_SETTINGS_TABLE', $settings);
define('MP_NEWSLETTERS_TABLE', $newsletters);
define('MP_LISTS_TABLE', $lists);
define('MP_SUBSCRIBER_LIST_TABLE', $subscriber_list);
define('MP_SUBSCRIBER_SEGMENT_TABLE', $subscriber_segment);
}
function setupActivator() {

View File

@ -14,7 +14,7 @@ class Migrator {
'settings',
'newsletters',
'lists',
'subscriber_list'
'subscriber_segment'
);
}
@ -91,7 +91,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes);
}
function subscriber_list() {
function subscriber_segment() {
$attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'subscriber_id mediumint(9) NOT NULL,',

View File

@ -3,7 +3,7 @@ namespace MailPoet\Models;
if(!defined('ABSPATH')) exit;
class SList extends Model {
class Segment extends Model {
public static $_table = MP_LISTS_TABLE;
function __construct() {
@ -30,6 +30,6 @@ class SList extends Model {
}
public function subscribers() {
return self::has_many_through(__NAMESPACE__ . '\Subscriber', __NAMESPACE__ . '\SubscriberList', 'list_id', 'subscriber_id');
return self::has_many_through(__NAMESPACE__ . '\Subscriber', __NAMESPACE__ . '\SubscriberSegment', 'list_id', 'subscriber_id');
}
}

View File

@ -16,6 +16,6 @@ class Subscriber extends Model {
}
public function lists() {
return self::has_many_through(__NAMESPACE__ . '\SList', __NAMESPACE__ . '\SubscriberList', 'subscriber_id', 'list_id');
return self::has_many_through(__NAMESPACE__ . '\Segment', __NAMESPACE__ . '\SubscriberSegment', 'subscriber_id', 'list_id');
}
}

View File

@ -3,8 +3,8 @@ namespace MailPoet\Models;
if(!defined('ABSPATH')) exit;
class SubscriberList extends Model {
public static $_table = MP_SUBSCRIBER_LIST_TABLE;
class SubscriberSegment extends Model {
public static $_table = MP_SUBSCRIBER_SEGMENT_TABLE;
function __construct() {
parent::__construct();

View File

@ -10,8 +10,8 @@ $models = array(
'Subscriber',
'Setting',
'Newsletter',
'SList',
'SubscriberList'
'Segment',
'SubscriberSegment'
);
$destroy = function ($model) {
Model::factory('\MailPoet\Models\\' . $model)

View File

@ -1,8 +1,8 @@
<?php
use MailPoet\Models\SubscriberList;
use MailPoet\Models\SubscriberSegment;
use MailPoet\Models\Subscriber;
use MailPoet\Models\SList;
use MailPoet\Models\Segment;
class SListCest {
function _before() {
@ -11,7 +11,7 @@ class SListCest {
'name' => 'some name',
);
$this->list = SList::create();
$this->list = Segment::create();
$this->list->hydrate($this->data);
$this->saved = $this->list->save();
}
@ -22,28 +22,28 @@ class SListCest {
function itHasToBeValid() {
expect($this->saved)->equals(true);
$empty_model = SList::create();
$empty_model = Segment::create();
expect($empty_model->save())->equals(false);
$validations = $empty_model->getValidationErrors();
expect(count($validations))->equals(2);
}
function itHasACreatedAtOnCreation() {
$list = SList::where('name', $this->data['name'])
$list = Segment::where('name', $this->data['name'])
->findOne();
$time_difference = strtotime($list->created_at) >= $this->before_time;
expect($time_difference)->equals(true);
}
function itHasAnUpdatedAtOnCreation() {
$list = SList::where('name', $this->data['name'])
$list = Segment::where('name', $this->data['name'])
->findOne();
$time_difference = strtotime($list->updated_at) >= $this->before_time;
expect($time_difference)->equals(true);
}
function itKeepsTheCreatedAtOnUpdate() {
$list = SList::where('name', $this->data['name'])
$list = Segment::where('name', $this->data['name'])
->findOne();
$old_created_at = $list->created_at;
$list->name = 'new name';
@ -52,7 +52,7 @@ class SListCest {
}
function itUpdatesTheUpdatedAtOnUpdate() {
$list = SList::where('name', $this->data['name'])
$list = Segment::where('name', $this->data['name'])
->findOne();
$update_time = time();
$list->name = 'new name';
@ -65,15 +65,15 @@ class SListCest {
$data = array(
'name' => 'some other new name'
);
$createNewRecord = SList::createOrUpdate($data);
$createNewRecord = Segment::createOrUpdate($data);
$data = array(
'name' => $this->data['name'],
'name_updated' => 'updated name',
);
$updateExistingRecord = SList::createOrUpdate($data);
$updateExistingRecord = Segment::createOrUpdate($data);
$allRecords = SList::find_array();
$allRecords = Segment::find_array();
expect(count($allRecords))->equals(2);
expect($allRecords[0]['name'])->equals($data['name_updated']);
}
@ -95,24 +95,24 @@ class SListCest {
$subscriber = Subscriber::create();
$subscriber->hydrate($subscriberData);
$subscriber->save();
$association = SubscriberList::create();
$association = SubscriberSegment::create();
$association->subscriber_id = $subscriber->id;
$association->list_id = $this->list->id;
$association->save();
}
$list = SList::find_one($this->list->id);
$list = Segment::find_one($this->list->id);
$subscribers = $list->subscribers()
->find_array();
expect(count($subscribers))->equals(2);
}
function _after() {
ORM::for_table(SList::$_table)
ORM::for_table(Segment::$_table)
->delete_many();
ORM::for_table(Subscriber::$_table)
->delete_many();
ORM::for_table(SubscriberList::$_table)
ORM::for_table(SubscriberSegment::$_table)
->delete_many();
}

View File

@ -1,7 +1,7 @@
<?php
use MailPoet\Models\Subscriber;
use MailPoet\Models\SList;
use MailPoet\Models\SubscriberList;
use MailPoet\Models\Segment;
use MailPoet\Models\SubscriberSegment;
class SubscriberCest {
@ -58,10 +58,10 @@ class SubscriberCest {
'name' => 'some name'
);
$list = SList::create();
$list = Segment::create();
$list->hydrate($listData);
$list->save();
$association = SubscriberList::create();
$association = SubscriberSegment::create();
$association->subscriber_id = $this->subscriber->id;
$association->list_id = $list->id;
$association->save();
@ -75,9 +75,9 @@ class SubscriberCest {
function _after() {
ORM::for_table(Subscriber::$_table)
->delete_many();
ORM::for_table(SList::$_table)
ORM::for_table(Segment::$_table)
->delete_many();
ORM::for_table(SubscriberList::$_table)
ORM::for_table(SubscriberSegment::$_table)
->delete_many();
}
}