├── .editorconfig ├── .eslintrc.json ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── pull_request_template.md └── workflows │ └── build-and-test.yml ├── .gitignore ├── .mocharc.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── index.js ├── package-lock.json ├── package.json └── test ├── bootstrap.v0.11.test.js ├── bootstrap.v0.12.test.js ├── bootstrap.v1.x-create-db-schemes.test.js ├── bootstrap.v1.x-many-schemes.test.js ├── bootstrap.v1.x-migrate-safe.test.js ├── bootstrap.v1.x-no-conn.test.js ├── bootstrap.v1.x-sequelize-waterline.test.js ├── bootstrap.v1.x-sqlite.test.js ├── bootstrap.v1.x.test.js ├── fixtures ├── instances.json ├── v0.11-app │ ├── .gitignore │ ├── .sailsrc │ ├── api │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── models │ │ │ ├── .gitkeep │ │ │ ├── Group.js │ │ │ ├── Image.js │ │ │ └── User.js │ │ ├── policies │ │ │ └── sessionAuth.js │ │ ├── responses │ │ │ ├── badRequest.js │ │ │ ├── created.js │ │ │ ├── forbidden.js │ │ │ ├── notFound.js │ │ │ ├── ok.js │ │ │ └── serverError.js │ │ └── services │ │ │ └── .gitkeep │ ├── app.js │ ├── config │ │ ├── blueprints.js │ │ ├── bootstrap.js │ │ ├── connections.js │ │ ├── cors.js │ │ ├── csrf.js │ │ ├── globals.js │ │ ├── http.js │ │ ├── i18n.js │ │ ├── log.js │ │ ├── models.js │ │ ├── policies.js │ │ ├── routes.js │ │ ├── sequelize.js │ │ ├── session.js │ │ ├── sockets.js │ │ └── views.js │ ├── package-lock.json │ ├── package.json │ └── views │ │ ├── 403.ejs │ │ ├── 404.ejs │ │ ├── 500.ejs │ │ ├── homepage.ejs │ │ └── layout.ejs ├── v0.12-app │ ├── .sailsrc │ ├── api │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── models │ │ │ ├── .gitkeep │ │ │ ├── Group.js │ │ │ ├── Image.js │ │ │ └── User.js │ │ ├── policies │ │ │ └── sessionAuth.js │ │ ├── responses │ │ │ ├── badRequest.js │ │ │ ├── created.js │ │ │ ├── forbidden.js │ │ │ ├── notFound.js │ │ │ ├── ok.js │ │ │ └── serverError.js │ │ └── services │ │ │ └── .gitkeep │ ├── app.js │ ├── config │ │ ├── blueprints.js │ │ ├── bootstrap.js │ │ ├── connections.js │ │ ├── cors.js │ │ ├── csrf.js │ │ ├── globals.js │ │ ├── http.js │ │ ├── i18n.js │ │ ├── log.js │ │ ├── models.js │ │ ├── policies.js │ │ ├── routes.js │ │ ├── sequelize.js │ │ ├── session.js │ │ ├── sockets.js │ │ └── views.js │ ├── package-lock.json │ ├── package.json │ └── views │ │ ├── 403.ejs │ │ ├── 404.ejs │ │ ├── 500.ejs │ │ ├── homepage.ejs │ │ └── layout.ejs ├── v1.x-app │ ├── .gitignore │ ├── .sailsrc │ ├── api │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── models │ │ │ ├── .gitkeep │ │ │ ├── Group.js │ │ │ ├── Image.js │ │ │ └── User.js │ │ ├── policies │ │ │ └── sessionAuth.js │ │ ├── responses │ │ │ ├── badRequest.js │ │ │ ├── created.js │ │ │ ├── forbidden.js │ │ │ ├── notFound.js │ │ │ ├── ok.js │ │ │ └── serverError.js │ │ └── services │ │ │ └── .gitkeep │ ├── app.js │ ├── config │ │ ├── blueprints.js │ │ ├── bootstrap.js │ │ ├── csrf.js │ │ ├── datastores.js │ │ ├── globals.js │ │ ├── http.js │ │ ├── i18n.js │ │ ├── log.js │ │ ├── models.js │ │ ├── policies.js │ │ ├── routes.js │ │ ├── sequelize.js │ │ ├── session.js │ │ ├── sockets.js │ │ └── views.js │ └── views │ │ ├── 403.ejs │ │ ├── 404.ejs │ │ ├── 500.ejs │ │ ├── homepage.ejs │ │ └── layout.ejs ├── v1.x-create-db-schemes-app │ ├── .gitignore │ ├── .sailsrc │ ├── api │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── models │ │ │ ├── .gitkeep │ │ │ ├── Group.js │ │ │ ├── Image.js │ │ │ └── User.js │ │ ├── policies │ │ │ └── sessionAuth.js │ │ ├── responses │ │ │ ├── badRequest.js │ │ │ ├── created.js │ │ │ ├── forbidden.js │ │ │ ├── notFound.js │ │ │ ├── ok.js │ │ │ └── serverError.js │ │ └── services │ │ │ └── .gitkeep │ ├── app.js │ ├── config │ │ ├── blueprints.js │ │ ├── bootstrap.js │ │ ├── csrf.js │ │ ├── datastores.js │ │ ├── globals.js │ │ ├── http.js │ │ ├── i18n.js │ │ ├── log.js │ │ ├── models.js │ │ ├── policies.js │ │ ├── routes.js │ │ ├── sequelize.js │ │ ├── session.js │ │ ├── sockets.js │ │ └── views.js │ └── views │ │ ├── 403.ejs │ │ ├── 404.ejs │ │ ├── 500.ejs │ │ ├── homepage.ejs │ │ └── layout.ejs ├── v1.x-many-schemes-app │ ├── .gitignore │ ├── .sailsrc │ ├── api │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── models │ │ │ ├── .gitkeep │ │ │ ├── Group.js │ │ │ ├── Image.js │ │ │ └── User.js │ │ ├── policies │ │ │ └── sessionAuth.js │ │ ├── responses │ │ │ ├── badRequest.js │ │ │ ├── created.js │ │ │ ├── forbidden.js │ │ │ ├── notFound.js │ │ │ ├── ok.js │ │ │ └── serverError.js │ │ └── services │ │ │ └── .gitkeep │ ├── app.js │ ├── config │ │ ├── blueprints.js │ │ ├── bootstrap.js │ │ ├── csrf.js │ │ ├── datastores.js │ │ ├── globals.js │ │ ├── http.js │ │ ├── i18n.js │ │ ├── log.js │ │ ├── models.js │ │ ├── policies.js │ │ ├── routes.js │ │ ├── sequelize.js │ │ ├── session.js │ │ ├── sockets.js │ │ └── views.js │ └── views │ │ ├── 403.ejs │ │ ├── 404.ejs │ │ ├── 500.ejs │ │ ├── homepage.ejs │ │ └── layout.ejs ├── v1.x-migrate-safe-app │ ├── .gitignore │ ├── .sailsrc │ ├── api │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── models │ │ │ ├── .gitkeep │ │ │ ├── Group.js │ │ │ ├── Image.js │ │ │ └── User.js │ │ ├── policies │ │ │ └── sessionAuth.js │ │ ├── responses │ │ │ ├── badRequest.js │ │ │ ├── created.js │ │ │ ├── forbidden.js │ │ │ ├── notFound.js │ │ │ ├── ok.js │ │ │ └── serverError.js │ │ └── services │ │ │ └── .gitkeep │ ├── app.js │ ├── config │ │ ├── blueprints.js │ │ ├── bootstrap.js │ │ ├── csrf.js │ │ ├── datastores.js │ │ ├── globals.js │ │ ├── http.js │ │ ├── i18n.js │ │ ├── log.js │ │ ├── models.js │ │ ├── policies.js │ │ ├── routes.js │ │ ├── sequelize.js │ │ ├── session.js │ │ ├── sockets.js │ │ └── views.js │ └── views │ │ ├── 403.ejs │ │ ├── 404.ejs │ │ ├── 500.ejs │ │ ├── homepage.ejs │ │ └── layout.ejs ├── v1.x-no-conn-app │ ├── .gitignore │ ├── .sailsrc │ ├── api │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── models │ │ │ ├── .gitkeep │ │ │ ├── Group.js │ │ │ ├── Image.js │ │ │ └── User.js │ │ ├── policies │ │ │ └── sessionAuth.js │ │ ├── responses │ │ │ ├── badRequest.js │ │ │ ├── created.js │ │ │ ├── forbidden.js │ │ │ ├── notFound.js │ │ │ ├── ok.js │ │ │ └── serverError.js │ │ └── services │ │ │ └── .gitkeep │ ├── app.js │ ├── config │ │ ├── blueprints.js │ │ ├── bootstrap.js │ │ ├── csrf.js │ │ ├── datastores.js │ │ ├── globals.js │ │ ├── http.js │ │ ├── i18n.js │ │ ├── log.js │ │ ├── models.js │ │ ├── policies.js │ │ ├── routes.js │ │ ├── sequelize.js │ │ ├── session.js │ │ ├── sockets.js │ │ └── views.js │ ├── db │ │ └── sequelize.sqlite │ └── views │ │ ├── 403.ejs │ │ ├── 404.ejs │ │ ├── 500.ejs │ │ ├── homepage.ejs │ │ └── layout.ejs ├── v1.x-sequelize-waterline-app │ ├── .gitignore │ ├── .sailsrc │ ├── api │ │ ├── controllers │ │ │ └── .gitkeep │ │ ├── models │ │ │ ├── .gitkeep │ │ │ ├── Good.js │ │ │ ├── Group.js │ │ │ ├── Image.js │ │ │ └── User.js │ │ ├── policies │ │ │ └── sessionAuth.js │ │ ├── responses │ │ │ ├── badRequest.js │ │ │ ├── created.js │ │ │ ├── forbidden.js │ │ │ ├── notFound.js │ │ │ ├── ok.js │ │ │ └── serverError.js │ │ └── services │ │ │ └── .gitkeep │ ├── app.js │ ├── config │ │ ├── blueprints.js │ │ ├── bootstrap.js │ │ ├── csrf.js │ │ ├── datastores.js │ │ ├── globals.js │ │ ├── http.js │ │ ├── i18n.js │ │ ├── log.js │ │ ├── models.js │ │ ├── policies.js │ │ ├── routes.js │ │ ├── sequelize.js │ │ ├── session.js │ │ ├── sockets.js │ │ └── views.js │ ├── db │ │ └── sequelize.sqlite │ └── views │ │ ├── 403.ejs │ │ ├── 404.ejs │ │ ├── 500.ejs │ │ ├── homepage.ejs │ │ └── layout.ejs └── v1.x-sqlite3-app │ ├── .gitignore │ ├── .sailsrc │ ├── api │ ├── controllers │ │ └── .gitkeep │ ├── models │ │ ├── .gitkeep │ │ ├── Group.js │ │ ├── Image.js │ │ └── User.js │ ├── policies │ │ └── sessionAuth.js │ ├── responses │ │ ├── badRequest.js │ │ ├── created.js │ │ ├── forbidden.js │ │ ├── notFound.js │ │ ├── ok.js │ │ └── serverError.js │ └── services │ │ └── .gitkeep │ ├── app.js │ ├── config │ ├── blueprints.js │ ├── bootstrap.js │ ├── csrf.js │ ├── datastores.js │ ├── globals.js │ ├── http.js │ ├── i18n.js │ ├── log.js │ ├── models.js │ ├── policies.js │ ├── routes.js │ ├── sequelize.js │ ├── session.js │ ├── sockets.js │ └── views.js │ ├── db │ └── sequelize.sqlite │ └── views │ ├── 403.ejs │ ├── 404.ejs │ ├── 500.ejs │ ├── homepage.ejs │ └── layout.ejs ├── overall.test.js └── unit ├── associations.test.js ├── create.test.js └── scope.test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 4 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [package.json] 13 | indent_size = 2 14 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint:recommended", 3 | "rules": { 4 | "indent": ["error", 4, {"SwitchCase": 1}], 5 | "quotes": ["error", "single"], 6 | "linebreak-style": ["error", "unix"], 7 | "semi": ["error", "always"], 8 | "no-unused-vars": ["warn", {"vars": "all", "args": "none"}], 9 | "no-console": "off", 10 | "curly": "warn", 11 | "radix": "error", 12 | "wrap-iife": ["error", "outside"], 13 | "no-undefined": "error", 14 | "no-use-before-define": "error", 15 | "array-bracket-spacing": ["warn", "never"], 16 | "block-spacing": ["warn", "always"], 17 | "comma-spacing": ["warn", { "before": false, "after": true }], 18 | "comma-style": ["warn", "last"], 19 | "computed-property-spacing": ["warn", "never"], 20 | "consistent-this": ["warn", "self"], 21 | "eol-last": "warn", 22 | "max-depth": ["error", 5], 23 | "max-nested-callbacks": ["error", 5], 24 | "max-params": ["error", 5], 25 | "no-trailing-spaces": ["warn"], 26 | "object-curly-spacing": ["warn", "always"], 27 | "keyword-spacing": ["warn", { "before": true, "after": true, "overrides": {} }], 28 | "space-before-blocks": "warn", 29 | "space-before-function-paren": "warn", 30 | "space-in-parens": ["warn", "never"], 31 | "space-infix-ops": "warn", 32 | "space-unary-ops": ["warn", { "words": true, "nonwords": false }] 33 | }, 34 | "parserOptions": { 35 | "ecmaVersion": 6, 36 | "sourceType": "module" 37 | }, 38 | "env": { 39 | "es6": true, 40 | "commonjs": true, 41 | "node": true, 42 | "mocha": true 43 | }, 44 | "globals": { 45 | "Sequelize": true, 46 | "Image": true, 47 | "User": true, 48 | "Group": true 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | 1. Sails configuration samples 13 | 2. Sequelize model definitions samples 14 | 3. When and where error is happening 15 | 4. Error description 16 | 17 | **Expected behavior** 18 | A clear and concise description of what you expected to happen. 19 | 20 | **Screenshots** 21 | If applicable, add screenshots to help explain your problem. 22 | 23 | **Desktop (please complete the following information):** 24 | - OS: [e.g. Mac, Linux] 25 | - Node.js version 26 | - Sequelize version 27 | 28 | **Additional context** 29 | Add any other context about the problem here. 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ### Description, Motivation and Context 4 | (Describe your changes in detail) 5 | 6 | 7 | 8 | ### What is the current behavior? 9 | (You can also link to an open issue here) 10 | 11 | ### What is the new behavior? 12 | (if this is a feature change) 13 | 14 | ### What kind of change does this PR introduce? 15 | 16 | - [ ] Bug fix (non-breaking change which fixes an issue) 17 | - [ ] New feature (non-breaking change which adds functionality) 18 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) 19 | 20 | ### Checklist: 21 | 22 | 23 | - [ ] My code follows the code style of this project. 24 | - [ ] I have added tests to cover my changes. 25 | - [ ] Overall test coverage is not decreased. 26 | - [ ] All new and existing tests passed. 27 | - [ ] My change requires a change to the documentation. 28 | - [ ] I have updated the documentation accordingly. 29 | -------------------------------------------------------------------------------- /.github/workflows/build-and-test.yml: -------------------------------------------------------------------------------- 1 | name: Build and Test 2 | on: 3 | push: 4 | paths-ignore: 5 | - 'README.md' 6 | pull_request: 7 | paths-ignore: 8 | - 'README.md' 9 | 10 | jobs: 11 | build_and_test: 12 | name: Build and run tests 13 | runs-on: ubuntu-latest 14 | services: 15 | postgres: 16 | image: postgres:10 17 | env: 18 | POSTGRES_USER: postgres 19 | POSTGRES_PASSWORD: postgres 20 | POSTGRES_DB: sequelize 21 | ports: 22 | - 5432:5432 23 | options: 24 | --health-cmd pg_isready 25 | --health-interval 10s 26 | --health-timeout 5s 27 | --health-retries 5 28 | strategy: 29 | matrix: 30 | node-version: [16, 18] 31 | steps: 32 | - uses: actions/checkout@v2 33 | - uses: actions/setup-node@v2 34 | with: 35 | node-version: ${{ matrix.node-version }} 36 | cache: 'npm' 37 | - run: psql -h 127.0.0.1 -U postgres -d sequelize -c 'create schema if not exists sails;' 38 | env: 39 | PGPASSWORD: postgres 40 | - run: npm ci 41 | - run: npm test 42 | env: 43 | PGPASSWORD: postgres 44 | - name: Create test coverage report 45 | run: ./node_modules/nyc/bin/nyc.js report --reporter=lcovonly 46 | - name: Coveralls 47 | uses: coverallsapp/github-action@master 48 | with: 49 | github-token: ${{ secrets.GITHUB_TOKEN }} 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | -------------------------------------------------------------------------------- /.mocharc.yml: -------------------------------------------------------------------------------- 1 | timeout: 12000 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 César Augusto D. Azevedo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sails-hook-sequelize", 3 | "version": "2.0.1", 4 | "description": "Sails.js hook to use sequelize ORM", 5 | "main": "index.js", 6 | "sails": { 7 | "isHook": true 8 | }, 9 | "scripts": { 10 | "lint": "node ./node_modules/.bin/eslint index.js test/*.js test/unit/*.js", 11 | "lint:fix": "node ./node_modules/.bin/eslint --fix index.js test/*.js test/unit/*.js", 12 | "test": "NODE_ENV=test nyc mocha --exit test/overall.test.js", 13 | "cover": "nyc report", 14 | "pretest": "cd ./test/fixtures/v0.11-app && npm i --prefix ./ && cd - && cd ./test/fixtures/v0.12-app && npm i --prefix ./ && cd -", 15 | "posttest": "git checkout -- test/fixtures/v1.x-sqlite3-app/db/sequelize.sqlite && git checkout -- test/fixtures/v1.x-sequelize-waterline-app/db/sequelize.sqlite" 16 | }, 17 | "engines": { 18 | "node": ">=12.0.0" 19 | }, 20 | "nyc": { 21 | "include": [ 22 | "index.js" 23 | ], 24 | "report-dir": "./coverage", 25 | "temp-dir": "./coverage", 26 | "reporter": [ 27 | "lcov", 28 | "text-summary", 29 | "html" 30 | ] 31 | }, 32 | "keywords": [ 33 | "sails", 34 | "sequelize", 35 | "orm" 36 | ], 37 | "author": "Gergely Munkacsy", 38 | "contributors": [ 39 | "Konstantin Burkalev", 40 | "Dmitry Demenchuk", 41 | "Damien Marble", 42 | "Abel M. Osorio" 43 | ], 44 | "license": "MIT", 45 | "devDependencies": { 46 | "coveralls": "^3.1.1", 47 | "decache": "^4.6.2", 48 | "eslint": "^8.15.0", 49 | "istanbul": "^0.4.5", 50 | "json3": "^3.3.3", 51 | "minimatch": "^5.0.1", 52 | "mocha": "^10.0.0", 53 | "nyc": "^15.1.0", 54 | "pg": "^8.11.1", 55 | "pg-hstore": "^2.3.4", 56 | "sails": "^1.5.6", 57 | "sails-hook-orm": "^4.0.1", 58 | "sails-memory": "^0.10.7", 59 | "should": "^13.2.3", 60 | "sqlite3": "^5.1.6", 61 | "supertest": "^6.3.3" 62 | }, 63 | "dependencies": { 64 | "cls-hooked": "^4.2.2", 65 | "sequelize": "^6.32.1" 66 | }, 67 | "directories": { 68 | "test": "test" 69 | }, 70 | "repository": { 71 | "type": "git", 72 | "url": "git@github.com:KSDaemon/sails-hook-sequelize.git" 73 | }, 74 | "bugs": { 75 | "url": "https://github.com/KSDaemon/sails-hook-sequelize/issues" 76 | }, 77 | "homepage": "https://github.com/KSDaemon/sails-hook-sequelize" 78 | } 79 | -------------------------------------------------------------------------------- /test/bootstrap.v0.11.test.js: -------------------------------------------------------------------------------- 1 | describe('Sails.js v0.11 Sequelize hook tests', () => { 2 | 3 | let Sails, rc, sails; 4 | 5 | // Before running any tests, attempt to lift Sails 6 | before(function (done) { 7 | 8 | // Hook will timeout in 10 seconds 9 | this.timeout(11000); 10 | 11 | Sails = require('./fixtures/v0.11-app/app').sails; 12 | rc = require('rc'); 13 | 14 | const config = rc('sails'); 15 | config.hooks.sequelize = require('../index'); 16 | 17 | // Attempt to lift sails 18 | Sails().lift(config, (err, _sails) => { 19 | if (err) { return done(err); } 20 | sails = _sails; 21 | return done(err, sails); 22 | }); 23 | }); 24 | 25 | // Test that Sails can lift with the hook in place 26 | it('sails does not crash', () => true); 27 | 28 | require('./unit/create.test'); 29 | require('./unit/associations.test'); 30 | require('./unit/scope.test'); 31 | 32 | after(done => { 33 | sails.lower(err => { 34 | if (err) { 35 | return console.log('Error occurred lowering Sails app: ', err); 36 | } 37 | console.log('Sails app lowered successfully!'); 38 | done(); 39 | }); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /test/bootstrap.v0.12.test.js: -------------------------------------------------------------------------------- 1 | describe('Sails.js v0.12 Sequelize hook tests', () => { 2 | 3 | let Sails, rc, sails; 4 | 5 | // Before running any tests, attempt to lift Sails 6 | before(function (done) { 7 | 8 | // Hook will timeout in 10 seconds 9 | this.timeout(11000); 10 | 11 | Sails = require('./fixtures/v0.12-app/app').sails; 12 | rc = require('rc'); 13 | 14 | const config = rc('sails'); 15 | config.hooks.sequelize = require('../index'); 16 | 17 | // Attempt to lift sails 18 | Sails().lift(config, (err, _sails) => { 19 | if (err) { return done(err); } 20 | sails = _sails; 21 | return done(err, sails); 22 | }); 23 | }); 24 | 25 | // Test that Sails can lift with the hook in place 26 | it('sails does not crash', () => true); 27 | 28 | require('./unit/create.test'); 29 | require('./unit/associations.test'); 30 | require('./unit/scope.test'); 31 | 32 | after(done => { 33 | sails.lower(err => { 34 | if (err) { 35 | return console.log('Error occurred lowering Sails app: ', err); 36 | } 37 | console.log('Sails app lowered successfully!'); 38 | done(); 39 | }); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /test/bootstrap.v1.x-create-db-schemes.test.js: -------------------------------------------------------------------------------- 1 | describe('Sails.js v1.x Sequelize hook tests with db schemes (psql)', () => { 2 | 3 | let Sails, rc, sails; 4 | 5 | // Before running any tests, attempt to lift Sails 6 | before(function (done) { 7 | 8 | // Hook will timeout in 10 seconds 9 | this.timeout(11000); 10 | 11 | const Sequelize = require('sequelize'), 12 | connInfo = require('./fixtures/v1.x-create-db-schemes-app/config/datastores').datastores.somePostgresqlServer; 13 | 14 | let connection = new Sequelize(connInfo.url, connInfo.options); 15 | 16 | // Drop schemas if exists 17 | connection.query('DROP SCHEMA IF EXISTS sails, sails_img CASCADE;').then(() => { 18 | Sails = require('./fixtures/v1.x-create-db-schemes-app/app').sails; 19 | rc = require('rc'); 20 | 21 | const config = rc('sails'); 22 | config.hooks.sequelize = require('../index'); 23 | 24 | // Attempt to lift sails 25 | Sails().lift(config, (err, _sails) => { 26 | if (err) { return done(err); } 27 | sails = _sails; 28 | return done(err, sails); 29 | }); 30 | }); 31 | 32 | }); 33 | 34 | // Test that Sails can lift with the hook in place 35 | it('sails does not crash', () => true); 36 | 37 | require('./unit/create.test'); 38 | require('./unit/associations.test'); 39 | require('./unit/scope.test'); 40 | 41 | after(done => { 42 | sails.lower(err => { 43 | if (err) { 44 | return console.log('Error occurred lowering Sails app: ', err); 45 | } 46 | console.log('Sails app lowered successfully!'); 47 | done(); 48 | }); 49 | }); 50 | }); 51 | -------------------------------------------------------------------------------- /test/bootstrap.v1.x-many-schemes.test.js: -------------------------------------------------------------------------------- 1 | describe('Sails.js v1.x Sequelize hook tests with db schemes (psql)', () => { 2 | 3 | let Sails, rc, sails; 4 | 5 | // Before running any tests, attempt to lift Sails 6 | before(function (done) { 7 | 8 | // Hook will timeout in 10 seconds 9 | this.timeout(11000); 10 | 11 | const Sequelize = require('sequelize'), 12 | connInfo = require('./fixtures/v1.x-many-schemes-app/config/datastores').datastores.somePostgresqlServer; 13 | 14 | let connection = new Sequelize(connInfo.url, connInfo.options); 15 | 16 | // Drop schemas if exists 17 | connection.query('DROP SCHEMA IF EXISTS sails, sails_img CASCADE;').then(() => { 18 | Sails = require('./fixtures/v1.x-many-schemes-app/app').sails; 19 | rc = require('rc'); 20 | 21 | const config = rc('sails'); 22 | config.hooks.sequelize = require('../index'); 23 | 24 | // Attempt to lift sails 25 | Sails().lift(config, (err, _sails) => { 26 | if (err) { return done(err); } 27 | sails = _sails; 28 | return done(err, sails); 29 | }); 30 | }); 31 | 32 | }); 33 | 34 | // Test that Sails can lift with the hook in place 35 | it('sails does not crash', () => true); 36 | 37 | require('./unit/create.test'); 38 | require('./unit/associations.test'); 39 | require('./unit/scope.test'); 40 | 41 | after(done => { 42 | sails.lower(err => { 43 | if (err) { 44 | return console.log('Error occurred lowering Sails app: ', err); 45 | } 46 | console.log('Sails app lowered successfully!'); 47 | done(); 48 | }); 49 | }); 50 | }); 51 | -------------------------------------------------------------------------------- /test/bootstrap.v1.x-migrate-safe.test.js: -------------------------------------------------------------------------------- 1 | describe('Sails.js v1.x Sequelize hook tests with migrate "safe" option and default connection', () => { 2 | 3 | let Sails, rc, sails; 4 | 5 | // Before running any tests, attempt to lift Sails 6 | before(function (done) { 7 | 8 | // Hook will timeout in 10 seconds 9 | this.timeout(11000); 10 | 11 | Sails = require('./fixtures/v1.x-migrate-safe-app/app').sails; 12 | rc = require('rc'); 13 | 14 | const config = rc('sails'); 15 | config.hooks.sequelize = require('../index'); 16 | 17 | // Attempt to lift sails 18 | Sails().lift(config, (err, _sails) => { 19 | if (err) { return done(err); } 20 | sails = _sails; 21 | return done(err, sails); 22 | }); 23 | }); 24 | 25 | // Test that Sails can lift with the hook in place 26 | it('sails does not crash', () => true); 27 | 28 | require('./unit/create.test'); 29 | require('./unit/associations.test'); 30 | require('./unit/scope.test'); 31 | 32 | after(done => { 33 | sails.lower(err => { 34 | if (err) { 35 | return console.log('Error occurred lowering Sails app: ', err); 36 | } 37 | console.log('Sails app lowered successfully!'); 38 | done(); 39 | }); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /test/bootstrap.v1.x-no-conn.test.js: -------------------------------------------------------------------------------- 1 | describe('Sails.js v1.x Sequelize hook tests without connections', () => { 2 | 3 | let Sails, rc; 4 | 5 | // Before running any tests, attempt to lift Sails 6 | before(function () { 7 | 8 | // Hook will timeout in 10 seconds 9 | this.timeout(11000); 10 | 11 | }); 12 | 13 | // Test that Sails cannot lift without connections provided 14 | it('should fail lifting without db connections ', done => { 15 | 16 | Sails = require('./fixtures/v1.x-no-conn-app/app').sails; 17 | rc = require('rc'); 18 | 19 | const config = rc('sails'); 20 | config.hooks.sequelize = require('../index'); 21 | 22 | // Attempt to lift sails 23 | Sails().lift(config, (err, _sails) => { 24 | if (err) { return done(); } 25 | return done(err); 26 | }); 27 | 28 | }); 29 | 30 | }); 31 | -------------------------------------------------------------------------------- /test/bootstrap.v1.x-sequelize-waterline.test.js: -------------------------------------------------------------------------------- 1 | describe('Sails.js v1.x Sequelize hook tests alongside with Waterline ORM', () => { 2 | 3 | let Sails, rc, sails; 4 | 5 | // Before running any tests, attempt to lift Sails 6 | before(function (done) { 7 | 8 | // Hook will timeout in 10 seconds 9 | this.timeout(11000); 10 | 11 | Sails = require('./fixtures/v1.x-sequelize-waterline-app/app').sails; 12 | rc = require('rc'); 13 | 14 | const config = rc('sails'); 15 | config.hooks.sequelize = require('../index'); 16 | 17 | // Attempt to lift sails 18 | Sails().lift(config, (err, _sails) => { 19 | if (err) { return done(err); } 20 | sails = _sails; 21 | return done(err, sails); 22 | }); 23 | }); 24 | 25 | // Test that Sails can lift with the hook in place 26 | it('sails does not crash', () => true); 27 | 28 | // require('./unit/create.test'); 29 | // require('./unit/associations.test'); 30 | // require('./unit/scope.test'); 31 | 32 | after(done => { 33 | sails.lower(err => { 34 | if (err) { 35 | return console.log('Error occurred lowering Sails app: ', err); 36 | } 37 | console.log('Sails app lowered successfully!'); 38 | done(); 39 | }); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /test/bootstrap.v1.x-sqlite.test.js: -------------------------------------------------------------------------------- 1 | describe('Sails.js v1.x Sequelize hook tests against sqlite db', () => { 2 | 3 | let Sails, rc, sails; 4 | 5 | // Before running any tests, attempt to lift Sails 6 | before(function (done) { 7 | 8 | // Hook will timeout in 10 seconds 9 | this.timeout(11000); 10 | 11 | Sails = require('./fixtures/v1.x-sqlite3-app/app').sails; 12 | rc = require('rc'); 13 | 14 | const config = rc('sails'); 15 | config.hooks.sequelize = require('../index'); 16 | 17 | // Attempt to lift sails 18 | Sails().lift(config, (err, _sails) => { 19 | if (err) { return done(err); } 20 | sails = _sails; 21 | return done(err, sails); 22 | }); 23 | }); 24 | 25 | // Test that Sails can lift with the hook in place 26 | it('sails does not crash', () => true); 27 | 28 | require('./unit/create.test'); 29 | require('./unit/associations.test'); 30 | require('./unit/scope.test'); 31 | 32 | after(done => { 33 | sails.lower(err => { 34 | if (err) { 35 | return console.log('Error occurred lowering Sails app: ', err); 36 | } 37 | console.log('Sails app lowered successfully!'); 38 | done(); 39 | }); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /test/bootstrap.v1.x.test.js: -------------------------------------------------------------------------------- 1 | describe('Sails.js v1.x Sequelize hook tests', () => { 2 | 3 | let Sails, rc, sails; 4 | 5 | // Before running any tests, attempt to lift Sails 6 | before(function (done) { 7 | 8 | // Hook will timeout in 10 seconds 9 | this.timeout(11000); 10 | 11 | Sails = require('./fixtures/v1.x-app/app').sails; 12 | rc = require('rc'); 13 | 14 | const config = rc('sails'); 15 | config.hooks.sequelize = require('../index'); 16 | 17 | // Attempt to lift sails 18 | Sails().lift(config, (err, _sails) => { 19 | if (err) { return done(err); } 20 | sails = _sails; 21 | return done(err, sails); 22 | }); 23 | }); 24 | 25 | // Test that Sails can lift with the hook in place 26 | it('sails does not crash', () => true); 27 | 28 | require('./unit/create.test'); 29 | require('./unit/associations.test'); 30 | require('./unit/scope.test'); 31 | 32 | after(done => { 33 | sails.lower(err => { 34 | if (err) { 35 | return console.log('Error occurred lowering Sails app: ', err); 36 | } 37 | console.log('Sails app lowered successfully!'); 38 | done(); 39 | }); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /test/fixtures/instances.json: -------------------------------------------------------------------------------- 1 | { 2 | "user": { 3 | "name": "Tester", 4 | "age": 21 5 | }, 6 | "image": { 7 | "url": "http://google.com" 8 | }, 9 | "group": { 10 | "name": "public", 11 | "role": "USER" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/.sailsrc: -------------------------------------------------------------------------------- 1 | { 2 | "generators": { 3 | "modules": {} 4 | }, 5 | "hooks": { 6 | "blueprints": false, 7 | "grunt": false, 8 | "sockets": false, 9 | "pubsub": false, 10 | "orm": false, 11 | "i18n": false 12 | }, 13 | "log": { 14 | "level": "info" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/api/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v0.11-app/api/controllers/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/api/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v0.11-app/api/models/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/api/models/Group.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Group.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | name: { 11 | type: Sequelize.STRING 12 | }, 13 | role: { 14 | type: Sequelize.ENUM('USER', 'ADMIN') 15 | } 16 | }, 17 | associations: function () { 18 | Group.hasMany(User, { as: 'users', foreignKey: 'groupId' }); 19 | }, 20 | defaultScope: function () { 21 | return { 22 | include: [ 23 | { model: User, as: 'users' } 24 | ] 25 | }; 26 | }, 27 | options : { 28 | freezeTableName : false, 29 | tableName : 'group', 30 | schema : 'sails', 31 | classMethods : {}, 32 | instanceMethods : {}, 33 | hooks : {} 34 | } 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/api/models/Image.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Image.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | url: { 11 | type: Sequelize.STRING 12 | } 13 | }, 14 | associations: function () { 15 | Image.belongsTo(User, { foreignKey: 'userId' }); 16 | }, 17 | options : { 18 | freezeTableName : false, 19 | tableName : 'image', 20 | schema : 'sails', 21 | classMethods : {}, 22 | instanceMethods : {}, 23 | hooks : {} 24 | } 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/api/models/User.js: -------------------------------------------------------------------------------- 1 | /** 2 | * User.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | name: { 11 | type: Sequelize.STRING 12 | }, 13 | age : { 14 | type: Sequelize.INTEGER 15 | } 16 | }, 17 | associations: function () { 18 | User.hasMany(Image, { as: 'images', foreignKey: 'userId' }); 19 | }, 20 | defaultScope: function () { 21 | return { 22 | include: [ 23 | { model: Image, as: 'images' } 24 | ] 25 | }; 26 | }, 27 | options : { 28 | freezeTableName : false, 29 | tableName : 'user', 30 | schema : 'sails', 31 | classMethods : { 32 | oneUniqueClassMethod: function () { 33 | return 'User class method'; 34 | } 35 | }, 36 | instanceMethods : { 37 | toJSON: function () { 38 | let obj = this.get(); 39 | obj.ageString = '' + obj.age + ' years'; 40 | return obj; 41 | } 42 | }, 43 | hooks : {} 44 | } 45 | }; 46 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/api/policies/sessionAuth.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sessionAuth 3 | * 4 | * @module :: Policy 5 | * @description :: Simple policy to allow any authenticated user 6 | * Assumes that your login action in one of your controllers sets `req.session.authenticated = true;` 7 | * @docs :: http://sailsjs.org/#!/documentation/concepts/Policies 8 | * 9 | */ 10 | module.exports = function(req, res, next) { 11 | 12 | // User is allowed, proceed to the next policy, 13 | // or if this is the last policy, the controller 14 | if (req.session.authenticated) { 15 | return next(); 16 | } 17 | 18 | // User is not allowed 19 | // (default res.forbidden() behavior can be overridden in `config/403.js`) 20 | return res.forbidden('You are not permitted to perform this action.'); 21 | }; 22 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/api/responses/badRequest.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 400 (Bad Request) Handler 3 | * 4 | * Usage: 5 | * return res.badRequest(); 6 | * return res.badRequest(data); 7 | * return res.badRequest(data, 'some/specific/badRequest/view'); 8 | * 9 | * e.g.: 10 | * ``` 11 | * return res.badRequest( 12 | * 'Please choose a valid `password` (6-12 characters)', 13 | * 'trial/signup' 14 | * ); 15 | * ``` 16 | */ 17 | 18 | module.exports = function badRequest(data, options) { 19 | 20 | // Get access to `req`, `res`, & `sails` 21 | var req = this.req; 22 | var res = this.res; 23 | var sails = req._sails; 24 | 25 | // Set status code 26 | res.status(400); 27 | 28 | // Log error to console 29 | if (data !== undefined) { 30 | sails.log.verbose('Sending 400 ("Bad Request") response: \n',data); 31 | } 32 | else sails.log.verbose('Sending 400 ("Bad Request") response'); 33 | 34 | // Only include errors in response if application environment 35 | // is not set to 'production'. In production, we shouldn't 36 | // send back any identifying information about errors. 37 | if (sails.config.environment === 'production' && sails.config.keepResponseErrors !== true) { 38 | data = undefined; 39 | } 40 | 41 | // If the user-agent wants JSON, always respond with JSON 42 | // If views are disabled, revert to json 43 | if (req.wantsJSON || sails.config.hooks.views === false) { 44 | return res.jsonx(data); 45 | } 46 | 47 | // If second argument is a string, we take that to mean it refers to a view. 48 | // If it was omitted, use an empty object (`{}`) 49 | options = (typeof options === 'string') ? { view: options } : options || {}; 50 | 51 | // Attempt to prettify data for views, if it's a non-error object 52 | var viewData = data; 53 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 54 | try { 55 | viewData = require('util').inspect(data, {depth: null}); 56 | } 57 | catch(e) { 58 | viewData = undefined; 59 | } 60 | } 61 | 62 | // If a view was provided in options, serve it. 63 | // Otherwise try to guess an appropriate view, or if that doesn't 64 | // work, just send JSON. 65 | if (options.view) { 66 | return res.view(options.view, { data: viewData, title: 'Bad Request' }); 67 | } 68 | 69 | // If no second argument provided, try to serve the implied view, 70 | // but fall back to sending JSON(P) if no view can be inferred. 71 | else return res.guessView({ data: viewData, title: 'Bad Request' }, function couldNotGuessView () { 72 | return res.jsonx(data); 73 | }); 74 | 75 | }; 76 | 77 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/api/responses/created.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 201 (CREATED) Response 3 | * 4 | * Usage: 5 | * return res.created(); 6 | * return res.created(data); 7 | * return res.created(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function created (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.created() :: Sending 201 ("CREATED") response'); 22 | 23 | // Set status code 24 | res.status(201); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'Created' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'Created' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/api/responses/ok.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 200 (OK) Response 3 | * 4 | * Usage: 5 | * return res.ok(); 6 | * return res.ok(data); 7 | * return res.ok(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function sendOK (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.ok() :: Sending 200 ("OK") response'); 22 | 23 | // Set status code 24 | res.status(200); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'OK' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'OK' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/api/services/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v0.11-app/api/services/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/app.js: -------------------------------------------------------------------------------- 1 | /** 2 | * app.js 3 | * 4 | * Use `app.js` to run your app without `sails lift`. 5 | * To start the server, run: `node app.js`. 6 | * 7 | * This is handy in situations where the sails CLI is not relevant or useful. 8 | * 9 | * For example: 10 | * => `node app.js` 11 | * => `forever start app.js` 12 | * => `node debug app.js` 13 | * => `modulus deploy` 14 | * => `heroku scale` 15 | * 16 | * 17 | * The same command-line arguments are supported, e.g.: 18 | * `node app.js --silent --port=80 --prod` 19 | */ 20 | 21 | 22 | // Ensure we're in the project directory, so cwd-relative paths work as expected 23 | // no matter where we actually lift from. 24 | // > Note: This is not required in order to lift, but it is a convenient default. 25 | process.chdir(__dirname); 26 | 27 | // Ensure a "sails" can be located: 28 | (function () { 29 | 30 | // Attempt to import `sails`. 31 | var sails; 32 | try { 33 | sails = require('sails'); 34 | } catch (e) { 35 | console.error( 36 | 'To run an app using `node app.js`, you usually need to have a version of `sails` installed in the same directory as your app.'); 37 | console.error('To do that, run `npm install sails`'); 38 | console.error(''); 39 | console.error( 40 | 'Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.'); 41 | console.error( 42 | 'When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,'); 43 | console.error('but if it doesn\'t, the app will run with the global sails instead!'); 44 | return; 45 | } 46 | 47 | // --• 48 | // Try to get `rc` dependency (for loading `.sailsrc` files). 49 | // var rc; 50 | // try { 51 | // rc = require('rc'); 52 | // } catch (e0) { 53 | // try { 54 | // rc = require('sails/node_modules/rc'); 55 | // } catch (e1) { 56 | // console.error('Could not find dependency: `rc`.'); 57 | // console.error('Your `.sailsrc` file(s) will be ignored.'); 58 | // console.error('To resolve this, run:'); 59 | // console.error('npm install rc --save'); 60 | // rc = function () { 61 | // return {}; 62 | // }; 63 | // } 64 | // } 65 | 66 | // // Start server 67 | // sails.lift(rc('sails')); 68 | module.exports.sails = sails.Sails; 69 | 70 | }()); 71 | 72 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/config/bootstrap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Bootstrap 3 | * (sails.config.bootstrap) 4 | * 5 | * An asynchronous bootstrap function that runs before your Sails app gets lifted. 6 | * This gives you an opportunity to set up your data model, run jobs, or perform some special logic. 7 | * 8 | * For more information on bootstrapping your app, check out: 9 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.bootstrap.html 10 | */ 11 | 12 | module.exports.bootstrap = function(cb) { 13 | 14 | // It's very important to trigger this callback method when you are finished 15 | // with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap) 16 | cb(); 17 | }; 18 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/config/connections.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Connections 3 | * (sails.config.connections) 4 | * 5 | * `Connections` are like "saved settings" for your adapters. What's the difference between 6 | * a connection and an adapter, you might ask? An adapter (e.g. `sails-mysql`) is generic-- 7 | * it needs some additional information to work (e.g. your database host, password, user, etc.) 8 | * A `connection` is that additional information. 9 | * 10 | * Each model must have a `connection` property (a string) which is references the name of one 11 | * of these connections. If it doesn't, the default `connection` configured in `config/models.js` 12 | * will be applied. Of course, a connection can (and usually is) shared by multiple models. 13 | * . 14 | * Note: If you're using version control, you should put your passwords/api keys 15 | * in `config/local.js`, environment variables, or use another strategy. 16 | * (this is to prevent you inadvertently sensitive credentials up to your repository.) 17 | * 18 | * For more information on configuration, check out: 19 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.connections.html 20 | */ 21 | 22 | module.exports.connections = { 23 | 24 | somePostgresqlServer: { 25 | user: 'postgres', 26 | password: '', 27 | database: 'sequelize', 28 | dialect: 'postgres', 29 | options: { 30 | dialect: 'postgres', 31 | host : 'localhost', 32 | port : 5432, 33 | logging: null 34 | } 35 | } 36 | 37 | }; 38 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/config/log.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Built-in Log Configuration 3 | * (sails.config.log) 4 | * 5 | * Configure the log level for your app, as well as the transport 6 | * (Underneath the covers, Sails uses Winston for logging, which 7 | * allows for some pretty neat custom transports/adapters for log messages) 8 | * 9 | * For more information on the Sails logger, check out: 10 | * http://sailsjs.org/#!/documentation/concepts/Logging 11 | */ 12 | 13 | module.exports.log = { 14 | 15 | /*************************************************************************** 16 | * * 17 | * Valid `level` configs: i.e. the minimum log level to capture with * 18 | * sails.log.*() * 19 | * * 20 | * The order of precedence for log levels from lowest to highest is: * 21 | * silly, verbose, info, debug, warn, error * 22 | * * 23 | * You may also set the level to "silent" to suppress all logs. * 24 | * * 25 | ***************************************************************************/ 26 | 27 | // level: 'info' 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/config/models.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Default model configuration 3 | * (sails.config.models) 4 | * 5 | * Unless you override them, the following properties will be included 6 | * in each of your models. 7 | * 8 | * For more info on Sails models, see: 9 | * http://sailsjs.org/#!/documentation/concepts/ORM 10 | */ 11 | 12 | module.exports.models = { 13 | 14 | connection: 'somePostgresqlServer', 15 | migrate: 'drop' 16 | 17 | }; 18 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/config/policies.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Policy Mappings 3 | * (sails.config.policies) 4 | * 5 | * Policies are simple functions which run **before** your controllers. 6 | * You can apply one or more policies to a given controller, or protect 7 | * its actions individually. 8 | * 9 | * Any policy file (e.g. `api/policies/authenticated.js`) can be accessed 10 | * below by its filename, minus the extension, (e.g. "authenticated") 11 | * 12 | * For more information on how policies work, see: 13 | * http://sailsjs.org/#!/documentation/concepts/Policies 14 | * 15 | * For more information on configuring policies, check out: 16 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.policies.html 17 | */ 18 | 19 | 20 | module.exports.policies = { 21 | 22 | /*************************************************************************** 23 | * * 24 | * Default policy for all controllers and actions (`true` allows public * 25 | * access) * 26 | * * 27 | ***************************************************************************/ 28 | 29 | // '*': true, 30 | 31 | /*************************************************************************** 32 | * * 33 | * Here's an example of mapping some policies to run before a controller * 34 | * and its actions * 35 | * * 36 | ***************************************************************************/ 37 | // RabbitController: { 38 | 39 | // Apply the `false` policy as the default for all of RabbitController's actions 40 | // (`false` prevents all access, which ensures that nothing bad happens to our rabbits) 41 | // '*': false, 42 | 43 | // For the action `nurture`, apply the 'isRabbitMother' policy 44 | // (this overrides `false` above) 45 | // nurture : 'isRabbitMother', 46 | 47 | // Apply the `isNiceToAnimals` AND `hasRabbitFood` policies 48 | // before letting any users feed our rabbits 49 | // feed : ['isNiceToAnimals', 'hasRabbitFood'] 50 | // } 51 | }; 52 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/config/routes.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Route Mappings 3 | * (sails.config.routes) 4 | * 5 | * Your routes map URLs to views and controllers. 6 | * 7 | * If Sails receives a URL that doesn't match any of the routes below, 8 | * it will check for matching files (images, scripts, stylesheets, etc.) 9 | * in your assets directory. e.g. `http://localhost:1337/images/foo.jpg` 10 | * might match an image file: `/assets/images/foo.jpg` 11 | * 12 | * Finally, if those don't match either, the default 404 handler is triggered. 13 | * See `api/responses/notFound.js` to adjust your app's 404 logic. 14 | * 15 | * Note: Sails doesn't ACTUALLY serve stuff from `assets`-- the default Gruntfile in Sails copies 16 | * flat files from `assets` to `.tmp/public`. This allows you to do things like compile LESS or 17 | * CoffeeScript for the front-end. 18 | * 19 | * For more information on configuring custom routes, check out: 20 | * http://sailsjs.org/#!/documentation/concepts/Routes/RouteTargetSyntax.html 21 | */ 22 | 23 | module.exports.routes = { 24 | 25 | /*************************************************************************** 26 | * * 27 | * Make the view located at `views/homepage.ejs` (or `views/homepage.jade`, * 28 | * etc. depending on your default view engine) your home page. * 29 | * * 30 | * (Alternatively, remove this and add an `index.html` file in your * 31 | * `assets` directory) * 32 | * * 33 | ***************************************************************************/ 34 | 35 | '/': { 36 | view: 'homepage' 37 | } 38 | 39 | /*************************************************************************** 40 | * * 41 | * Custom routes here... * 42 | * * 43 | * If a request to a URL doesn't match any of the custom routes above, it * 44 | * is matched against Sails route blueprints. See `config/blueprints.js` * 45 | * for configuration options and examples. * 46 | * * 47 | ***************************************************************************/ 48 | 49 | }; 50 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/config/sequelize.js: -------------------------------------------------------------------------------- 1 | module.exports.sequelize = { 2 | 'clsNamespace' : 'myAppCLSNamespace', 3 | 'exposeToGlobal': true 4 | }; 5 | -------------------------------------------------------------------------------- /test/fixtures/v0.11-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 3 | "private": true, 4 | "version": "0.0.0", 5 | "description": "a Sails application", 6 | "keywords": [], 7 | "dependencies": { 8 | "ejs": "~0.8.4", 9 | "grunt": "0.4.2", 10 | "grunt-contrib-clean": "~0.5.0", 11 | "grunt-contrib-coffee": "~0.10.1", 12 | "grunt-contrib-concat": "~0.3.0", 13 | "grunt-contrib-copy": "~0.5.0", 14 | "grunt-contrib-cssmin": "~0.9.0", 15 | "grunt-contrib-jst": "~0.6.0", 16 | "grunt-contrib-less": "0.11.1", 17 | "grunt-contrib-uglify": "~0.4.0", 18 | "grunt-contrib-watch": "^0.6.0", 19 | "grunt-sails-linker": "~0.9.5", 20 | "grunt-sync": "~0.0.4", 21 | "include-all": "~0.1.3", 22 | "rc": "~0.5.0", 23 | "sails": "~0.11.5", 24 | "sails-disk": "~0.10.0" 25 | }, 26 | "scripts": { 27 | "debug": "node debug app.js", 28 | "start": "node app.js" 29 | }, 30 | "main": "app.js", 31 | "repository": { 32 | "type": "git", 33 | "url": "git://github.com/kostik/app.git" 34 | }, 35 | "author": "kostik", 36 | "license": "" 37 | } 38 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/.sailsrc: -------------------------------------------------------------------------------- 1 | { 2 | "generators": { 3 | "modules": {} 4 | }, 5 | "hooks": { 6 | "blueprints": false, 7 | "grunt": false, 8 | "sockets": false, 9 | "pubsub": false, 10 | "orm": false, 11 | "i18n": false 12 | }, 13 | "log": { 14 | "level": "info" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/api/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v0.12-app/api/controllers/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/api/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v0.12-app/api/models/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/api/models/Group.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Group.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | name: { 11 | type: Sequelize.STRING 12 | }, 13 | role: { 14 | type: Sequelize.ENUM('USER', 'ADMIN') 15 | } 16 | }, 17 | associations: function () { 18 | Group.hasMany(User, { as: 'users', foreignKey: 'groupId' }); 19 | }, 20 | defaultScope: function () { 21 | return { 22 | include: [ 23 | { model: User, as: 'users' } 24 | ] 25 | }; 26 | }, 27 | options : { 28 | freezeTableName : false, 29 | tableName : 'group', 30 | schema : 'sails', 31 | classMethods : {}, 32 | instanceMethods : {}, 33 | hooks : {} 34 | } 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/api/models/Image.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Image.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | url: { 11 | type: Sequelize.STRING 12 | } 13 | }, 14 | associations: function () { 15 | Image.belongsTo(User, { foreignKey: 'userId' }); 16 | }, 17 | options : { 18 | freezeTableName : false, 19 | tableName : 'image', 20 | schema : 'sails', 21 | classMethods : {}, 22 | instanceMethods : {}, 23 | hooks : {} 24 | } 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/api/models/User.js: -------------------------------------------------------------------------------- 1 | /** 2 | * User.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | name: { 11 | type: Sequelize.STRING 12 | }, 13 | age : { 14 | type: Sequelize.INTEGER 15 | } 16 | }, 17 | associations: function () { 18 | User.hasMany(Image, { as: 'images', foreignKey: 'userId' }); 19 | }, 20 | defaultScope: function () { 21 | return { 22 | include: [ 23 | { model: Image, as: 'images' } 24 | ] 25 | }; 26 | }, 27 | options : { 28 | freezeTableName : false, 29 | tableName : 'user', 30 | schema : 'sails', 31 | classMethods : { 32 | oneUniqueClassMethod: function () { 33 | return 'User class method'; 34 | } 35 | }, 36 | instanceMethods : { 37 | toJSON: function () { 38 | let obj = this.get(); 39 | obj.ageString = '' + obj.age + ' years'; 40 | return obj; 41 | } 42 | }, 43 | hooks : {} 44 | } 45 | }; 46 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/api/policies/sessionAuth.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sessionAuth 3 | * 4 | * @module :: Policy 5 | * @description :: Simple policy to allow any authenticated user 6 | * Assumes that your login action in one of your controllers sets `req.session.authenticated = true;` 7 | * @docs :: http://sailsjs.org/#!/documentation/concepts/Policies 8 | * 9 | */ 10 | module.exports = function(req, res, next) { 11 | 12 | // User is allowed, proceed to the next policy, 13 | // or if this is the last policy, the controller 14 | if (req.session.authenticated) { 15 | return next(); 16 | } 17 | 18 | // User is not allowed 19 | // (default res.forbidden() behavior can be overridden in `config/403.js`) 20 | return res.forbidden('You are not permitted to perform this action.'); 21 | }; 22 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/api/responses/badRequest.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 400 (Bad Request) Handler 3 | * 4 | * Usage: 5 | * return res.badRequest(); 6 | * return res.badRequest(data); 7 | * return res.badRequest(data, 'some/specific/badRequest/view'); 8 | * 9 | * e.g.: 10 | * ``` 11 | * return res.badRequest( 12 | * 'Please choose a valid `password` (6-12 characters)', 13 | * 'trial/signup' 14 | * ); 15 | * ``` 16 | */ 17 | 18 | module.exports = function badRequest(data, options) { 19 | 20 | // Get access to `req`, `res`, & `sails` 21 | var req = this.req; 22 | var res = this.res; 23 | var sails = req._sails; 24 | 25 | // Set status code 26 | res.status(400); 27 | 28 | // Log error to console 29 | if (data !== undefined) { 30 | sails.log.verbose('Sending 400 ("Bad Request") response: \n',data); 31 | } 32 | else sails.log.verbose('Sending 400 ("Bad Request") response'); 33 | 34 | // Only include errors in response if application environment 35 | // is not set to 'production'. In production, we shouldn't 36 | // send back any identifying information about errors. 37 | if (sails.config.environment === 'production' && sails.config.keepResponseErrors !== true) { 38 | data = undefined; 39 | } 40 | 41 | // If the user-agent wants JSON, always respond with JSON 42 | // If views are disabled, revert to json 43 | if (req.wantsJSON || sails.config.hooks.views === false) { 44 | return res.jsonx(data); 45 | } 46 | 47 | // If second argument is a string, we take that to mean it refers to a view. 48 | // If it was omitted, use an empty object (`{}`) 49 | options = (typeof options === 'string') ? { view: options } : options || {}; 50 | 51 | // Attempt to prettify data for views, if it's a non-error object 52 | var viewData = data; 53 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 54 | try { 55 | viewData = require('util').inspect(data, {depth: null}); 56 | } 57 | catch(e) { 58 | viewData = undefined; 59 | } 60 | } 61 | 62 | // If a view was provided in options, serve it. 63 | // Otherwise try to guess an appropriate view, or if that doesn't 64 | // work, just send JSON. 65 | if (options.view) { 66 | return res.view(options.view, { data: viewData, title: 'Bad Request' }); 67 | } 68 | 69 | // If no second argument provided, try to serve the implied view, 70 | // but fall back to sending JSON(P) if no view can be inferred. 71 | else return res.guessView({ data: viewData, title: 'Bad Request' }, function couldNotGuessView () { 72 | return res.jsonx(data); 73 | }); 74 | 75 | }; 76 | 77 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/api/responses/created.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 201 (CREATED) Response 3 | * 4 | * Usage: 5 | * return res.created(); 6 | * return res.created(data); 7 | * return res.created(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function created (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.created() :: Sending 201 ("CREATED") response'); 22 | 23 | // Set status code 24 | res.status(201); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'Created' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'Created' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/api/responses/ok.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 200 (OK) Response 3 | * 4 | * Usage: 5 | * return res.ok(); 6 | * return res.ok(data); 7 | * return res.ok(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function sendOK (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.ok() :: Sending 200 ("OK") response'); 22 | 23 | // Set status code 24 | res.status(200); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'OK' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'OK' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/api/services/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v0.12-app/api/services/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/app.js: -------------------------------------------------------------------------------- 1 | /** 2 | * app.js 3 | * 4 | * Use `app.js` to run your app without `sails lift`. 5 | * To start the server, run: `node app.js`. 6 | * 7 | * This is handy in situations where the sails CLI is not relevant or useful. 8 | * 9 | * For example: 10 | * => `node app.js` 11 | * => `forever start app.js` 12 | * => `node debug app.js` 13 | * => `modulus deploy` 14 | * => `heroku scale` 15 | * 16 | * 17 | * The same command-line arguments are supported, e.g.: 18 | * `node app.js --silent --port=80 --prod` 19 | */ 20 | 21 | 22 | // Ensure we're in the project directory, so cwd-relative paths work as expected 23 | // no matter where we actually lift from. 24 | // > Note: This is not required in order to lift, but it is a convenient default. 25 | process.chdir(__dirname); 26 | 27 | // Ensure a "sails" can be located: 28 | (function () { 29 | 30 | // Attempt to import `sails`. 31 | var sails; 32 | try { 33 | sails = require('sails'); 34 | } catch (e) { 35 | console.error( 36 | 'To run an app using `node app.js`, you usually need to have a version of `sails` installed in the same directory as your app.'); 37 | console.error('To do that, run `npm install sails`'); 38 | console.error(''); 39 | console.error( 40 | 'Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.'); 41 | console.error( 42 | 'When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,'); 43 | console.error('but if it doesn\'t, the app will run with the global sails instead!'); 44 | return; 45 | } 46 | 47 | // --• 48 | // Try to get `rc` dependency (for loading `.sailsrc` files). 49 | // var rc; 50 | // try { 51 | // rc = require('rc'); 52 | // } catch (e0) { 53 | // try { 54 | // rc = require('sails/node_modules/rc'); 55 | // } catch (e1) { 56 | // console.error('Could not find dependency: `rc`.'); 57 | // console.error('Your `.sailsrc` file(s) will be ignored.'); 58 | // console.error('To resolve this, run:'); 59 | // console.error('npm install rc --save'); 60 | // rc = function () { 61 | // return {}; 62 | // }; 63 | // } 64 | // } 65 | 66 | // // Start server 67 | // sails.lift(rc('sails')); 68 | module.exports.sails = sails.Sails; 69 | 70 | }()); 71 | 72 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/config/bootstrap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Bootstrap 3 | * (sails.config.bootstrap) 4 | * 5 | * An asynchronous bootstrap function that runs before your Sails app gets lifted. 6 | * This gives you an opportunity to set up your data model, run jobs, or perform some special logic. 7 | * 8 | * For more information on bootstrapping your app, check out: 9 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.bootstrap.html 10 | */ 11 | 12 | module.exports.bootstrap = function(cb) { 13 | 14 | // It's very important to trigger this callback method when you are finished 15 | // with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap) 16 | cb(); 17 | }; 18 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/config/connections.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Connections 3 | * (sails.config.connections) 4 | * 5 | * `Connections` are like "saved settings" for your adapters. What's the difference between 6 | * a connection and an adapter, you might ask? An adapter (e.g. `sails-mysql`) is generic-- 7 | * it needs some additional information to work (e.g. your database host, password, user, etc.) 8 | * A `connection` is that additional information. 9 | * 10 | * Each model must have a `connection` property (a string) which is references the name of one 11 | * of these connections. If it doesn't, the default `connection` configured in `config/models.js` 12 | * will be applied. Of course, a connection can (and usually is) shared by multiple models. 13 | * . 14 | * Note: If you're using version control, you should put your passwords/api keys 15 | * in `config/local.js`, environment variables, or use another strategy. 16 | * (this is to prevent you inadvertently sensitive credentials up to your repository.) 17 | * 18 | * For more information on configuration, check out: 19 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.connections.html 20 | */ 21 | 22 | module.exports.connections = { 23 | 24 | somePostgresqlServer: { 25 | user: 'postgres', 26 | password: '', 27 | database: 'sequelize', 28 | dialect: 'postgres', 29 | options: { 30 | dialect: 'postgres', 31 | host : 'localhost', 32 | port : 5432, 33 | logging: null 34 | } 35 | } 36 | 37 | }; 38 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/config/log.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Built-in Log Configuration 3 | * (sails.config.log) 4 | * 5 | * Configure the log level for your app, as well as the transport 6 | * (Underneath the covers, Sails uses Winston for logging, which 7 | * allows for some pretty neat custom transports/adapters for log messages) 8 | * 9 | * For more information on the Sails logger, check out: 10 | * http://sailsjs.org/#!/documentation/concepts/Logging 11 | */ 12 | 13 | module.exports.log = { 14 | 15 | /*************************************************************************** 16 | * * 17 | * Valid `level` configs: i.e. the minimum log level to capture with * 18 | * sails.log.*() * 19 | * * 20 | * The order of precedence for log levels from lowest to highest is: * 21 | * silly, verbose, info, debug, warn, error * 22 | * * 23 | * You may also set the level to "silent" to suppress all logs. * 24 | * * 25 | ***************************************************************************/ 26 | 27 | // level: 'info' 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/config/models.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Default model configuration 3 | * (sails.config.models) 4 | * 5 | * Unless you override them, the following properties will be included 6 | * in each of your models. 7 | * 8 | * For more info on Sails models, see: 9 | * http://sailsjs.org/#!/documentation/concepts/ORM 10 | */ 11 | 12 | module.exports.models = { 13 | 14 | connection: 'somePostgresqlServer', 15 | migrate: 'drop' 16 | 17 | }; 18 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/config/policies.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Policy Mappings 3 | * (sails.config.policies) 4 | * 5 | * Policies are simple functions which run **before** your controllers. 6 | * You can apply one or more policies to a given controller, or protect 7 | * its actions individually. 8 | * 9 | * Any policy file (e.g. `api/policies/authenticated.js`) can be accessed 10 | * below by its filename, minus the extension, (e.g. "authenticated") 11 | * 12 | * For more information on how policies work, see: 13 | * http://sailsjs.org/#!/documentation/concepts/Policies 14 | * 15 | * For more information on configuring policies, check out: 16 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.policies.html 17 | */ 18 | 19 | 20 | module.exports.policies = { 21 | 22 | /*************************************************************************** 23 | * * 24 | * Default policy for all controllers and actions (`true` allows public * 25 | * access) * 26 | * * 27 | ***************************************************************************/ 28 | 29 | // '*': true, 30 | 31 | /*************************************************************************** 32 | * * 33 | * Here's an example of mapping some policies to run before a controller * 34 | * and its actions * 35 | * * 36 | ***************************************************************************/ 37 | // RabbitController: { 38 | 39 | // Apply the `false` policy as the default for all of RabbitController's actions 40 | // (`false` prevents all access, which ensures that nothing bad happens to our rabbits) 41 | // '*': false, 42 | 43 | // For the action `nurture`, apply the 'isRabbitMother' policy 44 | // (this overrides `false` above) 45 | // nurture : 'isRabbitMother', 46 | 47 | // Apply the `isNiceToAnimals` AND `hasRabbitFood` policies 48 | // before letting any users feed our rabbits 49 | // feed : ['isNiceToAnimals', 'hasRabbitFood'] 50 | // } 51 | }; 52 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/config/routes.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Route Mappings 3 | * (sails.config.routes) 4 | * 5 | * Your routes map URLs to views and controllers. 6 | * 7 | * If Sails receives a URL that doesn't match any of the routes below, 8 | * it will check for matching files (images, scripts, stylesheets, etc.) 9 | * in your assets directory. e.g. `http://localhost:1337/images/foo.jpg` 10 | * might match an image file: `/assets/images/foo.jpg` 11 | * 12 | * Finally, if those don't match either, the default 404 handler is triggered. 13 | * See `api/responses/notFound.js` to adjust your app's 404 logic. 14 | * 15 | * Note: Sails doesn't ACTUALLY serve stuff from `assets`-- the default Gruntfile in Sails copies 16 | * flat files from `assets` to `.tmp/public`. This allows you to do things like compile LESS or 17 | * CoffeeScript for the front-end. 18 | * 19 | * For more information on configuring custom routes, check out: 20 | * http://sailsjs.org/#!/documentation/concepts/Routes/RouteTargetSyntax.html 21 | */ 22 | 23 | module.exports.routes = { 24 | 25 | /*************************************************************************** 26 | * * 27 | * Make the view located at `views/homepage.ejs` (or `views/homepage.jade`, * 28 | * etc. depending on your default view engine) your home page. * 29 | * * 30 | * (Alternatively, remove this and add an `index.html` file in your * 31 | * `assets` directory) * 32 | * * 33 | ***************************************************************************/ 34 | 35 | '/': { 36 | view: 'homepage' 37 | } 38 | 39 | /*************************************************************************** 40 | * * 41 | * Custom routes here... * 42 | * * 43 | * If a request to a URL doesn't match any of the custom routes above, it * 44 | * is matched against Sails route blueprints. See `config/blueprints.js` * 45 | * for configuration options and examples. * 46 | * * 47 | ***************************************************************************/ 48 | 49 | }; 50 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/config/sequelize.js: -------------------------------------------------------------------------------- 1 | module.exports.sequelize = { 2 | 'clsNamespace' : 'myAppCLSNamespace', 3 | 'exposeToGlobal': true 4 | }; 5 | -------------------------------------------------------------------------------- /test/fixtures/v0.12-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 3 | "private": true, 4 | "version": "0.0.0", 5 | "description": "a Sails application", 6 | "keywords": [], 7 | "dependencies": { 8 | "ejs": "^2.3.4", 9 | "grunt": "^1.0.1", 10 | "grunt-contrib-clean": "^1.0.0", 11 | "grunt-contrib-coffee": "^1.0.0", 12 | "grunt-contrib-concat": "^1.0.1", 13 | "grunt-contrib-copy": "^1.0.0", 14 | "grunt-contrib-cssmin": "^1.0.1", 15 | "grunt-contrib-jst": "^1.0.0", 16 | "grunt-contrib-less": "^1.3.0", 17 | "grunt-contrib-uglify": "^1.0.1", 18 | "grunt-contrib-watch": "^1.0.0", 19 | "grunt-sails-linker": "^0.10.1", 20 | "grunt-sync": "^0.5.2", 21 | "include-all": "^1.0.8", 22 | "rc": "^1.0.1", 23 | "sails": "^0.12.14", 24 | "sails-disk": "^0.10.10", 25 | "sails-hook-orm": "^1.0.9", 26 | "sails-memory": "^0.10.7" 27 | }, 28 | "scripts": { 29 | "debug": "node debug app.js", 30 | "start": "node app.js" 31 | }, 32 | "main": "app.js", 33 | "repository": { 34 | "type": "git", 35 | "url": "git://github.com/kostik/app.git" 36 | }, 37 | "author": "kostik", 38 | "license": "" 39 | } 40 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/.sailsrc: -------------------------------------------------------------------------------- 1 | { 2 | "generators": { 3 | "modules": {} 4 | }, 5 | "hooks": { 6 | "blueprints": false, 7 | "grunt": false, 8 | "sockets": false, 9 | "pubsub": false, 10 | "orm": false, 11 | "i18n": false 12 | }, 13 | "log": { 14 | "level": "info" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/api/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-app/api/controllers/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/api/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-app/api/models/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/api/models/Group.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Group.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | name: { 11 | type: Sequelize.STRING 12 | }, 13 | role: { 14 | type: Sequelize.ENUM('USER', 'ADMIN') 15 | } 16 | }, 17 | associations: function () { 18 | Group.hasMany(User, { as: 'users', foreignKey: 'groupId' }); 19 | }, 20 | defaultScope: function () { 21 | return { 22 | include: [ 23 | { model: User, as: 'users' } 24 | ] 25 | }; 26 | }, 27 | options : { 28 | freezeTableName : false, 29 | tableName : 'group', 30 | schema : 'sails', 31 | classMethods : {}, 32 | instanceMethods : {}, 33 | hooks : {} 34 | } 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/api/models/Image.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Image.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | url: { 11 | type: Sequelize.STRING 12 | } 13 | }, 14 | associations: function () { 15 | Image.belongsTo(User, { foreignKey: 'userId' }); 16 | }, 17 | options : { 18 | freezeTableName : false, 19 | tableName : 'image', 20 | schema : 'sails', 21 | classMethods : {}, 22 | instanceMethods : {}, 23 | hooks : {} 24 | } 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/api/models/User.js: -------------------------------------------------------------------------------- 1 | /** 2 | * User.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | name: { 11 | type: Sequelize.STRING 12 | }, 13 | age : { 14 | type: Sequelize.INTEGER 15 | } 16 | }, 17 | associations: function () { 18 | User.hasMany(Image, { as: 'images', foreignKey: 'userId' }); 19 | }, 20 | defaultScope: function () { 21 | return { 22 | include: [ 23 | { model: Image, as: 'images' } 24 | ] 25 | }; 26 | }, 27 | options : { 28 | freezeTableName : false, 29 | tableName : 'user', 30 | schema : 'sails', 31 | classMethods : { 32 | oneUniqueClassMethod: function () { 33 | return 'User class method'; 34 | } 35 | }, 36 | instanceMethods : { 37 | toJSON: function () { 38 | let obj = this.get(); 39 | obj.ageString = '' + obj.age + ' years'; 40 | return obj; 41 | } 42 | }, 43 | hooks : {} 44 | } 45 | }; 46 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/api/policies/sessionAuth.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sessionAuth 3 | * 4 | * @module :: Policy 5 | * @description :: Simple policy to allow any authenticated user 6 | * Assumes that your login action in one of your controllers sets `req.session.authenticated = true;` 7 | * @docs :: http://sailsjs.org/#!/documentation/concepts/Policies 8 | * 9 | */ 10 | module.exports = function(req, res, next) { 11 | 12 | // User is allowed, proceed to the next policy, 13 | // or if this is the last policy, the controller 14 | if (req.session.authenticated) { 15 | return next(); 16 | } 17 | 18 | // User is not allowed 19 | // (default res.forbidden() behavior can be overridden in `config/403.js`) 20 | return res.forbidden('You are not permitted to perform this action.'); 21 | }; 22 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/api/responses/badRequest.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 400 (Bad Request) Handler 3 | * 4 | * Usage: 5 | * return res.badRequest(); 6 | * return res.badRequest(data); 7 | * return res.badRequest(data, 'some/specific/badRequest/view'); 8 | * 9 | * e.g.: 10 | * ``` 11 | * return res.badRequest( 12 | * 'Please choose a valid `password` (6-12 characters)', 13 | * 'trial/signup' 14 | * ); 15 | * ``` 16 | */ 17 | 18 | module.exports = function badRequest(data, options) { 19 | 20 | // Get access to `req`, `res`, & `sails` 21 | var req = this.req; 22 | var res = this.res; 23 | var sails = req._sails; 24 | 25 | // Set status code 26 | res.status(400); 27 | 28 | // Log error to console 29 | if (data !== undefined) { 30 | sails.log.verbose('Sending 400 ("Bad Request") response: \n',data); 31 | } 32 | else sails.log.verbose('Sending 400 ("Bad Request") response'); 33 | 34 | // Only include errors in response if application environment 35 | // is not set to 'production'. In production, we shouldn't 36 | // send back any identifying information about errors. 37 | if (sails.config.environment === 'production' && sails.config.keepResponseErrors !== true) { 38 | data = undefined; 39 | } 40 | 41 | // If the user-agent wants JSON, always respond with JSON 42 | // If views are disabled, revert to json 43 | if (req.wantsJSON || sails.config.hooks.views === false) { 44 | return res.jsonx(data); 45 | } 46 | 47 | // If second argument is a string, we take that to mean it refers to a view. 48 | // If it was omitted, use an empty object (`{}`) 49 | options = (typeof options === 'string') ? { view: options } : options || {}; 50 | 51 | // Attempt to prettify data for views, if it's a non-error object 52 | var viewData = data; 53 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 54 | try { 55 | viewData = require('util').inspect(data, {depth: null}); 56 | } 57 | catch(e) { 58 | viewData = undefined; 59 | } 60 | } 61 | 62 | // If a view was provided in options, serve it. 63 | // Otherwise try to guess an appropriate view, or if that doesn't 64 | // work, just send JSON. 65 | if (options.view) { 66 | return res.view(options.view, { data: viewData, title: 'Bad Request' }); 67 | } 68 | 69 | // If no second argument provided, try to serve the implied view, 70 | // but fall back to sending JSON(P) if no view can be inferred. 71 | else return res.guessView({ data: viewData, title: 'Bad Request' }, function couldNotGuessView () { 72 | return res.jsonx(data); 73 | }); 74 | 75 | }; 76 | 77 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/api/responses/created.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 201 (CREATED) Response 3 | * 4 | * Usage: 5 | * return res.created(); 6 | * return res.created(data); 7 | * return res.created(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function created (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.created() :: Sending 201 ("CREATED") response'); 22 | 23 | // Set status code 24 | res.status(201); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'Created' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'Created' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/api/responses/ok.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 200 (OK) Response 3 | * 4 | * Usage: 5 | * return res.ok(); 6 | * return res.ok(data); 7 | * return res.ok(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function sendOK (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.ok() :: Sending 200 ("OK") response'); 22 | 23 | // Set status code 24 | res.status(200); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'OK' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'OK' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/api/services/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-app/api/services/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/app.js: -------------------------------------------------------------------------------- 1 | /** 2 | * app.js 3 | * 4 | * Use `app.js` to run your app without `sails lift`. 5 | * To start the server, run: `node app.js`. 6 | * 7 | * This is handy in situations where the sails CLI is not relevant or useful. 8 | * 9 | * For example: 10 | * => `node app.js` 11 | * => `forever start app.js` 12 | * => `node debug app.js` 13 | * => `modulus deploy` 14 | * => `heroku scale` 15 | * 16 | * The same command-line arguments are supported, e.g.: 17 | * `node app.js --silent --port=80 --prod` 18 | * 19 | * For more information see: 20 | * https://sailsjs.com/anatomy/app.js 21 | */ 22 | 23 | 24 | // Ensure we're in the project directory, so cwd-relative paths work as expected 25 | // no matter where we actually lift from. 26 | // > Note: This is not required in order to lift, but it is a convenient default. 27 | process.chdir(__dirname); 28 | 29 | 30 | // Ensure a "sails" can be located: 31 | (function () { 32 | 33 | // Attempt to import `sails` dependency, as well as `rc` (for loading `.sailsrc` files). 34 | var sails; 35 | var rc; 36 | try { 37 | sails = require('sails'); 38 | rc = require('sails/accessible/rc'); 39 | } catch (e) { 40 | console.error('Encountered an error when attempting to require(\'sails\'):'); 41 | console.error(e.stack); 42 | console.error('--'); 43 | console.error( 44 | 'To run an app using `node app.js`, you usually need to have a version of `sails` installed in the same directory as your app.'); 45 | console.error('To do that, run `npm install sails`'); 46 | console.error(); 47 | console.error( 48 | 'Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.'); 49 | console.error( 50 | 'When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,'); 51 | console.error('but if it doesn\'t, the app will run with the global sails instead!'); 52 | return; 53 | }//-• 54 | 55 | // // Start server 56 | // sails.lift(rc('sails')); 57 | module.exports.sails = sails.Sails; 58 | 59 | }()); 60 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/config/bootstrap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Bootstrap 3 | * (sails.config.bootstrap) 4 | * 5 | * An asynchronous bootstrap function that runs before your Sails app gets lifted. 6 | * This gives you an opportunity to set up your data model, run jobs, or perform some special logic. 7 | * 8 | * For more information on bootstrapping your app, check out: 9 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.bootstrap.html 10 | */ 11 | 12 | module.exports.bootstrap = function(cb) { 13 | 14 | // It's very important to trigger this callback method when you are finished 15 | // with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap) 16 | cb(); 17 | }; 18 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/config/datastores.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Connections 3 | * (sails.config.connections) 4 | * 5 | * `Connections` are like "saved settings" for your adapters. What's the difference between 6 | * a connection and an adapter, you might ask? An adapter (e.g. `sails-mysql`) is generic-- 7 | * it needs some additional information to work (e.g. your database host, password, user, etc.) 8 | * A `connection` is that additional information. 9 | * 10 | * Each model must have a `connection` property (a string) which is references the name of one 11 | * of these connections. If it doesn't, the default `connection` configured in `config/models.js` 12 | * will be applied. Of course, a connection can (and usually is) shared by multiple models. 13 | * . 14 | * Note: If you're using version control, you should put your passwords/api keys 15 | * in `config/local.js`, environment variables, or use another strategy. 16 | * (this is to prevent you inadvertently sensitive credentials up to your repository.) 17 | * 18 | * For more information on configuration, check out: 19 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.connections.html 20 | */ 21 | 22 | module.exports.datastores = { 23 | 24 | somePostgresqlServer: { 25 | user: 'postgres', 26 | password: '', 27 | database: 'sequelize', 28 | dialect: 'postgres', 29 | options: { 30 | dialect: 'postgres', 31 | host : 'localhost', 32 | port : 5432, 33 | logging: 'verbose' 34 | } 35 | }, 36 | 37 | memory: { 38 | adapter: 'sails-memory' 39 | } 40 | }; 41 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/config/log.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Built-in Log Configuration 3 | * (sails.config.log) 4 | * 5 | * Configure the log level for your app, as well as the transport 6 | * (Underneath the covers, Sails uses Winston for logging, which 7 | * allows for some pretty neat custom transports/adapters for log messages) 8 | * 9 | * For more information on the Sails logger, check out: 10 | * http://sailsjs.org/#!/documentation/concepts/Logging 11 | */ 12 | 13 | module.exports.log = { 14 | 15 | /*************************************************************************** 16 | * * 17 | * Valid `level` configs: i.e. the minimum log level to capture with * 18 | * sails.log.*() * 19 | * * 20 | * The order of precedence for log levels from lowest to highest is: * 21 | * silly, verbose, info, debug, warn, error * 22 | * * 23 | * You may also set the level to "silent" to suppress all logs. * 24 | * * 25 | ***************************************************************************/ 26 | 27 | // level: 'info' 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/config/models.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Default model configuration 3 | * (sails.config.models) 4 | * 5 | * Unless you override them, the following properties will be included 6 | * in each of your models. 7 | * 8 | * For more info on Sails models, see: 9 | * http://sailsjs.org/#!/documentation/concepts/ORM 10 | */ 11 | 12 | module.exports.models = { 13 | 14 | datastore: 'somePostgresqlServer', 15 | migrate: 'drop' 16 | 17 | }; 18 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/config/policies.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Policy Mappings 3 | * (sails.config.policies) 4 | * 5 | * Policies are simple functions which run **before** your controllers. 6 | * You can apply one or more policies to a given controller, or protect 7 | * its actions individually. 8 | * 9 | * Any policy file (e.g. `api/policies/authenticated.js`) can be accessed 10 | * below by its filename, minus the extension, (e.g. "authenticated") 11 | * 12 | * For more information on how policies work, see: 13 | * http://sailsjs.org/#!/documentation/concepts/Policies 14 | * 15 | * For more information on configuring policies, check out: 16 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.policies.html 17 | */ 18 | 19 | 20 | module.exports.policies = { 21 | 22 | /*************************************************************************** 23 | * * 24 | * Default policy for all controllers and actions (`true` allows public * 25 | * access) * 26 | * * 27 | ***************************************************************************/ 28 | 29 | // '*': true, 30 | 31 | /*************************************************************************** 32 | * * 33 | * Here's an example of mapping some policies to run before a controller * 34 | * and its actions * 35 | * * 36 | ***************************************************************************/ 37 | // RabbitController: { 38 | 39 | // Apply the `false` policy as the default for all of RabbitController's actions 40 | // (`false` prevents all access, which ensures that nothing bad happens to our rabbits) 41 | // '*': false, 42 | 43 | // For the action `nurture`, apply the 'isRabbitMother' policy 44 | // (this overrides `false` above) 45 | // nurture : 'isRabbitMother', 46 | 47 | // Apply the `isNiceToAnimals` AND `hasRabbitFood` policies 48 | // before letting any users feed our rabbits 49 | // feed : ['isNiceToAnimals', 'hasRabbitFood'] 50 | // } 51 | }; 52 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/config/routes.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Route Mappings 3 | * (sails.config.routes) 4 | * 5 | * Your routes map URLs to views and controllers. 6 | * 7 | * If Sails receives a URL that doesn't match any of the routes below, 8 | * it will check for matching files (images, scripts, stylesheets, etc.) 9 | * in your assets directory. e.g. `http://localhost:1337/images/foo.jpg` 10 | * might match an image file: `/assets/images/foo.jpg` 11 | * 12 | * Finally, if those don't match either, the default 404 handler is triggered. 13 | * See `api/responses/notFound.js` to adjust your app's 404 logic. 14 | * 15 | * Note: Sails doesn't ACTUALLY serve stuff from `assets`-- the default Gruntfile in Sails copies 16 | * flat files from `assets` to `.tmp/public`. This allows you to do things like compile LESS or 17 | * CoffeeScript for the front-end. 18 | * 19 | * For more information on configuring custom routes, check out: 20 | * http://sailsjs.org/#!/documentation/concepts/Routes/RouteTargetSyntax.html 21 | */ 22 | 23 | module.exports.routes = { 24 | 25 | /*************************************************************************** 26 | * * 27 | * Make the view located at `views/homepage.ejs` (or `views/homepage.jade`, * 28 | * etc. depending on your default view engine) your home page. * 29 | * * 30 | * (Alternatively, remove this and add an `index.html` file in your * 31 | * `assets` directory) * 32 | * * 33 | ***************************************************************************/ 34 | 35 | '/': { 36 | view: 'homepage' 37 | } 38 | 39 | /*************************************************************************** 40 | * * 41 | * Custom routes here... * 42 | * * 43 | * If a request to a URL doesn't match any of the custom routes above, it * 44 | * is matched against Sails route blueprints. See `config/blueprints.js` * 45 | * for configuration options and examples. * 46 | * * 47 | ***************************************************************************/ 48 | 49 | }; 50 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-app/config/sequelize.js: -------------------------------------------------------------------------------- 1 | module.exports.sequelize = { 2 | 'clsNamespace' : 'myAppCLSNamespace', 3 | 'exposeToGlobal': true 4 | }; 5 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/.sailsrc: -------------------------------------------------------------------------------- 1 | { 2 | "generators": { 3 | "modules": {} 4 | }, 5 | "hooks": { 6 | "blueprints": false, 7 | "grunt": false, 8 | "sockets": false, 9 | "pubsub": false, 10 | "orm": false, 11 | "i18n": false 12 | }, 13 | "log": { 14 | "level": "info" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/api/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-create-db-schemes-app/api/controllers/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/api/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-create-db-schemes-app/api/models/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/api/models/Group.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Group.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | name: { 11 | type: Sequelize.STRING 12 | }, 13 | role: { 14 | type: Sequelize.ENUM('USER', 'ADMIN') 15 | } 16 | }, 17 | associations: function () { 18 | Group.hasMany(User, { as: 'users', foreignKey: 'groupId' }); 19 | }, 20 | defaultScope: function () { 21 | return { 22 | include: [ 23 | { model: User, as: 'users' } 24 | ] 25 | }; 26 | }, 27 | options : { 28 | freezeTableName : false, 29 | tableName : 'group', 30 | schema : 'sails', 31 | classMethods : {}, 32 | instanceMethods : {}, 33 | hooks : {} 34 | } 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/api/models/Image.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Image.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | url: { 11 | type: Sequelize.STRING 12 | } 13 | }, 14 | associations: function () { 15 | Image.belongsTo(User, { foreignKey: 'userId' }); 16 | }, 17 | options : { 18 | freezeTableName : false, 19 | tableName : 'image', 20 | schema : 'sails', 21 | classMethods : {}, 22 | instanceMethods : {}, 23 | hooks : {} 24 | } 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/api/models/User.js: -------------------------------------------------------------------------------- 1 | /** 2 | * User.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | name: { 11 | type: Sequelize.STRING 12 | }, 13 | age : { 14 | type: Sequelize.INTEGER 15 | } 16 | }, 17 | associations: function () { 18 | User.hasMany(Image, { as: 'images', foreignKey: 'userId' }); 19 | }, 20 | defaultScope: function () { 21 | return { 22 | include: [ 23 | { model: Image, as: 'images' } 24 | ] 25 | }; 26 | }, 27 | options : { 28 | freezeTableName : false, 29 | tableName : 'user', 30 | schema : 'sails', 31 | classMethods : { 32 | oneUniqueClassMethod: function () { 33 | return 'User class method'; 34 | } 35 | }, 36 | instanceMethods : { 37 | toJSON: function () { 38 | let obj = this.get(); 39 | obj.ageString = '' + obj.age + ' years'; 40 | return obj; 41 | } 42 | }, 43 | hooks : {} 44 | } 45 | }; 46 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/api/policies/sessionAuth.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sessionAuth 3 | * 4 | * @module :: Policy 5 | * @description :: Simple policy to allow any authenticated user 6 | * Assumes that your login action in one of your controllers sets `req.session.authenticated = true;` 7 | * @docs :: http://sailsjs.org/#!/documentation/concepts/Policies 8 | * 9 | */ 10 | module.exports = function(req, res, next) { 11 | 12 | // User is allowed, proceed to the next policy, 13 | // or if this is the last policy, the controller 14 | if (req.session.authenticated) { 15 | return next(); 16 | } 17 | 18 | // User is not allowed 19 | // (default res.forbidden() behavior can be overridden in `config/403.js`) 20 | return res.forbidden('You are not permitted to perform this action.'); 21 | }; 22 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/api/responses/created.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 201 (CREATED) Response 3 | * 4 | * Usage: 5 | * return res.created(); 6 | * return res.created(data); 7 | * return res.created(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function created (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.created() :: Sending 201 ("CREATED") response'); 22 | 23 | // Set status code 24 | res.status(201); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'Created' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'Created' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/api/responses/ok.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 200 (OK) Response 3 | * 4 | * Usage: 5 | * return res.ok(); 6 | * return res.ok(data); 7 | * return res.ok(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function sendOK (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.ok() :: Sending 200 ("OK") response'); 22 | 23 | // Set status code 24 | res.status(200); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'OK' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'OK' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/api/services/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-create-db-schemes-app/api/services/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/app.js: -------------------------------------------------------------------------------- 1 | /** 2 | * app.js 3 | * 4 | * Use `app.js` to run your app without `sails lift`. 5 | * To start the server, run: `node app.js`. 6 | * 7 | * This is handy in situations where the sails CLI is not relevant or useful. 8 | * 9 | * For example: 10 | * => `node app.js` 11 | * => `forever start app.js` 12 | * => `node debug app.js` 13 | * => `modulus deploy` 14 | * => `heroku scale` 15 | * 16 | * The same command-line arguments are supported, e.g.: 17 | * `node app.js --silent --port=80 --prod` 18 | * 19 | * For more information see: 20 | * https://sailsjs.com/anatomy/app.js 21 | */ 22 | 23 | 24 | // Ensure we're in the project directory, so cwd-relative paths work as expected 25 | // no matter where we actually lift from. 26 | // > Note: This is not required in order to lift, but it is a convenient default. 27 | process.chdir(__dirname); 28 | 29 | 30 | // Ensure a "sails" can be located: 31 | (function () { 32 | 33 | // Attempt to import `sails` dependency, as well as `rc` (for loading `.sailsrc` files). 34 | var sails; 35 | var rc; 36 | try { 37 | sails = require('sails'); 38 | rc = require('sails/accessible/rc'); 39 | } catch (e) { 40 | console.error('Encountered an error when attempting to require(\'sails\'):'); 41 | console.error(e.stack); 42 | console.error('--'); 43 | console.error( 44 | 'To run an app using `node app.js`, you usually need to have a version of `sails` installed in the same directory as your app.'); 45 | console.error('To do that, run `npm install sails`'); 46 | console.error(); 47 | console.error( 48 | 'Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.'); 49 | console.error( 50 | 'When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,'); 51 | console.error('but if it doesn\'t, the app will run with the global sails instead!'); 52 | return; 53 | }//-• 54 | 55 | // // Start server 56 | // sails.lift(rc('sails')); 57 | module.exports.sails = sails.Sails; 58 | 59 | }()); 60 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/config/bootstrap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Bootstrap 3 | * (sails.config.bootstrap) 4 | * 5 | * An asynchronous bootstrap function that runs before your Sails app gets lifted. 6 | * This gives you an opportunity to set up your data model, run jobs, or perform some special logic. 7 | * 8 | * For more information on bootstrapping your app, check out: 9 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.bootstrap.html 10 | */ 11 | 12 | module.exports.bootstrap = function(cb) { 13 | 14 | // It's very important to trigger this callback method when you are finished 15 | // with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap) 16 | cb(); 17 | }; 18 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/config/datastores.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Connections 3 | * (sails.config.connections) 4 | * 5 | * `Connections` are like "saved settings" for your adapters. What's the difference between 6 | * a connection and an adapter, you might ask? An adapter (e.g. `sails-mysql`) is generic-- 7 | * it needs some additional information to work (e.g. your database host, password, user, etc.) 8 | * A `connection` is that additional information. 9 | * 10 | * Each model must have a `connection` property (a string) which is references the name of one 11 | * of these connections. If it doesn't, the default `connection` configured in `config/models.js` 12 | * will be applied. Of course, a connection can (and usually is) shared by multiple models. 13 | * . 14 | * Note: If you're using version control, you should put your passwords/api keys 15 | * in `config/local.js`, environment variables, or use another strategy. 16 | * (this is to prevent you inadvertently sensitive credentials up to your repository.) 17 | * 18 | * For more information on configuration, check out: 19 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.connections.html 20 | */ 21 | 22 | module.exports.datastores = { 23 | 24 | somePostgresqlServer: { 25 | url: 'postgres://postgres@localhost:5432/sequelize', 26 | options: { 27 | dialect: 'postgres', 28 | logging: false 29 | }, 30 | dialect: 'postgres' 31 | } 32 | 33 | }; 34 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/config/log.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Built-in Log Configuration 3 | * (sails.config.log) 4 | * 5 | * Configure the log level for your app, as well as the transport 6 | * (Underneath the covers, Sails uses Winston for logging, which 7 | * allows for some pretty neat custom transports/adapters for log messages) 8 | * 9 | * For more information on the Sails logger, check out: 10 | * http://sailsjs.org/#!/documentation/concepts/Logging 11 | */ 12 | 13 | module.exports.log = { 14 | 15 | /*************************************************************************** 16 | * * 17 | * Valid `level` configs: i.e. the minimum log level to capture with * 18 | * sails.log.*() * 19 | * * 20 | * The order of precedence for log levels from lowest to highest is: * 21 | * silly, verbose, info, debug, warn, error * 22 | * * 23 | * You may also set the level to "silent" to suppress all logs. * 24 | * * 25 | ***************************************************************************/ 26 | 27 | // level: 'info' 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/config/models.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Default model configuration 3 | * (sails.config.models) 4 | * 5 | * Unless you override them, the following properties will be included 6 | * in each of your models. 7 | * 8 | * For more info on Sails models, see: 9 | * http://sailsjs.org/#!/documentation/concepts/ORM 10 | */ 11 | 12 | module.exports.models = { 13 | 14 | connection: 'somePostgresqlServer', 15 | migrate: 'drop' 16 | 17 | }; 18 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/config/policies.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Policy Mappings 3 | * (sails.config.policies) 4 | * 5 | * Policies are simple functions which run **before** your controllers. 6 | * You can apply one or more policies to a given controller, or protect 7 | * its actions individually. 8 | * 9 | * Any policy file (e.g. `api/policies/authenticated.js`) can be accessed 10 | * below by its filename, minus the extension, (e.g. "authenticated") 11 | * 12 | * For more information on how policies work, see: 13 | * http://sailsjs.org/#!/documentation/concepts/Policies 14 | * 15 | * For more information on configuring policies, check out: 16 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.policies.html 17 | */ 18 | 19 | 20 | module.exports.policies = { 21 | 22 | /*************************************************************************** 23 | * * 24 | * Default policy for all controllers and actions (`true` allows public * 25 | * access) * 26 | * * 27 | ***************************************************************************/ 28 | 29 | // '*': true, 30 | 31 | /*************************************************************************** 32 | * * 33 | * Here's an example of mapping some policies to run before a controller * 34 | * and its actions * 35 | * * 36 | ***************************************************************************/ 37 | // RabbitController: { 38 | 39 | // Apply the `false` policy as the default for all of RabbitController's actions 40 | // (`false` prevents all access, which ensures that nothing bad happens to our rabbits) 41 | // '*': false, 42 | 43 | // For the action `nurture`, apply the 'isRabbitMother' policy 44 | // (this overrides `false` above) 45 | // nurture : 'isRabbitMother', 46 | 47 | // Apply the `isNiceToAnimals` AND `hasRabbitFood` policies 48 | // before letting any users feed our rabbits 49 | // feed : ['isNiceToAnimals', 'hasRabbitFood'] 50 | // } 51 | }; 52 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-create-db-schemes-app/config/sequelize.js: -------------------------------------------------------------------------------- 1 | module.exports.sequelize = { 2 | 'clsNamespace' : 'myAppCLSNamespace', 3 | 'exposeToGlobal': true 4 | }; 5 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/.sailsrc: -------------------------------------------------------------------------------- 1 | { 2 | "generators": { 3 | "modules": {} 4 | }, 5 | "hooks": { 6 | "blueprints": false, 7 | "grunt": false, 8 | "sockets": false, 9 | "pubsub": false, 10 | "orm": false, 11 | "i18n": false 12 | }, 13 | "log": { 14 | "level": "info" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/api/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-many-schemes-app/api/controllers/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/api/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-many-schemes-app/api/models/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/api/models/Group.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Group.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | name: { 11 | type: Sequelize.STRING 12 | }, 13 | role: { 14 | type: Sequelize.ENUM('USER', 'ADMIN') 15 | } 16 | }, 17 | associations: function () { 18 | Group.hasMany(User, { as: 'users', foreignKey: 'groupId' }); 19 | }, 20 | defaultScope: function () { 21 | return { 22 | include: [ 23 | { model: User, as: 'users' } 24 | ] 25 | }; 26 | }, 27 | options : { 28 | freezeTableName : false, 29 | tableName : 'group', 30 | schema : 'sails', 31 | classMethods : {}, 32 | instanceMethods : {}, 33 | hooks : {} 34 | } 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/api/models/Image.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Image.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | url: { 11 | type: Sequelize.STRING 12 | } 13 | }, 14 | associations: function () { 15 | Image.belongsTo(User, { foreignKey: 'userId' }); 16 | }, 17 | options : { 18 | freezeTableName : false, 19 | tableName : 'image', 20 | schema : 'sails_img', 21 | classMethods : {}, 22 | instanceMethods : {}, 23 | hooks : {} 24 | } 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/api/models/User.js: -------------------------------------------------------------------------------- 1 | /** 2 | * User.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | name: { 11 | type: Sequelize.STRING 12 | }, 13 | age : { 14 | type: Sequelize.INTEGER 15 | } 16 | }, 17 | associations: function () { 18 | User.hasMany(Image, { as: 'images', foreignKey: 'userId' }); 19 | }, 20 | defaultScope: function () { 21 | return { 22 | include: [ 23 | { model: Image, as: 'images' } 24 | ] 25 | }; 26 | }, 27 | options : { 28 | freezeTableName : false, 29 | tableName : 'user', 30 | schema : 'sails', 31 | classMethods : { 32 | oneUniqueClassMethod: function () { 33 | return 'User class method'; 34 | } 35 | }, 36 | instanceMethods : { 37 | toJSON: function () { 38 | let obj = this.get(); 39 | obj.ageString = '' + obj.age + ' years'; 40 | return obj; 41 | } 42 | }, 43 | hooks : {} 44 | } 45 | }; 46 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/api/policies/sessionAuth.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sessionAuth 3 | * 4 | * @module :: Policy 5 | * @description :: Simple policy to allow any authenticated user 6 | * Assumes that your login action in one of your controllers sets `req.session.authenticated = true;` 7 | * @docs :: http://sailsjs.org/#!/documentation/concepts/Policies 8 | * 9 | */ 10 | module.exports = function(req, res, next) { 11 | 12 | // User is allowed, proceed to the next policy, 13 | // or if this is the last policy, the controller 14 | if (req.session.authenticated) { 15 | return next(); 16 | } 17 | 18 | // User is not allowed 19 | // (default res.forbidden() behavior can be overridden in `config/403.js`) 20 | return res.forbidden('You are not permitted to perform this action.'); 21 | }; 22 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/api/responses/created.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 201 (CREATED) Response 3 | * 4 | * Usage: 5 | * return res.created(); 6 | * return res.created(data); 7 | * return res.created(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function created (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.created() :: Sending 201 ("CREATED") response'); 22 | 23 | // Set status code 24 | res.status(201); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'Created' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'Created' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/api/responses/ok.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 200 (OK) Response 3 | * 4 | * Usage: 5 | * return res.ok(); 6 | * return res.ok(data); 7 | * return res.ok(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function sendOK (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.ok() :: Sending 200 ("OK") response'); 22 | 23 | // Set status code 24 | res.status(200); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'OK' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'OK' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/api/services/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-many-schemes-app/api/services/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/app.js: -------------------------------------------------------------------------------- 1 | /** 2 | * app.js 3 | * 4 | * Use `app.js` to run your app without `sails lift`. 5 | * To start the server, run: `node app.js`. 6 | * 7 | * This is handy in situations where the sails CLI is not relevant or useful. 8 | * 9 | * For example: 10 | * => `node app.js` 11 | * => `forever start app.js` 12 | * => `node debug app.js` 13 | * => `modulus deploy` 14 | * => `heroku scale` 15 | * 16 | * The same command-line arguments are supported, e.g.: 17 | * `node app.js --silent --port=80 --prod` 18 | * 19 | * For more information see: 20 | * https://sailsjs.com/anatomy/app.js 21 | */ 22 | 23 | 24 | // Ensure we're in the project directory, so cwd-relative paths work as expected 25 | // no matter where we actually lift from. 26 | // > Note: This is not required in order to lift, but it is a convenient default. 27 | process.chdir(__dirname); 28 | 29 | 30 | // Ensure a "sails" can be located: 31 | (function () { 32 | 33 | // Attempt to import `sails` dependency, as well as `rc` (for loading `.sailsrc` files). 34 | var sails; 35 | var rc; 36 | try { 37 | sails = require('sails'); 38 | rc = require('sails/accessible/rc'); 39 | } catch (e) { 40 | console.error('Encountered an error when attempting to require(\'sails\'):'); 41 | console.error(e.stack); 42 | console.error('--'); 43 | console.error( 44 | 'To run an app using `node app.js`, you usually need to have a version of `sails` installed in the same directory as your app.'); 45 | console.error('To do that, run `npm install sails`'); 46 | console.error(); 47 | console.error( 48 | 'Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.'); 49 | console.error( 50 | 'When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,'); 51 | console.error('but if it doesn\'t, the app will run with the global sails instead!'); 52 | return; 53 | }//-• 54 | 55 | // // Start server 56 | // sails.lift(rc('sails')); 57 | module.exports.sails = sails.Sails; 58 | 59 | }()); 60 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/config/bootstrap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Bootstrap 3 | * (sails.config.bootstrap) 4 | * 5 | * An asynchronous bootstrap function that runs before your Sails app gets lifted. 6 | * This gives you an opportunity to set up your data model, run jobs, or perform some special logic. 7 | * 8 | * For more information on bootstrapping your app, check out: 9 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.bootstrap.html 10 | */ 11 | 12 | module.exports.bootstrap = function(cb) { 13 | 14 | // It's very important to trigger this callback method when you are finished 15 | // with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap) 16 | cb(); 17 | }; 18 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/config/datastores.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Connections 3 | * (sails.config.connections) 4 | * 5 | * `Connections` are like "saved settings" for your adapters. What's the difference between 6 | * a connection and an adapter, you might ask? An adapter (e.g. `sails-mysql`) is generic-- 7 | * it needs some additional information to work (e.g. your database host, password, user, etc.) 8 | * A `connection` is that additional information. 9 | * 10 | * Each model must have a `connection` property (a string) which is references the name of one 11 | * of these connections. If it doesn't, the default `connection` configured in `config/models.js` 12 | * will be applied. Of course, a connection can (and usually is) shared by multiple models. 13 | * . 14 | * Note: If you're using version control, you should put your passwords/api keys 15 | * in `config/local.js`, environment variables, or use another strategy. 16 | * (this is to prevent you inadvertently sensitive credentials up to your repository.) 17 | * 18 | * For more information on configuration, check out: 19 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.connections.html 20 | */ 21 | 22 | module.exports.datastores = { 23 | 24 | somePostgresqlServer: { 25 | url: 'postgres://postgres@localhost:5432/sequelize', 26 | options: { 27 | dialect: 'postgres', 28 | logging: false 29 | }, 30 | dialect: 'postgres' 31 | } 32 | 33 | }; 34 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/config/log.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Built-in Log Configuration 3 | * (sails.config.log) 4 | * 5 | * Configure the log level for your app, as well as the transport 6 | * (Underneath the covers, Sails uses Winston for logging, which 7 | * allows for some pretty neat custom transports/adapters for log messages) 8 | * 9 | * For more information on the Sails logger, check out: 10 | * http://sailsjs.org/#!/documentation/concepts/Logging 11 | */ 12 | 13 | module.exports.log = { 14 | 15 | /*************************************************************************** 16 | * * 17 | * Valid `level` configs: i.e. the minimum log level to capture with * 18 | * sails.log.*() * 19 | * * 20 | * The order of precedence for log levels from lowest to highest is: * 21 | * silly, verbose, info, debug, warn, error * 22 | * * 23 | * You may also set the level to "silent" to suppress all logs. * 24 | * * 25 | ***************************************************************************/ 26 | 27 | // level: 'info' 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/config/models.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Default model configuration 3 | * (sails.config.models) 4 | * 5 | * Unless you override them, the following properties will be included 6 | * in each of your models. 7 | * 8 | * For more info on Sails models, see: 9 | * http://sailsjs.org/#!/documentation/concepts/ORM 10 | */ 11 | 12 | module.exports.models = { 13 | 14 | connection: 'somePostgresqlServer', 15 | migrate: 'drop' 16 | 17 | }; 18 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/config/policies.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Policy Mappings 3 | * (sails.config.policies) 4 | * 5 | * Policies are simple functions which run **before** your controllers. 6 | * You can apply one or more policies to a given controller, or protect 7 | * its actions individually. 8 | * 9 | * Any policy file (e.g. `api/policies/authenticated.js`) can be accessed 10 | * below by its filename, minus the extension, (e.g. "authenticated") 11 | * 12 | * For more information on how policies work, see: 13 | * http://sailsjs.org/#!/documentation/concepts/Policies 14 | * 15 | * For more information on configuring policies, check out: 16 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.policies.html 17 | */ 18 | 19 | 20 | module.exports.policies = { 21 | 22 | /*************************************************************************** 23 | * * 24 | * Default policy for all controllers and actions (`true` allows public * 25 | * access) * 26 | * * 27 | ***************************************************************************/ 28 | 29 | // '*': true, 30 | 31 | /*************************************************************************** 32 | * * 33 | * Here's an example of mapping some policies to run before a controller * 34 | * and its actions * 35 | * * 36 | ***************************************************************************/ 37 | // RabbitController: { 38 | 39 | // Apply the `false` policy as the default for all of RabbitController's actions 40 | // (`false` prevents all access, which ensures that nothing bad happens to our rabbits) 41 | // '*': false, 42 | 43 | // For the action `nurture`, apply the 'isRabbitMother' policy 44 | // (this overrides `false` above) 45 | // nurture : 'isRabbitMother', 46 | 47 | // Apply the `isNiceToAnimals` AND `hasRabbitFood` policies 48 | // before letting any users feed our rabbits 49 | // feed : ['isNiceToAnimals', 'hasRabbitFood'] 50 | // } 51 | }; 52 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-many-schemes-app/config/sequelize.js: -------------------------------------------------------------------------------- 1 | module.exports.sequelize = { 2 | 'clsNamespace' : 'myAppCLSNamespace', 3 | 'exposeToGlobal': true 4 | }; 5 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/.sailsrc: -------------------------------------------------------------------------------- 1 | { 2 | "generators": { 3 | "modules": {} 4 | }, 5 | "hooks": { 6 | "blueprints": false, 7 | "grunt": false, 8 | "sockets": false, 9 | "pubsub": false, 10 | "orm": false, 11 | "i18n": false 12 | }, 13 | "log": { 14 | "level": "info" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/api/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-migrate-safe-app/api/controllers/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/api/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-migrate-safe-app/api/models/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/api/models/Group.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Group.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | name: { 11 | type: Sequelize.STRING 12 | }, 13 | role: { 14 | type: Sequelize.ENUM('USER', 'ADMIN') 15 | } 16 | }, 17 | associations: function () { 18 | Group.hasMany(User, { as: 'users', foreignKey: 'groupId' }); 19 | }, 20 | defaultScope: function () { 21 | return { 22 | include: [ 23 | { model: User, as: 'users' } 24 | ] 25 | }; 26 | }, 27 | options : { 28 | freezeTableName : false, 29 | tableName : 'group', 30 | schema : 'sails', 31 | classMethods : {}, 32 | instanceMethods : {}, 33 | hooks : {} 34 | } 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/api/models/Image.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Image.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | url: { 11 | type: Sequelize.STRING 12 | } 13 | }, 14 | associations: function () { 15 | Image.belongsTo(User, { foreignKey: 'userId' }); 16 | }, 17 | options : { 18 | freezeTableName : false, 19 | tableName : 'image', 20 | schema : 'sails', 21 | classMethods : {}, 22 | instanceMethods : {}, 23 | hooks : {} 24 | } 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/api/models/User.js: -------------------------------------------------------------------------------- 1 | /** 2 | * User.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | name: { 11 | type: Sequelize.STRING 12 | }, 13 | age : { 14 | type: Sequelize.INTEGER 15 | } 16 | }, 17 | associations: function () { 18 | User.hasMany(Image, { as: 'images', foreignKey: 'userId' }); 19 | }, 20 | defaultScope: function () { 21 | return { 22 | include: [ 23 | { model: Image, as: 'images' } 24 | ] 25 | }; 26 | }, 27 | options : { 28 | freezeTableName : false, 29 | tableName : 'user', 30 | schema : 'sails', 31 | classMethods : {}, 32 | instanceMethods : {}, 33 | hooks : {} 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/api/policies/sessionAuth.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sessionAuth 3 | * 4 | * @module :: Policy 5 | * @description :: Simple policy to allow any authenticated user 6 | * Assumes that your login action in one of your controllers sets `req.session.authenticated = true;` 7 | * @docs :: http://sailsjs.org/#!/documentation/concepts/Policies 8 | * 9 | */ 10 | module.exports = function(req, res, next) { 11 | 12 | // User is allowed, proceed to the next policy, 13 | // or if this is the last policy, the controller 14 | if (req.session.authenticated) { 15 | return next(); 16 | } 17 | 18 | // User is not allowed 19 | // (default res.forbidden() behavior can be overridden in `config/403.js`) 20 | return res.forbidden('You are not permitted to perform this action.'); 21 | }; 22 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/api/responses/created.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 201 (CREATED) Response 3 | * 4 | * Usage: 5 | * return res.created(); 6 | * return res.created(data); 7 | * return res.created(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function created (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.created() :: Sending 201 ("CREATED") response'); 22 | 23 | // Set status code 24 | res.status(201); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'Created' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'Created' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/api/responses/ok.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 200 (OK) Response 3 | * 4 | * Usage: 5 | * return res.ok(); 6 | * return res.ok(data); 7 | * return res.ok(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function sendOK (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.ok() :: Sending 200 ("OK") response'); 22 | 23 | // Set status code 24 | res.status(200); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'OK' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'OK' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/api/services/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-migrate-safe-app/api/services/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/app.js: -------------------------------------------------------------------------------- 1 | /** 2 | * app.js 3 | * 4 | * Use `app.js` to run your app without `sails lift`. 5 | * To start the server, run: `node app.js`. 6 | * 7 | * This is handy in situations where the sails CLI is not relevant or useful. 8 | * 9 | * For example: 10 | * => `node app.js` 11 | * => `forever start app.js` 12 | * => `node debug app.js` 13 | * => `modulus deploy` 14 | * => `heroku scale` 15 | * 16 | * The same command-line arguments are supported, e.g.: 17 | * `node app.js --silent --port=80 --prod` 18 | * 19 | * For more information see: 20 | * https://sailsjs.com/anatomy/app.js 21 | */ 22 | 23 | 24 | // Ensure we're in the project directory, so cwd-relative paths work as expected 25 | // no matter where we actually lift from. 26 | // > Note: This is not required in order to lift, but it is a convenient default. 27 | process.chdir(__dirname); 28 | 29 | 30 | // Ensure a "sails" can be located: 31 | (function () { 32 | 33 | // Attempt to import `sails` dependency, as well as `rc` (for loading `.sailsrc` files). 34 | var sails; 35 | var rc; 36 | try { 37 | sails = require('sails'); 38 | rc = require('sails/accessible/rc'); 39 | } catch (e) { 40 | console.error('Encountered an error when attempting to require(\'sails\'):'); 41 | console.error(e.stack); 42 | console.error('--'); 43 | console.error( 44 | 'To run an app using `node app.js`, you usually need to have a version of `sails` installed in the same directory as your app.'); 45 | console.error('To do that, run `npm install sails`'); 46 | console.error(); 47 | console.error( 48 | 'Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.'); 49 | console.error( 50 | 'When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,'); 51 | console.error('but if it doesn\'t, the app will run with the global sails instead!'); 52 | return; 53 | }//-• 54 | 55 | // // Start server 56 | // sails.lift(rc('sails')); 57 | module.exports.sails = sails.Sails; 58 | 59 | }()); 60 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/config/bootstrap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Bootstrap 3 | * (sails.config.bootstrap) 4 | * 5 | * An asynchronous bootstrap function that runs before your Sails app gets lifted. 6 | * This gives you an opportunity to set up your data model, run jobs, or perform some special logic. 7 | * 8 | * For more information on bootstrapping your app, check out: 9 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.bootstrap.html 10 | */ 11 | 12 | module.exports.bootstrap = function(cb) { 13 | 14 | // It's very important to trigger this callback method when you are finished 15 | // with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap) 16 | cb(); 17 | }; 18 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/config/datastores.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Connections 3 | * (sails.config.connections) 4 | * 5 | * `Connections` are like "saved settings" for your adapters. What's the difference between 6 | * a connection and an adapter, you might ask? An adapter (e.g. `sails-mysql`) is generic-- 7 | * it needs some additional information to work (e.g. your database host, password, user, etc.) 8 | * A `connection` is that additional information. 9 | * 10 | * Each model must have a `connection` property (a string) which is references the name of one 11 | * of these connections. If it doesn't, the default `connection` configured in `config/models.js` 12 | * will be applied. Of course, a connection can (and usually is) shared by multiple models. 13 | * . 14 | * Note: If you're using version control, you should put your passwords/api keys 15 | * in `config/local.js`, environment variables, or use another strategy. 16 | * (this is to prevent you inadvertently sensitive credentials up to your repository.) 17 | * 18 | * For more information on configuration, check out: 19 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.connections.html 20 | */ 21 | 22 | module.exports.datastores = { 23 | 24 | default: { 25 | url: 'postgres://postgres@localhost:5432/sequelize', 26 | options: { 27 | logging: false 28 | }, 29 | dialect: 'postgres' 30 | } 31 | 32 | }; 33 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/config/log.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Built-in Log Configuration 3 | * (sails.config.log) 4 | * 5 | * Configure the log level for your app, as well as the transport 6 | * (Underneath the covers, Sails uses Winston for logging, which 7 | * allows for some pretty neat custom transports/adapters for log messages) 8 | * 9 | * For more information on the Sails logger, check out: 10 | * http://sailsjs.org/#!/documentation/concepts/Logging 11 | */ 12 | 13 | module.exports.log = { 14 | 15 | /*************************************************************************** 16 | * * 17 | * Valid `level` configs: i.e. the minimum log level to capture with * 18 | * sails.log.*() * 19 | * * 20 | * The order of precedence for log levels from lowest to highest is: * 21 | * silly, verbose, info, debug, warn, error * 22 | * * 23 | * You may also set the level to "silent" to suppress all logs. * 24 | * * 25 | ***************************************************************************/ 26 | 27 | // level: 'info' 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/config/models.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Default model configuration 3 | * (sails.config.models) 4 | * 5 | * Unless you override them, the following properties will be included 6 | * in each of your models. 7 | * 8 | * For more info on Sails models, see: 9 | * http://sailsjs.org/#!/documentation/concepts/ORM 10 | */ 11 | 12 | module.exports.models = { 13 | 14 | migrate: 'safe' 15 | 16 | }; 17 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/config/policies.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Policy Mappings 3 | * (sails.config.policies) 4 | * 5 | * Policies are simple functions which run **before** your controllers. 6 | * You can apply one or more policies to a given controller, or protect 7 | * its actions individually. 8 | * 9 | * Any policy file (e.g. `api/policies/authenticated.js`) can be accessed 10 | * below by its filename, minus the extension, (e.g. "authenticated") 11 | * 12 | * For more information on how policies work, see: 13 | * http://sailsjs.org/#!/documentation/concepts/Policies 14 | * 15 | * For more information on configuring policies, check out: 16 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.policies.html 17 | */ 18 | 19 | 20 | module.exports.policies = { 21 | 22 | /*************************************************************************** 23 | * * 24 | * Default policy for all controllers and actions (`true` allows public * 25 | * access) * 26 | * * 27 | ***************************************************************************/ 28 | 29 | // '*': true, 30 | 31 | /*************************************************************************** 32 | * * 33 | * Here's an example of mapping some policies to run before a controller * 34 | * and its actions * 35 | * * 36 | ***************************************************************************/ 37 | // RabbitController: { 38 | 39 | // Apply the `false` policy as the default for all of RabbitController's actions 40 | // (`false` prevents all access, which ensures that nothing bad happens to our rabbits) 41 | // '*': false, 42 | 43 | // For the action `nurture`, apply the 'isRabbitMother' policy 44 | // (this overrides `false` above) 45 | // nurture : 'isRabbitMother', 46 | 47 | // Apply the `isNiceToAnimals` AND `hasRabbitFood` policies 48 | // before letting any users feed our rabbits 49 | // feed : ['isNiceToAnimals', 'hasRabbitFood'] 50 | // } 51 | }; 52 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-migrate-safe-app/config/sequelize.js: -------------------------------------------------------------------------------- 1 | module.exports.sequelize = { 2 | 'clsNamespace' : 'myAppCLSNamespace', 3 | 'exposeToGlobal': true 4 | }; 5 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/.sailsrc: -------------------------------------------------------------------------------- 1 | { 2 | "generators": { 3 | "modules": {} 4 | }, 5 | "hooks": { 6 | "blueprints": false, 7 | "grunt": false, 8 | "sockets": false, 9 | "pubsub": false, 10 | "orm": false, 11 | "i18n": false 12 | }, 13 | "log": { 14 | "level": "info" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/api/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-no-conn-app/api/controllers/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/api/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-no-conn-app/api/models/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/api/models/Group.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Group.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | name: { 11 | type: Sequelize.STRING 12 | }, 13 | role: { 14 | type: Sequelize.ENUM('USER', 'ADMIN') 15 | } 16 | }, 17 | associations: function () { 18 | Group.hasMany(User, { as: 'users', foreignKey: 'groupId' }); 19 | }, 20 | defaultScope: function () { 21 | return { 22 | include: [ 23 | { model: User, as: 'users' } 24 | ] 25 | }; 26 | }, 27 | options : { 28 | freezeTableName : false, 29 | tableName : 'group', 30 | schema : 'sails', 31 | classMethods : {}, 32 | instanceMethods : {}, 33 | hooks : {} 34 | } 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/api/models/Image.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Image.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | url: { 11 | type: Sequelize.STRING 12 | } 13 | }, 14 | associations: function () { 15 | Image.belongsTo(User, { foreignKey: 'userId' }); 16 | }, 17 | options : { 18 | freezeTableName : false, 19 | tableName : 'image', 20 | schema : 'sails', 21 | classMethods : {}, 22 | instanceMethods : {}, 23 | hooks : {} 24 | } 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/api/models/User.js: -------------------------------------------------------------------------------- 1 | /** 2 | * User.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | name: { 11 | type: Sequelize.STRING 12 | }, 13 | age : { 14 | type: Sequelize.INTEGER 15 | } 16 | }, 17 | associations: function () { 18 | User.hasMany(Image, { as: 'images', foreignKey: 'userId' }); 19 | }, 20 | defaultScope: function () { 21 | return { 22 | include: [ 23 | { model: Image, as: 'images' } 24 | ] 25 | }; 26 | }, 27 | options : { 28 | freezeTableName : false, 29 | tableName : 'user', 30 | schema : 'sails', 31 | classMethods : {}, 32 | instanceMethods : {}, 33 | hooks : {} 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/api/policies/sessionAuth.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sessionAuth 3 | * 4 | * @module :: Policy 5 | * @description :: Simple policy to allow any authenticated user 6 | * Assumes that your login action in one of your controllers sets `req.session.authenticated = true;` 7 | * @docs :: http://sailsjs.org/#!/documentation/concepts/Policies 8 | * 9 | */ 10 | module.exports = function(req, res, next) { 11 | 12 | // User is allowed, proceed to the next policy, 13 | // or if this is the last policy, the controller 14 | if (req.session.authenticated) { 15 | return next(); 16 | } 17 | 18 | // User is not allowed 19 | // (default res.forbidden() behavior can be overridden in `config/403.js`) 20 | return res.forbidden('You are not permitted to perform this action.'); 21 | }; 22 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/api/responses/badRequest.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 400 (Bad Request) Handler 3 | * 4 | * Usage: 5 | * return res.badRequest(); 6 | * return res.badRequest(data); 7 | * return res.badRequest(data, 'some/specific/badRequest/view'); 8 | * 9 | * e.g.: 10 | * ``` 11 | * return res.badRequest( 12 | * 'Please choose a valid `password` (6-12 characters)', 13 | * 'trial/signup' 14 | * ); 15 | * ``` 16 | */ 17 | 18 | module.exports = function badRequest(data, options) { 19 | 20 | // Get access to `req`, `res`, & `sails` 21 | var req = this.req; 22 | var res = this.res; 23 | var sails = req._sails; 24 | 25 | // Set status code 26 | res.status(400); 27 | 28 | // Log error to console 29 | if (data !== undefined) { 30 | sails.log.verbose('Sending 400 ("Bad Request") response: \n',data); 31 | } 32 | else sails.log.verbose('Sending 400 ("Bad Request") response'); 33 | 34 | // Only include errors in response if application environment 35 | // is not set to 'production'. In production, we shouldn't 36 | // send back any identifying information about errors. 37 | if (sails.config.environment === 'production' && sails.config.keepResponseErrors !== true) { 38 | data = undefined; 39 | } 40 | 41 | // If the user-agent wants JSON, always respond with JSON 42 | // If views are disabled, revert to json 43 | if (req.wantsJSON || sails.config.hooks.views === false) { 44 | return res.jsonx(data); 45 | } 46 | 47 | // If second argument is a string, we take that to mean it refers to a view. 48 | // If it was omitted, use an empty object (`{}`) 49 | options = (typeof options === 'string') ? { view: options } : options || {}; 50 | 51 | // Attempt to prettify data for views, if it's a non-error object 52 | var viewData = data; 53 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 54 | try { 55 | viewData = require('util').inspect(data, {depth: null}); 56 | } 57 | catch(e) { 58 | viewData = undefined; 59 | } 60 | } 61 | 62 | // If a view was provided in options, serve it. 63 | // Otherwise try to guess an appropriate view, or if that doesn't 64 | // work, just send JSON. 65 | if (options.view) { 66 | return res.view(options.view, { data: viewData, title: 'Bad Request' }); 67 | } 68 | 69 | // If no second argument provided, try to serve the implied view, 70 | // but fall back to sending JSON(P) if no view can be inferred. 71 | else return res.guessView({ data: viewData, title: 'Bad Request' }, function couldNotGuessView () { 72 | return res.jsonx(data); 73 | }); 74 | 75 | }; 76 | 77 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/api/responses/created.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 201 (CREATED) Response 3 | * 4 | * Usage: 5 | * return res.created(); 6 | * return res.created(data); 7 | * return res.created(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function created (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.created() :: Sending 201 ("CREATED") response'); 22 | 23 | // Set status code 24 | res.status(201); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'Created' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'Created' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/api/responses/ok.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 200 (OK) Response 3 | * 4 | * Usage: 5 | * return res.ok(); 6 | * return res.ok(data); 7 | * return res.ok(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function sendOK (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.ok() :: Sending 200 ("OK") response'); 22 | 23 | // Set status code 24 | res.status(200); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'OK' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'OK' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/api/services/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-no-conn-app/api/services/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/app.js: -------------------------------------------------------------------------------- 1 | /** 2 | * app.js 3 | * 4 | * Use `app.js` to run your app without `sails lift`. 5 | * To start the server, run: `node app.js`. 6 | * 7 | * This is handy in situations where the sails CLI is not relevant or useful. 8 | * 9 | * For example: 10 | * => `node app.js` 11 | * => `forever start app.js` 12 | * => `node debug app.js` 13 | * => `modulus deploy` 14 | * => `heroku scale` 15 | * 16 | * The same command-line arguments are supported, e.g.: 17 | * `node app.js --silent --port=80 --prod` 18 | * 19 | * For more information see: 20 | * https://sailsjs.com/anatomy/app.js 21 | */ 22 | 23 | 24 | // Ensure we're in the project directory, so cwd-relative paths work as expected 25 | // no matter where we actually lift from. 26 | // > Note: This is not required in order to lift, but it is a convenient default. 27 | process.chdir(__dirname); 28 | 29 | 30 | // Ensure a "sails" can be located: 31 | (function () { 32 | 33 | // Attempt to import `sails` dependency, as well as `rc` (for loading `.sailsrc` files). 34 | var sails; 35 | var rc; 36 | try { 37 | sails = require('sails'); 38 | rc = require('sails/accessible/rc'); 39 | } catch (e) { 40 | console.error('Encountered an error when attempting to require(\'sails\'):'); 41 | console.error(e.stack); 42 | console.error('--'); 43 | console.error( 44 | 'To run an app using `node app.js`, you usually need to have a version of `sails` installed in the same directory as your app.'); 45 | console.error('To do that, run `npm install sails`'); 46 | console.error(); 47 | console.error( 48 | 'Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.'); 49 | console.error( 50 | 'When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,'); 51 | console.error('but if it doesn\'t, the app will run with the global sails instead!'); 52 | return; 53 | }//-• 54 | 55 | // // Start server 56 | // sails.lift(rc('sails')); 57 | module.exports.sails = sails.Sails; 58 | 59 | }()); 60 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/config/bootstrap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Bootstrap 3 | * (sails.config.bootstrap) 4 | * 5 | * An asynchronous bootstrap function that runs before your Sails app gets lifted. 6 | * This gives you an opportunity to set up your data model, run jobs, or perform some special logic. 7 | * 8 | * For more information on bootstrapping your app, check out: 9 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.bootstrap.html 10 | */ 11 | 12 | module.exports.bootstrap = function(cb) { 13 | 14 | // It's very important to trigger this callback method when you are finished 15 | // with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap) 16 | cb(); 17 | }; 18 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/config/datastores.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Connections 3 | * (sails.config.connections) 4 | * 5 | * `Connections` are like "saved settings" for your adapters. What's the difference between 6 | * a connection and an adapter, you might ask? An adapter (e.g. `sails-mysql`) is generic-- 7 | * it needs some additional information to work (e.g. your database host, password, user, etc.) 8 | * A `connection` is that additional information. 9 | * 10 | * Each model must have a `connection` property (a string) which is references the name of one 11 | * of these connections. If it doesn't, the default `connection` configured in `config/models.js` 12 | * will be applied. Of course, a connection can (and usually is) shared by multiple models. 13 | * . 14 | * Note: If you're using version control, you should put your passwords/api keys 15 | * in `config/local.js`, environment variables, or use another strategy. 16 | * (this is to prevent you inadvertently sensitive credentials up to your repository.) 17 | * 18 | * For more information on configuration, check out: 19 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.connections.html 20 | */ 21 | 22 | module.exports.datastores = { 23 | 24 | // No connection specified 25 | // default: { 26 | // database: 'db.sqlite', 27 | // options: { 28 | // dialect: 'sqlite', 29 | // storage: 'db/sequelize.sqlite' 30 | // } 31 | // } 32 | 33 | }; 34 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/config/log.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Built-in Log Configuration 3 | * (sails.config.log) 4 | * 5 | * Configure the log level for your app, as well as the transport 6 | * (Underneath the covers, Sails uses Winston for logging, which 7 | * allows for some pretty neat custom transports/adapters for log messages) 8 | * 9 | * For more information on the Sails logger, check out: 10 | * http://sailsjs.org/#!/documentation/concepts/Logging 11 | */ 12 | 13 | module.exports.log = { 14 | 15 | /*************************************************************************** 16 | * * 17 | * Valid `level` configs: i.e. the minimum log level to capture with * 18 | * sails.log.*() * 19 | * * 20 | * The order of precedence for log levels from lowest to highest is: * 21 | * silly, verbose, info, debug, warn, error * 22 | * * 23 | * You may also set the level to "silent" to suppress all logs. * 24 | * * 25 | ***************************************************************************/ 26 | 27 | // level: 'info' 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/config/models.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Default model configuration 3 | * (sails.config.models) 4 | * 5 | * Unless you override them, the following properties will be included 6 | * in each of your models. 7 | * 8 | * For more info on Sails models, see: 9 | * http://sailsjs.org/#!/documentation/concepts/ORM 10 | */ 11 | 12 | module.exports.models = { 13 | 14 | migrate: 'drop' 15 | 16 | }; 17 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/config/policies.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Policy Mappings 3 | * (sails.config.policies) 4 | * 5 | * Policies are simple functions which run **before** your controllers. 6 | * You can apply one or more policies to a given controller, or protect 7 | * its actions individually. 8 | * 9 | * Any policy file (e.g. `api/policies/authenticated.js`) can be accessed 10 | * below by its filename, minus the extension, (e.g. "authenticated") 11 | * 12 | * For more information on how policies work, see: 13 | * http://sailsjs.org/#!/documentation/concepts/Policies 14 | * 15 | * For more information on configuring policies, check out: 16 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.policies.html 17 | */ 18 | 19 | 20 | module.exports.policies = { 21 | 22 | /*************************************************************************** 23 | * * 24 | * Default policy for all controllers and actions (`true` allows public * 25 | * access) * 26 | * * 27 | ***************************************************************************/ 28 | 29 | // '*': true, 30 | 31 | /*************************************************************************** 32 | * * 33 | * Here's an example of mapping some policies to run before a controller * 34 | * and its actions * 35 | * * 36 | ***************************************************************************/ 37 | // RabbitController: { 38 | 39 | // Apply the `false` policy as the default for all of RabbitController's actions 40 | // (`false` prevents all access, which ensures that nothing bad happens to our rabbits) 41 | // '*': false, 42 | 43 | // For the action `nurture`, apply the 'isRabbitMother' policy 44 | // (this overrides `false` above) 45 | // nurture : 'isRabbitMother', 46 | 47 | // Apply the `isNiceToAnimals` AND `hasRabbitFood` policies 48 | // before letting any users feed our rabbits 49 | // feed : ['isNiceToAnimals', 'hasRabbitFood'] 50 | // } 51 | }; 52 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/config/sequelize.js: -------------------------------------------------------------------------------- 1 | module.exports.sequelize = { 2 | 'clsNamespace' : 'myAppCLSNamespace', 3 | 'exposeToGlobal': true 4 | }; 5 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-no-conn-app/db/sequelize.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-no-conn-app/db/sequelize.sqlite -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/.sailsrc: -------------------------------------------------------------------------------- 1 | { 2 | "generators": { 3 | "modules": {} 4 | }, 5 | "hooks": { 6 | "blueprints": false, 7 | "grunt": false, 8 | "sockets": false, 9 | "pubsub": false, 10 | "orm": false, 11 | "i18n": false 12 | }, 13 | "log": { 14 | "level": "info" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/api/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-sequelize-waterline-app/api/controllers/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/api/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-sequelize-waterline-app/api/models/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/api/models/Good.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Image.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | connection: 'memory', 10 | attributes: { 11 | name : { 12 | type : 'string' 13 | }, 14 | goodId: { 15 | type : 'integer', 16 | autoIncrement: true 17 | } 18 | } 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/api/models/Group.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Group.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | connection: 'sqlite', 10 | attributes : { 11 | name: { 12 | type: Sequelize.STRING 13 | }, 14 | role: { 15 | type: Sequelize.ENUM('USER', 'ADMIN') 16 | } 17 | }, 18 | associations: function () { 19 | Group.hasMany(User, { as: 'users', foreignKey: 'groupId' }); 20 | }, 21 | defaultScope: function () { 22 | return { 23 | include: [ 24 | { model: User, as: 'users' } 25 | ] 26 | }; 27 | }, 28 | options : { 29 | freezeTableName : false, 30 | tableName : 'group', 31 | classMethods : {}, 32 | instanceMethods : {}, 33 | hooks : {} 34 | } 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/api/models/Image.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Image.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | connection: 'sqlite', 10 | attributes : { 11 | url: { 12 | type: Sequelize.STRING 13 | } 14 | }, 15 | associations: function () { 16 | Image.belongsTo(User, { foreignKey: 'userId' }); 17 | }, 18 | options : { 19 | freezeTableName : false, 20 | tableName : 'image', 21 | classMethods : {}, 22 | instanceMethods : {}, 23 | hooks : {} 24 | } 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/api/models/User.js: -------------------------------------------------------------------------------- 1 | /** 2 | * User.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | connection: 'sqlite', 10 | attributes : { 11 | name: { 12 | type: Sequelize.STRING 13 | }, 14 | age : { 15 | type: Sequelize.INTEGER 16 | } 17 | }, 18 | associations: function () { 19 | User.hasMany(Image, { as: 'images', foreignKey: 'userId' }); 20 | }, 21 | defaultScope: function () { 22 | return { 23 | include: [ 24 | { model: Image, as: 'images' } 25 | ] 26 | }; 27 | }, 28 | options : { 29 | freezeTableName : false, 30 | tableName : 'user', 31 | classMethods : {}, 32 | instanceMethods : {}, 33 | hooks : {} 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/api/policies/sessionAuth.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sessionAuth 3 | * 4 | * @module :: Policy 5 | * @description :: Simple policy to allow any authenticated user 6 | * Assumes that your login action in one of your controllers sets `req.session.authenticated = true;` 7 | * @docs :: http://sailsjs.org/#!/documentation/concepts/Policies 8 | * 9 | */ 10 | module.exports = function(req, res, next) { 11 | 12 | // User is allowed, proceed to the next policy, 13 | // or if this is the last policy, the controller 14 | if (req.session.authenticated) { 15 | return next(); 16 | } 17 | 18 | // User is not allowed 19 | // (default res.forbidden() behavior can be overridden in `config/403.js`) 20 | return res.forbidden('You are not permitted to perform this action.'); 21 | }; 22 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/api/responses/created.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 201 (CREATED) Response 3 | * 4 | * Usage: 5 | * return res.created(); 6 | * return res.created(data); 7 | * return res.created(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function created (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.created() :: Sending 201 ("CREATED") response'); 22 | 23 | // Set status code 24 | res.status(201); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'Created' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'Created' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/api/responses/ok.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 200 (OK) Response 3 | * 4 | * Usage: 5 | * return res.ok(); 6 | * return res.ok(data); 7 | * return res.ok(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function sendOK (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.ok() :: Sending 200 ("OK") response'); 22 | 23 | // Set status code 24 | res.status(200); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'OK' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'OK' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/api/services/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-sequelize-waterline-app/api/services/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/app.js: -------------------------------------------------------------------------------- 1 | /** 2 | * app.js 3 | * 4 | * Use `app.js` to run your app without `sails lift`. 5 | * To start the server, run: `node app.js`. 6 | * 7 | * This is handy in situations where the sails CLI is not relevant or useful. 8 | * 9 | * For example: 10 | * => `node app.js` 11 | * => `forever start app.js` 12 | * => `node debug app.js` 13 | * => `modulus deploy` 14 | * => `heroku scale` 15 | * 16 | * The same command-line arguments are supported, e.g.: 17 | * `node app.js --silent --port=80 --prod` 18 | * 19 | * For more information see: 20 | * https://sailsjs.com/anatomy/app.js 21 | */ 22 | 23 | 24 | // Ensure we're in the project directory, so cwd-relative paths work as expected 25 | // no matter where we actually lift from. 26 | // > Note: This is not required in order to lift, but it is a convenient default. 27 | process.chdir(__dirname); 28 | 29 | 30 | // Ensure a "sails" can be located: 31 | (function () { 32 | 33 | // Attempt to import `sails` dependency, as well as `rc` (for loading `.sailsrc` files). 34 | var sails; 35 | var rc; 36 | try { 37 | sails = require('sails'); 38 | rc = require('sails/accessible/rc'); 39 | } catch (e) { 40 | console.error('Encountered an error when attempting to require(\'sails\'):'); 41 | console.error(e.stack); 42 | console.error('--'); 43 | console.error( 44 | 'To run an app using `node app.js`, you usually need to have a version of `sails` installed in the same directory as your app.'); 45 | console.error('To do that, run `npm install sails`'); 46 | console.error(); 47 | console.error( 48 | 'Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.'); 49 | console.error( 50 | 'When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,'); 51 | console.error('but if it doesn\'t, the app will run with the global sails instead!'); 52 | return; 53 | }//-• 54 | 55 | // // Start server 56 | // sails.lift(rc('sails')); 57 | module.exports.sails = sails.Sails; 58 | 59 | }()); 60 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/config/bootstrap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Bootstrap 3 | * (sails.config.bootstrap) 4 | * 5 | * An asynchronous bootstrap function that runs before your Sails app gets lifted. 6 | * This gives you an opportunity to set up your data model, run jobs, or perform some special logic. 7 | * 8 | * For more information on bootstrapping your app, check out: 9 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.bootstrap.html 10 | */ 11 | 12 | module.exports.bootstrap = function(cb) { 13 | 14 | // It's very important to trigger this callback method when you are finished 15 | // with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap) 16 | cb(); 17 | }; 18 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/config/datastores.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Connections 3 | * (sails.config.connections) 4 | * 5 | * `Connections` are like "saved settings" for your adapters. What's the difference between 6 | * a connection and an adapter, you might ask? An adapter (e.g. `sails-mysql`) is generic-- 7 | * it needs some additional information to work (e.g. your database host, password, user, etc.) 8 | * A `connection` is that additional information. 9 | * 10 | * Each model must have a `connection` property (a string) which is references the name of one 11 | * of these connections. If it doesn't, the default `connection` configured in `config/models.js` 12 | * will be applied. Of course, a connection can (and usually is) shared by multiple models. 13 | * . 14 | * Note: If you're using version control, you should put your passwords/api keys 15 | * in `config/local.js`, environment variables, or use another strategy. 16 | * (this is to prevent you inadvertently sensitive credentials up to your repository.) 17 | * 18 | * For more information on configuration, check out: 19 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.connections.html 20 | */ 21 | 22 | module.exports.datastores = { 23 | 24 | sqlite: { 25 | database: 'db.sqlite', 26 | options: { 27 | dialect: 'sqlite', 28 | storage: 'db/sequelize.sqlite', 29 | logging: false 30 | } 31 | }, 32 | memory: { 33 | adapter: 'sails-memory' 34 | } 35 | 36 | }; 37 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/config/log.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Built-in Log Configuration 3 | * (sails.config.log) 4 | * 5 | * Configure the log level for your app, as well as the transport 6 | * (Underneath the covers, Sails uses Winston for logging, which 7 | * allows for some pretty neat custom transports/adapters for log messages) 8 | * 9 | * For more information on the Sails logger, check out: 10 | * http://sailsjs.org/#!/documentation/concepts/Logging 11 | */ 12 | 13 | module.exports.log = { 14 | 15 | /*************************************************************************** 16 | * * 17 | * Valid `level` configs: i.e. the minimum log level to capture with * 18 | * sails.log.*() * 19 | * * 20 | * The order of precedence for log levels from lowest to highest is: * 21 | * silly, verbose, info, debug, warn, error * 22 | * * 23 | * You may also set the level to "silent" to suppress all logs. * 24 | * * 25 | ***************************************************************************/ 26 | 27 | // level: 'info' 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/config/models.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Default model configuration 3 | * (sails.config.models) 4 | * 5 | * Unless you override them, the following properties will be included 6 | * in each of your models. 7 | * 8 | * For more info on Sails models, see: 9 | * http://sailsjs.org/#!/documentation/concepts/ORM 10 | */ 11 | 12 | module.exports.models = { 13 | 14 | connection: 'memory', 15 | migrate: 'drop' 16 | 17 | }; 18 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/config/policies.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Policy Mappings 3 | * (sails.config.policies) 4 | * 5 | * Policies are simple functions which run **before** your controllers. 6 | * You can apply one or more policies to a given controller, or protect 7 | * its actions individually. 8 | * 9 | * Any policy file (e.g. `api/policies/authenticated.js`) can be accessed 10 | * below by its filename, minus the extension, (e.g. "authenticated") 11 | * 12 | * For more information on how policies work, see: 13 | * http://sailsjs.org/#!/documentation/concepts/Policies 14 | * 15 | * For more information on configuring policies, check out: 16 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.policies.html 17 | */ 18 | 19 | 20 | module.exports.policies = { 21 | 22 | /*************************************************************************** 23 | * * 24 | * Default policy for all controllers and actions (`true` allows public * 25 | * access) * 26 | * * 27 | ***************************************************************************/ 28 | 29 | // '*': true, 30 | 31 | /*************************************************************************** 32 | * * 33 | * Here's an example of mapping some policies to run before a controller * 34 | * and its actions * 35 | * * 36 | ***************************************************************************/ 37 | // RabbitController: { 38 | 39 | // Apply the `false` policy as the default for all of RabbitController's actions 40 | // (`false` prevents all access, which ensures that nothing bad happens to our rabbits) 41 | // '*': false, 42 | 43 | // For the action `nurture`, apply the 'isRabbitMother' policy 44 | // (this overrides `false` above) 45 | // nurture : 'isRabbitMother', 46 | 47 | // Apply the `isNiceToAnimals` AND `hasRabbitFood` policies 48 | // before letting any users feed our rabbits 49 | // feed : ['isNiceToAnimals', 'hasRabbitFood'] 50 | // } 51 | }; 52 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/config/sequelize.js: -------------------------------------------------------------------------------- 1 | module.exports.sequelize = { 2 | 'clsNamespace' : 'myAppCLSNamespace', 3 | 'exposeToGlobal': true 4 | }; 5 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sequelize-waterline-app/db/sequelize.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-sequelize-waterline-app/db/sequelize.sqlite -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/.sailsrc: -------------------------------------------------------------------------------- 1 | { 2 | "generators": { 3 | "modules": {} 4 | }, 5 | "hooks": { 6 | "blueprints": false, 7 | "grunt": false, 8 | "sockets": false, 9 | "pubsub": false, 10 | "orm": false, 11 | "i18n": false 12 | }, 13 | "log": { 14 | "level": "info" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/api/controllers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-sqlite3-app/api/controllers/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/api/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-sqlite3-app/api/models/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/api/models/Group.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Group.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | name: { 11 | type: Sequelize.STRING 12 | }, 13 | role: { 14 | type: Sequelize.ENUM('USER', 'ADMIN') 15 | } 16 | }, 17 | associations: function () { 18 | Group.hasMany(User, { as: 'users', foreignKey: 'groupId' }); 19 | }, 20 | defaultScope: function () { 21 | return { 22 | include: [ 23 | { model: User, as: 'users' } 24 | ] 25 | }; 26 | }, 27 | options : { 28 | freezeTableName : false, 29 | tableName : 'group', 30 | classMethods : {}, 31 | instanceMethods : {}, 32 | hooks : {} 33 | } 34 | }; 35 | 36 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/api/models/Image.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Image.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | url: { 11 | type: Sequelize.STRING 12 | } 13 | }, 14 | associations: function () { 15 | Image.belongsTo(User, { foreignKey: 'userId' }); 16 | }, 17 | options : { 18 | freezeTableName : false, 19 | tableName : 'image', 20 | classMethods : {}, 21 | instanceMethods : {}, 22 | hooks : {} 23 | } 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/api/models/User.js: -------------------------------------------------------------------------------- 1 | /** 2 | * User.js 3 | * 4 | * @description :: TODO: You might write a short summary of how this model works and what it represents here. 5 | * @docs :: http://sailsjs.org/#!documentation/models 6 | */ 7 | 8 | module.exports = { 9 | attributes : { 10 | name: { 11 | type: Sequelize.STRING 12 | }, 13 | age : { 14 | type: Sequelize.INTEGER 15 | } 16 | }, 17 | associations: function () { 18 | User.hasMany(Image, { as: 'images', foreignKey: 'userId' }); 19 | }, 20 | defaultScope: function () { 21 | return { 22 | include: [ 23 | { model: Image, as: 'images' } 24 | ] 25 | }; 26 | }, 27 | options : { 28 | freezeTableName : false, 29 | tableName : 'user', 30 | classMethods : {}, 31 | instanceMethods : {}, 32 | hooks : {} 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/api/policies/sessionAuth.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sessionAuth 3 | * 4 | * @module :: Policy 5 | * @description :: Simple policy to allow any authenticated user 6 | * Assumes that your login action in one of your controllers sets `req.session.authenticated = true;` 7 | * @docs :: http://sailsjs.org/#!/documentation/concepts/Policies 8 | * 9 | */ 10 | module.exports = function(req, res, next) { 11 | 12 | // User is allowed, proceed to the next policy, 13 | // or if this is the last policy, the controller 14 | if (req.session.authenticated) { 15 | return next(); 16 | } 17 | 18 | // User is not allowed 19 | // (default res.forbidden() behavior can be overridden in `config/403.js`) 20 | return res.forbidden('You are not permitted to perform this action.'); 21 | }; 22 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/api/responses/created.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 201 (CREATED) Response 3 | * 4 | * Usage: 5 | * return res.created(); 6 | * return res.created(data); 7 | * return res.created(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function created (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.created() :: Sending 201 ("CREATED") response'); 22 | 23 | // Set status code 24 | res.status(201); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'Created' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'Created' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/api/responses/ok.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 200 (OK) Response 3 | * 4 | * Usage: 5 | * return res.ok(); 6 | * return res.ok(data); 7 | * return res.ok(data, 'auth/login'); 8 | * 9 | * @param {Object} data 10 | * @param {String|Object} options 11 | * - pass string to render specified view 12 | */ 13 | 14 | module.exports = function sendOK (data, options) { 15 | 16 | // Get access to `req`, `res`, & `sails` 17 | var req = this.req; 18 | var res = this.res; 19 | var sails = req._sails; 20 | 21 | sails.log.silly('res.ok() :: Sending 200 ("OK") response'); 22 | 23 | // Set status code 24 | res.status(200); 25 | 26 | // If appropriate, serve data as JSON(P) 27 | // If views are disabled, revert to json 28 | if (req.wantsJSON || sails.config.hooks.views === false) { 29 | return res.jsonx(data); 30 | } 31 | 32 | // If second argument is a string, we take that to mean it refers to a view. 33 | // If it was omitted, use an empty object (`{}`) 34 | options = (typeof options === 'string') ? { view: options } : options || {}; 35 | 36 | // Attempt to prettify data for views, if it's a non-error object 37 | var viewData = data; 38 | if (!(viewData instanceof Error) && 'object' == typeof viewData) { 39 | try { 40 | viewData = require('util').inspect(data, {depth: null}); 41 | } 42 | catch(e) { 43 | viewData = undefined; 44 | } 45 | } 46 | 47 | // If a view was provided in options, serve it. 48 | // Otherwise try to guess an appropriate view, or if that doesn't 49 | // work, just send JSON. 50 | if (options.view) { 51 | return res.view(options.view, { data: viewData, title: 'OK' }); 52 | } 53 | 54 | // If no second argument provided, try to serve the implied view, 55 | // but fall back to sending JSON(P) if no view can be inferred. 56 | else return res.guessView({ data: viewData, title: 'OK' }, function couldNotGuessView () { 57 | return res.jsonx(data); 58 | }); 59 | 60 | }; 61 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/api/services/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-sqlite3-app/api/services/.gitkeep -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/app.js: -------------------------------------------------------------------------------- 1 | /** 2 | * app.js 3 | * 4 | * Use `app.js` to run your app without `sails lift`. 5 | * To start the server, run: `node app.js`. 6 | * 7 | * This is handy in situations where the sails CLI is not relevant or useful. 8 | * 9 | * For example: 10 | * => `node app.js` 11 | * => `forever start app.js` 12 | * => `node debug app.js` 13 | * => `modulus deploy` 14 | * => `heroku scale` 15 | * 16 | * 17 | * The same command-line arguments are supported, e.g.: 18 | * `node app.js --silent --port=80 --prod` 19 | */ 20 | 21 | 22 | // Ensure we're in the project directory, so cwd-relative paths work as expected 23 | // no matter where we actually lift from. 24 | // > Note: This is not required in order to lift, but it is a convenient default. 25 | process.chdir(__dirname); 26 | 27 | // Ensure a "sails" can be located: 28 | (function () { 29 | 30 | // Attempt to import `sails`. 31 | var sails; 32 | try { 33 | sails = require('sails'); 34 | } catch (e) { 35 | console.error( 36 | 'To run an app using `node app.js`, you usually need to have a version of `sails` installed in the same directory as your app.'); 37 | console.error('To do that, run `npm install sails`'); 38 | console.error(''); 39 | console.error( 40 | 'Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.'); 41 | console.error( 42 | 'When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,'); 43 | console.error('but if it doesn\'t, the app will run with the global sails instead!'); 44 | return; 45 | } 46 | 47 | // --• 48 | // Try to get `rc` dependency (for loading `.sailsrc` files). 49 | // var rc; 50 | // try { 51 | // rc = require('rc'); 52 | // } catch (e0) { 53 | // try { 54 | // rc = require('sails/node_modules/rc'); 55 | // } catch (e1) { 56 | // console.error('Could not find dependency: `rc`.'); 57 | // console.error('Your `.sailsrc` file(s) will be ignored.'); 58 | // console.error('To resolve this, run:'); 59 | // console.error('npm install rc --save'); 60 | // rc = function () { 61 | // return {}; 62 | // }; 63 | // } 64 | // } 65 | 66 | // // Start server 67 | // sails.lift(rc('sails')); 68 | module.exports.sails = sails.Sails; 69 | 70 | }()); 71 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/config/bootstrap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Bootstrap 3 | * (sails.config.bootstrap) 4 | * 5 | * An asynchronous bootstrap function that runs before your Sails app gets lifted. 6 | * This gives you an opportunity to set up your data model, run jobs, or perform some special logic. 7 | * 8 | * For more information on bootstrapping your app, check out: 9 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.bootstrap.html 10 | */ 11 | 12 | module.exports.bootstrap = function(cb) { 13 | 14 | // It's very important to trigger this callback method when you are finished 15 | // with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap) 16 | cb(); 17 | }; 18 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/config/datastores.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Connections 3 | * (sails.config.connections) 4 | * 5 | * `Connections` are like "saved settings" for your adapters. What's the difference between 6 | * a connection and an adapter, you might ask? An adapter (e.g. `sails-mysql`) is generic-- 7 | * it needs some additional information to work (e.g. your database host, password, user, etc.) 8 | * A `connection` is that additional information. 9 | * 10 | * Each model must have a `connection` property (a string) which is references the name of one 11 | * of these connections. If it doesn't, the default `connection` configured in `config/models.js` 12 | * will be applied. Of course, a connection can (and usually is) shared by multiple models. 13 | * . 14 | * Note: If you're using version control, you should put your passwords/api keys 15 | * in `config/local.js`, environment variables, or use another strategy. 16 | * (this is to prevent you inadvertently sensitive credentials up to your repository.) 17 | * 18 | * For more information on configuration, check out: 19 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.connections.html 20 | */ 21 | 22 | module.exports.datastores = { 23 | 24 | default: { 25 | database: 'db.sqlite', 26 | options: { 27 | dialect: 'sqlite', 28 | storage: 'db/sequelize.sqlite', 29 | logging: false 30 | } 31 | } 32 | 33 | }; 34 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/config/log.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Built-in Log Configuration 3 | * (sails.config.log) 4 | * 5 | * Configure the log level for your app, as well as the transport 6 | * (Underneath the covers, Sails uses Winston for logging, which 7 | * allows for some pretty neat custom transports/adapters for log messages) 8 | * 9 | * For more information on the Sails logger, check out: 10 | * http://sailsjs.org/#!/documentation/concepts/Logging 11 | */ 12 | 13 | module.exports.log = { 14 | 15 | /*************************************************************************** 16 | * * 17 | * Valid `level` configs: i.e. the minimum log level to capture with * 18 | * sails.log.*() * 19 | * * 20 | * The order of precedence for log levels from lowest to highest is: * 21 | * silly, verbose, info, debug, warn, error * 22 | * * 23 | * You may also set the level to "silent" to suppress all logs. * 24 | * * 25 | ***************************************************************************/ 26 | 27 | // level: 'info' 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/config/models.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Default model configuration 3 | * (sails.config.models) 4 | * 5 | * Unless you override them, the following properties will be included 6 | * in each of your models. 7 | * 8 | * For more info on Sails models, see: 9 | * http://sailsjs.org/#!/documentation/concepts/ORM 10 | */ 11 | 12 | module.exports.models = { 13 | 14 | migrate: 'drop' 15 | 16 | }; 17 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/config/policies.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Policy Mappings 3 | * (sails.config.policies) 4 | * 5 | * Policies are simple functions which run **before** your controllers. 6 | * You can apply one or more policies to a given controller, or protect 7 | * its actions individually. 8 | * 9 | * Any policy file (e.g. `api/policies/authenticated.js`) can be accessed 10 | * below by its filename, minus the extension, (e.g. "authenticated") 11 | * 12 | * For more information on how policies work, see: 13 | * http://sailsjs.org/#!/documentation/concepts/Policies 14 | * 15 | * For more information on configuring policies, check out: 16 | * http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.policies.html 17 | */ 18 | 19 | 20 | module.exports.policies = { 21 | 22 | /*************************************************************************** 23 | * * 24 | * Default policy for all controllers and actions (`true` allows public * 25 | * access) * 26 | * * 27 | ***************************************************************************/ 28 | 29 | // '*': true, 30 | 31 | /*************************************************************************** 32 | * * 33 | * Here's an example of mapping some policies to run before a controller * 34 | * and its actions * 35 | * * 36 | ***************************************************************************/ 37 | // RabbitController: { 38 | 39 | // Apply the `false` policy as the default for all of RabbitController's actions 40 | // (`false` prevents all access, which ensures that nothing bad happens to our rabbits) 41 | // '*': false, 42 | 43 | // For the action `nurture`, apply the 'isRabbitMother' policy 44 | // (this overrides `false` above) 45 | // nurture : 'isRabbitMother', 46 | 47 | // Apply the `isNiceToAnimals` AND `hasRabbitFood` policies 48 | // before letting any users feed our rabbits 49 | // feed : ['isNiceToAnimals', 'hasRabbitFood'] 50 | // } 51 | }; 52 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/config/sequelize.js: -------------------------------------------------------------------------------- 1 | module.exports.sequelize = { 2 | 'clsNamespace' : 'myAppCLSNamespace', 3 | 'exposeToGlobal': true 4 | }; 5 | -------------------------------------------------------------------------------- /test/fixtures/v1.x-sqlite3-app/db/sequelize.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KSDaemon/sails-hook-sequelize/e8f8d1ad2bad0257133f69dcbbcc3b0830b51bcc/test/fixtures/v1.x-sqlite3-app/db/sequelize.sqlite -------------------------------------------------------------------------------- /test/overall.test.js: -------------------------------------------------------------------------------- 1 | describe('Sails.js Sequelize hook test suite', () => { 2 | 3 | const decache = require('decache'); 4 | 5 | let clean = () => { 6 | decache('./unit/create.test'); 7 | decache('./unit/associations.test'); 8 | decache('./unit/scope.test'); 9 | }; 10 | 11 | require('./bootstrap.v0.11.test'); 12 | clean(); 13 | 14 | require('./bootstrap.v0.12.test'); 15 | clean(); 16 | 17 | require('./bootstrap.v1.x.test'); 18 | clean(); 19 | 20 | require('./bootstrap.v1.x-many-schemes.test'); 21 | clean(); 22 | 23 | require('./bootstrap.v1.x-create-db-schemes.test'); 24 | clean(); 25 | 26 | // this test should run after bootstrap.v1.x-create-db-schemes because it doesn't create tables 27 | require('./bootstrap.v1.x-migrate-safe.test'); 28 | clean(); 29 | 30 | require('./bootstrap.v1.x-sqlite.test'); 31 | clean(); 32 | 33 | require('./bootstrap.v1.x-no-conn.test'); 34 | clean(); 35 | 36 | require('./bootstrap.v1.x-sequelize-waterline.test'); 37 | clean(); 38 | 39 | }); 40 | -------------------------------------------------------------------------------- /test/unit/create.test.js: -------------------------------------------------------------------------------- 1 | // var request = require('supertest'); 2 | const should = require('should'); 3 | const fixtures = require('./../fixtures/instances.json'); 4 | 5 | describe('User model', () => { 6 | it('should create user instance', done => { 7 | User.create(fixtures.user).then(user => { 8 | user.should.be.type('object'); 9 | user.should.have.property('name', fixtures.user.name); 10 | user.should.have.property('id'); 11 | 12 | done(); 13 | }).catch(err => { 14 | done(err); 15 | }); 16 | }); 17 | }); 18 | 19 | describe('Image model', () => { 20 | it('should create image instance', done => { 21 | Image.create(fixtures.image).then(image => { 22 | image.should.be.type('object'); 23 | image.should.have.property('url', fixtures.image.url); 24 | image.should.have.property('id'); 25 | 26 | done(); 27 | }).catch(err => { 28 | done(err); 29 | }); 30 | }); 31 | }); 32 | 33 | describe('Group model', () => { 34 | it('should create user group instance', done => { 35 | Group.create(fixtures.group).then(group => { 36 | group.should.be.type('object'); 37 | group.should.have.property('name', fixtures.group.name); 38 | group.should.have.property('id'); 39 | 40 | done(); 41 | }).catch(err => { 42 | done(err); 43 | }); 44 | }); 45 | }); 46 | --------------------------------------------------------------------------------