json_voorhees 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +52 -4
- data/lib/generators/json_voorhees/app_make_authorizations/USAGE +1 -1
- data/lib/generators/json_voorhees/app_make_authorizations/app_make_authorizations_generator.rb +1 -0
- data/lib/generators/json_voorhees/app_make_authorizations/templates/auth_file.rb.erb +8 -1
- data/lib/generators/json_voorhees/app_make_tests/USAGE +1 -1
- data/lib/generators/json_voorhees/app_make_tests/app_make_tests_generator.rb +26 -0
- data/lib/generators/json_voorhees/app_make_tests/templates/factory.rb.erb +3 -1
- data/lib/generators/json_voorhees/app_make_tests/templates/model.rb.erb +5 -0
- data/lib/generators/json_voorhees/app_make_tests/templates/no_auth_request.rb.erb +90 -0
- data/lib/generators/json_voorhees/app_scaffold/USAGE +9 -0
- data/lib/generators/json_voorhees/app_scaffold/app_scaffold_generator.rb +22 -0
- data/lib/generators/json_voorhees/engine_create_controller/USAGE +1 -1
- data/lib/generators/json_voorhees/engine_create_controller/engine_create_controller_generator.rb +11 -0
- data/lib/generators/json_voorhees/engine_create_controller/templates/controller_template.rb.erb +1 -1
- data/lib/generators/json_voorhees/engine_create_controller/templates/no_auth_controller_template.rb.erb +1 -1
- data/lib/generators/json_voorhees/engine_create_serializer/USAGE +1 -1
- data/lib/generators/json_voorhees/engine_create_serializer/engine_create_serializer_generator.rb +1 -0
- data/lib/generators/json_voorhees/engine_create_serializer/templates/serializer.rb.erb +13 -0
- data/lib/generators/json_voorhees/engine_scaffold/USAGE +9 -0
- data/lib/generators/json_voorhees/engine_scaffold/engine_scaffold_generator.rb +18 -0
- data/lib/generators/json_voorhees/massive_scaffold/USAGE +10 -0
- data/lib/generators/json_voorhees/massive_scaffold/massive_scaffold_generator.rb +23 -0
- data/lib/generators/json_voorhees/setup_app/setup_app_generator.rb +10 -0
- data/lib/json_voorhees/version.rb +1 -1
- data/test/lib/generators/json_voorhees/app_scaffold_generator_test.rb +16 -0
- data/test/lib/generators/json_voorhees/engine_scaffold_generator_test.rb +16 -0
- data/test/lib/generators/json_voorhees/massive_scaffold_generator_test.rb +16 -0
- data/test/test_app/Gemfile +23 -0
- data/test/test_app/Gemfile.lock +99 -1
- data/test/test_app/README.md +1 -0
- data/test/test_app/app/controllers/api/v1/api_controller.rb +26 -0
- data/test/test_app/app/controllers/app_index_controller.rb +4 -0
- data/test/test_app/app/controllers/application_controller.rb +5 -0
- data/test/test_app/app/controllers/main_controller.rb +4 -0
- data/test/test_app/app/views/app_index/app.html.erb +0 -0
- data/test/test_app/app/views/layouts/app_index.html.erb +9 -0
- data/test/test_app/app/views/layouts/application.html.erb +8 -3
- data/test/test_app/app/views/main/admin.html.erb +9 -0
- data/test/test_app/config/application.rb +4 -0
- data/test/test_app/config/routes.rb +8 -0
- data/test/test_app/db/development.sqlite3 +0 -0
- data/test/test_app/db/migrate/20140905145354_create_people_users.people.rb +12 -0
- data/test/test_app/db/migrate/20140905145355_create_arcadex_tokens.arcadex.rb +12 -0
- data/test/test_app/db/migrate/20140905145356_add_index_to_token.arcadex.rb +6 -0
- data/test/test_app/db/production.sqlite3 +0 -0
- data/test/test_app/db/schema.rb +19 -1
- data/test/test_app/db/test.sqlite3 +0 -0
- data/test/test_app/engines/people/Gemfile +14 -0
- data/test/test_app/engines/people/Gemfile.lock +92 -0
- data/test/test_app/engines/people/MIT-LICENSE +20 -0
- data/test/test_app/engines/people/README.md +1 -0
- data/test/test_app/engines/people/Rakefile +34 -0
- data/test/test_app/engines/people/app/assets/javascripts/people/application.js +13 -0
- data/test/test_app/engines/people/app/assets/javascripts/people/users.js +2 -0
- data/test/test_app/engines/people/app/assets/stylesheets/people/application.css +15 -0
- data/test/test_app/engines/people/app/assets/stylesheets/people/users.css +4 -0
- data/test/test_app/engines/people/app/assets/stylesheets/scaffold.css +56 -0
- data/test/test_app/engines/people/app/controllers/people/api/v1/application_controller.rb +5 -0
- data/test/test_app/engines/people/app/controllers/people/api/v1/users_controller.rb +124 -0
- data/test/test_app/engines/people/app/controllers/people/application_controller.rb +4 -0
- data/test/test_app/engines/people/app/controllers/people/users_controller.rb +62 -0
- data/test/test_app/engines/people/app/helpers/people/application_helper.rb +4 -0
- data/test/test_app/engines/people/app/helpers/people/users_helper.rb +4 -0
- data/test/test_app/engines/people/app/models/people/user.rb +26 -0
- data/test/test_app/engines/people/app/serializers/people/user_serializer.rb +39 -0
- data/test/test_app/engines/people/app/views/layouts/people/default/application.html.erb +14 -0
- data/test/test_app/engines/people/app/views/people/users/_form.html.erb +29 -0
- data/test/test_app/engines/people/app/views/people/users/edit.html.erb +6 -0
- data/test/test_app/engines/people/app/views/people/users/index.html.erb +29 -0
- data/test/test_app/engines/people/app/views/people/users/new.html.erb +5 -0
- data/test/test_app/engines/people/app/views/people/users/show.html.erb +19 -0
- data/test/test_app/engines/people/bin/rails +12 -0
- data/test/test_app/engines/people/config/routes.rb +24 -0
- data/test/test_app/engines/people/db/migrate/20140905145341_create_people_users.rb +11 -0
- data/test/test_app/engines/people/lib/people/engine.rb +5 -0
- data/test/test_app/engines/people/lib/people/version.rb +3 -0
- data/test/test_app/engines/people/lib/people.rb +4 -0
- data/test/test_app/engines/people/lib/tasks/people_tasks.rake +4 -0
- data/test/test_app/engines/people/people.gemspec +31 -0
- data/test/test_app/engines/people/test/controllers/people/users_controller_test.rb +51 -0
- data/test/test_app/{README.rdoc → engines/people/test/dummy/README.rdoc} +0 -0
- data/test/test_app/engines/people/test/dummy/Rakefile +6 -0
- data/test/test_app/engines/people/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/test_app/engines/people/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/test_app/engines/people/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/test_app/engines/people/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/test_app/engines/people/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/test_app/engines/people/test/dummy/bin/bundle +3 -0
- data/test/test_app/engines/people/test/dummy/bin/rails +4 -0
- data/test/test_app/engines/people/test/dummy/bin/rake +4 -0
- data/test/test_app/engines/people/test/dummy/config/application.rb +23 -0
- data/test/test_app/engines/people/test/dummy/config/boot.rb +5 -0
- data/test/test_app/engines/people/test/dummy/config/database.yml +25 -0
- data/test/test_app/engines/people/test/dummy/config/environment.rb +5 -0
- data/test/test_app/engines/people/test/dummy/config/environments/development.rb +37 -0
- data/test/test_app/engines/people/test/dummy/config/environments/production.rb +82 -0
- data/test/test_app/engines/people/test/dummy/config/environments/test.rb +39 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/assets.rb +8 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/test_app/engines/people/test/dummy/config/locales/en.yml +23 -0
- data/test/test_app/engines/people/test/dummy/config/routes.rb +4 -0
- data/test/test_app/engines/people/test/dummy/config/secrets.yml +22 -0
- data/test/test_app/engines/people/test/dummy/config.ru +4 -0
- data/test/test_app/engines/people/test/dummy/db/schema.rb +24 -0
- data/test/test_app/engines/people/test/dummy/public/404.html +67 -0
- data/test/test_app/engines/people/test/dummy/public/422.html +67 -0
- data/test/test_app/engines/people/test/dummy/public/500.html +66 -0
- data/test/test_app/engines/people/test/dummy/public/favicon.ico +0 -0
- data/test/test_app/engines/people/test/fixtures/people/users.yml +11 -0
- data/test/test_app/engines/people/test/helpers/people/users_helper_test.rb +6 -0
- data/test/test_app/engines/people/test/integration/navigation_test.rb +10 -0
- data/test/test_app/engines/people/test/models/people/user_test.rb +9 -0
- data/test/test_app/engines/people/test/people_test.rb +7 -0
- data/test/test_app/engines/people/test/test_helper.rb +15 -0
- data/test/test_app/gems/authorization/Gemfile +14 -0
- data/test/test_app/gems/authorization/Gemfile.lock +92 -0
- data/test/test_app/gems/authorization/MIT-LICENSE +20 -0
- data/test/test_app/gems/authorization/README.rdoc +3 -0
- data/test/test_app/gems/authorization/Rakefile +32 -0
- data/test/test_app/gems/authorization/authorization.gemspec +23 -0
- data/test/test_app/gems/authorization/lib/authorization/people/user.rb +82 -0
- data/test/test_app/gems/authorization/lib/authorization/version.rb +3 -0
- data/test/test_app/gems/authorization/lib/authorization.rb +3 -0
- data/test/test_app/gems/authorization/lib/tasks/authorization_tasks.rake +4 -0
- data/test/test_app/gems/authorization/test/authorization_test.rb +7 -0
- data/test/test_app/gems/authorization/test/dummy/README.rdoc +28 -0
- data/test/test_app/gems/authorization/test/dummy/Rakefile +6 -0
- data/test/test_app/gems/authorization/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/test_app/gems/authorization/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/test_app/gems/authorization/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/test_app/gems/authorization/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/test_app/gems/authorization/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/test_app/gems/authorization/test/dummy/bin/bundle +3 -0
- data/test/test_app/gems/authorization/test/dummy/bin/rails +4 -0
- data/test/test_app/gems/authorization/test/dummy/bin/rake +4 -0
- data/test/test_app/gems/authorization/test/dummy/config/application.rb +23 -0
- data/test/test_app/gems/authorization/test/dummy/config/boot.rb +5 -0
- data/test/test_app/gems/authorization/test/dummy/config/database.yml +25 -0
- data/test/test_app/gems/authorization/test/dummy/config/environment.rb +5 -0
- data/test/test_app/gems/authorization/test/dummy/config/environments/development.rb +37 -0
- data/test/test_app/gems/authorization/test/dummy/config/environments/production.rb +82 -0
- data/test/test_app/gems/authorization/test/dummy/config/environments/test.rb +39 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/assets.rb +8 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/test_app/gems/authorization/test/dummy/config/locales/en.yml +23 -0
- data/test/test_app/gems/authorization/test/dummy/config/routes.rb +56 -0
- data/test/test_app/gems/authorization/test/dummy/config/secrets.yml +22 -0
- data/test/test_app/gems/authorization/test/dummy/config.ru +4 -0
- data/test/test_app/gems/authorization/test/dummy/public/404.html +67 -0
- data/test/test_app/gems/authorization/test/dummy/public/422.html +67 -0
- data/test/test_app/gems/authorization/test/dummy/public/500.html +66 -0
- data/test/test_app/gems/authorization/test/dummy/public/favicon.ico +0 -0
- data/test/test_app/gems/authorization/test/test_helper.rb +15 -0
- data/test/test_app/log/development.log +195 -0
- data/test/test_app/log/production.log +20 -0
- data/test/test_app/log/test.log +8427 -0
- data/test/test_app/spec/controllers/app_index_controller_spec.rb +12 -0
- data/test/test_app/spec/engines/people/api/v1/models/user_spec.rb +59 -0
- data/test/test_app/spec/engines/people/api/v1/requests/user_spec.rb +154 -0
- data/test/test_app/spec/engines/people/api/v1/routing/user_spec.rb +77 -0
- data/test/test_app/spec/factories/people_user_factory.rb +14 -0
- data/test/test_app/spec/rails_helper.rb +47 -0
- data/test/test_app/spec/spec_helper.rb +78 -0
- data/test/test_app/spec/support/factory_girl.rb +16 -0
- data/test/test_app/spec/support/request_helpers.rb +7 -0
- metadata +293 -6
- data/test/test_app/test/test_helper.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4f093f809f09e2c46269d6041ab640569ad40b3
|
4
|
+
data.tar.gz: 96a9615de58292694f815a2feaee0afcce3c102e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f817868b48bd28e2a20dfe3ff9acc9ab0b7a9fb8fd9b3eb9acae44bdf2383eac8e9bd99dff981507ea0e62dfca4055e75e17d0240ccac363d2304ce9919b7d26
|
7
|
+
data.tar.gz: 93c3e86f4989e71a86b89351eeebe225ffa10cb03824bac7e9823fa3c871ae2067e01a2a5f630803d1403eac79e631c2dfde7bc2bb75fa82354761ccc7fc585a
|
data/README.md
CHANGED
@@ -8,7 +8,53 @@ I abstracted away all of the code that I typically use into a series of generato
|
|
8
8
|
namespaced under json_voorhees. Not only does it set your project up, it also
|
9
9
|
helps build the project if you follow the conventions.
|
10
10
|
|
11
|
-
## Use
|
11
|
+
## Scaffold Use
|
12
|
+
|
13
|
+
To install, put this in your main_app
|
14
|
+
|
15
|
+
```bash
|
16
|
+
gem "json_voorhees"
|
17
|
+
```
|
18
|
+
To setup your application use
|
19
|
+
|
20
|
+
```bash
|
21
|
+
rails g json_voorhees:setup_app
|
22
|
+
```
|
23
|
+
Go to the engines folder and create an engine like so.
|
24
|
+
|
25
|
+
```bash
|
26
|
+
rails plugin new [engine name] --mountable
|
27
|
+
cd [engine name]
|
28
|
+
```
|
29
|
+
Now add the gem to your gemspec like so and execute the following command
|
30
|
+
|
31
|
+
```bash
|
32
|
+
s.add_development_dependency "json_voorhees"
|
33
|
+
rails g json_voorhees:setup_engine [engine name]
|
34
|
+
```
|
35
|
+
Make sure the engine is mounted in your app.
|
36
|
+
Now go to the main_app and create your resources
|
37
|
+
```bash
|
38
|
+
rails g json_voorhees:massive_scaffold [engine name] [resource name] [api_version] [scaffold parameters]
|
39
|
+
```
|
40
|
+
Now make sure the resource is in the correct scoping in the Engines routing file.
|
41
|
+
Make sure everything is setup correctly by running rspec from the main_app.
|
42
|
+
The factory girl factory may not be setup correction depending on your passed type.
|
43
|
+
|
44
|
+
## Project Flow
|
45
|
+
|
46
|
+
1. Create main app
|
47
|
+
2. (in app) rails g json_voorhees:setup_app
|
48
|
+
3. Create engine
|
49
|
+
4. Mount engine
|
50
|
+
5. (in engine) rails g json_voorhees:setup_engine [engine name]
|
51
|
+
6. Add json_voorhees to the engines gemspec
|
52
|
+
7. (in app) rails g json_voorhees:massive_scaffod [engine name] [resource name] [api_version] [field:type field:type]
|
53
|
+
8. Fix the engines route file
|
54
|
+
9. Copy migrations to main app and run db migrations in main app
|
55
|
+
10. (in app) Run rspec to check for errors
|
56
|
+
|
57
|
+
## Individual Generator Use
|
12
58
|
|
13
59
|
To install, put this in your main_app
|
14
60
|
|
@@ -74,6 +120,8 @@ params in the controller to fit accordingly.
|
|
74
120
|
|
75
121
|
## To Do
|
76
122
|
|
77
|
-
1.
|
78
|
-
2.
|
79
|
-
3.
|
123
|
+
1. Refactor everything
|
124
|
+
2. Figure out a better way to test this thing
|
125
|
+
3. Use option for namespaced engine or no engine
|
126
|
+
4. Pass options from scaffolds to individual generators
|
127
|
+
5. Make massive_scaffold automatically put the routes in the correct spot
|
@@ -4,7 +4,7 @@ Description:
|
|
4
4
|
Run this generator from the main_app
|
5
5
|
|
6
6
|
Example:
|
7
|
-
rails g json_voorhees:app_make_authorizations People User
|
7
|
+
rails g json_voorhees:app_make_authorizations People User 1 username:string email:string
|
8
8
|
|
9
9
|
This will create:
|
10
10
|
A file in gems/authorization.
|
data/lib/generators/json_voorhees/app_make_authorizations/app_make_authorizations_generator.rb
CHANGED
@@ -3,6 +3,7 @@ module JsonVoorhees
|
|
3
3
|
source_root File.expand_path('../templates', __FILE__)
|
4
4
|
argument :module_name, :type => :string
|
5
5
|
argument :resource_name, :type => :string
|
6
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
6
7
|
|
7
8
|
def sprint
|
8
9
|
template "auth_file.rb.erb", "gems/authorization/lib/authorization/#{module_name.underscore}/#{resource_singular}.rb"
|
@@ -31,7 +31,14 @@ module Authorization
|
|
31
31
|
controller = options[:url_options][:_recall][:controller]
|
32
32
|
return true
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
|
+
<% attributes.each do |pair| %>
|
36
|
+
def self.include_<%= pair.split(/:/)[0] %>?(current_user,<%= resource_singular %>_object,options)
|
37
|
+
action = options[:url_options][:_recall][:action]
|
38
|
+
controller = options[:url_options][:_recall][:controller]
|
39
|
+
return true
|
40
|
+
end
|
41
|
+
<% end %>
|
35
42
|
def self.include_created_at?(current_user,<%= resource_singular %>_object,options)
|
36
43
|
action = options[:url_options][:_recall][:action]
|
37
44
|
controller = options[:url_options][:_recall][:controller]
|
@@ -4,6 +4,7 @@ module JsonVoorhees
|
|
4
4
|
argument :module_name, :type => :string
|
5
5
|
argument :resource_name, :type => :string
|
6
6
|
argument :api_version, :type => :string, :default => "1"
|
7
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
7
8
|
class_option :model, :type => :boolean, :default => true, :description => "Create model stub tests"
|
8
9
|
class_option :request, :type => :boolean, :default => true, :description => "Create request stub tests"
|
9
10
|
class_option :routing, :type => :boolean, :default => true, :description => "Create routing stub tests"
|
@@ -17,6 +18,7 @@ module JsonVoorhees
|
|
17
18
|
if options.arcadex?
|
18
19
|
template "request.rb.erb", "spec/engines/#{module_name.underscore}/api/v#{api_version}/requests/#{resource_singular}_spec.rb"
|
19
20
|
else
|
21
|
+
template "no_auth_request.rb.erb", "spec/engines/#{module_name.underscore}/api/v#{api_version}/requests/#{resource_singular}_spec.rb"
|
20
22
|
end
|
21
23
|
end
|
22
24
|
if options.routing?
|
@@ -27,6 +29,30 @@ module JsonVoorhees
|
|
27
29
|
|
28
30
|
private
|
29
31
|
|
32
|
+
def default_values(field1)
|
33
|
+
field = field1.downcase
|
34
|
+
if field == "integer"
|
35
|
+
return 1
|
36
|
+
end
|
37
|
+
if field == "boolean"
|
38
|
+
return true
|
39
|
+
end
|
40
|
+
if field == "string"
|
41
|
+
return "\"Default String\""
|
42
|
+
end
|
43
|
+
if field == "text"
|
44
|
+
return "\"Default Text\""
|
45
|
+
end
|
46
|
+
if field == "float"
|
47
|
+
return 3.14
|
48
|
+
end
|
49
|
+
if field == "decimal"
|
50
|
+
return 3.14159
|
51
|
+
end
|
52
|
+
#Theres also date, datetime, time and timestamp
|
53
|
+
return nil
|
54
|
+
end
|
55
|
+
|
30
56
|
def resource_singular
|
31
57
|
resource_name.underscore.singularize
|
32
58
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
FactoryGirl.define do
|
2
|
-
#sequence :
|
2
|
+
#sequence :name do |n|
|
3
3
|
# "name#{n}"
|
4
4
|
#end
|
5
5
|
factory :<%= module_snake %>_<%= resource_singular %>, class: ::<%= module_camel %>::<%= resource_camel %> do
|
6
|
+
<% attributes.each do |pair| %><% field = pair.split(":")[0]; default = default_values(pair.split(":")[1]) %><% if default != nil%>
|
7
|
+
<%= field %> <%= default %><% end %><% end %>
|
6
8
|
#name
|
7
9
|
#attr "Default value"
|
8
10
|
end
|
@@ -6,6 +6,11 @@ RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, '.username', :type
|
|
6
6
|
#<%= resource_singular %> = FactoryGirl.build(:<%= module_snake %>_<%= resource_singular %>, :attribute => nil)
|
7
7
|
#expect(<%= resource_singular %>.save).to equal(false)
|
8
8
|
end
|
9
|
+
<% attributes.each do |pair| %>
|
10
|
+
it "does not save when <%= pair.split(":")[0] %> is ..." do
|
11
|
+
#expect(<%= resource_singular %>.save).to equal(false)
|
12
|
+
end
|
13
|
+
<% end %>
|
9
14
|
end
|
10
15
|
end
|
11
16
|
RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :model do
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
#-#-#-#-#REST#-#-#-#-#
|
4
|
+
RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request do
|
5
|
+
describe "Rest Routes" do
|
6
|
+
before(:example) do
|
7
|
+
end
|
8
|
+
# get /api/<%= api_version %>/<%= resource_plural %>
|
9
|
+
it "Gets all of the <%= resource_singular %>s" do
|
10
|
+
FactoryGirl.create_list(:<%= module_snake %>_<%= resource_singular %>, 10)
|
11
|
+
get 'api/<%= api_version %>/<%= resource_plural %>'
|
12
|
+
expect(response.status).to eq(200) #ok
|
13
|
+
end
|
14
|
+
# get /api/<%= api_version %>/<%= resource_plural %>/1
|
15
|
+
it "Gets a <%= resource_singular %> by id" do
|
16
|
+
FactoryGirl.create(:<%= module_snake %>_<%= resource_singular %>)
|
17
|
+
get 'api/<%= api_version %>/<%= resource_plural %>/1'
|
18
|
+
expect(response.status).to eq(200) #ok
|
19
|
+
end
|
20
|
+
# post /api/<%= api_version %>/<%= resource_plural %>
|
21
|
+
it "Creates <%= resource_singular %>" do
|
22
|
+
attrs = FactoryGirl.attributes_for(:<%= module_snake %>_<%= resource_singular %>)
|
23
|
+
#attrs[:column] = "LaunchU"
|
24
|
+
hash = {"<%= resource_singular %>" => attrs}
|
25
|
+
post 'api/<%= api_version %>/<%= resource_plural %>', hash
|
26
|
+
expect(response.status).to eq(200) #ok
|
27
|
+
end
|
28
|
+
# patch/put /api/<%= api_version %>/<%= resource_plural %>/1
|
29
|
+
it "Updates <%= resource_singular %>" do
|
30
|
+
#Create the <%= resource_singular %> through the api
|
31
|
+
attrs = FactoryGirl.attributes_for(:<%= module_snake %>_<%= resource_singular %>)
|
32
|
+
#attrs[:column] = "LaunchU"
|
33
|
+
hash = {"<%= resource_singular %>" => attrs}
|
34
|
+
post 'api/<%= api_version %>/<%= resource_plural %>', hash
|
35
|
+
#Now update the created <%= resource_singular %> by changing the <%= resource_singular %>name
|
36
|
+
#attrs[:column] = "BlastOff"
|
37
|
+
hash = {"<%= resource_singular %>" => attrs}
|
38
|
+
put "api/<%= api_version %>/<%= resource_plural %>/1", hash
|
39
|
+
expect(response.status).to eq(200) #ok
|
40
|
+
end
|
41
|
+
# delete /api/<%= api_version %>/<%= resource_plural %>/1
|
42
|
+
it "Deletes <%= resource_singular %>" do
|
43
|
+
#Create the <%= resource_singular %> through the api
|
44
|
+
attrs = FactoryGirl.attributes_for(:<%= module_snake %>_<%= resource_singular %>)
|
45
|
+
#attrs[:column] = "LaunchU"
|
46
|
+
hash = {"<%= resource_singular %>" => attrs}
|
47
|
+
post 'api/<%= api_version %>/<%= resource_plural %>', hash
|
48
|
+
expect(<%= module_camel %>::<%= resource_camel %>.count).to eq(1)
|
49
|
+
#Now delete the <%= resource_singular %> through the api
|
50
|
+
delete 'api/<%= api_version %>/<%= resource_plural %>/1'
|
51
|
+
expect(json).to eq({})
|
52
|
+
expect(response.status).to eq(200) #ok
|
53
|
+
expect(<%= module_camel %>::<%= resource_camel %>.count).to eq(0)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
#-#-#-#-#Collection Routes#-#-#-#-#
|
58
|
+
RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request do
|
59
|
+
describe "Collection Routes" do
|
60
|
+
before(:example) do
|
61
|
+
end
|
62
|
+
# get /api/1/collection
|
63
|
+
it "checks response of a collection route" do
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
#-#-#-#-#Serialization#-#-#-#-#
|
69
|
+
RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request do
|
70
|
+
describe "Serialization" do
|
71
|
+
before(:example) do
|
72
|
+
end
|
73
|
+
it "checks the index json sent back" do
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
#-#-#-#-#Errors#-#-#-#-#
|
79
|
+
RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request do
|
80
|
+
describe "Errors" do
|
81
|
+
before(:example) do
|
82
|
+
end
|
83
|
+
# get /api/<%= api_version %>/<%= resource_plural %>/1
|
84
|
+
it "checks for a 404" do
|
85
|
+
FactoryGirl.create(:<%= module_snake %>_<%= resource_singular %>)
|
86
|
+
get 'api/<%= api_version %>/<%= resource_plural %>/20'
|
87
|
+
expect(response.status).to eq(404) #ok
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Description:
|
2
|
+
It runs both the app_make_authorizations and app_make_tests generators.
|
3
|
+
Runs the generators with the default options.
|
4
|
+
|
5
|
+
Example:
|
6
|
+
rails g json_voorhees:app_scaffold People User 1 username:string email:string
|
7
|
+
|
8
|
+
This will create:
|
9
|
+
authorizations and tests in main_app
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module JsonVoorhees
|
2
|
+
class AppScaffoldGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
argument :module_name, :type => :string
|
5
|
+
argument :resource_name, :type => :string
|
6
|
+
argument :api_version, :type => :string, :default => "1"
|
7
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
8
|
+
class_option :model, :type => :boolean, :default => true, :description => "Create model stub tests"
|
9
|
+
class_option :request, :type => :boolean, :default => true, :description => "Create request stub tests"
|
10
|
+
class_option :routing, :type => :boolean, :default => true, :description => "Create routing stub tests"
|
11
|
+
class_option :arcadex, :type => :boolean, :default => true, :description => "Send requests with an arcadex header"
|
12
|
+
|
13
|
+
|
14
|
+
def sprint
|
15
|
+
run "rails g json_voorhees:app_make_authorizations #{module_name} #{resource_name} #{attributes.join(" ")}"
|
16
|
+
run "rails g json_voorhees:app_make_tests #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")}"
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -4,7 +4,7 @@ Description:
|
|
4
4
|
Run this generator inside the engine.
|
5
5
|
|
6
6
|
Example:
|
7
|
-
rails g json_voorhees:engine_create_controller People User
|
7
|
+
rails g json_voorhees:engine_create_controller People User 1 username:string email:string
|
8
8
|
|
9
9
|
This will create:
|
10
10
|
Some files in app/controllers
|
data/lib/generators/json_voorhees/engine_create_controller/engine_create_controller_generator.rb
CHANGED
@@ -4,6 +4,7 @@ module JsonVoorhees
|
|
4
4
|
argument :module_name, :type => :string
|
5
5
|
argument :resource_name, :type => :string
|
6
6
|
argument :api_version, :type => :string, :default => "1"
|
7
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
7
8
|
class_option :authorization, :type => :boolean, :default => true, :description => "Include authorization in controller"
|
8
9
|
|
9
10
|
def sprint
|
@@ -16,6 +17,16 @@ module JsonVoorhees
|
|
16
17
|
|
17
18
|
private
|
18
19
|
|
20
|
+
def params_list
|
21
|
+
params = []
|
22
|
+
attributes.each do |pair|
|
23
|
+
elem = pair.split(/:/)[0]
|
24
|
+
field = ":#{elem}"
|
25
|
+
params << field
|
26
|
+
end
|
27
|
+
return params.join(",")
|
28
|
+
end
|
29
|
+
|
19
30
|
def resource_singular
|
20
31
|
resource_name.underscore.singularize
|
21
32
|
end
|
data/lib/generators/json_voorhees/engine_create_controller/templates/controller_template.rb.erb
CHANGED
@@ -60,7 +60,7 @@ module <%= module_camel %>
|
|
60
60
|
# Only allow a trusted parameter "white list" through.
|
61
61
|
|
62
62
|
def <%= resource_singular %>_params
|
63
|
-
params.require(:<%= resource_singular %>).permit(
|
63
|
+
params.require(:<%= resource_singular %>).permit(<%= params_list %>)
|
64
64
|
end
|
65
65
|
|
66
66
|
# Authorizations below here
|
@@ -55,7 +55,7 @@ module <%= module_camel %>
|
|
55
55
|
# Only allow a trusted parameter "white list" through.
|
56
56
|
|
57
57
|
def <%= resource_singular %>_params
|
58
|
-
params.require(:<%= resource_singular %>).permit(
|
58
|
+
params.require(:<%= resource_singular %>).permit(<%= params_list %>)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -3,7 +3,7 @@ Description:
|
|
3
3
|
It needs to match a resource. Run this generator inside an engine.
|
4
4
|
|
5
5
|
Example:
|
6
|
-
rails g json_voorhees:engine_create_serializer People User
|
6
|
+
rails g json_voorhees:engine_create_serializer People User 1 username:string email:string
|
7
7
|
|
8
8
|
This will create:
|
9
9
|
A file in app/serializers
|
data/lib/generators/json_voorhees/engine_create_serializer/engine_create_serializer_generator.rb
CHANGED
@@ -3,6 +3,7 @@ module JsonVoorhees
|
|
3
3
|
source_root File.expand_path('../templates', __FILE__)
|
4
4
|
argument :module_name, :type => :string
|
5
5
|
argument :resource_name, :type => :string
|
6
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
6
7
|
|
7
8
|
def sprint
|
8
9
|
template "serializer.rb.erb", "app/serializers/#{module_name.underscore}/#{resource_singular}_serializer.rb"
|
@@ -14,6 +14,19 @@ module <%= module_camel %>
|
|
14
14
|
return ::Authorization::<%= module_camel %>::<%= resource_camel %>.include_id?(current_user,object,@options)
|
15
15
|
end
|
16
16
|
|
17
|
+
<% attributes.each do |pair| %>
|
18
|
+
def include_<%= pair.split(/:/)[0] %>?(current_user,<%= resource_singular %>_object,options)
|
19
|
+
return ::Authorization::<%= module_camel %>::<%= resource_camel %>.include_created_at?(current_user,object,@options)
|
20
|
+
end
|
21
|
+
<% end %>
|
22
|
+
def include_created_at?
|
23
|
+
return ::Authorization::<%= module_camel %>::<%= resource_camel %>.include_created_at?(current_user,object,@options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def include_updated_at?
|
27
|
+
return ::Authorization::<%= module_camel %>::<%= resource_camel %>.include_updated_at?(current_user,object,@options)
|
28
|
+
end
|
29
|
+
|
17
30
|
def include_associations!
|
18
31
|
#include! :bulletin if ::Authorization::<%= module_camel %>::<%= resource_camel %>.include_bulletin?(current_user,object,@options)
|
19
32
|
#include! :posts if ::Authorization::<%= module_camel %>::<%= resource_camel %>.include_posts?(current_user,object,@options)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Description:
|
2
|
+
It runs both the engine_create_controller and engine_create_serializer generators.
|
3
|
+
Runs the generators with the default options.
|
4
|
+
|
5
|
+
Example:
|
6
|
+
rails g json_voorhees:engine_scaffold People User 1 username:string email:string
|
7
|
+
|
8
|
+
This will create:
|
9
|
+
a controller and serializer in an engine
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module JsonVoorhees
|
2
|
+
class EngineScaffoldGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
argument :module_name, :type => :string
|
5
|
+
argument :resource_name, :type => :string
|
6
|
+
argument :api_version, :type => :string, :default => "1"
|
7
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
8
|
+
class_option :authorization, :type => :boolean, :default => true, :description => "Include authorization in controller"
|
9
|
+
|
10
|
+
def sprint
|
11
|
+
run "rails g json_voorhees:engine_create_controller #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")}"
|
12
|
+
run "rails g json_voorhees:engine_create_serializer #{module_name} #{resource_name} #{attributes.join(" ")}"
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Description:
|
2
|
+
It takes care of a resource and the work that needs to be done around it, run
|
3
|
+
from the main_app. All of the scaffolds it calls are run with the default options.
|
4
|
+
|
5
|
+
Example:
|
6
|
+
rails g json_voorhees:massive_scaffold People User 1 username:string email:string
|
7
|
+
|
8
|
+
This will create:
|
9
|
+
An api controller, serializer, authorizations and tests.
|
10
|
+
If the regular option is not skipped it will also run a scaffold in the engine
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module JsonVoorhees
|
2
|
+
class MassiveScaffoldGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
argument :module_name, :type => :string
|
5
|
+
argument :resource_name, :type => :string
|
6
|
+
argument :api_version, :type => :string, :default => "1"
|
7
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
8
|
+
class_option :both, :type => :boolean, :default => true, :description => "Run the rails scaffold in addition to this one"
|
9
|
+
|
10
|
+
def sprint
|
11
|
+
inside "engines/#{module_name.underscore}" do
|
12
|
+
if options.both?
|
13
|
+
run "rails g scaffold #{resource_name} #{attributes.join(" ")}"
|
14
|
+
end
|
15
|
+
run "rails g json_voorhees:engine_scaffold #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")}"
|
16
|
+
end
|
17
|
+
run "rails g json_voorhees:app_scaffold #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")}"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -91,6 +91,7 @@ module JsonVoorhees
|
|
91
91
|
inside('engines/people') do
|
92
92
|
#This needs to run the generator for setting up engines
|
93
93
|
run "rails g json_voorhees:setup_engine people"
|
94
|
+
add_generator
|
94
95
|
#Now it needs to create the user class
|
95
96
|
run "rails g scaffold user username:string email:string password_digest:string"
|
96
97
|
run_db_migrations
|
@@ -109,6 +110,15 @@ module JsonVoorhees
|
|
109
110
|
end
|
110
111
|
end
|
111
112
|
|
113
|
+
def add_generator
|
114
|
+
inject_into_file "people.gemspec", after: "s.test_files = Dir[\"test/**/*\"]\n" do <<-'RUBY'
|
115
|
+
|
116
|
+
s.add_development_dependency "json_voorhees"
|
117
|
+
|
118
|
+
RUBY
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
112
122
|
def insert_people_engine
|
113
123
|
inject_into_file 'Gemfile', after: "source \'https://rubygems.org\'\n" do <<-'RUBY'
|
114
124
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'generators/app_scaffold/app_scaffold_generator'
|
3
|
+
|
4
|
+
module JsonVoorhees
|
5
|
+
class AppScaffoldGeneratorTest < Rails::Generators::TestCase
|
6
|
+
tests AppScaffoldGenerator
|
7
|
+
destination Rails.root.join('tmp/generators')
|
8
|
+
setup :prepare_destination
|
9
|
+
|
10
|
+
# test "generator runs without errors" do
|
11
|
+
# assert_nothing_raised do
|
12
|
+
# run_generator ["arguments"]
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'generators/engine_scaffold/engine_scaffold_generator'
|
3
|
+
|
4
|
+
module JsonVoorhees
|
5
|
+
class EngineScaffoldGeneratorTest < Rails::Generators::TestCase
|
6
|
+
tests EngineScaffoldGenerator
|
7
|
+
destination Rails.root.join('tmp/generators')
|
8
|
+
setup :prepare_destination
|
9
|
+
|
10
|
+
# test "generator runs without errors" do
|
11
|
+
# assert_nothing_raised do
|
12
|
+
# run_generator ["arguments"]
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'generators/massive_scaffold/massive_scaffold_generator'
|
3
|
+
|
4
|
+
module JsonVoorhees
|
5
|
+
class MassiveScaffoldGeneratorTest < Rails::Generators::TestCase
|
6
|
+
tests MassiveScaffoldGenerator
|
7
|
+
destination Rails.root.join('tmp/generators')
|
8
|
+
setup :prepare_destination
|
9
|
+
|
10
|
+
# test "generator runs without errors" do
|
11
|
+
# assert_nothing_raised do
|
12
|
+
# run_generator ["arguments"]
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
end
|
16
|
+
end
|
data/test/test_app/Gemfile
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
+
gem 'people', :path => "engines/people"
|
4
|
+
|
5
|
+
|
3
6
|
|
4
7
|
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
5
8
|
gem 'rails', '4.1.5'
|
@@ -40,3 +43,23 @@ gem 'spring', group: :development
|
|
40
43
|
|
41
44
|
#gem "json_voorhees", :git => "https://github.com/cleor41/json_voorhees.git"
|
42
45
|
gem "json_voorhees", :path => "../../../json_voorhees"
|
46
|
+
|
47
|
+
group :development, :test do
|
48
|
+
gem "figaro", "~> 0.7.0"
|
49
|
+
gem "annotate", ">=2.6.0"
|
50
|
+
gem "better_errors", "~> 1.1.0"
|
51
|
+
gem "binding_of_caller", "~> 0.7.1"
|
52
|
+
gem "rspec-rails", "~> 3.0.0"
|
53
|
+
gem "byebug", "~> 3.2.0"
|
54
|
+
gem "factory_girl_rails", "~> 4.0"
|
55
|
+
gem "database_cleaner", "~> 1.3.0"
|
56
|
+
end
|
57
|
+
|
58
|
+
gem "authorization", path: "gems/authorization"
|
59
|
+
gem "active_model_serializers", "~> 0.8.0"
|
60
|
+
gem "rails-api"
|
61
|
+
gem "kaminari"
|
62
|
+
gem "bcrypt", "~> 3.1.7"
|
63
|
+
gem "type_cartographer"
|
64
|
+
gem "devise", "~> 3.2.4"
|
65
|
+
gem "arcadex", "~> 1.0.4"
|