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.
- checksums.yaml +4 -4
- data/README.md +52 -4
- data/lib/generators/json_voorhees/app_make_authorizations/USAGE +1 -1
- data/lib/generators/json_voorhees/app_make_authorizations/app_make_authorizations_generator.rb +1 -0
- data/lib/generators/json_voorhees/app_make_authorizations/templates/auth_file.rb.erb +8 -1
- data/lib/generators/json_voorhees/app_make_tests/USAGE +1 -1
- data/lib/generators/json_voorhees/app_make_tests/app_make_tests_generator.rb +26 -0
- data/lib/generators/json_voorhees/app_make_tests/templates/factory.rb.erb +3 -1
- data/lib/generators/json_voorhees/app_make_tests/templates/model.rb.erb +5 -0
- data/lib/generators/json_voorhees/app_make_tests/templates/no_auth_request.rb.erb +90 -0
- data/lib/generators/json_voorhees/app_scaffold/USAGE +9 -0
- data/lib/generators/json_voorhees/app_scaffold/app_scaffold_generator.rb +22 -0
- data/lib/generators/json_voorhees/engine_create_controller/USAGE +1 -1
- data/lib/generators/json_voorhees/engine_create_controller/engine_create_controller_generator.rb +11 -0
- data/lib/generators/json_voorhees/engine_create_controller/templates/controller_template.rb.erb +1 -1
- data/lib/generators/json_voorhees/engine_create_controller/templates/no_auth_controller_template.rb.erb +1 -1
- data/lib/generators/json_voorhees/engine_create_serializer/USAGE +1 -1
- data/lib/generators/json_voorhees/engine_create_serializer/engine_create_serializer_generator.rb +1 -0
- data/lib/generators/json_voorhees/engine_create_serializer/templates/serializer.rb.erb +13 -0
- data/lib/generators/json_voorhees/engine_scaffold/USAGE +9 -0
- data/lib/generators/json_voorhees/engine_scaffold/engine_scaffold_generator.rb +18 -0
- data/lib/generators/json_voorhees/massive_scaffold/USAGE +10 -0
- data/lib/generators/json_voorhees/massive_scaffold/massive_scaffold_generator.rb +23 -0
- data/lib/generators/json_voorhees/setup_app/setup_app_generator.rb +10 -0
- data/lib/json_voorhees/version.rb +1 -1
- data/test/lib/generators/json_voorhees/app_scaffold_generator_test.rb +16 -0
- data/test/lib/generators/json_voorhees/engine_scaffold_generator_test.rb +16 -0
- data/test/lib/generators/json_voorhees/massive_scaffold_generator_test.rb +16 -0
- data/test/test_app/Gemfile +23 -0
- data/test/test_app/Gemfile.lock +99 -1
- data/test/test_app/README.md +1 -0
- data/test/test_app/app/controllers/api/v1/api_controller.rb +26 -0
- data/test/test_app/app/controllers/app_index_controller.rb +4 -0
- data/test/test_app/app/controllers/application_controller.rb +5 -0
- data/test/test_app/app/controllers/main_controller.rb +4 -0
- data/test/test_app/app/views/app_index/app.html.erb +0 -0
- data/test/test_app/app/views/layouts/app_index.html.erb +9 -0
- data/test/test_app/app/views/layouts/application.html.erb +8 -3
- data/test/test_app/app/views/main/admin.html.erb +9 -0
- data/test/test_app/config/application.rb +4 -0
- data/test/test_app/config/routes.rb +8 -0
- data/test/test_app/db/development.sqlite3 +0 -0
- data/test/test_app/db/migrate/20140905145354_create_people_users.people.rb +12 -0
- data/test/test_app/db/migrate/20140905145355_create_arcadex_tokens.arcadex.rb +12 -0
- data/test/test_app/db/migrate/20140905145356_add_index_to_token.arcadex.rb +6 -0
- data/test/test_app/db/production.sqlite3 +0 -0
- data/test/test_app/db/schema.rb +19 -1
- data/test/test_app/db/test.sqlite3 +0 -0
- data/test/test_app/engines/people/Gemfile +14 -0
- data/test/test_app/engines/people/Gemfile.lock +92 -0
- data/test/test_app/engines/people/MIT-LICENSE +20 -0
- data/test/test_app/engines/people/README.md +1 -0
- data/test/test_app/engines/people/Rakefile +34 -0
- data/test/test_app/engines/people/app/assets/javascripts/people/application.js +13 -0
- data/test/test_app/engines/people/app/assets/javascripts/people/users.js +2 -0
- data/test/test_app/engines/people/app/assets/stylesheets/people/application.css +15 -0
- data/test/test_app/engines/people/app/assets/stylesheets/people/users.css +4 -0
- data/test/test_app/engines/people/app/assets/stylesheets/scaffold.css +56 -0
- data/test/test_app/engines/people/app/controllers/people/api/v1/application_controller.rb +5 -0
- data/test/test_app/engines/people/app/controllers/people/api/v1/users_controller.rb +124 -0
- data/test/test_app/engines/people/app/controllers/people/application_controller.rb +4 -0
- data/test/test_app/engines/people/app/controllers/people/users_controller.rb +62 -0
- data/test/test_app/engines/people/app/helpers/people/application_helper.rb +4 -0
- data/test/test_app/engines/people/app/helpers/people/users_helper.rb +4 -0
- data/test/test_app/engines/people/app/models/people/user.rb +26 -0
- data/test/test_app/engines/people/app/serializers/people/user_serializer.rb +39 -0
- data/test/test_app/engines/people/app/views/layouts/people/default/application.html.erb +14 -0
- data/test/test_app/engines/people/app/views/people/users/_form.html.erb +29 -0
- data/test/test_app/engines/people/app/views/people/users/edit.html.erb +6 -0
- data/test/test_app/engines/people/app/views/people/users/index.html.erb +29 -0
- data/test/test_app/engines/people/app/views/people/users/new.html.erb +5 -0
- data/test/test_app/engines/people/app/views/people/users/show.html.erb +19 -0
- data/test/test_app/engines/people/bin/rails +12 -0
- data/test/test_app/engines/people/config/routes.rb +24 -0
- data/test/test_app/engines/people/db/migrate/20140905145341_create_people_users.rb +11 -0
- data/test/test_app/engines/people/lib/people/engine.rb +5 -0
- data/test/test_app/engines/people/lib/people/version.rb +3 -0
- data/test/test_app/engines/people/lib/people.rb +4 -0
- data/test/test_app/engines/people/lib/tasks/people_tasks.rake +4 -0
- data/test/test_app/engines/people/people.gemspec +31 -0
- data/test/test_app/engines/people/test/controllers/people/users_controller_test.rb +51 -0
- data/test/test_app/{README.rdoc → engines/people/test/dummy/README.rdoc} +0 -0
- data/test/test_app/engines/people/test/dummy/Rakefile +6 -0
- data/test/test_app/engines/people/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/test_app/engines/people/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/test_app/engines/people/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/test_app/engines/people/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/test_app/engines/people/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/test_app/engines/people/test/dummy/bin/bundle +3 -0
- data/test/test_app/engines/people/test/dummy/bin/rails +4 -0
- data/test/test_app/engines/people/test/dummy/bin/rake +4 -0
- data/test/test_app/engines/people/test/dummy/config/application.rb +23 -0
- data/test/test_app/engines/people/test/dummy/config/boot.rb +5 -0
- data/test/test_app/engines/people/test/dummy/config/database.yml +25 -0
- data/test/test_app/engines/people/test/dummy/config/environment.rb +5 -0
- data/test/test_app/engines/people/test/dummy/config/environments/development.rb +37 -0
- data/test/test_app/engines/people/test/dummy/config/environments/production.rb +82 -0
- data/test/test_app/engines/people/test/dummy/config/environments/test.rb +39 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/assets.rb +8 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/test_app/engines/people/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/test_app/engines/people/test/dummy/config/locales/en.yml +23 -0
- data/test/test_app/engines/people/test/dummy/config/routes.rb +4 -0
- data/test/test_app/engines/people/test/dummy/config/secrets.yml +22 -0
- data/test/test_app/engines/people/test/dummy/config.ru +4 -0
- data/test/test_app/engines/people/test/dummy/db/schema.rb +24 -0
- data/test/test_app/engines/people/test/dummy/public/404.html +67 -0
- data/test/test_app/engines/people/test/dummy/public/422.html +67 -0
- data/test/test_app/engines/people/test/dummy/public/500.html +66 -0
- data/test/test_app/engines/people/test/dummy/public/favicon.ico +0 -0
- data/test/test_app/engines/people/test/fixtures/people/users.yml +11 -0
- data/test/test_app/engines/people/test/helpers/people/users_helper_test.rb +6 -0
- data/test/test_app/engines/people/test/integration/navigation_test.rb +10 -0
- data/test/test_app/engines/people/test/models/people/user_test.rb +9 -0
- data/test/test_app/engines/people/test/people_test.rb +7 -0
- data/test/test_app/engines/people/test/test_helper.rb +15 -0
- data/test/test_app/gems/authorization/Gemfile +14 -0
- data/test/test_app/gems/authorization/Gemfile.lock +92 -0
- data/test/test_app/gems/authorization/MIT-LICENSE +20 -0
- data/test/test_app/gems/authorization/README.rdoc +3 -0
- data/test/test_app/gems/authorization/Rakefile +32 -0
- data/test/test_app/gems/authorization/authorization.gemspec +23 -0
- data/test/test_app/gems/authorization/lib/authorization/people/user.rb +82 -0
- data/test/test_app/gems/authorization/lib/authorization/version.rb +3 -0
- data/test/test_app/gems/authorization/lib/authorization.rb +3 -0
- data/test/test_app/gems/authorization/lib/tasks/authorization_tasks.rake +4 -0
- data/test/test_app/gems/authorization/test/authorization_test.rb +7 -0
- data/test/test_app/gems/authorization/test/dummy/README.rdoc +28 -0
- data/test/test_app/gems/authorization/test/dummy/Rakefile +6 -0
- data/test/test_app/gems/authorization/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/test_app/gems/authorization/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/test_app/gems/authorization/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/test_app/gems/authorization/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/test_app/gems/authorization/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/test_app/gems/authorization/test/dummy/bin/bundle +3 -0
- data/test/test_app/gems/authorization/test/dummy/bin/rails +4 -0
- data/test/test_app/gems/authorization/test/dummy/bin/rake +4 -0
- data/test/test_app/gems/authorization/test/dummy/config/application.rb +23 -0
- data/test/test_app/gems/authorization/test/dummy/config/boot.rb +5 -0
- data/test/test_app/gems/authorization/test/dummy/config/database.yml +25 -0
- data/test/test_app/gems/authorization/test/dummy/config/environment.rb +5 -0
- data/test/test_app/gems/authorization/test/dummy/config/environments/development.rb +37 -0
- data/test/test_app/gems/authorization/test/dummy/config/environments/production.rb +82 -0
- data/test/test_app/gems/authorization/test/dummy/config/environments/test.rb +39 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/assets.rb +8 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/test_app/gems/authorization/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/test_app/gems/authorization/test/dummy/config/locales/en.yml +23 -0
- data/test/test_app/gems/authorization/test/dummy/config/routes.rb +56 -0
- data/test/test_app/gems/authorization/test/dummy/config/secrets.yml +22 -0
- data/test/test_app/gems/authorization/test/dummy/config.ru +4 -0
- data/test/test_app/gems/authorization/test/dummy/public/404.html +67 -0
- data/test/test_app/gems/authorization/test/dummy/public/422.html +67 -0
- data/test/test_app/gems/authorization/test/dummy/public/500.html +66 -0
- data/test/test_app/gems/authorization/test/dummy/public/favicon.ico +0 -0
- data/test/test_app/gems/authorization/test/test_helper.rb +15 -0
- data/test/test_app/log/development.log +195 -0
- data/test/test_app/log/production.log +20 -0
- data/test/test_app/log/test.log +8427 -0
- data/test/test_app/spec/controllers/app_index_controller_spec.rb +12 -0
- data/test/test_app/spec/engines/people/api/v1/models/user_spec.rb +59 -0
- data/test/test_app/spec/engines/people/api/v1/requests/user_spec.rb +154 -0
- data/test/test_app/spec/engines/people/api/v1/routing/user_spec.rb +77 -0
- data/test/test_app/spec/factories/people_user_factory.rb +14 -0
- data/test/test_app/spec/rails_helper.rb +47 -0
- data/test/test_app/spec/spec_helper.rb +78 -0
- data/test/test_app/spec/support/factory_girl.rb +16 -0
- data/test/test_app/spec/support/request_helpers.rb +7 -0
- metadata +293 -6
- data/test/test_app/test/test_helper.rb +0 -10
@@ -0,0 +1,59 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::People::User, '.username', :type => :model do
|
4
|
+
it "does not save when nil" do
|
5
|
+
user = FactoryGirl.build(:people_user, :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, :username => "!@#$%)")
|
10
|
+
#expect(user.save).to equal(false)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
RSpec.describe ::People::User, '.email', :type => :model do
|
14
|
+
it "does not save when nil" do
|
15
|
+
user = FactoryGirl.build(:people_user, :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, :email => "!@#$%)")
|
20
|
+
#expect(user.save).to equal(false)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
RSpec.describe ::People::User, '.password_digest', :type => :model do
|
24
|
+
it "does not save when nil" do
|
25
|
+
user = FactoryGirl.build(:people_user, :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, :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, :password => "good_password", :password_confirmation => "good_password")
|
34
|
+
expect(user.save).to equal(true)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
RSpec.describe ::People::User, :type => :model do
|
38
|
+
describe "dependencies" do
|
39
|
+
before(:example) do
|
40
|
+
@user = FactoryGirl.create(:people_user)
|
41
|
+
end
|
42
|
+
it "deletes ... when deleted" do
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
RSpec.describe ::People::User, :type => :model do
|
48
|
+
describe "callbacks" do
|
49
|
+
before(:example) do
|
50
|
+
@user = FactoryGirl.create(:people_user)
|
51
|
+
end
|
52
|
+
it "creates an authentication token" do
|
53
|
+
expect(@user.tokens.any?).to equal(true)
|
54
|
+
end
|
55
|
+
it "does not create an empty auth token" do
|
56
|
+
expect(@user.tokens[0].auth_token.nil?).to equal(false)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::People::User, :type => :request do
|
4
|
+
describe "sign up process" do
|
5
|
+
before(:example) do
|
6
|
+
@attrs = FactoryGirl.attributes_for(:people_user)
|
7
|
+
end
|
8
|
+
# post /api/1/users/register
|
9
|
+
it "checks response of a register request with a valid user object" do
|
10
|
+
post 'api/1/users/register', :user => @attrs
|
11
|
+
expect(response.status).to eq(200) #ok
|
12
|
+
expect(::People::User.all.count).to eq(1)
|
13
|
+
#A valid token needs to be returned
|
14
|
+
expect(json["token"]["auth_token"]).to_not eq(nil)
|
15
|
+
token = ::People::User.find(1).tokens[0]
|
16
|
+
expect(json["token"]["auth_token"]).to eq(token.auth_token)
|
17
|
+
end
|
18
|
+
# post /api/1/users/login
|
19
|
+
it "checks response of a register request with mismatched passwords" do
|
20
|
+
@attrs["password"] = "password1"
|
21
|
+
@attrs["password_confirmation"] = "password2"
|
22
|
+
post 'api/1/users/register', :user => @attrs
|
23
|
+
expect(response.status).to eq(422) #invalid_resource
|
24
|
+
expect(::People::User.all.count).to eq(0)
|
25
|
+
#Errors need to be returned
|
26
|
+
expect(json["errors"]).to_not eq(nil)
|
27
|
+
end
|
28
|
+
# post /api/1/users/login
|
29
|
+
it "checks response of a valid login request" do
|
30
|
+
@attrs["password"] = "password123"
|
31
|
+
@attrs["password_confirmation"] = "password123"
|
32
|
+
user = FactoryGirl.create(:people_user,@attrs)
|
33
|
+
old_auth_token = user.tokens[0].auth_token
|
34
|
+
#It needs to send an email and password
|
35
|
+
post 'api/1/users/login', @attrs
|
36
|
+
expect(response.status).to eq(200) #ok
|
37
|
+
#A valid and new token need to be returned
|
38
|
+
expect(json["token"]["auth_token"]).to_not eq(old_auth_token)
|
39
|
+
#This token should be the newest token in the database
|
40
|
+
new_auth_token = ::People::User.find(1).tokens.order("created_at").last.auth_token
|
41
|
+
expect(json["token"]["auth_token"]).to eq(new_auth_token)
|
42
|
+
end
|
43
|
+
# post /api/1/users/login
|
44
|
+
it "checks response of an invalid login request with an invalid password" do
|
45
|
+
@attrs["password"] = "password123"
|
46
|
+
@attrs["password_confirmation"] = "password123"
|
47
|
+
user = FactoryGirl.create(:people_user,@attrs)
|
48
|
+
#The password needs to be invalid
|
49
|
+
@attrs["password"] = "wrongPassword"
|
50
|
+
#It needs to send an email and password
|
51
|
+
post 'api/1/users/login', @attrs
|
52
|
+
expect(response.status).to eq(401) #unauthorized
|
53
|
+
#Errors need to be returned
|
54
|
+
expect(json["errors"]).to_not eq(nil)
|
55
|
+
end
|
56
|
+
# get /api/1/users/1/logout
|
57
|
+
it "checks logout response and makes sure token is deleted" do
|
58
|
+
user = FactoryGirl.create(:people_user,@attrs)
|
59
|
+
token = user.tokens[0].auth_token
|
60
|
+
header = {"Auth-Token" => token, "Email" => user.email}
|
61
|
+
get 'api/1/users/logout', nil, header
|
62
|
+
expect(::People::User.count).to eq(1)
|
63
|
+
expect(response.status).to eq(200) #ok
|
64
|
+
expect(::Arcadex::Token.count).to eq(0)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
RSpec.describe ::People::User, :type => :request do
|
69
|
+
describe "Rest Routes" do
|
70
|
+
before(:example) do
|
71
|
+
@user = FactoryGirl.create(:people_user)
|
72
|
+
token = @user.tokens[0].auth_token
|
73
|
+
@header = {"Auth-Token" => token, "Email" => @user.email}
|
74
|
+
end
|
75
|
+
# get /api/1/users
|
76
|
+
it "checks index json response" do
|
77
|
+
FactoryGirl.create_list(:people_user, 10)
|
78
|
+
get 'api/1/users', nil, @header
|
79
|
+
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")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
RSpec.describe ::People::User, :type => :request do
|
105
|
+
describe "Authorization" do
|
106
|
+
before(:example) do
|
107
|
+
@user = FactoryGirl.create(:people_user)
|
108
|
+
token = @user.tokens[0].auth_token
|
109
|
+
@header = {"Auth-Token" => token, "Email" => @user.email}
|
110
|
+
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
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
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(:get => "/api/1/users/logout").to route_to(
|
21
|
+
:controller => "people/api/v1/users",
|
22
|
+
:action => "logout"
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
#The standard rest routes for the user controller
|
27
|
+
RSpec.describe "Users controller rest routing", :type => :routing do
|
28
|
+
routes { People::Engine.routes }
|
29
|
+
|
30
|
+
it "routes to index" do
|
31
|
+
expect(:get => "/api/1/users").to route_to(
|
32
|
+
:controller => "people/api/v1/users",
|
33
|
+
:action => "index"
|
34
|
+
)
|
35
|
+
end
|
36
|
+
it "routes to show" do
|
37
|
+
expect(:get => "/api/1/users/1").to route_to(
|
38
|
+
:controller => "people/api/v1/users",
|
39
|
+
:action => "show",
|
40
|
+
:id => "1"
|
41
|
+
)
|
42
|
+
end
|
43
|
+
it "routes to edit" do
|
44
|
+
expect(:get => "/api/1/users/1/edit").to route_to(
|
45
|
+
:controller => "people/api/v1/users",
|
46
|
+
:action => "edit",
|
47
|
+
:id => "1"
|
48
|
+
)
|
49
|
+
end
|
50
|
+
it "routes to create" do
|
51
|
+
expect(:post => "/api/1/users/").to route_to(
|
52
|
+
:controller => "people/api/v1/users",
|
53
|
+
:action => "create"
|
54
|
+
)
|
55
|
+
end
|
56
|
+
it "routes to update" do
|
57
|
+
expect(:put => "/api/1/users/1/").to route_to(
|
58
|
+
:controller => "people/api/v1/users",
|
59
|
+
:action => "update",
|
60
|
+
:id => "1"
|
61
|
+
)
|
62
|
+
end
|
63
|
+
it "routes to update" do
|
64
|
+
expect(:patch => "/api/1/users/1/").to route_to(
|
65
|
+
:controller => "people/api/v1/users",
|
66
|
+
:action => "update",
|
67
|
+
:id => "1"
|
68
|
+
)
|
69
|
+
end
|
70
|
+
it "routes to delete" do
|
71
|
+
expect(:delete => "/api/1/users/1/").to route_to(
|
72
|
+
:controller => "people/api/v1/users",
|
73
|
+
:action => "destroy",
|
74
|
+
:id => "1"
|
75
|
+
)
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,14 @@
|
|
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, class: ::People::User do
|
9
|
+
username
|
10
|
+
email
|
11
|
+
password "password123"
|
12
|
+
password_confirmation "password123"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
require 'spec_helper'
|
4
|
+
require File.expand_path("../../config/environment", __FILE__)
|
5
|
+
require 'rspec/rails'
|
6
|
+
|
7
|
+
# Requires supporting ruby files with custom matchers and macros, etc, in
|
8
|
+
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
9
|
+
# run as spec files by default. This means that files in spec/support that end
|
10
|
+
# in _spec.rb will both be required and run as specs, causing the specs to be
|
11
|
+
# run twice. It is recommended that you do not name files matching this glob to
|
12
|
+
# end with _spec.rb. You can configure this pattern with the --pattern
|
13
|
+
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
14
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
15
|
+
|
16
|
+
# Checks for pending migrations before tests are run.
|
17
|
+
# If you are not using ActiveRecord, you can remove this line.
|
18
|
+
ActiveRecord::Migration.maintain_test_schema!
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
|
22
|
+
config.include ::Requests::JsonHelpers, :type => :request
|
23
|
+
config.include ::Requests::JsonHelpers, :type => :controller
|
24
|
+
|
25
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
26
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
27
|
+
|
28
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
29
|
+
# examples within a transaction, remove the following line or assign false
|
30
|
+
# instead of true.
|
31
|
+
config.use_transactional_fixtures = true
|
32
|
+
|
33
|
+
# RSpec Rails can automatically mix in different behaviours to your tests
|
34
|
+
# based on their file location, for example enabling you to call `get` and
|
35
|
+
# `post` in specs under `spec/controllers`.
|
36
|
+
#
|
37
|
+
# You can disable this behaviour by removing the line below, and instead
|
38
|
+
# explicitly tag your specs with their type, e.g.:
|
39
|
+
#
|
40
|
+
# RSpec.describe UsersController, :type => :controller do
|
41
|
+
# # ...
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# The different available types are documented in the features, such as in
|
45
|
+
# https://relishapp.com/rspec/rspec-rails/docs
|
46
|
+
config.infer_spec_type_from_file_location!
|
47
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, make a
|
10
|
+
# separate helper file that requires this one and then use it only in the specs
|
11
|
+
# that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
RSpec.configure do |config|
|
18
|
+
# The settings below are suggested to provide a good initial experience
|
19
|
+
# with RSpec, but feel free to customize to your heart's content.
|
20
|
+
=begin
|
21
|
+
# These two settings work together to allow you to limit a spec run
|
22
|
+
# to individual examples or groups you care about by tagging them with
|
23
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
24
|
+
# get run.
|
25
|
+
config.filter_run :focus
|
26
|
+
config.run_all_when_everything_filtered = true
|
27
|
+
|
28
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
29
|
+
# file, and it's useful to allow more verbose output when running an
|
30
|
+
# individual spec file.
|
31
|
+
if config.files_to_run.one?
|
32
|
+
# Use the documentation formatter for detailed output,
|
33
|
+
# unless a formatter has already been configured
|
34
|
+
# (e.g. via a command-line flag).
|
35
|
+
config.default_formatter = 'doc'
|
36
|
+
end
|
37
|
+
|
38
|
+
# Print the 10 slowest examples and example groups at the
|
39
|
+
# end of the spec run, to help surface which specs are running
|
40
|
+
# particularly slow.
|
41
|
+
config.profile_examples = 10
|
42
|
+
|
43
|
+
# Run specs in random order to surface order dependencies. If you find an
|
44
|
+
# order dependency and want to debug it, you can fix the order by providing
|
45
|
+
# the seed, which is printed after each run.
|
46
|
+
# --seed 1234
|
47
|
+
config.order = :random
|
48
|
+
|
49
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
50
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
51
|
+
# test failures related to randomization by passing the same `--seed` value
|
52
|
+
# as the one that triggered the failure.
|
53
|
+
Kernel.srand config.seed
|
54
|
+
|
55
|
+
# rspec-expectations config goes here. You can use an alternate
|
56
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
57
|
+
# assertions if you prefer.
|
58
|
+
config.expect_with :rspec do |expectations|
|
59
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
60
|
+
# For more details, see:
|
61
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
62
|
+
expectations.syntax = :expect
|
63
|
+
end
|
64
|
+
|
65
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
66
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
67
|
+
config.mock_with :rspec do |mocks|
|
68
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
69
|
+
# For more details, see:
|
70
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
71
|
+
mocks.syntax = :expect
|
72
|
+
|
73
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
74
|
+
# a real object. This is generally recommended.
|
75
|
+
mocks.verify_partial_doubles = true
|
76
|
+
end
|
77
|
+
=end
|
78
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
RSpec.configure do |config|
|
2
|
+
#additional factory_girl configuration
|
3
|
+
|
4
|
+
# Factory girl methods don't need to be prefaced with FactoryGirl
|
5
|
+
config.include FactoryGirl::Syntax::Methods
|
6
|
+
|
7
|
+
# Best each test suite is run, make sure the factories are valid
|
8
|
+
config.before(:suite) do
|
9
|
+
begin
|
10
|
+
DatabaseCleaner.start
|
11
|
+
FactoryGirl.lint
|
12
|
+
ensure
|
13
|
+
DatabaseCleaner.clean
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|