goma 0.0.1.rc2 → 0.0.1.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/Rakefile +11 -6
  4. data/lib/generators/goma/helpers/helpers.rb +39 -0
  5. data/lib/generators/goma/install/templates/goma.rb +1 -2
  6. data/lib/generators/goma/mailer/templates/mailer.rb +1 -1
  7. data/lib/generators/goma/model/active_record_generator.rb +3 -1
  8. data/lib/generators/goma/scaffold/user_generator.rb +2 -0
  9. data/lib/generators/goma/scaffold_controller/scaffold_controller_generator.rb +2 -0
  10. data/lib/generators/goma/scaffold_controller/templates/confirmation_controller.rb +4 -4
  11. data/lib/generators/goma/scaffold_controller/templates/user_controller.rb +3 -3
  12. data/lib/generators/test_unit/goma/model/model_generator.rb +13 -0
  13. data/lib/generators/test_unit/goma/model/templates/fixtures.yml +30 -0
  14. data/lib/generators/test_unit/goma/model/templates/unit_test.rb +9 -0
  15. data/lib/generators/test_unit/goma/scaffold/scaffold_generator.rb +36 -0
  16. data/lib/generators/test_unit/goma/scaffold/templates/confirmation_functional_test.rb +137 -0
  17. data/lib/generators/test_unit/goma/scaffold/templates/functional_test.rb +51 -0
  18. data/lib/generators/test_unit/goma/scaffold/templates/oauth_functional_test.rb +6 -0
  19. data/lib/generators/test_unit/goma/scaffold/templates/password_functional_test.rb +67 -0
  20. data/lib/generators/test_unit/goma/scaffold/templates/session_functional_test.rb +122 -0
  21. data/lib/generators/test_unit/goma/scaffold/templates/unlock_functional_test.rb +47 -0
  22. data/lib/generators/test_unit/goma/scaffold/templates/user_functional_test.rb +118 -0
  23. data/lib/goma.rb +1 -1
  24. data/lib/goma/config.rb +0 -1
  25. data/lib/goma/controller_test_helpers.rb +65 -0
  26. data/lib/goma/controllers.rb +1 -1
  27. data/lib/goma/models/authenticatable.rb +20 -11
  28. data/lib/goma/models/confirmable.rb +1 -1
  29. data/lib/goma/models/lockable.rb +1 -2
  30. data/lib/goma/version.rb +1 -1
  31. data/test/models/lockable_test.rb +0 -2
  32. data/test/rails_app/app/controllers/confirmations_controller.rb +4 -4
  33. data/test/rails_app/app/controllers/users_controller.rb +3 -3
  34. data/test/rails_app/app/mailers/user_mailer.rb +1 -1
  35. data/test/rails_app/config/initializers/goma.rb +1 -2
  36. data/test/rails_app/db/migrate/{20140515111009_create_users.rb → 20140524062919_create_users.rb} +0 -1
  37. data/test/rails_app/db/migrate/{20140515111010_create_authentications.rb → 20140524062920_create_authentications.rb} +0 -0
  38. data/test/rails_app/db/schema.rb +1 -2
  39. data/test/rails_app/test/controllers/authentications_controller_test.rb +4 -0
  40. data/test/rails_app/test/controllers/confirmations_controller_test.rb +127 -0
  41. data/test/rails_app/test/controllers/passwords_controller_test.rb +65 -0
  42. data/test/rails_app/test/controllers/sessions_controller_test.rb +70 -0
  43. data/test/rails_app/test/controllers/unlocks_controller_test.rb +43 -0
  44. data/test/rails_app/test/controllers/users_controller_test.rb +109 -0
  45. data/test/rails_app/test/fixtures/authentications.yml +11 -0
  46. data/test/rails_app/test/fixtures/users.yml +17 -0
  47. data/test/rails_app/test/helpers/authentications_helper_test.rb +4 -0
  48. data/test/rails_app/test/helpers/confirmations_helper_test.rb +4 -0
  49. data/test/rails_app/test/helpers/passwords_helper_test.rb +4 -0
  50. data/test/rails_app/test/helpers/sessions_helper_test.rb +4 -0
  51. data/test/rails_app/test/helpers/unlocks_helper_test.rb +4 -0
  52. data/test/rails_app/test/helpers/users_helper_test.rb +4 -0
  53. data/test/rails_app/test/mailers/user_mailer_test.rb +7 -0
  54. data/test/rails_app/test/models/authentication_test.rb +7 -0
  55. data/test/rails_app/test/models/user_test.rb +7 -0
  56. data/test/rails_app/test/test_helper.rb +16 -0
  57. data/test/test_helper.rb +1 -1
  58. metadata +54 -7
  59. data/lib/goma/test_helpers.rb +0 -67
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+
3
+ class UnlocksControllerTest < ActionController::TestCase
4
+ setup do
5
+ @user = users(:one)
6
+ end
7
+
8
+ test "should get new" do
9
+ get :new
10
+ assert_response :success
11
+ end
12
+
13
+ test "should resend unlock token with email" do
14
+ @user.lock_access!
15
+ unlock_token = @user.unlock_token
16
+ assert_difference 'ActionMailer::Base.deliveries.size', 1 do
17
+ post :create, username_or_email: @user.email
18
+ end
19
+ assert_redirected_to new_session_url
20
+ @user.reload
21
+ assert_not_equal unlock_token, @user.unlock_token
22
+ end
23
+
24
+ test "should unlock user" do
25
+ @user.lock_access!
26
+ raw_unlock_token = @user.raw_unlock_token
27
+ get :show, id: raw_unlock_token
28
+ assert_redirected_to new_session_url
29
+ assert_match /Your account has been unlocked successfully/, flash[:notice]
30
+ @user.reload
31
+ refute @user.access_locked?
32
+ end
33
+
34
+ test "should not unlock user with wrong token" do
35
+ @user.lock_access!
36
+ raw_unlock_token = @user.raw_unlock_token
37
+ get :show, id: 'oops'
38
+ assert_template :new
39
+ assert_match /Not found any account by this URL/, flash[:alert]
40
+ @user.reload
41
+ assert @user.access_locked?
42
+ end
43
+ end
@@ -0,0 +1,109 @@
1
+ require 'test_helper'
2
+
3
+ class UsersControllerTest < ActionController::TestCase
4
+ setup do
5
+ @user = users(:one)
6
+ end
7
+
8
+ test "should get index" do
9
+ get :index
10
+ assert_response :success
11
+ assert_not_nil assigns(:users)
12
+ end
13
+
14
+ test "should get new" do
15
+ get :new
16
+ assert_response :success
17
+ end
18
+
19
+ test "should create user" do
20
+ assert_difference('User.count') do
21
+ post :create, user: { username: "username1", email: "user1@example.com", password: "password", password_confirmation: "password" }
22
+ end
23
+
24
+ assert_redirected_to new_session_path
25
+ end
26
+
27
+ test "should show user" do
28
+ get :show, id: @user
29
+ assert_response :success
30
+ end
31
+
32
+ test "should not get edit unless logged in" do
33
+ get :edit, id: @user
34
+ assert_redirected_to root_path
35
+ assert_match /Login required/, flash[:alert]
36
+ end
37
+
38
+ test "should get edit" do
39
+ force_login(@user)
40
+ get :edit, id: @user
41
+ assert_response :success
42
+ end
43
+
44
+ test "should not get edit of another user" do
45
+ force_login(@user)
46
+ get :edit, id: users(:two)
47
+ assert_redirected_to root_url
48
+ end
49
+
50
+ test "should not update email unless logged in" do
51
+ original_email = @user.email
52
+ patch :update, id: @user, user: { email: 'new@example.com' }
53
+ assert_redirected_to root_path
54
+ assert_match /Login required/, flash[:alert]
55
+ @user.reload
56
+ assert_equal original_email, @user.email
57
+ assert_equal nil, @user.unconfirmed_email
58
+ end
59
+
60
+ test "should confirm email before update" do
61
+ force_login(@user)
62
+ original_email = @user.email
63
+ assert_difference 'ActionMailer::Base.deliveries.size', 1 do
64
+ patch :update, id: @user, user: { email: 'new@example.com' }
65
+ end
66
+ assert_redirected_to user_path(assigns(:user))
67
+ assert_match /we need to verify your new email address/, flash[:notice]
68
+ @user.reload
69
+ assert_equal original_email, @user.email
70
+ assert_equal 'new@example.com', @user.unconfirmed_email
71
+ end
72
+
73
+
74
+ test "should not update username unless logged in" do
75
+ original = @user.username
76
+ patch :update, id: @user, user: { username: 'new_username' }
77
+ assert_redirected_to root_path
78
+ @user.reload
79
+ assert_equal original, @user.username
80
+ assert_match /Login required/, flash[:alert]
81
+ end
82
+
83
+ test "should update username" do
84
+ force_login(@user)
85
+ patch :update, id: @user, user: { username: 'new_username' }
86
+ assert_redirected_to user_path(assigns(:user))
87
+ @user.reload
88
+ assert_equal 'new_username', @user.username
89
+ end
90
+
91
+
92
+ test "should not destroy user unless logged in" do
93
+ assert_no_difference('User.count') do
94
+ delete :destroy, id: @user
95
+ end
96
+
97
+ assert_redirected_to root_path
98
+ assert_match /Login required/, flash[:alert]
99
+ end
100
+
101
+ test "should destroy user" do
102
+ force_login(@user)
103
+ assert_difference('User.count', -1) do
104
+ delete :destroy, id: @user
105
+ end
106
+
107
+ assert_redirected_to users_path
108
+ end
109
+ end
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ # This model initially had no columns defined. If you add columns to the
4
+ # model remove the '{}' from the fixture names and add the columns immediately
5
+ # below each fixture, per the syntax in the comments below
6
+ #
7
+ one: {}
8
+ # column: value
9
+ #
10
+ two: {}
11
+ # column: value
@@ -0,0 +1,17 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ username: 'one_username'
5
+ email: one@example.com
6
+ encrypted_password: <%= Goma.encryptor.encrypt('password', '') %>
7
+ activated_at: <%= Time.now.utc %>
8
+ two:
9
+ username: 'two_username'
10
+ email: two@example.com
11
+ encrypted_password: <%= Goma.encryptor.encrypt('password', '') %>
12
+ activated_at: <%= Time.now.utc %>
13
+
14
+ unactivated_user:
15
+ username: 'unactivated_user_username'
16
+ email: unactivated_user@example.com
17
+ encrypted_password: <%= Goma.encryptor.encrypt('password', '') %>
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class AuthenticationsHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class ConfirmationsHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class PasswordsHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class SessionsHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class UnlocksHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class UsersHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class UserMailerTest < ActionMailer::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class AuthenticationTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class UserTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,16 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
7
+ #
8
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
9
+ # -- they do not yet inherit this setting
10
+ fixtures :all
11
+
12
+ # Add more helper methods to be used by all tests here...
13
+ end
14
+ class ActionController::TestCase
15
+ include Goma::ControllerTestHelpers
16
+ end
@@ -45,7 +45,7 @@ class ActiveSupport::TestCase
45
45
  end
46
46
 
47
47
  class ActionController::TestCase
48
- include Warden::Test::ControllerHelpers
48
+ include Goma::ControllerTestHelpers
49
49
  end
50
50
 
51
51
  class ActionDispatch::IntegrationTest
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.rc2
4
+ version: 0.0.1.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kentaro Imai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-21 00:00:00.000000000 Z
11
+ date: 2014-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -249,8 +249,20 @@ files:
249
249
  - lib/generators/goma/scaffold_controller/templates/session_controller.rb
250
250
  - lib/generators/goma/scaffold_controller/templates/unlock_controller.rb
251
251
  - lib/generators/goma/scaffold_controller/templates/user_controller.rb
252
+ - lib/generators/test_unit/goma/model/model_generator.rb
253
+ - lib/generators/test_unit/goma/model/templates/fixtures.yml
254
+ - lib/generators/test_unit/goma/model/templates/unit_test.rb
255
+ - lib/generators/test_unit/goma/scaffold/scaffold_generator.rb
256
+ - lib/generators/test_unit/goma/scaffold/templates/confirmation_functional_test.rb
257
+ - lib/generators/test_unit/goma/scaffold/templates/functional_test.rb
258
+ - lib/generators/test_unit/goma/scaffold/templates/oauth_functional_test.rb
259
+ - lib/generators/test_unit/goma/scaffold/templates/password_functional_test.rb
260
+ - lib/generators/test_unit/goma/scaffold/templates/session_functional_test.rb
261
+ - lib/generators/test_unit/goma/scaffold/templates/unlock_functional_test.rb
262
+ - lib/generators/test_unit/goma/scaffold/templates/user_functional_test.rb
252
263
  - lib/goma.rb
253
264
  - lib/goma/config.rb
265
+ - lib/goma/controller_test_helpers.rb
254
266
  - lib/goma/controllers.rb
255
267
  - lib/goma/controllers/confirmable.rb
256
268
  - lib/goma/controllers/password_authenticatable.rb
@@ -275,7 +287,6 @@ files:
275
287
  - lib/goma/railtie.rb
276
288
  - lib/goma/routes.rb
277
289
  - lib/goma/strategies/rememberable.rb
278
- - lib/goma/test_helpers.rb
279
290
  - lib/goma/token_generator.rb
280
291
  - lib/goma/version.rb
281
292
  - lib/goma/warden.rb
@@ -389,8 +400,8 @@ files:
389
400
  - test/rails_app/config/initializers/wrap_parameters.rb
390
401
  - test/rails_app/config/locales/en.yml
391
402
  - test/rails_app/config/routes.rb
392
- - test/rails_app/db/migrate/20140515111009_create_users.rb
393
- - test/rails_app/db/migrate/20140515111010_create_authentications.rb
403
+ - test/rails_app/db/migrate/20140524062919_create_users.rb
404
+ - test/rails_app/db/migrate/20140524062920_create_authentications.rb
394
405
  - test/rails_app/db/schema.rb
395
406
  - test/rails_app/lib/assets/.keep
396
407
  - test/rails_app/log/.keep
@@ -398,6 +409,24 @@ files:
398
409
  - test/rails_app/public/422.html
399
410
  - test/rails_app/public/500.html
400
411
  - test/rails_app/public/favicon.ico
412
+ - test/rails_app/test/controllers/authentications_controller_test.rb
413
+ - test/rails_app/test/controllers/confirmations_controller_test.rb
414
+ - test/rails_app/test/controllers/passwords_controller_test.rb
415
+ - test/rails_app/test/controllers/sessions_controller_test.rb
416
+ - test/rails_app/test/controllers/unlocks_controller_test.rb
417
+ - test/rails_app/test/controllers/users_controller_test.rb
418
+ - test/rails_app/test/fixtures/authentications.yml
419
+ - test/rails_app/test/fixtures/users.yml
420
+ - test/rails_app/test/helpers/authentications_helper_test.rb
421
+ - test/rails_app/test/helpers/confirmations_helper_test.rb
422
+ - test/rails_app/test/helpers/passwords_helper_test.rb
423
+ - test/rails_app/test/helpers/sessions_helper_test.rb
424
+ - test/rails_app/test/helpers/unlocks_helper_test.rb
425
+ - test/rails_app/test/helpers/users_helper_test.rb
426
+ - test/rails_app/test/mailers/user_mailer_test.rb
427
+ - test/rails_app/test/models/authentication_test.rb
428
+ - test/rails_app/test/models/user_test.rb
429
+ - test/rails_app/test/test_helper.rb
401
430
  - test/test_helper.rb
402
431
  homepage: https://github.com/kentaroi/goma
403
432
  licenses:
@@ -542,8 +571,8 @@ test_files:
542
571
  - test/rails_app/config/initializers/wrap_parameters.rb
543
572
  - test/rails_app/config/locales/en.yml
544
573
  - test/rails_app/config/routes.rb
545
- - test/rails_app/db/migrate/20140515111009_create_users.rb
546
- - test/rails_app/db/migrate/20140515111010_create_authentications.rb
574
+ - test/rails_app/db/migrate/20140524062919_create_users.rb
575
+ - test/rails_app/db/migrate/20140524062920_create_authentications.rb
547
576
  - test/rails_app/db/schema.rb
548
577
  - test/rails_app/lib/assets/.keep
549
578
  - test/rails_app/log/.keep
@@ -551,4 +580,22 @@ test_files:
551
580
  - test/rails_app/public/422.html
552
581
  - test/rails_app/public/500.html
553
582
  - test/rails_app/public/favicon.ico
583
+ - test/rails_app/test/controllers/authentications_controller_test.rb
584
+ - test/rails_app/test/controllers/confirmations_controller_test.rb
585
+ - test/rails_app/test/controllers/passwords_controller_test.rb
586
+ - test/rails_app/test/controllers/sessions_controller_test.rb
587
+ - test/rails_app/test/controllers/unlocks_controller_test.rb
588
+ - test/rails_app/test/controllers/users_controller_test.rb
589
+ - test/rails_app/test/fixtures/authentications.yml
590
+ - test/rails_app/test/fixtures/users.yml
591
+ - test/rails_app/test/helpers/authentications_helper_test.rb
592
+ - test/rails_app/test/helpers/confirmations_helper_test.rb
593
+ - test/rails_app/test/helpers/passwords_helper_test.rb
594
+ - test/rails_app/test/helpers/sessions_helper_test.rb
595
+ - test/rails_app/test/helpers/unlocks_helper_test.rb
596
+ - test/rails_app/test/helpers/users_helper_test.rb
597
+ - test/rails_app/test/mailers/user_mailer_test.rb
598
+ - test/rails_app/test/models/authentication_test.rb
599
+ - test/rails_app/test/models/user_test.rb
600
+ - test/rails_app/test/test_helper.rb
554
601
  - test/test_helper.rb
@@ -1,67 +0,0 @@
1
- module Warden
2
- # Warden::Test::ControllerHelpers provides a facility to test controllers in isolation
3
- # Most of the code was extracted from Devise's Devise::TestHelpers.
4
- module Test
5
- module ControllerHelpers
6
- def self.included(base)
7
- base.class_eval do
8
- setup :setup_controller_for_warden, :warden if respond_to?(:setup)
9
- end
10
- end
11
-
12
- # Override process to consider warden.
13
- def process(*)
14
- # Make sure we always return @response, a la ActionController::TestCase::Behavior#process, even if warden interrupts
15
- _catch_warden {super} || @response
16
- end
17
-
18
- # We need to setup the environment variables and the response in the controller
19
- def setup_controller_for_warden
20
- @request.env['action_controller.instance'] = @controller
21
- end
22
-
23
- # Quick access to Warden::Proxy.
24
- def warden
25
- @warden ||= begin
26
- manager = Warden::Manager.new(nil, &Rails.application.config.middleware.detect{|m| m.name == 'Warden::Manager'}.block)
27
- @request.env['warden'] = Warden::Proxy.new(@request.env, manager)
28
- end
29
- end
30
-
31
- protected
32
-
33
- # Catch warden continuations and handle like the middleware would.
34
- # Returns nil when interrupted, otherwise the normal result of the block.
35
- def _catch_warden(&block)
36
- result = catch(:warden, &block)
37
-
38
- if result.is_a?(Hash) && !warden.custom_failure? && !@controller.send(:performed?)
39
- result[:action] ||= :unauthenticated
40
-
41
- env = @controller.request.env
42
- env['PATH_INFO'] = "/#{result[:action]}"
43
- env['warden.options'] = result
44
- Warden::Manager._run_callbacks(:before_failure, env, result)
45
-
46
- status, headers, body = warden.config[:failure_app].call(env).to_a
47
- @controller.send :render, :status => status, :text => body,
48
- :content_type => headers['Content-Type'], :location => headers['Location']
49
-
50
- nil
51
- else
52
- result
53
- end
54
- end
55
-
56
- def method_missing(m, *args)
57
- name = m.to_s
58
- if name =~ /^(?:(#{Goma.config.scopes.join('|')})_)?(?:login!?|logout|logged_in\?)$/ || name == 'force_login' || name =~ /^current_(#{Goma.config.scopes.join('|')})$/
59
- @controller.send(m, *args)
60
- else
61
- super
62
- end
63
- end
64
- end
65
- end
66
- end
67
-