testapi 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +66 -0
- data/Rakefile +12 -0
- data/app/controllers/testapi/application_controller.rb +21 -0
- data/app/controllers/testapi/databases_controller.rb +6 -0
- data/app/controllers/testapi/factories_controller.rb +12 -0
- data/app/controllers/testapi/models_controller.rb +36 -0
- data/config/routes.rb +5 -0
- data/lib/testapi/config.rb +11 -0
- data/lib/testapi/engine.rb +3 -0
- data/lib/testapi/version.rb +3 -0
- data/lib/testapi.rb +5 -0
- metadata +56 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5d2afa6dbeb5889a4722ecf0ce7651fcaf742078
|
4
|
+
data.tar.gz: 940cda919b2214c866b4d1bd1bff7a215da3d35e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 799cba1d972b24a238f1d3cb026f3ab0cf0c44c786400990a05615d39e2c6920c9c2174a8ea83d538e3ab6412c3911c3c447db1195101382449644aca296076d
|
7
|
+
data.tar.gz: c8003684a369e621731161ec8513b9bde46e88dbea7a507810ac985049248dc40984bf41bca894f9d3f4b505bfa010c02e228184beeacadb2e7bdc5f9436eaad
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 agilidée
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Testapi
|
2
|
+
|
3
|
+
A Test API for your models, factories, and database cleaner.
|
4
|
+
|
5
|
+
**Important :** NEVER use this gem in production.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
Examples with curl:
|
10
|
+
|
11
|
+
```bash
|
12
|
+
alias curl-json='curl -H "Content-Type: application/json"'
|
13
|
+
curl-json -X GET http://localhost:3000/testapi/models/User
|
14
|
+
curl-json -X POST http://localhost:3000/testapi/factories/user -d '{"attributes": {"name": "John"}}'
|
15
|
+
curl-json -X DELETE http://localhost:3000/testapi/database
|
16
|
+
```
|
17
|
+
|
18
|
+
All available routes :
|
19
|
+
```
|
20
|
+
DELETE /database => testapi/databases#destroy
|
21
|
+
POST /factories/:factory => testapi/factories#create
|
22
|
+
GET /models/:model => testapi/models#index
|
23
|
+
POST /models/:model => testapi/models#create
|
24
|
+
GET /models/:model/:id => testapi/models#show
|
25
|
+
PATCH /models/:model/:id => testapi/models#update
|
26
|
+
DELETE /models/:model/:id => testapi/models#destroy
|
27
|
+
```
|
28
|
+
|
29
|
+
## Notes
|
30
|
+
|
31
|
+
DatabaseCleaner use `truncation` strategy and ignore the following tables by default :
|
32
|
+
|
33
|
+
- ar_internal_metadata
|
34
|
+
- schema_migrations
|
35
|
+
- spatial_ref_sys
|
36
|
+
|
37
|
+
You can change it using :
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
Testapi.database_cleaner_ignored_tables = %w(my_table)
|
41
|
+
```
|
42
|
+
|
43
|
+
## Installation
|
44
|
+
|
45
|
+
Add this line to your application's Gemfile:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
gem "testapi", group: [:development, :test]
|
49
|
+
```
|
50
|
+
|
51
|
+
And then execute:
|
52
|
+
```bash
|
53
|
+
$ bundle
|
54
|
+
```
|
55
|
+
|
56
|
+
Add this to `routes.rb`:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
if Rails.env.development? || Rails.env.test?
|
60
|
+
mount Testapi::Engine => "/testapi"
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
begin
|
2
|
+
require "bundler/setup"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
|
+
end
|
6
|
+
|
7
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
8
|
+
load "rails/tasks/engine.rake"
|
9
|
+
|
10
|
+
load "rails/tasks/statistics.rake"
|
11
|
+
|
12
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Testapi::ApplicationController < ActionController::API
|
2
|
+
rescue_from StandardError, with: :render_error
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def render_json(json = {}, options = {})
|
7
|
+
render options.merge(json: json)
|
8
|
+
end
|
9
|
+
|
10
|
+
def render_object(object = @object)
|
11
|
+
render_json(object.attributes)
|
12
|
+
end
|
13
|
+
|
14
|
+
def render_error(e)
|
15
|
+
render_json({error: e.to_s}, {status: :unprocessable_entity})
|
16
|
+
end
|
17
|
+
|
18
|
+
def attributes
|
19
|
+
params.fetch(:attributes, {}).permit!.to_h.symbolize_keys
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Testapi::ModelsController < Testapi::ApplicationController
|
2
|
+
before_action :model
|
3
|
+
|
4
|
+
def index
|
5
|
+
@objects = model.all.reorder(:id)
|
6
|
+
render_json @objects.map(&:attributes)
|
7
|
+
end
|
8
|
+
|
9
|
+
def create
|
10
|
+
@object = model.create!(attributes)
|
11
|
+
render_object
|
12
|
+
end
|
13
|
+
|
14
|
+
def show
|
15
|
+
@object = model.find(params[:id])
|
16
|
+
render_object
|
17
|
+
end
|
18
|
+
|
19
|
+
def update
|
20
|
+
@object = model.find(params[:id])
|
21
|
+
@object.update!(attributes)
|
22
|
+
render_object
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy
|
26
|
+
@object = model.find(params[:id])
|
27
|
+
@object.destroy!
|
28
|
+
render_object
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def model
|
34
|
+
@model ||= params[:model].to_s.constantize
|
35
|
+
end
|
36
|
+
end
|
data/config/routes.rb
ADDED
data/lib/testapi.rb
ADDED
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: testapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- agilidée
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Test API
|
14
|
+
email:
|
15
|
+
- contact@agilidee.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- MIT-LICENSE
|
21
|
+
- README.md
|
22
|
+
- Rakefile
|
23
|
+
- app/controllers/testapi/application_controller.rb
|
24
|
+
- app/controllers/testapi/databases_controller.rb
|
25
|
+
- app/controllers/testapi/factories_controller.rb
|
26
|
+
- app/controllers/testapi/models_controller.rb
|
27
|
+
- config/routes.rb
|
28
|
+
- lib/testapi.rb
|
29
|
+
- lib/testapi/config.rb
|
30
|
+
- lib/testapi/engine.rb
|
31
|
+
- lib/testapi/version.rb
|
32
|
+
homepage: https://github.com/agilidee/testapi
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
metadata: {}
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 2.6.13
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: A Test API
|
56
|
+
test_files: []
|