json_voorhees 1.0.0 → 1.3.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 +17 -48
- data/lib/generators/json_voorhees/app_environment/USAGE +8 -0
- data/lib/generators/json_voorhees/app_environment/app_environment_generator.rb +93 -0
- data/lib/generators/json_voorhees/app_make_admin/app_make_admin_generator.rb +19 -34
- data/lib/generators/json_voorhees/app_make_tests/app_make_tests_generator.rb +5 -19
- data/lib/generators/json_voorhees/app_make_user/app_make_user_generator.rb +13 -73
- data/lib/generators/json_voorhees/app_scaffold/app_scaffold_generator.rb +2 -12
- data/lib/generators/json_voorhees/engine_create_controller/engine_create_controller_generator.rb +1 -6
- data/lib/generators/json_voorhees/engine_scaffold/engine_scaffold_generator.rb +3 -12
- data/lib/generators/json_voorhees/massive_scaffold/massive_scaffold_generator.rb +12 -28
- data/lib/generators/json_voorhees/setup_app/setup_app_generator.rb +32 -97
- data/lib/generators/json_voorhees/setup_app/templates/api_controller_with_arcadex.rb +8 -23
- data/lib/generators/json_voorhees/setup_engine/setup_engine_generator.rb +0 -3
- data/lib/json_voorhees/version.rb +1 -1
- data/test/fresh_copy/test_app/Gemfile +12 -17
- data/test/fresh_copy/test_app/Gemfile.lock +56 -61
- data/test/fresh_copy/test_app/Rakefile +1 -1
- data/test/fresh_copy/test_app/app/assets/stylesheets/application.css +5 -3
- data/test/fresh_copy/test_app/app/views/layouts/application.html.erb +2 -2
- data/test/fresh_copy/test_app/bin/rails +4 -0
- data/test/fresh_copy/test_app/bin/rake +4 -0
- data/test/fresh_copy/test_app/bin/spring +18 -0
- data/test/fresh_copy/test_app/config/database.yml +8 -8
- data/test/fresh_copy/test_app/config/environment.rb +1 -1
- data/test/fresh_copy/test_app/config/environments/development.rb +10 -2
- data/test/fresh_copy/test_app/config/environments/production.rb +7 -9
- data/test/fresh_copy/test_app/config/environments/test.rb +5 -2
- data/test/fresh_copy/test_app/config/initializers/assets.rb +8 -0
- data/test/fresh_copy/test_app/config/initializers/cookies_serializer.rb +3 -0
- data/test/fresh_copy/test_app/config/initializers/mime_types.rb +0 -1
- data/test/fresh_copy/test_app/config/initializers/session_store.rb +1 -1
- data/test/fresh_copy/test_app/config/routes.rb +1 -1
- data/test/fresh_copy/test_app/config/secrets.yml +22 -0
- data/test/fresh_copy/test_app/public/404.html +20 -11
- data/test/fresh_copy/test_app/public/422.html +20 -11
- data/test/fresh_copy/test_app/public/500.html +19 -10
- data/test/fresh_copy/test_app/test/test_helper.rb +1 -6
- data/test/lib/generators/json_voorhees/app_environment_generator_test.rb +16 -0
- metadata +15 -21
- data/lib/generators/json_voorhees/app_make_admin/templates/views/admin_home_no_user +0 -1
- data/lib/generators/json_voorhees/app_make_tests/templates/no_auth_request.rb.erb +0 -114
- data/lib/generators/json_voorhees/app_make_user/templates/active_admin_register.rb.erb +0 -83
- data/lib/generators/json_voorhees/app_make_user/templates/user/include_authorization.rb +0 -4
- data/lib/generators/json_voorhees/app_make_user/templates/user/specs/factory_girl.rb +0 -14
- data/lib/generators/json_voorhees/app_make_user/templates/user/specs/model_specs.rb +0 -61
- data/lib/generators/json_voorhees/app_make_user/templates/user/specs/no_arcadex_request_specs.rb +0 -85
- data/lib/generators/json_voorhees/app_make_user/templates/user/specs/request_specs.rb +0 -244
- data/lib/generators/json_voorhees/app_make_user/templates/user/specs/route_specs.rb +0 -91
- data/lib/generators/json_voorhees/app_make_user/templates/user/user_authorizations.rb +0 -92
- data/lib/generators/json_voorhees/app_make_user/templates/user/user_controller.rb +0 -169
- data/lib/generators/json_voorhees/app_make_user/templates/user/user_model.rb +0 -35
- data/lib/generators/json_voorhees/app_make_user/templates/user/user_routes.rb +0 -32
- data/lib/generators/json_voorhees/app_make_user/templates/user/user_serializer.rb +0 -43
- data/lib/generators/json_voorhees/engine_create_controller/templates/no_auth_controller_template.rb.erb +0 -61
- data/lib/generators/json_voorhees/setup_app/templates/api_controller_no_arcadex.rb +0 -33
- data/test/fresh_copy/test_app/config/initializers/secret_token.rb +0 -12
@@ -1,83 +0,0 @@
|
|
1
|
-
ActiveAdmin.register People::User do
|
2
|
-
|
3
|
-
menu :label => "Users"
|
4
|
-
config.per_page = 30
|
5
|
-
|
6
|
-
form do |f|
|
7
|
-
f.semantic_errors # shows errors on :base
|
8
|
-
#f.inputs # builds an input field for every attribute
|
9
|
-
f.inputs do
|
10
|
-
f.input :id
|
11
|
-
f.input :username
|
12
|
-
f.input :email
|
13
|
-
f.input :password
|
14
|
-
f.input :password_confirmation
|
15
|
-
f.input :updated_at
|
16
|
-
f.input :created_at
|
17
|
-
end
|
18
|
-
f.actions # adds the 'Submit' and 'Cancel' buttons
|
19
|
-
end
|
20
|
-
|
21
|
-
controller do
|
22
|
-
def create
|
23
|
-
@user = ::People::V1::User.new(user_params)
|
24
|
-
if @user.save
|
25
|
-
flash[:notice] = "Created Successfully!"
|
26
|
-
redirect_to resource_path @user
|
27
|
-
else
|
28
|
-
flash[:notice] = "#{@user.errors.full_messages}"
|
29
|
-
redirect_to new_resource_path @user
|
30
|
-
#super
|
31
|
-
#render :new
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def update
|
36
|
-
@user = ::People::V1::User.find(params[:id])
|
37
|
-
if @user.update(user_params)
|
38
|
-
flash[:notice] = "Updated Successfully!"
|
39
|
-
redirect_to resource_path @user
|
40
|
-
else
|
41
|
-
flash.now[:notice] = "#{@user.errors.full_messages}"
|
42
|
-
render :edit
|
43
|
-
#super
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def destroy
|
48
|
-
@user = ::People::V1::User.find(params[:id])
|
49
|
-
@user.destroy
|
50
|
-
flash.now[:notice] = "Deleted Successfully!"
|
51
|
-
render :index
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def user_params
|
57
|
-
params.require(:user).permit(:username,:email,:password,:password_confirmation)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
index do
|
62
|
-
column :id
|
63
|
-
column :username
|
64
|
-
column :email
|
65
|
-
column :password_digest
|
66
|
-
column :updated_at
|
67
|
-
column :created_at
|
68
|
-
actions
|
69
|
-
end
|
70
|
-
|
71
|
-
show do
|
72
|
-
attributes_table do
|
73
|
-
row :id
|
74
|
-
row :username
|
75
|
-
row :email
|
76
|
-
row :password_digest
|
77
|
-
row :updated_at
|
78
|
-
row :created_at
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
|
83
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
FactoryGirl.define do
|
2
|
-
sequence :username do |n|
|
3
|
-
"username#{n}"
|
4
|
-
end
|
5
|
-
sequence :email do |n|
|
6
|
-
"username#{n}@LaunchU.com"
|
7
|
-
end
|
8
|
-
factory :people_user_1, class: ::People::V1::User do
|
9
|
-
username
|
10
|
-
email
|
11
|
-
password "password123"
|
12
|
-
password_confirmation "password123"
|
13
|
-
end
|
14
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
RSpec.describe ::People::V1::User, '.username', :type => :model do
|
4
|
-
it "does not save when nil" do
|
5
|
-
user = FactoryGirl.build(:people_user_1, :username => nil)
|
6
|
-
expect(user.save).to equal(false)
|
7
|
-
end
|
8
|
-
it "does not save with invalid characters" do
|
9
|
-
#user = FactoryGirl.build(:people_user_1, :username => "!@#$%)")
|
10
|
-
#expect(user.save).to equal(false)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
RSpec.describe ::People::V1::User, '.email', :type => :model do
|
14
|
-
it "does not save when nil" do
|
15
|
-
user = FactoryGirl.build(:people_user_1, :email => nil)
|
16
|
-
expect(user.save).to equal(false)
|
17
|
-
end
|
18
|
-
it "does not save with invalid characters" do
|
19
|
-
#user = FactoryGirl.build(:people_user_1, :email => "!@#$%)")
|
20
|
-
#expect(user.save).to equal(false)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
RSpec.describe ::People::V1::User, '.password_digest', :type => :model do
|
24
|
-
it "does not save when nil" do
|
25
|
-
user = FactoryGirl.build(:people_user_1, :password => nil, :password_confirmation => nil)
|
26
|
-
expect(user.save).to equal(false)
|
27
|
-
end
|
28
|
-
it "does not save when not a match" do
|
29
|
-
user = FactoryGirl.build(:people_user_1, :password => "firstAttempt", :password_confirmation => "secondAttempt")
|
30
|
-
expect(user.save).to equal(false)
|
31
|
-
end
|
32
|
-
it "saves with a matching password and password_confirmation" do
|
33
|
-
user = FactoryGirl.build(:people_user_1, :password => "good_password", :password_confirmation => "good_password")
|
34
|
-
expect(user.save).to equal(true)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
RSpec.describe ::People::V1::User, :type => :model do
|
38
|
-
describe "dependencies" do
|
39
|
-
before(:example) do
|
40
|
-
@user = FactoryGirl.create(:people_user_1)
|
41
|
-
end
|
42
|
-
it "deletes ... when deleted" do
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
RSpec.describe ::People::V1::User, :type => :model do
|
48
|
-
describe "callbacks" do
|
49
|
-
before(:example) do
|
50
|
-
@user = FactoryGirl.create(:people_user_1)
|
51
|
-
end
|
52
|
-
<% if options.arcadex? %>
|
53
|
-
it "creates an authentication token" do
|
54
|
-
expect(@user.tokens.any?).to equal(true)
|
55
|
-
end
|
56
|
-
it "does not create an empty auth token" do
|
57
|
-
expect(@user.tokens[0].auth_token.nil?).to equal(false)
|
58
|
-
end
|
59
|
-
<% end %>
|
60
|
-
end
|
61
|
-
end
|
data/lib/generators/json_voorhees/app_make_user/templates/user/specs/no_arcadex_request_specs.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
#-#-#-#-#REST#-#-#-#-#
|
4
|
-
RSpec.describe ::People::V1::User, :type => :request do
|
5
|
-
describe "Index" do
|
6
|
-
before(:example) do
|
7
|
-
@user = FactoryGirl.create(:people_user_1)
|
8
|
-
end
|
9
|
-
# get /api/1/users
|
10
|
-
it "checks index json response" do
|
11
|
-
FactoryGirl.create_list(:people_user_1, 10)
|
12
|
-
get 'api/1/users'
|
13
|
-
expect(response.status).to eq(200) #ok
|
14
|
-
expect(json["users"]).to_not eq(nil)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
RSpec.describe ::People::V1::User, :type => :request do
|
19
|
-
describe "Show" do
|
20
|
-
before(:example) do
|
21
|
-
@user = FactoryGirl.create(:people_user_1)
|
22
|
-
end
|
23
|
-
# get /api/1/users/1
|
24
|
-
it "checks show json response" do
|
25
|
-
get 'api/1/users/1'
|
26
|
-
expect(response.status).to eq(200) #ok
|
27
|
-
expect(json["user"]["id"]).to eq(1)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
RSpec.describe ::People::V1::User, :type => :request do
|
32
|
-
describe "Update" do
|
33
|
-
before(:example) do
|
34
|
-
@user = FactoryGirl.create(:people_user_1)
|
35
|
-
end
|
36
|
-
# put /api/1/users/1
|
37
|
-
it "checks update json response" do
|
38
|
-
attrs = FactoryGirl.attributes_for(:people_user_1)
|
39
|
-
attrs["email"] = "Cole@LaunchU.com"
|
40
|
-
hash = {"user" => attrs}
|
41
|
-
put 'api/1/users/1', hash
|
42
|
-
expect(response.status).to eq(200) #ok
|
43
|
-
expect(json["user"]["email"]).to eq("Cole@LaunchU.com")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
#-#-#-#-#Collection Routes#-#-#-#-#
|
48
|
-
RSpec.describe ::People::V1::User, :type => :request do
|
49
|
-
describe "Collection" do
|
50
|
-
before(:example) do
|
51
|
-
@attrs = FactoryGirl.attributes_for(:people_user_1)
|
52
|
-
end
|
53
|
-
it "Collection" do
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
#-#-#-#-#Serialization#-#-#-#-#
|
58
|
-
RSpec.describe ::People::V1::User, :type => :request do
|
59
|
-
describe "Serialization" do
|
60
|
-
before(:example) do
|
61
|
-
@user = FactoryGirl.create(:people_user_1)
|
62
|
-
end
|
63
|
-
# get /api/1/users
|
64
|
-
it "checks only appropriate attributes are sent back for index" do
|
65
|
-
FactoryGirl.create_list(:people_user_1, 10)
|
66
|
-
get 'api/1/users'
|
67
|
-
expect(response.status).to eq(200) #ok
|
68
|
-
expect(json["users"][0]["password_digest"]).to eq(nil)
|
69
|
-
expect(json["users"][0]["created_at"]).to_not eq(nil)
|
70
|
-
expect(json["users"][0]["updated_at"]).to_not eq(nil)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
#-#-#-#-#Errors#-#-#-#-#
|
75
|
-
RSpec.describe ::People::V1::User, :type => :request do
|
76
|
-
describe "Authorization" do
|
77
|
-
before(:example) do
|
78
|
-
@user = FactoryGirl.create(:people_user_1)
|
79
|
-
end
|
80
|
-
it "checks for 404 response" do
|
81
|
-
get 'api/1/users/20'
|
82
|
-
expect(response.status).to eq(404) #not_found
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,244 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
#-#-#-#-#REST#-#-#-#-#
|
4
|
-
RSpec.describe ::People::V1::User, :type => :request do
|
5
|
-
describe "Index" do
|
6
|
-
before(:example) do
|
7
|
-
@user = FactoryGirl.create(:people_user_1)
|
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_1, 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::V1::User, :type => :request do
|
21
|
-
describe "Show" do
|
22
|
-
before(:example) do
|
23
|
-
@user = FactoryGirl.create(:people_user_1)
|
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::V1::User, :type => :request do
|
36
|
-
describe "Update" do
|
37
|
-
before(:example) do
|
38
|
-
@user = FactoryGirl.create(:people_user_1)
|
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_1)
|
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_1)
|
54
|
-
attrs = FactoryGirl.attributes_for(:people_user_1)
|
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_1)
|
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::V1::User, :type => :request do
|
73
|
-
describe "Register" do
|
74
|
-
before(:example) do
|
75
|
-
@attrs = FactoryGirl.attributes_for(:people_user_1)
|
76
|
-
end
|
77
|
-
# post /api/1/users/register
|
78
|
-
it "checks response of a register request with a valid user object" do
|
79
|
-
post 'api/1/users/register', :user => @attrs
|
80
|
-
expect(response.status).to eq(200) #ok
|
81
|
-
expect(::People::V1::User.all.count).to eq(1)
|
82
|
-
#A valid token needs to be returned
|
83
|
-
expect(json["token"]["auth_token"]).to_not eq(nil)
|
84
|
-
token = ::People::V1::User.find(1).tokens[0]
|
85
|
-
expect(json["token"]["auth_token"]).to eq(token.auth_token)
|
86
|
-
end
|
87
|
-
# post /api/1/users/register
|
88
|
-
it "checks response of a register request with mismatched passwords" do
|
89
|
-
@attrs["password"] = "password1"
|
90
|
-
@attrs["password_confirmation"] = "password2"
|
91
|
-
post 'api/1/users/register', :user => @attrs
|
92
|
-
expect(response.status).to eq(422) #invalid_resource
|
93
|
-
expect(::People::V1::User.all.count).to eq(0)
|
94
|
-
#Errors need to be returned
|
95
|
-
expect(json["errors"]).to_not eq(nil)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
RSpec.describe ::People::V1::User, :type => :request do
|
100
|
-
describe "Login" do
|
101
|
-
before(:example) do
|
102
|
-
@attrs = FactoryGirl.attributes_for(:people_user_1)
|
103
|
-
end
|
104
|
-
# post /api/1/users/login
|
105
|
-
it "checks response of a valid login request" do
|
106
|
-
@attrs["password"] = "password123"
|
107
|
-
@attrs["password_confirmation"] = "password123"
|
108
|
-
user = FactoryGirl.create(:people_user_1,@attrs)
|
109
|
-
old_auth_token = user.tokens[0].auth_token
|
110
|
-
#It needs to send an email and password
|
111
|
-
hash = {"user" => @attrs}
|
112
|
-
post 'api/1/users/login', hash
|
113
|
-
expect(response.status).to eq(200) #ok
|
114
|
-
#A valid and new token need to be returned
|
115
|
-
expect(json["token"]["auth_token"]).to_not eq(old_auth_token)
|
116
|
-
#This token should be the newest token in the database
|
117
|
-
new_auth_token = ::People::V1::User.find(1).tokens.order("created_at").last.auth_token
|
118
|
-
expect(json["token"]["auth_token"]).to eq(new_auth_token)
|
119
|
-
end
|
120
|
-
# post /api/1/users/login
|
121
|
-
it "checks response of an invalid login request with an invalid password" do
|
122
|
-
@attrs["password"] = "password123"
|
123
|
-
@attrs["password_confirmation"] = "password123"
|
124
|
-
user = FactoryGirl.create(:people_user_1,@attrs)
|
125
|
-
#The password needs to be invalid
|
126
|
-
@attrs["password"] = "wrongPassword"
|
127
|
-
hash = {"user" => @attrs}
|
128
|
-
#It needs to send an email and password
|
129
|
-
post 'api/1/users/login', hash
|
130
|
-
expect(response.status).to eq(401) #unauthorized
|
131
|
-
#Errors need to be returned
|
132
|
-
expect(json["errors"]).to_not eq(nil)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
RSpec.describe ::People::V1::User, :type => :request do
|
137
|
-
describe "Logout" do
|
138
|
-
before(:example) do
|
139
|
-
@attrs = FactoryGirl.attributes_for(:people_user_1)
|
140
|
-
end
|
141
|
-
# get /api/1/users/1/logout
|
142
|
-
it "checks logout response and makes sure token is deleted" do
|
143
|
-
user = FactoryGirl.create(:people_user_1,@attrs)
|
144
|
-
token = user.tokens[0].auth_token
|
145
|
-
header = {"Auth-Token" => token, "Email" => user.email}
|
146
|
-
post 'api/1/users/logout', nil, header
|
147
|
-
expect(::People::V1::User.count).to eq(1)
|
148
|
-
expect(response.status).to eq(200) #ok
|
149
|
-
expect(::Arcadex::Token.count).to eq(0)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
RSpec.describe ::People::V1::User, :type => :request do
|
154
|
-
describe "Authenticate" do
|
155
|
-
before(:example) do
|
156
|
-
@attrs = FactoryGirl.attributes_for(:people_user_1)
|
157
|
-
end
|
158
|
-
# post /api/1/users/authenticate
|
159
|
-
it "checks a valid authenticate request" do
|
160
|
-
user = FactoryGirl.create(:people_user_1,@attrs)
|
161
|
-
token = user.tokens[0].auth_token
|
162
|
-
header = {"Auth-Token" => token, "Email" => user.email}
|
163
|
-
hash = {"user" => @attrs}
|
164
|
-
post "api/1/users/authenticate/#{user.id}", hash, header
|
165
|
-
expect(response.status).to eq(200) #ok
|
166
|
-
end
|
167
|
-
# post /api/1/users/authenticate
|
168
|
-
it "checks an invalid authenticate request" do
|
169
|
-
user = FactoryGirl.create(:people_user_1,@attrs)
|
170
|
-
token = user.tokens[0].auth_token
|
171
|
-
header = {"Auth-Token" => token, "Email" => user.email}
|
172
|
-
@attrs["password"] = "false_password"
|
173
|
-
hash = {"user" => @attrs}
|
174
|
-
post "api/1/users/authenticate/#{user.id}", hash, header
|
175
|
-
expect(response.status).to eq(401) #unauthorized
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
RSpec.describe ::People::V1::User, :type => :request do
|
180
|
-
describe "Login_Status" do
|
181
|
-
before(:example) do
|
182
|
-
@attrs = FactoryGirl.attributes_for(:people_user_1)
|
183
|
-
end
|
184
|
-
# get /api/1/users/login_status
|
185
|
-
it "returns 200 okay if token is valid" do
|
186
|
-
user = FactoryGirl.create(:people_user_1,@attrs)
|
187
|
-
token = user.tokens[0].auth_token
|
188
|
-
header = {"Auth-Token" => token, "Email" => user.email}
|
189
|
-
get "api/1/users/login_status", nil, header
|
190
|
-
expect(response.status).to eq(200) #ok
|
191
|
-
end
|
192
|
-
# get /api/1/users/login_status
|
193
|
-
it "returns a 401 if token is not valid" do
|
194
|
-
user = FactoryGirl.create(:people_user_1,@attrs)
|
195
|
-
token = user.tokens[0].auth_token + "not_valid"
|
196
|
-
header = {"Auth-Token" => token, "Email" => user.email}
|
197
|
-
get "api/1/users/login_status", nil, header
|
198
|
-
expect(response.status).to eq(401) #unauthorized
|
199
|
-
end
|
200
|
-
# get /api/1/users/login_status
|
201
|
-
it "returns a 401 if token does not exist" do
|
202
|
-
user = FactoryGirl.create(:people_user_1,@attrs)
|
203
|
-
token = user.tokens[0].auth_token
|
204
|
-
header = {"Email" => user.email}
|
205
|
-
get "api/1/users/login_status", nil, header
|
206
|
-
expect(response.status).to eq(401) #unauthorized
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
#-#-#-#-#Serialization#-#-#-#-#
|
211
|
-
RSpec.describe ::People::V1::User, :type => :request do
|
212
|
-
describe "Serialization" do
|
213
|
-
before(:example) do
|
214
|
-
@user = FactoryGirl.create(:people_user_1)
|
215
|
-
token = @user.tokens[0].auth_token
|
216
|
-
@header = {"Auth-Token" => token, "Email" => @user.email}
|
217
|
-
end
|
218
|
-
# get /api/1/users
|
219
|
-
it "checks only appropriate attributes are sent back for index" do
|
220
|
-
FactoryGirl.create_list(:people_user_1, 10)
|
221
|
-
get 'api/1/users', nil, @header
|
222
|
-
expect(response.status).to eq(200) #ok
|
223
|
-
expect(::People::V1::User.count).to eq(11)
|
224
|
-
expect(::Arcadex::Token.count).to eq(11)
|
225
|
-
expect(json["users"][0]["password_digest"]).to eq(nil)
|
226
|
-
expect(json["users"][0]["created_at"]).to_not eq(nil)
|
227
|
-
expect(json["users"][0]["updated_at"]).to_not eq(nil)
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
#-#-#-#-#Errors#-#-#-#-#
|
232
|
-
RSpec.describe ::People::V1::User, :type => :request do
|
233
|
-
describe "Authorization" do
|
234
|
-
before(:example) do
|
235
|
-
@user = FactoryGirl.create(:people_user_1)
|
236
|
-
token = @user.tokens[0].auth_token
|
237
|
-
@header = {"Auth-Token" => token, "Email" => @user.email}
|
238
|
-
end
|
239
|
-
it "checks for 404 response" do
|
240
|
-
get 'api/1/users/20', nil, @header
|
241
|
-
expect(response.status).to eq(404) #not_found
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
<% if options.arcadex? %>
|
3
|
-
#The register, login, and logout routes
|
4
|
-
RSpec.describe "Users sign up process routing", :type => :routing do
|
5
|
-
routes { People::Engine.routes }
|
6
|
-
|
7
|
-
it "routes to register" do
|
8
|
-
expect(:post => "/api/1/users/register").to route_to(
|
9
|
-
:controller => "people/api/v1/users",
|
10
|
-
:action => "register"
|
11
|
-
)
|
12
|
-
end
|
13
|
-
it "routes to login" do
|
14
|
-
expect(:post => "/api/1/users/login").to route_to(
|
15
|
-
:controller => "people/api/v1/users",
|
16
|
-
:action => "login"
|
17
|
-
)
|
18
|
-
end
|
19
|
-
it "routes to logout" do
|
20
|
-
expect(:post => "/api/1/users/logout").to route_to(
|
21
|
-
:controller => "people/api/v1/users",
|
22
|
-
:action => "logout"
|
23
|
-
)
|
24
|
-
end
|
25
|
-
it "routes to authenticate" do
|
26
|
-
expect(:post => "/api/1/users/authenticate/1").to route_to(
|
27
|
-
:controller => "people/api/v1/users",
|
28
|
-
:action => "authenticate",
|
29
|
-
:id => "1"
|
30
|
-
)
|
31
|
-
end
|
32
|
-
it "routes to login_status" do
|
33
|
-
expect(:get => "/api/1/users/login_status").to route_to(
|
34
|
-
:controller => "people/api/v1/users",
|
35
|
-
:action => "login_status"
|
36
|
-
)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
<% end %>
|
40
|
-
#The standard rest routes for the user controller
|
41
|
-
RSpec.describe "Users controller rest routing", :type => :routing do
|
42
|
-
routes { People::Engine.routes }
|
43
|
-
|
44
|
-
it "routes to index" do
|
45
|
-
expect(:get => "/api/1/users").to route_to(
|
46
|
-
:controller => "people/api/v1/users",
|
47
|
-
:action => "index"
|
48
|
-
)
|
49
|
-
end
|
50
|
-
it "routes to show" do
|
51
|
-
expect(:get => "/api/1/users/1").to route_to(
|
52
|
-
:controller => "people/api/v1/users",
|
53
|
-
:action => "show",
|
54
|
-
:id => "1"
|
55
|
-
)
|
56
|
-
end
|
57
|
-
it "routes to edit" do
|
58
|
-
expect(:get => "/api/1/users/1/edit").to route_to(
|
59
|
-
:controller => "people/api/v1/users",
|
60
|
-
:action => "edit",
|
61
|
-
:id => "1"
|
62
|
-
)
|
63
|
-
end
|
64
|
-
it "routes to create" do
|
65
|
-
expect(:post => "/api/1/users/").to route_to(
|
66
|
-
:controller => "people/api/v1/users",
|
67
|
-
:action => "create"
|
68
|
-
)
|
69
|
-
end
|
70
|
-
it "routes to update" do
|
71
|
-
expect(:put => "/api/1/users/1/").to route_to(
|
72
|
-
:controller => "people/api/v1/users",
|
73
|
-
:action => "update",
|
74
|
-
:id => "1"
|
75
|
-
)
|
76
|
-
end
|
77
|
-
it "routes to update" do
|
78
|
-
expect(:patch => "/api/1/users/1/").to route_to(
|
79
|
-
:controller => "people/api/v1/users",
|
80
|
-
:action => "update",
|
81
|
-
:id => "1"
|
82
|
-
)
|
83
|
-
end
|
84
|
-
it "routes to delete" do
|
85
|
-
expect(:delete => "/api/1/users/1/").to route_to(
|
86
|
-
:controller => "people/api/v1/users",
|
87
|
-
:action => "destroy",
|
88
|
-
:id => "1"
|
89
|
-
)
|
90
|
-
end
|
91
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
module Authorization
|
2
|
-
module People
|
3
|
-
module V1
|
4
|
-
module User
|
5
|
-
|
6
|
-
#Used in the controller
|
7
|
-
|
8
|
-
<% if options.arcadex? %>
|
9
|
-
def self.register?
|
10
|
-
return true
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.login?
|
14
|
-
return true
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.logout?(tokenUser)
|
18
|
-
return true
|
19
|
-
end
|
20
|
-
<% end %>
|
21
|
-
|
22
|
-
def self.index?(tokenUser)
|
23
|
-
return true
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.show?(targetUser,tokenUser)
|
27
|
-
return true
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
def self.update?(targetUser,tokenUser)
|
32
|
-
<% if options.arcadex? %>
|
33
|
-
if targetUser != tokenUser
|
34
|
-
#Can only update your own data
|
35
|
-
return false
|
36
|
-
else
|
37
|
-
return true
|
38
|
-
end
|
39
|
-
<% else %>
|
40
|
-
return true
|
41
|
-
<% end %>
|
42
|
-
end
|
43
|
-
|
44
|
-
#Used in the serializer, current_user may be nil
|
45
|
-
|
46
|
-
def self.include_id?(current_user,user_object,options)
|
47
|
-
action = options[:url_options][:_recall][:action]
|
48
|
-
controller = options[:url_options][:_recall][:controller]
|
49
|
-
return true
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.include_email?(current_user,user_object,options)
|
53
|
-
action = options[:url_options][:_recall][:action]
|
54
|
-
controller = options[:url_options][:_recall][:controller]
|
55
|
-
return true
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.include_username?(current_user,user_object,options)
|
59
|
-
action = options[:url_options][:_recall][:action]
|
60
|
-
controller = options[:url_options][:_recall][:controller]
|
61
|
-
return true
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.include_created_at?(current_user,user_object,options)
|
65
|
-
action = options[:url_options][:_recall][:action]
|
66
|
-
controller = options[:url_options][:_recall][:controller]
|
67
|
-
return true
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.include_updated_at?(current_user,user_object,options)
|
71
|
-
action = options[:url_options][:_recall][:action]
|
72
|
-
controller = options[:url_options][:_recall][:controller]
|
73
|
-
return true
|
74
|
-
end
|
75
|
-
|
76
|
-
<% if options.arcadex? %>
|
77
|
-
def self.include_tokens?(current_user,user_object,options)
|
78
|
-
action = options[:url_options][:_recall][:action]
|
79
|
-
controller = options[:url_options][:_recall][:controller]
|
80
|
-
#if action == "index" && controller == "people/api/v1/users"
|
81
|
-
#return false
|
82
|
-
#end
|
83
|
-
return false
|
84
|
-
end
|
85
|
-
<% end %>
|
86
|
-
|
87
|
-
private
|
88
|
-
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|