json_voorhees 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +52 -4
  3. data/lib/generators/json_voorhees/app_make_authorizations/USAGE +1 -1
  4. data/lib/generators/json_voorhees/app_make_authorizations/app_make_authorizations_generator.rb +1 -0
  5. data/lib/generators/json_voorhees/app_make_authorizations/templates/auth_file.rb.erb +8 -1
  6. data/lib/generators/json_voorhees/app_make_tests/USAGE +1 -1
  7. data/lib/generators/json_voorhees/app_make_tests/app_make_tests_generator.rb +26 -0
  8. data/lib/generators/json_voorhees/app_make_tests/templates/factory.rb.erb +3 -1
  9. data/lib/generators/json_voorhees/app_make_tests/templates/model.rb.erb +5 -0
  10. data/lib/generators/json_voorhees/app_make_tests/templates/no_auth_request.rb.erb +90 -0
  11. data/lib/generators/json_voorhees/app_scaffold/USAGE +9 -0
  12. data/lib/generators/json_voorhees/app_scaffold/app_scaffold_generator.rb +22 -0
  13. data/lib/generators/json_voorhees/engine_create_controller/USAGE +1 -1
  14. data/lib/generators/json_voorhees/engine_create_controller/engine_create_controller_generator.rb +11 -0
  15. data/lib/generators/json_voorhees/engine_create_controller/templates/controller_template.rb.erb +1 -1
  16. data/lib/generators/json_voorhees/engine_create_controller/templates/no_auth_controller_template.rb.erb +1 -1
  17. data/lib/generators/json_voorhees/engine_create_serializer/USAGE +1 -1
  18. data/lib/generators/json_voorhees/engine_create_serializer/engine_create_serializer_generator.rb +1 -0
  19. data/lib/generators/json_voorhees/engine_create_serializer/templates/serializer.rb.erb +13 -0
  20. data/lib/generators/json_voorhees/engine_scaffold/USAGE +9 -0
  21. data/lib/generators/json_voorhees/engine_scaffold/engine_scaffold_generator.rb +18 -0
  22. data/lib/generators/json_voorhees/massive_scaffold/USAGE +10 -0
  23. data/lib/generators/json_voorhees/massive_scaffold/massive_scaffold_generator.rb +23 -0
  24. data/lib/generators/json_voorhees/setup_app/setup_app_generator.rb +10 -0
  25. data/lib/json_voorhees/version.rb +1 -1
  26. data/test/lib/generators/json_voorhees/app_scaffold_generator_test.rb +16 -0
  27. data/test/lib/generators/json_voorhees/engine_scaffold_generator_test.rb +16 -0
  28. data/test/lib/generators/json_voorhees/massive_scaffold_generator_test.rb +16 -0
  29. data/test/test_app/Gemfile +23 -0
  30. data/test/test_app/Gemfile.lock +99 -1
  31. data/test/test_app/README.md +1 -0
  32. data/test/test_app/app/controllers/api/v1/api_controller.rb +26 -0
  33. data/test/test_app/app/controllers/app_index_controller.rb +4 -0
  34. data/test/test_app/app/controllers/application_controller.rb +5 -0
  35. data/test/test_app/app/controllers/main_controller.rb +4 -0
  36. data/test/test_app/app/views/app_index/app.html.erb +0 -0
  37. data/test/test_app/app/views/layouts/app_index.html.erb +9 -0
  38. data/test/test_app/app/views/layouts/application.html.erb +8 -3
  39. data/test/test_app/app/views/main/admin.html.erb +9 -0
  40. data/test/test_app/config/application.rb +4 -0
  41. data/test/test_app/config/routes.rb +8 -0
  42. data/test/test_app/db/development.sqlite3 +0 -0
  43. data/test/test_app/db/migrate/20140905145354_create_people_users.people.rb +12 -0
  44. data/test/test_app/db/migrate/20140905145355_create_arcadex_tokens.arcadex.rb +12 -0
  45. data/test/test_app/db/migrate/20140905145356_add_index_to_token.arcadex.rb +6 -0
  46. data/test/test_app/db/production.sqlite3 +0 -0
  47. data/test/test_app/db/schema.rb +19 -1
  48. data/test/test_app/db/test.sqlite3 +0 -0
  49. data/test/test_app/engines/people/Gemfile +14 -0
  50. data/test/test_app/engines/people/Gemfile.lock +92 -0
  51. data/test/test_app/engines/people/MIT-LICENSE +20 -0
  52. data/test/test_app/engines/people/README.md +1 -0
  53. data/test/test_app/engines/people/Rakefile +34 -0
  54. data/test/test_app/engines/people/app/assets/javascripts/people/application.js +13 -0
  55. data/test/test_app/engines/people/app/assets/javascripts/people/users.js +2 -0
  56. data/test/test_app/engines/people/app/assets/stylesheets/people/application.css +15 -0
  57. data/test/test_app/engines/people/app/assets/stylesheets/people/users.css +4 -0
  58. data/test/test_app/engines/people/app/assets/stylesheets/scaffold.css +56 -0
  59. data/test/test_app/engines/people/app/controllers/people/api/v1/application_controller.rb +5 -0
  60. data/test/test_app/engines/people/app/controllers/people/api/v1/users_controller.rb +124 -0
  61. data/test/test_app/engines/people/app/controllers/people/application_controller.rb +4 -0
  62. data/test/test_app/engines/people/app/controllers/people/users_controller.rb +62 -0
  63. data/test/test_app/engines/people/app/helpers/people/application_helper.rb +4 -0
  64. data/test/test_app/engines/people/app/helpers/people/users_helper.rb +4 -0
  65. data/test/test_app/engines/people/app/models/people/user.rb +26 -0
  66. data/test/test_app/engines/people/app/serializers/people/user_serializer.rb +39 -0
  67. data/test/test_app/engines/people/app/views/layouts/people/default/application.html.erb +14 -0
  68. data/test/test_app/engines/people/app/views/people/users/_form.html.erb +29 -0
  69. data/test/test_app/engines/people/app/views/people/users/edit.html.erb +6 -0
  70. data/test/test_app/engines/people/app/views/people/users/index.html.erb +29 -0
  71. data/test/test_app/engines/people/app/views/people/users/new.html.erb +5 -0
  72. data/test/test_app/engines/people/app/views/people/users/show.html.erb +19 -0
  73. data/test/test_app/engines/people/bin/rails +12 -0
  74. data/test/test_app/engines/people/config/routes.rb +24 -0
  75. data/test/test_app/engines/people/db/migrate/20140905145341_create_people_users.rb +11 -0
  76. data/test/test_app/engines/people/lib/people/engine.rb +5 -0
  77. data/test/test_app/engines/people/lib/people/version.rb +3 -0
  78. data/test/test_app/engines/people/lib/people.rb +4 -0
  79. data/test/test_app/engines/people/lib/tasks/people_tasks.rake +4 -0
  80. data/test/test_app/engines/people/people.gemspec +31 -0
  81. data/test/test_app/engines/people/test/controllers/people/users_controller_test.rb +51 -0
  82. data/test/test_app/{README.rdoc → engines/people/test/dummy/README.rdoc} +0 -0
  83. data/test/test_app/engines/people/test/dummy/Rakefile +6 -0
  84. data/test/test_app/engines/people/test/dummy/app/assets/javascripts/application.js +13 -0
  85. data/test/test_app/engines/people/test/dummy/app/assets/stylesheets/application.css +15 -0
  86. data/test/test_app/engines/people/test/dummy/app/controllers/application_controller.rb +5 -0
  87. data/test/test_app/engines/people/test/dummy/app/helpers/application_helper.rb +2 -0
  88. data/test/test_app/engines/people/test/dummy/app/views/layouts/application.html.erb +14 -0
  89. data/test/test_app/engines/people/test/dummy/bin/bundle +3 -0
  90. data/test/test_app/engines/people/test/dummy/bin/rails +4 -0
  91. data/test/test_app/engines/people/test/dummy/bin/rake +4 -0
  92. data/test/test_app/engines/people/test/dummy/config/application.rb +23 -0
  93. data/test/test_app/engines/people/test/dummy/config/boot.rb +5 -0
  94. data/test/test_app/engines/people/test/dummy/config/database.yml +25 -0
  95. data/test/test_app/engines/people/test/dummy/config/environment.rb +5 -0
  96. data/test/test_app/engines/people/test/dummy/config/environments/development.rb +37 -0
  97. data/test/test_app/engines/people/test/dummy/config/environments/production.rb +82 -0
  98. data/test/test_app/engines/people/test/dummy/config/environments/test.rb +39 -0
  99. data/test/test_app/engines/people/test/dummy/config/initializers/assets.rb +8 -0
  100. data/test/test_app/engines/people/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  101. data/test/test_app/engines/people/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  102. data/test/test_app/engines/people/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  103. data/test/test_app/engines/people/test/dummy/config/initializers/inflections.rb +16 -0
  104. data/test/test_app/engines/people/test/dummy/config/initializers/mime_types.rb +4 -0
  105. data/test/test_app/engines/people/test/dummy/config/initializers/session_store.rb +3 -0
  106. data/test/test_app/engines/people/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  107. data/test/test_app/engines/people/test/dummy/config/locales/en.yml +23 -0
  108. data/test/test_app/engines/people/test/dummy/config/routes.rb +4 -0
  109. data/test/test_app/engines/people/test/dummy/config/secrets.yml +22 -0
  110. data/test/test_app/engines/people/test/dummy/config.ru +4 -0
  111. data/test/test_app/engines/people/test/dummy/db/schema.rb +24 -0
  112. data/test/test_app/engines/people/test/dummy/public/404.html +67 -0
  113. data/test/test_app/engines/people/test/dummy/public/422.html +67 -0
  114. data/test/test_app/engines/people/test/dummy/public/500.html +66 -0
  115. data/test/test_app/engines/people/test/dummy/public/favicon.ico +0 -0
  116. data/test/test_app/engines/people/test/fixtures/people/users.yml +11 -0
  117. data/test/test_app/engines/people/test/helpers/people/users_helper_test.rb +6 -0
  118. data/test/test_app/engines/people/test/integration/navigation_test.rb +10 -0
  119. data/test/test_app/engines/people/test/models/people/user_test.rb +9 -0
  120. data/test/test_app/engines/people/test/people_test.rb +7 -0
  121. data/test/test_app/engines/people/test/test_helper.rb +15 -0
  122. data/test/test_app/gems/authorization/Gemfile +14 -0
  123. data/test/test_app/gems/authorization/Gemfile.lock +92 -0
  124. data/test/test_app/gems/authorization/MIT-LICENSE +20 -0
  125. data/test/test_app/gems/authorization/README.rdoc +3 -0
  126. data/test/test_app/gems/authorization/Rakefile +32 -0
  127. data/test/test_app/gems/authorization/authorization.gemspec +23 -0
  128. data/test/test_app/gems/authorization/lib/authorization/people/user.rb +82 -0
  129. data/test/test_app/gems/authorization/lib/authorization/version.rb +3 -0
  130. data/test/test_app/gems/authorization/lib/authorization.rb +3 -0
  131. data/test/test_app/gems/authorization/lib/tasks/authorization_tasks.rake +4 -0
  132. data/test/test_app/gems/authorization/test/authorization_test.rb +7 -0
  133. data/test/test_app/gems/authorization/test/dummy/README.rdoc +28 -0
  134. data/test/test_app/gems/authorization/test/dummy/Rakefile +6 -0
  135. data/test/test_app/gems/authorization/test/dummy/app/assets/javascripts/application.js +13 -0
  136. data/test/test_app/gems/authorization/test/dummy/app/assets/stylesheets/application.css +15 -0
  137. data/test/test_app/gems/authorization/test/dummy/app/controllers/application_controller.rb +5 -0
  138. data/test/test_app/gems/authorization/test/dummy/app/helpers/application_helper.rb +2 -0
  139. data/test/test_app/gems/authorization/test/dummy/app/views/layouts/application.html.erb +14 -0
  140. data/test/test_app/gems/authorization/test/dummy/bin/bundle +3 -0
  141. data/test/test_app/gems/authorization/test/dummy/bin/rails +4 -0
  142. data/test/test_app/gems/authorization/test/dummy/bin/rake +4 -0
  143. data/test/test_app/gems/authorization/test/dummy/config/application.rb +23 -0
  144. data/test/test_app/gems/authorization/test/dummy/config/boot.rb +5 -0
  145. data/test/test_app/gems/authorization/test/dummy/config/database.yml +25 -0
  146. data/test/test_app/gems/authorization/test/dummy/config/environment.rb +5 -0
  147. data/test/test_app/gems/authorization/test/dummy/config/environments/development.rb +37 -0
  148. data/test/test_app/gems/authorization/test/dummy/config/environments/production.rb +82 -0
  149. data/test/test_app/gems/authorization/test/dummy/config/environments/test.rb +39 -0
  150. data/test/test_app/gems/authorization/test/dummy/config/initializers/assets.rb +8 -0
  151. data/test/test_app/gems/authorization/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  152. data/test/test_app/gems/authorization/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  153. data/test/test_app/gems/authorization/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  154. data/test/test_app/gems/authorization/test/dummy/config/initializers/inflections.rb +16 -0
  155. data/test/test_app/gems/authorization/test/dummy/config/initializers/mime_types.rb +4 -0
  156. data/test/test_app/gems/authorization/test/dummy/config/initializers/session_store.rb +3 -0
  157. data/test/test_app/gems/authorization/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  158. data/test/test_app/gems/authorization/test/dummy/config/locales/en.yml +23 -0
  159. data/test/test_app/gems/authorization/test/dummy/config/routes.rb +56 -0
  160. data/test/test_app/gems/authorization/test/dummy/config/secrets.yml +22 -0
  161. data/test/test_app/gems/authorization/test/dummy/config.ru +4 -0
  162. data/test/test_app/gems/authorization/test/dummy/public/404.html +67 -0
  163. data/test/test_app/gems/authorization/test/dummy/public/422.html +67 -0
  164. data/test/test_app/gems/authorization/test/dummy/public/500.html +66 -0
  165. data/test/test_app/gems/authorization/test/dummy/public/favicon.ico +0 -0
  166. data/test/test_app/gems/authorization/test/test_helper.rb +15 -0
  167. data/test/test_app/log/development.log +195 -0
  168. data/test/test_app/log/production.log +20 -0
  169. data/test/test_app/log/test.log +8427 -0
  170. data/test/test_app/spec/controllers/app_index_controller_spec.rb +12 -0
  171. data/test/test_app/spec/engines/people/api/v1/models/user_spec.rb +59 -0
  172. data/test/test_app/spec/engines/people/api/v1/requests/user_spec.rb +154 -0
  173. data/test/test_app/spec/engines/people/api/v1/routing/user_spec.rb +77 -0
  174. data/test/test_app/spec/factories/people_user_factory.rb +14 -0
  175. data/test/test_app/spec/rails_helper.rb +47 -0
  176. data/test/test_app/spec/spec_helper.rb +78 -0
  177. data/test/test_app/spec/support/factory_girl.rb +16 -0
  178. data/test/test_app/spec/support/request_helpers.rb +7 -0
  179. metadata +293 -6
  180. 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: a8a46f42ce5e5ab8312c001a103eff6ab1f02d4c
4
- data.tar.gz: 80b319405df68103ec5d76152d96ad5659240d7f
3
+ metadata.gz: f4f093f809f09e2c46269d6041ab640569ad40b3
4
+ data.tar.gz: 96a9615de58292694f815a2feaee0afcce3c102e
5
5
  SHA512:
6
- metadata.gz: 86832aa8c07eeb1f4a98a27532b83b7019c2729e59dd06e853782d700227428c34e5567dc83a38cc08cacdee1fcf879bf28c25e461a061adeb7eaac4ef92a058
7
- data.tar.gz: 522c99c2f1c1a0757b5d10a4525812d15a53f562d71127872a80bcfe8f8e5735aa247b1414a3fb84f6a638e83009d3fa53b2e81dcb9f54e2a5a51419ed6d8a02
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. Create a couple scaffolding services
78
- 2. Refactor everything
79
- 3. Figure out a better way to test this thing
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.
@@ -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]
@@ -3,7 +3,7 @@ Description:
3
3
  Run this generator in the main_app
4
4
 
5
5
  Example:
6
- rails g json_voorhees:app_make_tests People User
6
+ rails g json_voorhees:app_make_tests People User 1 username:string email:string
7
7
 
8
8
  This will create:
9
9
  Some files in spec
@@ -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 :email do |n|
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
@@ -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
@@ -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(:params_here)
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(:params_here)
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
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module JsonVoorhees
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -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
@@ -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"