json_voorhees 0.1.0 → 0.2.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.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -12
  3. data/lib/generators/json_voorhees/app_make_tests/app_make_tests_generator.rb +10 -1
  4. data/lib/generators/json_voorhees/app_make_tests/templates/no_auth_request.rb.erb +25 -1
  5. data/lib/generators/json_voorhees/app_make_tests/templates/request.rb.erb +37 -1
  6. data/lib/generators/json_voorhees/app_scaffold/app_scaffold_generator.rb +7 -2
  7. data/lib/generators/json_voorhees/engine_create_controller/engine_create_controller_generator.rb +2 -2
  8. data/lib/generators/json_voorhees/engine_create_controller/templates/controller_template.rb.erb +6 -6
  9. data/lib/generators/json_voorhees/engine_create_controller/templates/no_auth_controller_template.rb.erb +6 -6
  10. data/lib/generators/json_voorhees/engine_scaffold/engine_scaffold_generator.rb +8 -3
  11. data/lib/generators/json_voorhees/massive_scaffold/massive_scaffold_generator.rb +14 -2
  12. data/lib/generators/json_voorhees/setup_app/setup_app_generator.rb +2 -2
  13. data/lib/generators/json_voorhees/setup_app/templates/api_controller_no_arcadex.rb +6 -0
  14. data/lib/generators/json_voorhees/setup_app/templates/user/specs/request_specs.rb +96 -65
  15. data/lib/json_voorhees/version.rb +1 -1
  16. data/test/test_app/Gemfile.lock +1 -1
  17. data/test/test_app/db/development.sqlite3 +0 -0
  18. data/test/test_app/db/schema.rb +1 -19
  19. data/test/test_app/engines/people/test/dummy/db/development.sqlite3 +0 -0
  20. data/test/test_app/engines/people/test/dummy/log/development.log +0 -0
  21. data/test/test_app/log/development.log +91 -0
  22. data/test/test_app/log/production.log +9 -0
  23. data/test/test_app/log/test.log +4428 -0
  24. metadata +8 -9
  25. data/test/test_app/db/production.sqlite3 +0 -0
  26. data/test/test_app/db/test.sqlite3 +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4f093f809f09e2c46269d6041ab640569ad40b3
4
- data.tar.gz: 96a9615de58292694f815a2feaee0afcce3c102e
3
+ metadata.gz: 14c58653a601ff9a59fe56c2e082127440799685
4
+ data.tar.gz: 8a3d0b0c47448955b8ef5ac3ce61877b3e31f849
5
5
  SHA512:
6
- metadata.gz: f817868b48bd28e2a20dfe3ff9acc9ab0b7a9fb8fd9b3eb9acae44bdf2383eac8e9bd99dff981507ea0e62dfca4055e75e17d0240ccac363d2304ce9919b7d26
7
- data.tar.gz: 93c3e86f4989e71a86b89351eeebe225ffa10cb03824bac7e9823fa3c871ae2067e01a2a5f630803d1403eac79e631c2dfde7bc2bb75fa82354761ccc7fc585a
6
+ metadata.gz: c4ec8fa6272187474d702fb5e1700e7591ab70afd40f1bb6f98f9430ad72c803e1d0a4e9d577da007f873286ba94171f96a8ecf86205cf192516e22524a6642b
7
+ data.tar.gz: 4102ea63382fa288656c20ff26c5cd1e88dd1d208873215a5a01f6bcff7dc3945922888d78de5ca21eca17027b4f35bb4de5b3e3e01c477b4cda103b4118d10a
data/README.md CHANGED
@@ -95,33 +95,38 @@ After scaffolding out your resource, generate the necessary api controller
95
95
  and its serializer
96
96
 
97
97
  ```bash
98
- rails g json_voorhees:engine_create_controller [engine name] [resource name]
99
- rails g json_voorhees:engine_create_serializer [engine name] [resource name]
98
+ rails g json_voorhees:engine_scaffold [engine name] [resource name] [api_version] [field:type field:type]
99
+
100
+ or
101
+
102
+ rails g json_voorhees:engine_create_controller [engine name] [resource name] [api_version] [field:type field:type]
103
+ rails g json_voorhees:engine_create_serializer [engine name] [resource name] [field:type field:type]
100
104
  ```
101
105
 
102
106
  Authorizations are all handled in a gem called authorization.
103
107
  Specs are also ran through RSpec and FactoryGirl, Go to the main_app and run
104
108
 
105
109
  ```bash
106
- rails g json_voorhees:app_make_authorizations [engine name] [resource name]
107
- rails g json_voorhees:app_make_tests [engine name] [resource name]
110
+ rails g json_voorhees:app_scaffold [engine name] [resource name] [api_version] [field:type field:type]
111
+
112
+ or
113
+
114
+ rails g json_voorhees:app_make_authorizations [engine name] [resource name] [field:type field:type]
115
+ rails g json_voorhees:app_make_tests [engine name] [resource name] [api_version] [field:type field:type]
108
116
  ```
109
117
 
110
118
  For every resource created, those 4 are ran in their respective locations.
111
119
 
112
120
  ## Notes
113
121
 
114
- 1. Remember to put your engine inside the main_apps Gemfile after you create it.
115
- 2. Remember to mount the engine inside the main_apps routing file.
116
- 3. Your engines resource routes also need to go inside the correct scoping inside the engine.
117
- 4. After you create your model and create the api_controller, change the white listed
118
- params in the controller to fit accordingly.
119
- 5. The attribute changes need to also be accurately represented in the factory girl factory and also in the serializer and authorization gem.
122
+ 1. After scaffolding and migrating, make sure to run rspec to make sure everything is setup correctly
123
+ 2. For advanced use, check out the description of each generators options
120
124
 
121
125
  ## To Do
122
126
 
123
127
  1. Refactor everything
124
128
  2. Figure out a better way to test this thing
125
129
  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
130
+ 4. Pass more options from scaffolds to individual generators
131
+ 5. Create a better admin page and system
132
+ 6. Maybe give an option to include pagination?
@@ -49,7 +49,16 @@ module JsonVoorhees
49
49
  if field == "decimal"
50
50
  return 3.14159
51
51
  end
52
- #Theres also date, datetime, time and timestamp
52
+ if field == "date"
53
+ return "\"#{Date.new}\""
54
+ end
55
+ if field == "time"
56
+ return "\"#{Time.new}\""
57
+ end
58
+ if field == "datetime"
59
+ return "\"#{DateTime.new}\""
60
+ end
61
+ #If there are any values that I missed
53
62
  return nil
54
63
  end
55
64
 
@@ -2,7 +2,7 @@ require "rails_helper"
2
2
 
3
3
  #-#-#-#-#REST#-#-#-#-#
4
4
  RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request do
5
- describe "Rest Routes" do
5
+ describe "Index" do
6
6
  before(:example) do
7
7
  end
8
8
  # get /api/<%= api_version %>/<%= resource_plural %>
@@ -11,12 +11,24 @@ RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request d
11
11
  get 'api/<%= api_version %>/<%= resource_plural %>'
12
12
  expect(response.status).to eq(200) #ok
13
13
  end
14
+ end
15
+ end
16
+ RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request do
17
+ describe "Show" do
18
+ before(:example) do
19
+ end
14
20
  # get /api/<%= api_version %>/<%= resource_plural %>/1
15
21
  it "Gets a <%= resource_singular %> by id" do
16
22
  FactoryGirl.create(:<%= module_snake %>_<%= resource_singular %>)
17
23
  get 'api/<%= api_version %>/<%= resource_plural %>/1'
18
24
  expect(response.status).to eq(200) #ok
19
25
  end
26
+ end
27
+ end
28
+ RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request do
29
+ describe "Create" do
30
+ before(:example) do
31
+ end
20
32
  # post /api/<%= api_version %>/<%= resource_plural %>
21
33
  it "Creates <%= resource_singular %>" do
22
34
  attrs = FactoryGirl.attributes_for(:<%= module_snake %>_<%= resource_singular %>)
@@ -25,6 +37,12 @@ RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request d
25
37
  post 'api/<%= api_version %>/<%= resource_plural %>', hash
26
38
  expect(response.status).to eq(200) #ok
27
39
  end
40
+ end
41
+ end
42
+ RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request do
43
+ describe "Update" do
44
+ before(:example) do
45
+ end
28
46
  # patch/put /api/<%= api_version %>/<%= resource_plural %>/1
29
47
  it "Updates <%= resource_singular %>" do
30
48
  #Create the <%= resource_singular %> through the api
@@ -38,6 +56,12 @@ RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request d
38
56
  put "api/<%= api_version %>/<%= resource_plural %>/1", hash
39
57
  expect(response.status).to eq(200) #ok
40
58
  end
59
+ end
60
+ end
61
+ RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request do
62
+ describe "Destroy" do
63
+ before(:example) do
64
+ end
41
65
  # delete /api/<%= api_version %>/<%= resource_plural %>/1
42
66
  it "Deletes <%= resource_singular %>" do
43
67
  #Create the <%= resource_singular %> through the api
@@ -2,7 +2,7 @@ require "rails_helper"
2
2
 
3
3
  #-#-#-#-#REST#-#-#-#-#
4
4
  RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request do
5
- describe "Rest Routes" do
5
+ describe "Index" do
6
6
  before(:example) do
7
7
  @user = FactoryGirl.create(:people_user)
8
8
  token = @user.tokens[0].auth_token
@@ -14,12 +14,30 @@ RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request d
14
14
  get 'api/<%= api_version %>/<%= resource_plural %>', nil, @header
15
15
  expect(response.status).to eq(200) #ok
16
16
  end
17
+ end
18
+ end
19
+ RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request do
20
+ describe "Show" do
21
+ before(:example) do
22
+ @user = FactoryGirl.create(:people_user)
23
+ token = @user.tokens[0].auth_token
24
+ @header = {"Auth-Token" => token, "Email" => @user.email}
25
+ end
17
26
  # get /api/<%= api_version %>/<%= resource_plural %>/1
18
27
  it "Gets a <%= resource_singular %> by id" do
19
28
  FactoryGirl.create(:<%= module_snake %>_<%= resource_singular %>)
20
29
  get 'api/<%= api_version %>/<%= resource_plural %>/1', nil, @header
21
30
  expect(response.status).to eq(200) #ok
22
31
  end
32
+ end
33
+ end
34
+ RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request do
35
+ describe "Create" do
36
+ before(:example) do
37
+ @user = FactoryGirl.create(:people_user)
38
+ token = @user.tokens[0].auth_token
39
+ @header = {"Auth-Token" => token, "Email" => @user.email}
40
+ end
23
41
  # post /api/<%= api_version %>/<%= resource_plural %>
24
42
  it "Creates <%= resource_singular %>" do
25
43
  attrs = FactoryGirl.attributes_for(:<%= module_snake %>_<%= resource_singular %>)
@@ -28,6 +46,15 @@ RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request d
28
46
  post 'api/<%= api_version %>/<%= resource_plural %>', hash, @header
29
47
  expect(response.status).to eq(200) #ok
30
48
  end
49
+ end
50
+ end
51
+ RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request do
52
+ describe "Update" do
53
+ before(:example) do
54
+ @user = FactoryGirl.create(:people_user)
55
+ token = @user.tokens[0].auth_token
56
+ @header = {"Auth-Token" => token, "Email" => @user.email}
57
+ end
31
58
  # patch/put /api/<%= api_version %>/<%= resource_plural %>/1
32
59
  it "Updates <%= resource_singular %>" do
33
60
  #Create the <%= resource_singular %> through the api
@@ -41,6 +68,15 @@ RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request d
41
68
  put "api/<%= api_version %>/<%= resource_plural %>/1", hash, @header
42
69
  expect(response.status).to eq(200) #ok
43
70
  end
71
+ end
72
+ end
73
+ RSpec.describe ::<%= module_camel %>::<%= resource_camel %>, :type => :request do
74
+ describe "Destroy" do
75
+ before(:example) do
76
+ @user = FactoryGirl.create(:people_user)
77
+ token = @user.tokens[0].auth_token
78
+ @header = {"Auth-Token" => token, "Email" => @user.email}
79
+ end
44
80
  # delete /api/<%= api_version %>/<%= resource_plural %>/1
45
81
  it "Deletes <%= resource_singular %>" do
46
82
  #Create the <%= resource_singular %> through the api
@@ -12,8 +12,13 @@ module JsonVoorhees
12
12
 
13
13
 
14
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(" ")}"
15
+ if options.arcadex?
16
+ run "rails g json_voorhees:app_make_authorizations #{module_name} #{resource_name} #{attributes.join(" ")}"
17
+ run "rails g json_voorhees:app_make_tests #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")}"
18
+ else
19
+ run "rails g json_voorhees:app_make_authorizations --skip-arcadex #{module_name} #{resource_name} #{attributes.join(" ")}"
20
+ run "rails g json_voorhees:app_make_tests --skip-arcadex #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")}"
21
+ end
17
22
  end
18
23
 
19
24
  private
@@ -5,10 +5,10 @@ module JsonVoorhees
5
5
  argument :resource_name, :type => :string
6
6
  argument :api_version, :type => :string, :default => "1"
7
7
  argument :attributes, type: :array, default: [], banner: "field:type field:type"
8
- class_option :authorization, :type => :boolean, :default => true, :description => "Include authorization in controller"
8
+ class_option :arcadex, :type => :boolean, :default => true, :description => "Include authorization in controller"
9
9
 
10
10
  def sprint
11
- if options.authorization?
11
+ if options.arcadex?
12
12
  template "controller_template.rb.erb", "app/controllers/#{module_name.underscore}/api/v#{api_version}/#{resource_plural}_controller.rb"
13
13
  else
14
14
  template "no_auth_controller_template.rb.erb", "app/controllers/#{module_name.underscore}/api/v#{api_version}/#{resource_plural}_controller.rb"
@@ -2,7 +2,7 @@ require_dependency "<%= module_snake %>/api/v<%= api_version %>/application_cont
2
2
  require 'authorization'
3
3
 
4
4
  module <%= module_camel %>
5
- class Api::V1::<%= resource_camel.pluralize %>Controller < Api::V1::ApplicationController
5
+ class Api::V<%= api_version %>::<%= resource_camel.pluralize %>Controller < Api::V<%= api_version %>::ApplicationController
6
6
  before_action :set_<%= resource_singular %>, only: [:show, :update, :destroy]
7
7
  before_action :index_authorize, only: [:index]
8
8
  before_action :show_authorize, only: [:show]
@@ -10,18 +10,18 @@ module <%= module_camel %>
10
10
  before_action :update_authorize, only: [:update]
11
11
  before_action :destroy_authorize, only: [:destroy]
12
12
 
13
- # GET /api/1/<%= resource_plural %>
13
+ # GET /api/<%= api_version %>/<%= resource_plural %>
14
14
  def index
15
15
  @<%= resource_plural %> = ::<%= module_camel %>::<%= resource_camel %>.all
16
16
  render json: @<%= resource_plural %>
17
17
  end
18
18
 
19
- # GET /api/1/<%= resource_plural %>/1
19
+ # GET /api/<%= api_version %>/<%= resource_plural %>/1
20
20
  def show
21
21
  render json: @<%= resource_singular %>
22
22
  end
23
23
 
24
- # POST /api/1/<%= resource_plural %>
24
+ # POST /api/<%= api_version %>/<%= resource_plural %>
25
25
  def create
26
26
  @<%= resource_singular %> = ::<%= module_camel %>::<%= resource_camel %>.new(<%= resource_singular %>_params)
27
27
  if @<%= resource_singular %>.save
@@ -31,7 +31,7 @@ module <%= module_camel %>
31
31
  end
32
32
  end
33
33
 
34
- # PATCH/PUT /api/1/<%= resource_plural %>/1
34
+ # PATCH/PUT /api/<%= api_version %>/<%= resource_plural %>/1
35
35
  def update
36
36
  if @<%= resource_singular %>.update(<%= resource_singular %>_params)
37
37
  render json: @<%= resource_singular %>
@@ -40,7 +40,7 @@ module <%= module_camel %>
40
40
  end
41
41
  end
42
42
 
43
- # DELETE /api/1/<%= resource_plural %>/1
43
+ # DELETE /api/<%= api_version %>/<%= resource_plural %>/1
44
44
  def destroy
45
45
  @<%= resource_singular %>.destroy
46
46
  render json: {}
@@ -2,21 +2,21 @@ require_dependency "<%= module_snake %>/api/v<%= api_version %>/application_cont
2
2
  require 'authorization'
3
3
 
4
4
  module <%= module_camel %>
5
- class Api::V1::<%= resource_camel.pluralize %>Controller < Api::V1::ApplicationController
5
+ class Api::V<%= api_version %>::<%= resource_camel.pluralize %>Controller < Api::V<%= api_version %>::ApplicationController
6
6
  before_action :set_<%= resource_singular %>, only: [:show, :update, :destroy]
7
7
 
8
- # GET /api/1/<%= resource_plural %>
8
+ # GET /api/<%= api_version %>/<%= resource_plural %>
9
9
  def index
10
10
  @<%= resource_plural %> = ::<%= module_camel %>::<%= resource_camel %>.all
11
11
  render json: @<%= resource_plural %>
12
12
  end
13
13
 
14
- # GET /api/1/<%= resource_plural %>/1
14
+ # GET /api/<%= api_version %>/<%= resource_plural %>/1
15
15
  def show
16
16
  render json: @<%= resource_singular %>
17
17
  end
18
18
 
19
- # POST /api/1/<%= resource_plural %>
19
+ # POST /api/<%= api_version %>/<%= resource_plural %>
20
20
  def create
21
21
  @<%= resource_singular %> = ::<%= module_camel %>::<%= resource_camel %>.new(<%= resource_singular %>_params)
22
22
  if @<%= resource_singular %>.save
@@ -26,7 +26,7 @@ module <%= module_camel %>
26
26
  end
27
27
  end
28
28
 
29
- # PATCH/PUT /api/1/<%= resource_plural %>/1
29
+ # PATCH/PUT /api/<%= api_version %>/<%= resource_plural %>/1
30
30
  def update
31
31
  if @<%= resource_singular %>.update(<%= resource_singular %>_params)
32
32
  render json: @<%= resource_singular %>
@@ -35,7 +35,7 @@ module <%= module_camel %>
35
35
  end
36
36
  end
37
37
 
38
- # DELETE /api/1/<%= resource_plural %>/1
38
+ # DELETE /api/<%= api_version %>/<%= resource_plural %>/1
39
39
  def destroy
40
40
  @<%= resource_singular %>.destroy
41
41
  render json: {}
@@ -5,11 +5,16 @@ module JsonVoorhees
5
5
  argument :resource_name, :type => :string
6
6
  argument :api_version, :type => :string, :default => "1"
7
7
  argument :attributes, type: :array, default: [], banner: "field:type field:type"
8
- class_option :authorization, :type => :boolean, :default => true, :description => "Include authorization in controller"
8
+ class_option :arcadex, :type => :boolean, :default => true, :description => "Include authorization in controller"
9
9
 
10
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(" ")}"
11
+ if options.arcadex?
12
+ run "rails g json_voorhees:engine_create_controller #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")}"
13
+ run "rails g json_voorhees:engine_create_serializer #{module_name} #{resource_name} #{attributes.join(" ")}"
14
+ else
15
+ run "rails g json_voorhees:engine_create_controller --skip-arcadex #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")}"
16
+ run "rails g json_voorhees:engine_create_serializer --skip-arcadex #{module_name} #{resource_name} #{attributes.join(" ")}"
17
+ end
13
18
  end
14
19
 
15
20
  private
@@ -6,15 +6,27 @@ module JsonVoorhees
6
6
  argument :api_version, :type => :string, :default => "1"
7
7
  argument :attributes, type: :array, default: [], banner: "field:type field:type"
8
8
  class_option :both, :type => :boolean, :default => true, :description => "Run the rails scaffold in addition to this one"
9
+ class_option :model, :type => :boolean, :default => true, :description => "Create model stub tests"
10
+ class_option :request, :type => :boolean, :default => true, :description => "Create request stub tests"
11
+ class_option :routing, :type => :boolean, :default => true, :description => "Create routing stub tests"
12
+ class_option :arcadex, :type => :boolean, :default => true, :description => "Send requests with an arcadex header"
9
13
 
10
14
  def sprint
11
15
  inside "engines/#{module_name.underscore}" do
12
16
  if options.both?
13
17
  run "rails g scaffold #{resource_name} #{attributes.join(" ")}"
14
18
  end
15
- run "rails g json_voorhees:engine_scaffold #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")}"
19
+ if options.arcadex?
20
+ run "rails g json_voorhees:engine_scaffold #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")}"
21
+ else
22
+ run "rails g json_voorhees:engine_scaffold --skip-arcadex #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")}"
23
+ end
24
+ end
25
+ if options.arcadex?
26
+ run "rails g json_voorhees:app_scaffold #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")}"
27
+ else
28
+ run "rails g json_voorhees:app_scaffold --skip-arcadex #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")}"
16
29
  end
17
- run "rails g json_voorhees:app_scaffold #{module_name} #{resource_name} #{api_version} #{attributes.join(" ")}"
18
30
  end
19
31
 
20
32
  private
@@ -13,10 +13,10 @@ module JsonVoorhees
13
13
  run_bundle
14
14
  rspec
15
15
  api_controller
16
+ make_admin
16
17
  people
17
18
  routes
18
19
  make_controllers
19
- make_admin
20
20
  #seed db?
21
21
  #fancier admin?
22
22
  run_git
@@ -81,7 +81,7 @@ module JsonVoorhees
81
81
  if !options.test?
82
82
  git :init
83
83
  git add: "."
84
- git commit: "-m Initial commit"
84
+ run "git commit -m \"Initial commit\""
85
85
  end
86
86
  end
87
87
 
@@ -1,2 +1,8 @@
1
1
  class Api::V1::ApiController < ::ActionController::API
2
+
3
+ private
4
+
5
+ def current_user
6
+ nil
7
+ end
2
8
  end
@@ -1,7 +1,76 @@
1
1
  require "rails_helper"
2
2
 
3
+ #-#-#-#-#REST#-#-#-#-#
3
4
  RSpec.describe ::People::User, :type => :request do
4
- describe "sign up process" do
5
+ describe "Index" do
6
+ before(:example) do
7
+ @user = FactoryGirl.create(:people_user)
8
+ token = @user.tokens[0].auth_token
9
+ @header = {"Auth-Token" => token, "Email" => @user.email}
10
+ end
11
+ # get /api/1/users
12
+ it "checks index json response" do
13
+ FactoryGirl.create_list(:people_user, 10)
14
+ get 'api/1/users', nil, @header
15
+ expect(response.status).to eq(200) #ok
16
+ expect(json["users"]).to_not eq(nil)
17
+ end
18
+ end
19
+ end
20
+ RSpec.describe ::People::User, :type => :request do
21
+ describe "Show" do
22
+ before(:example) do
23
+ @user = FactoryGirl.create(:people_user)
24
+ token = @user.tokens[0].auth_token
25
+ @header = {"Auth-Token" => token, "Email" => @user.email}
26
+ end
27
+ # get /api/1/users/1
28
+ it "checks show json response" do
29
+ get 'api/1/users/1', nil, @header
30
+ expect(response.status).to eq(200) #ok
31
+ expect(json["user"]["id"]).to eq(1)
32
+ end
33
+ end
34
+ end
35
+ RSpec.describe ::People::User, :type => :request do
36
+ describe "Update" do
37
+ before(:example) do
38
+ @user = FactoryGirl.create(:people_user)
39
+ token = @user.tokens[0].auth_token
40
+ @header = {"Auth-Token" => token, "Email" => @user.email}
41
+ end
42
+ # put /api/1/users/1
43
+ it "checks update json response" do
44
+ attrs = FactoryGirl.attributes_for(:people_user)
45
+ attrs["email"] = "Cole@LaunchU.com"
46
+ hash = {"user" => attrs}
47
+ #This uses users 1 header
48
+ put 'api/1/users/1', hash, @header
49
+ expect(response.status).to eq(200) #ok
50
+ expect(json["user"]["email"]).to eq("Cole@LaunchU.com")
51
+ end
52
+ it "makes sure a user cannot alter another users information" do
53
+ FactoryGirl.create(:people_user)
54
+ attrs = FactoryGirl.attributes_for(:people_user)
55
+ attrs["email"] = "Cole@LaunchU.com"
56
+ hash = {"user" => attrs}
57
+ #This uses users 2 header
58
+ put 'api/1/users/2', hash, @header
59
+ expect(response.status).to eq(403) #forbidden
60
+ end
61
+ it "makes sure a user can't update to bad values" do
62
+ attrs = FactoryGirl.attributes_for(:people_user)
63
+ attrs["email"] = ""
64
+ hash = {"user" => attrs}
65
+ #This uses users 1 header
66
+ put 'api/1/users/1', hash, @header
67
+ expect(response.status).to eq(422) #ok
68
+ end
69
+ end
70
+ end
71
+ #-#-#-#-#Collection Routes#-#-#-#-#
72
+ RSpec.describe ::People::User, :type => :request do
73
+ describe "Register" do
5
74
  before(:example) do
6
75
  @attrs = FactoryGirl.attributes_for(:people_user)
7
76
  end
@@ -15,6 +84,13 @@ RSpec.describe ::People::User, :type => :request do
15
84
  token = ::People::User.find(1).tokens[0]
16
85
  expect(json["token"]["auth_token"]).to eq(token.auth_token)
17
86
  end
87
+ end
88
+ end
89
+ RSpec.describe ::People::User, :type => :request do
90
+ describe "Login" do
91
+ before(:example) do
92
+ @attrs = FactoryGirl.attributes_for(:people_user)
93
+ end
18
94
  # post /api/1/users/login
19
95
  it "checks response of a register request with mismatched passwords" do
20
96
  @attrs["password"] = "password1"
@@ -53,6 +129,13 @@ RSpec.describe ::People::User, :type => :request do
53
129
  #Errors need to be returned
54
130
  expect(json["errors"]).to_not eq(nil)
55
131
  end
132
+ end
133
+ end
134
+ RSpec.describe ::People::User, :type => :request do
135
+ describe "Logout" do
136
+ before(:example) do
137
+ @attrs = FactoryGirl.attributes_for(:people_user)
138
+ end
56
139
  # get /api/1/users/1/logout
57
140
  it "checks logout response and makes sure token is deleted" do
58
141
  user = FactoryGirl.create(:people_user,@attrs)
@@ -65,42 +148,28 @@ RSpec.describe ::People::User, :type => :request do
65
148
  end
66
149
  end
67
150
  end
151
+ #-#-#-#-#Serialization#-#-#-#-#
68
152
  RSpec.describe ::People::User, :type => :request do
69
- describe "Rest Routes" do
153
+ describe "Serialization" do
70
154
  before(:example) do
71
155
  @user = FactoryGirl.create(:people_user)
72
156
  token = @user.tokens[0].auth_token
73
157
  @header = {"Auth-Token" => token, "Email" => @user.email}
74
158
  end
75
159
  # get /api/1/users
76
- it "checks index json response" do
160
+ it "checks only appropriate attributes are sent back for index" do
77
161
  FactoryGirl.create_list(:people_user, 10)
78
162
  get 'api/1/users', nil, @header
79
163
  expect(response.status).to eq(200) #ok
80
- expect(json["users"]).to_not eq(nil)
81
- end
82
- # get /api/1/users/1
83
- it "checks show json response" do
84
- get 'api/1/users/1', nil, @header
85
- expect(response.status).to eq(200) #ok
86
- expect(json["user"]["id"]).to eq(1)
87
- end
88
- it "checks for 404 response" do
89
- get 'api/1/users/20', nil, @header
90
- expect(response.status).to eq(404) #not_found
91
- end
92
- # put /api/1/users/1
93
- it "checks update json response" do
94
- attrs = FactoryGirl.attributes_for(:people_user)
95
- attrs["email"] = "Cole@LaunchU.com"
96
- hash = {"user" => attrs}
97
- #This uses users 1 header
98
- put 'api/1/users/1', hash, @header
99
- expect(response.status).to eq(200) #ok
100
- expect(json["user"]["email"]).to eq("Cole@LaunchU.com")
164
+ expect(::People::User.count).to eq(11)
165
+ expect(::Arcadex::Token.count).to eq(11)
166
+ expect(json["users"][0]["password_digest"]).to eq(nil)
167
+ expect(json["users"][0]["created_at"]).to_not eq(nil)
168
+ expect(json["users"][0]["updated_at"]).to_not eq(nil)
101
169
  end
102
170
  end
103
171
  end
172
+ #-#-#-#-#Errors#-#-#-#-#
104
173
  RSpec.describe ::People::User, :type => :request do
105
174
  describe "Authorization" do
106
175
  before(:example) do
@@ -108,47 +177,9 @@ RSpec.describe ::People::User, :type => :request do
108
177
  token = @user.tokens[0].auth_token
109
178
  @header = {"Auth-Token" => token, "Email" => @user.email}
110
179
  end
111
- # put /api/1/users/1
112
- it "makes sure a user cannot alter another users information" do
113
- FactoryGirl.create(:people_user)
114
- attrs = FactoryGirl.attributes_for(:people_user)
115
- attrs["email"] = "Cole@LaunchU.com"
116
- hash = {"user" => attrs}
117
- #This uses users 2 header
118
- put 'api/1/users/2', hash, @header
119
- expect(response.status).to eq(403) #forbidden
120
- end
121
- it "makes sure a user can't update to bad values" do
122
- attrs = FactoryGirl.attributes_for(:people_user)
123
- attrs["email"] = ""
124
- hash = {"user" => attrs}
125
- #This uses users 1 header
126
- put 'api/1/users/1', hash, @header
127
- expect(response.status).to eq(422) #ok
128
- end
129
- end
130
- end
131
- RSpec.describe ::People::User, :type => :request do
132
- describe "Serialization" do
133
- before(:example) do
134
- @user = FactoryGirl.create(:people_user)
135
- token = @user.tokens[0].auth_token
136
- @header = {"Auth-Token" => token, "Email" => @user.email}
137
- end
138
- # get /api/1/users
139
- it "checks only appropriate attributes are sent back for index" do
140
- FactoryGirl.create_list(:people_user, 10)
141
- get 'api/1/users', nil, @header
142
- expect(response.status).to eq(200) #ok
143
- expect(::People::User.count).to eq(11)
144
- expect(::Arcadex::Token.count).to eq(11)
145
- expect(json["users"][0]["password_digest"]).to eq(nil)
146
- expect(json["users"][0]["created_at"]).to_not eq(nil)
147
- expect(json["users"][0]["updated_at"]).to_not eq(nil)
148
- end
149
- it "checks the show json sent back" do
150
- get 'api/1/users/1', nil, @header
151
- expect(response.status).to eq(200) #ok
180
+ it "checks for 404 response" do
181
+ get 'api/1/users/20', nil, @header
182
+ expect(response.status).to eq(404) #not_found
152
183
  end
153
184
  end
154
185
  end
@@ -1,3 +1,3 @@
1
1
  module JsonVoorhees
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../../../json_voorhees
3
3
  specs:
4
- json_voorhees (0.0.2)
4
+ json_voorhees (0.1.0)
5
5
  rails (>= 4.0.0)
6
6
 
7
7
  PATH
Binary file