Skip to content

Commit

Permalink
Re-recorded site deploy fixture, added no-changes state test
Browse files Browse the repository at this point in the history
  • Loading branch information
tesladethray committed Jan 26, 2016
1 parent 9623123 commit 0d78e9f
Show file tree
Hide file tree
Showing 8 changed files with 465 additions and 111 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ All notable changes to this project starting with the 0.6.0 release will be docu
- New command `site solr enable` to enable Solr indexing. (#814)
- New command `site solr disable` to disable Solr indexing. (#814)
- Added `--email=<email>` argument to `auth login` to retireve saved machine tokens. (#825)
- Added Environment#getParentEnvironment(). (#831)
- Added `Environment#getParentEnvironment()`. (#831)
- Added `CodeLogs` collection and `CodeLog` model. (#831)

### Changed
- `drush` and `wp` commands now issue a warning to change your connection mode to SFTP if it is in Git mode. (#807)
Expand All @@ -22,7 +23,6 @@ All notable changes to this project starting with the 0.6.0 release will be docu
- If a `drush` or `wp` command exits with any status except for 0, Terminus now exits with that status. (#827)
- Removed "Backup URL:" label from the single-record output of `site backups get`. (#828)
- Added machine_token to the error output blacklist. (#840)
- Renamed Environment#log() to Environment#getCodeLog(). (#831)
- `site deploy` will exit with status 1 and the message "There is nothing to deploy." if there are no changes to deploy. (#831)

### Fixed
Expand All @@ -32,7 +32,8 @@ All notable changes to this project starting with the 0.6.0 release will be docu

### Removed
- `--session=<session_id>` argument has been removed from `auth login`. (#826)
- `logInViaSessionToken()` as been removed from Auth. (#826)
- `logInViaSessionToken()` has been removed from `Auth`. (#826)
- `log()` has been removed from `Environment`. Use new code_log property (contains CodeLogs collection) instead. (#831)

## [0.10.1] - 2015-01-12
### Added
Expand Down
4 changes: 2 additions & 2 deletions php/Terminus/Commands/SiteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function code($args, $assoc_args) {
);
switch ($subcommand) {
case 'log':
$logs = $env->getCodeLog();
$logs = $env->code_logs->all();
$data = array();
foreach ($logs as $log) {
$data[] = array(
Expand Down Expand Up @@ -628,7 +628,7 @@ public function deploy($args, $assoc_args) {
if (!$env || !in_array($env->get('id'), array('test', 'live'))) {
$this->failure('You can only deploy to the test or live environment.');
}
if (!$env->hasUpstreamUpdates()) {
if (!$env->hasDeployableCode()) {
$this->failure('There is nothing to deploy.');
}

Expand Down
6 changes: 6 additions & 0 deletions php/Terminus/Models/CodeLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

namespace Terminus\Models;

class CodeLog extends TerminusModel {
}
31 changes: 31 additions & 0 deletions php/Terminus/Models/Collections/CodeLogs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Terminus\Models\Collections;

class CodeLogs extends TerminusCollection {

/**
* Give the URL for collection data fetching
*
* @return string URL to use in fetch query
*/
protected function getFetchUrl() {
$url = sprintf(
'sites/%s/environments/%s/code-log',
$this->environment->site->get('id'),
$this->environment->get('id')
);
return $url;
}

/**
* Names the model-owner of this collection
*
* @return string
*/
protected function getOwnerName() {
$owner_name = 'environment';
return $owner_name;
}

}
36 changes: 14 additions & 22 deletions php/Terminus/Models/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
use Terminus\Models\TerminusModel;
use Terminus\Models\Collections\Backups;
use Terminus\Models\Collections\Bindings;
use Terminus\Models\Collections\CodeLogs;

class Environment extends TerminusModel {
/**
* @var Backups
*/
public $backups;

/**
* @var CodeLogs
*/
public $code_logs;

/**
* @var Bindings
*/
Expand All @@ -28,8 +34,10 @@ class Environment extends TerminusModel {
*/
public function __construct($attributes, array $options = array()) {
parent::__construct($attributes, $options);
$this->backups = new Backups(array('environment' => $this));
$this->bindings = new Bindings(array('environment' => $this));
$options = ['environment' => $this];
$this->backups = new Backups($options);
$this->bindings = new Bindings($options);
$this->code_logs = new CodeLogs($options);
}

/**
Expand Down Expand Up @@ -383,22 +391,6 @@ public function domain() {
return $host;
}

/**
* Get the code log (commits)
*
* @return array
*/
public function getCodeLog() {
$path = sprintf('environments/%s/code-log', $this->get('id'));
$response = $this->request->request(
'sites',
$this->site->get('id'),
$path,
'GET'
);
return $response['data'];
}

/**
* Returns the connection mode of this environment
*
Expand Down Expand Up @@ -477,9 +469,9 @@ public function getParentEnvironment() {
*
* @return bool
*/
public function hasUpstreamUpdates() {
$parent_code_log = $this->getParentEnvironment()->getCodeLog();
$number_of_updates = count($parent_code_log) - count($this->getCodeLog());
public function hasDeployableCode() {
$parent_code_log = $this->getParentEnvironment()->code_logs->all();
$number_of_updates = count($parent_code_log) - count($this->code_logs->all());
return (boolean)$number_of_updates;
}

Expand Down Expand Up @@ -559,7 +551,7 @@ public function initializeBindings() {
public function isInitialized() {
// One can determine whether an environment has been initialized
// by checking if it has code commits. Uninitialized environments do not.
$commits = $this->getCodeLog();
$commits = $this->code_logs->all();
$has_commits = (count($commits) > 0);
return $has_commits;
}
Expand Down
9 changes: 8 additions & 1 deletion tests/features/site_deploy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ Feature: Site Deployment
And a site named "[[test_site_name]]"
When I run "terminus site deploy --site=[[test_site_name]] --env=test --sync-content --note='Deploy test'"
Then I should get "."
Then I should get "."
And I should get "."
Then I should get:
"""
Deploying code to "test", and cloning files from "live", and cloning database from "live"
"""

@vcr site_deploy_no_changes
Scenario: Failing to deploy dev to test because there are no changes to deploy
Given I am authenticated
And a site named "[[test_site_name]]"
When I run "terminus site deploy --site=[[test_site_name]] --env=test --sync-content --note='Deploy test'"
Then I should get: "There is nothing to deploy."

0 comments on commit 0d78e9f

Please sign in to comment.