From 108ebd781c23974291262025be64606d679515de Mon Sep 17 00:00:00 2001 From: Ivan Diaz Date: Sat, 14 May 2016 20:22:46 -0300 Subject: [PATCH] [Ivan Diaz] - OS-#39 - Fix test issues --- server/api-test/user/signup.rb | 12 ------------ server/database.sh | 9 --------- server/models/Comment.php | 2 +- server/models/Ticket.php | 2 +- server/models/User.php | 4 ++-- server/tests/models/DataStoreTest.php | 11 +++-------- {server/api-test => tests}/Gemfile | 0 tests/clean_db.sh | 9 +++++++++ server/api-test/run-test.rb => tests/init.rb | 1 + {server/api-test => tests}/libs.rb | 0 tests/run-tests.sh | 2 ++ {server/api-test => tests}/scripts.rb | 1 + {server/api-test => tests}/user/login.rb | 1 + tests/user/signup.rb | 12 ++++++++++++ 14 files changed, 33 insertions(+), 33 deletions(-) delete mode 100644 server/api-test/user/signup.rb delete mode 100755 server/database.sh rename {server/api-test => tests}/Gemfile (100%) create mode 100755 tests/clean_db.sh rename server/api-test/run-test.rb => tests/init.rb (86%) rename {server/api-test => tests}/libs.rb (100%) create mode 100755 tests/run-tests.sh rename {server/api-test => tests}/scripts.rb (96%) rename {server/api-test => tests}/user/login.rb (99%) create mode 100644 tests/user/signup.rb diff --git a/server/api-test/user/signup.rb b/server/api-test/user/signup.rb deleted file mode 100644 index 5be05330..00000000 --- a/server/api-test/user/signup.rb +++ /dev/null @@ -1,12 +0,0 @@ -describe '/user/signup' do - it 'should create user in database' do - response = request('/user/signup', { - 'email' => 'steve@jobs.com', - 'password' => 'custom' - }) - - userRow = $database.getRow('users', response['data']['userId']) - - (userRow['email']).should.equal('steve@jobs.com') - end -end diff --git a/server/database.sh b/server/database.sh deleted file mode 100755 index 08a1bcae..00000000 --- a/server/database.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -# DELETE ALL TABLES -TABLES=$(mysql -u os_dev -pos_dev os_dev -e "SHOW TABLES IN os_dev;" | awk '{ print $1}' | grep -v '^Tables') - -for t in $TABLES -do - mysql -u os_dev -pos_dev os_dev -e "DROP TABLE $t" -done diff --git a/server/models/Comment.php b/server/models/Comment.php index da011200..968e013b 100644 --- a/server/models/Comment.php +++ b/server/models/Comment.php @@ -1,7 +1,7 @@ [] ); diff --git a/server/tests/models/DataStoreTest.php b/server/tests/models/DataStoreTest.php index 07c02de7..ebccd886 100644 --- a/server/tests/models/DataStoreTest.php +++ b/server/tests/models/DataStoreTest.php @@ -17,16 +17,12 @@ class DataStoreMock extends DataStore { ); } - public function getDefaultProperties() { + public function getDefaultProps() { return array( 'prop1' => 0, 'prop2' => 'hello' ); } - - public static function deleteDataStore($dataStore) { - return parent::deleteDataStore($dataStore); - } } class DataStoreTest extends PHPUnit_Framework_TestCase { @@ -78,9 +74,8 @@ class DataStoreTest extends PHPUnit_Framework_TestCase { } public function testDeleteDataStore() { - $beanInstance = $this->instance->getBeanInstance(); - DataStoreMock::deleteDataStore($this->instance); + $this->instance->delete(); - $this->assertTrue(RedBean::get('trash')->hasBeenCalledWithArgs($beanInstance)); + $this->assertTrue(RedBean::get('trash')->hasBeenCalledWithArgs($this->instance->getBeanInstance())); } } diff --git a/server/api-test/Gemfile b/tests/Gemfile similarity index 100% rename from server/api-test/Gemfile rename to tests/Gemfile diff --git a/tests/clean_db.sh b/tests/clean_db.sh new file mode 100755 index 00000000..e0b432ae --- /dev/null +++ b/tests/clean_db.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# DELETE ALL TABLES +TABLES=$(mysql -u root development -e "SHOW TABLES IN os_dev;" | awk '{ print $1}' | grep -v '^Tables') + +for t in $TABLES +do + mysql -u root development -e "DROP TABLE $t" +done diff --git a/server/api-test/run-test.rb b/tests/init.rb similarity index 86% rename from server/api-test/run-test.rb rename to tests/init.rb index d54a219f..f09d7691 100644 --- a/server/api-test/run-test.rb +++ b/tests/init.rb @@ -5,6 +5,7 @@ require 'uri' require 'mysql' require 'json' require './libs.rb' +require './scripts.rb' # TESTS require './user/signup.rb' diff --git a/server/api-test/libs.rb b/tests/libs.rb similarity index 100% rename from server/api-test/libs.rb rename to tests/libs.rb diff --git a/tests/run-tests.sh b/tests/run-tests.sh new file mode 100755 index 00000000..e87ac4ca --- /dev/null +++ b/tests/run-tests.sh @@ -0,0 +1,2 @@ +./clean_db.sh +bacon init.rb \ No newline at end of file diff --git a/server/api-test/scripts.rb b/tests/scripts.rb similarity index 96% rename from server/api-test/scripts.rb rename to tests/scripts.rb index e7dccfb1..52956341 100644 --- a/server/api-test/scripts.rb +++ b/tests/scripts.rb @@ -7,5 +7,6 @@ class Scripts if response['status'] === 'fail' raise "Could not create user" + end end end diff --git a/server/api-test/user/login.rb b/tests/user/login.rb similarity index 99% rename from server/api-test/user/login.rb rename to tests/user/login.rb index 61bb33ac..398e90c5 100644 --- a/server/api-test/user/login.rb +++ b/tests/user/login.rb @@ -22,3 +22,4 @@ describe '/user/login' do it 'should fail if already logged in' do end +end \ No newline at end of file diff --git a/tests/user/signup.rb b/tests/user/signup.rb new file mode 100644 index 00000000..51c3885f --- /dev/null +++ b/tests/user/signup.rb @@ -0,0 +1,12 @@ +describe '/user/signup' do + it 'should create user in database' do + response = request('/user/signup', { + 'email' => 'steve@jobs.com', + 'password' => 'custom' + }) + + userRow = $database.getRow('users', response['data']['userId']) + + (userRow['email']).should.equal('steve@jobs.com') + end +end