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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d6099fa064157ae214f3a611bc179f97732ea87
4
- data.tar.gz: 5e9b12ea1433741c58da4a6b9abe08e7c4b320d9
3
+ metadata.gz: 398a6fc63442ad680bca1a497b146163cd7d9403
4
+ data.tar.gz: f55f88ac4e630605297ce4f054453ee7a3677adc
5
5
  SHA512:
6
- metadata.gz: 73a52d5b437db21c532f16b6179cc3a163ebac83ae496657337b24b58351e0985b7cab88d49663d0450c1bd443093e3f7542a52423340b20fb85957dd21b1425
7
- data.tar.gz: 0d62cf55a2bc7df0c209722eb3ae7e3347ea5b82b7ee549fd25dba5d16841a8d56480a8925fe84b921760352b76944cce87d0afaf50028d7eee7ea9d45631713
6
+ metadata.gz: eca7341609661f75c09dce50bf54a854b55a0f8d56a1fb8bbd4edf30bbe5c72fca1a098544afdb42ce6b025b41accc4d3f084f809f9d234f352ed5b4a8c5e3d5
7
+ data.tar.gz: 70c6036f1ba70bde98f26887287f79664d66b712f91bb1fbcb84c49fcd3172f83fa06c65cccbfce16b33a73dd704bebda255a246d86203ee9d164bc94640b475
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- goma (0.0.1.rc2)
4
+ goma (0.0.1.rc3)
5
5
  rails (~> 4.0)
6
6
  warden
7
7
 
data/Rakefile CHANGED
@@ -25,23 +25,28 @@ require 'single_test/tasks'
25
25
  Rake::TestTask.new(:test) do |t|
26
26
  t.libs << 'lib'
27
27
  t.libs << 'test'
28
- t.pattern = 'test/**/*_test.rb'
28
+ t.pattern = 'test/{models,controllers,integration}/*_test.rb'
29
29
  t.verbose = false
30
30
  end
31
31
 
32
32
  desc "Rebuild test app's resources"
33
33
  task "rebuild_test_app" do
34
- migration = 'migrate' == ARGV.last ? '' : ' --no-migration'
34
+ migration = (ENV['MIGRATE'] || ENV['MIGRATION']) ? '' : ' --no-migration'
35
+ quiet = ENV['VERVOSE'] ? '' : ' --quiet'
35
36
  cd "test/rails_app"
36
- sh "bundle exec rails d goma:scaffold User#{migration}"
37
- sh "bundle exec rails g goma:scaffold User#{migration}"
37
+ sh "bundle exec rails d goma:scaffold User#{migration}#{quiet}"
38
+ sh "bundle exec rails g goma:scaffold User#{migration}#{quiet}"
38
39
  if migration.empty?
39
40
  sh "RAILS_ENV=test bundle exec rake db:drop"
40
41
  sh "RAILS_ENV=test bundle exec rake db:create"
41
42
  sh "RAILS_ENV=test bundle exec rake db:migrate"
42
43
  end
43
- sh "rm -rf test/*"
44
- cd "../.."
44
+ end
45
+
46
+ desc "Run test in test app"
47
+ task "in_app_test" do
48
+ cd "test/rails_app"
49
+ sh "bundle exec rake test"
45
50
  end
46
51
 
47
52
  desc "Run tests for all environment variables"
@@ -59,9 +59,42 @@ module Goma
59
59
  false
60
60
  end
61
61
 
62
+ def login_path
63
+ longer_name? ? "new_#{resource_name}_session_path" : "new_session_path"
64
+ end
65
+
62
66
  def login_url
63
67
  longer_name? ? "new_#{resource_name}_session_url" : "new_session_url"
64
68
  end
69
+
70
+ def expire(within)
71
+ within.inspect.gsub(/^(\d+)\s*(\w*)$/) { "#{$1.to_i + 1}.#{$2}" }
72
+ end
73
+
74
+ def a_resource
75
+ "#{resource_name.to_s.pluralize}(:#{resource_name})"
76
+ end
77
+
78
+ def new_resource_attributes
79
+ h = {}
80
+ i = counter
81
+ goma_config.authentication_keys.map do |key|
82
+ if key == goma_config.email_attribute_name
83
+ h[key] = "#{goma_scope}#{i}@example.com"
84
+ else
85
+ h[key] = "#{key}#{i}"
86
+ end
87
+ end
88
+ [goma_config.password_attribute_name, goma_config.password_confirmation_attribute_name].map do |key|
89
+ h[key] = 'password'
90
+ end
91
+ h
92
+ end
93
+
94
+ def counter
95
+ @counter ||= 0
96
+ @counter += 1
97
+ end
65
98
  end
66
99
  end
67
100
  end
@@ -71,3 +104,9 @@ class Array
71
104
  self.to_sentence(words_connector: '_', two_words_connector: '_or_', last_word_connector: '_or_')
72
105
  end
73
106
  end
107
+
108
+ class Hash
109
+ def inspect19
110
+ '{ ' + map { |k, v| "#{k}: \"#{v}\"" }.join(', ') + ' }'
111
+ end
112
+ end
@@ -35,7 +35,7 @@ Goma.configure do |config|
35
35
  # config.activation_mailer_name = nil
36
36
  # config.email_confirmation_mailer_name = nil
37
37
  # config.confirmation_keys = [ :email ]
38
- # config.allow_unconfirmed_access_for = 0
38
+ # config.allow_unactivated_access_for = 0
39
39
  # config.activate_within = 3.days
40
40
  # config.activation_needed_email_method_name = :activation_needed_email
41
41
  # config.activation_success_email_method_name = :activation_success_email
@@ -78,7 +78,6 @@ Goma.configure do |config|
78
78
  # config.unlock_in = 1.hour
79
79
  # config.last_attempt_warning = false # TODO not yet implemented
80
80
  # config.unlock_token_attribute_name = :unlock_token
81
- # config.unlock_token_sent_at_attribute_name = :unlock_token_sent_at
82
81
  # config.unlock_token_to_send_attribute_name = :raw_unlock_token
83
82
 
84
83
  ####################################################
@@ -1,6 +1,6 @@
1
1
  <% module_namespacing do -%>
2
2
  class <%= class_name %> < ActionMailer::Base
3
- default from: "<%= goma_config.mailer_sender %>"
3
+ default from: Goma.config(:<%= resource_name %>).mailer_sender
4
4
 
5
5
  <% goma_actions.each do |action, subject| -%>
6
6
  # Subject can be set in your I18n file at config/locales/en.yml
@@ -1,4 +1,5 @@
1
1
  require 'rails/generators/active_record/model/model_generator'
2
+ require 'generators/test_unit/goma/model/model_generator'
2
3
 
3
4
  module Goma
4
5
  module Generators
@@ -24,6 +25,8 @@ module Goma
24
25
  end
25
26
  end
26
27
 
28
+ hook_for :test_framework, as: 'goma:model'
29
+
27
30
  private
28
31
  def merge_goma_user_attributes!
29
32
  self.attributes = (goma_user_attributes.map do |attr|
@@ -69,7 +72,6 @@ module Goma
69
72
  attrs << {type: :integer, field: goma_config.failed_attempts_attribute_name}
70
73
  attrs << {type: :datetime, field: goma_config.locked_at_attribute_name}
71
74
  attrs << {type: :string, field: goma_config.unlock_token_attribute_name, index: :uniq}
72
- attrs << {type: :datetime, field: goma_config.unlock_token_sent_at_attribute_name}
73
75
  end
74
76
 
75
77
  if goma_config.modules.include? :recoverable
@@ -4,6 +4,8 @@ module Goma
4
4
  module Generators
5
5
  module Scaffold
6
6
  class UserGenerator < Rails::Generators::ScaffoldGenerator
7
+ class_option :resource_name
8
+
7
9
  def initialize(args, *options)
8
10
  options[0] << '--controller-type=user'
9
11
  super
@@ -1,5 +1,6 @@
1
1
  require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
2
2
  require 'generators/goma/helpers/helpers'
3
+ require 'generators/test_unit/goma/scaffold/scaffold_generator'
3
4
 
4
5
  module Goma
5
6
  module Generators
@@ -19,6 +20,7 @@ module Goma
19
20
  end
20
21
 
21
22
  hook_for :template_engine, in: 'goma'
23
+ hook_for :test_framework, as: 'goma:scaffold'
22
24
  end
23
25
  end
24
26
  end
@@ -46,15 +46,15 @@ class <%= controller_class_name %>Controller < ApplicationController
46
46
  redirect_to root_url, notice: 'Your new email was successfully confirmed.'
47
47
  else
48
48
  if err == :token_expired
49
- flash.now[:alert] = "Your email confirmation URL has expired, please change your email again."
49
+ flash[:alert] = "Your email confirmation URL has expired, please change your email again."
50
50
  else
51
- flash.now[:alert] = "Email confirmation failed. Please make sure you used the full URL provided."
51
+ flash[:alert] = "Email confirmation failed. Please make sure you used the full URL provided."
52
52
  end
53
53
 
54
54
  if current_<%= resource_name %>
55
- render edit_<%= resource_name%>_url(current_<%= resource_name %>)
55
+ redirect_to edit_<%= resource_name%>_url(current_<%= resource_name %>)
56
56
  else
57
- render root_url
57
+ redirect_to root_url
58
58
  end
59
59
  end
60
60
  end
@@ -23,7 +23,7 @@ class <%= controller_class_name %>Controller < ApplicationController
23
23
 
24
24
  # GET <%= route_url %>/1/edit
25
25
  def edit
26
- <%= goma_config.not_authenticated_action %> unless current_user = @user
26
+ <%= goma_config.not_authenticated_action %> unless current_user == @user
27
27
  end
28
28
 
29
29
  # POST <%= route_url %>
@@ -49,7 +49,7 @@ class <%= controller_class_name %>Controller < ApplicationController
49
49
 
50
50
  # PATCH/PUT <%= route_url %>/1
51
51
  def update
52
- <%= goma_config.not_authenticated_action %> unless current_user = @user
52
+ <%= goma_config.not_authenticated_action %> unless current_user == @user
53
53
  if @<%= orm_instance.update("#{singular_table_name}_params") %>
54
54
  <% if goma_config.modules.include?(:confirmable) && goma_config.email_confirmation_enabled -%>
55
55
  flash[:notice] = @<%= singular_table_name %>.<%= goma_config.confirmation_token_to_send_attribute_name %> ?
@@ -66,7 +66,7 @@ class <%= controller_class_name %>Controller < ApplicationController
66
66
 
67
67
  # DELETE <%= route_url %>/1
68
68
  def destroy
69
- <%= goma_config.not_authenticated_action %> unless current_user = @user
69
+ <%= goma_config.not_authenticated_action %> unless current_user == @user
70
70
  @<%= orm_instance.destroy %>
71
71
  redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %>
72
72
  end
@@ -0,0 +1,13 @@
1
+ require 'rails/generators/test_unit/model/model_generator'
2
+ require 'generators/goma/helpers/helpers'
3
+
4
+ module TestUnit
5
+ module Generators
6
+ module Goma
7
+ class ModelGenerator < ::TestUnit::Generators::ModelGenerator
8
+ include ::Goma::Generators::Helpers
9
+ source_root File.expand_path('../templates', __FILE__)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ <% [:one, :two].each do |name| -%>
4
+ <%= name %>:
5
+ <% if goma_config.modules.include?(:password_authenticatable) -%>
6
+ <% (goma_config.authentication_keys - [goma_config.email_attribute_name]).each do |key| -%>
7
+ <%= key %>: '<%= "#{name}_#{key}" %>'
8
+ <% end -%>
9
+ <% if goma_config.email_attribute_name -%>
10
+ <%= goma_config.email_attribute_name %>: <%= name %>@example.com
11
+ <% end -%>
12
+ <%= goma_config.encrypted_password_attribute_name %>: <%%= Goma.encryptor.encrypt('password', '<%= goma_config.pepper %>') %>
13
+ <% end -%>
14
+ <% if goma_config.modules.include?(:confirmable) -%>
15
+ <%= goma_config.activated_at_attribute_name %>: <%%= Time.now.utc %>
16
+ <% end -%>
17
+ <% end -%>
18
+
19
+ <% if goma_config.modules.include?(:confirmable) -%>
20
+ unactivated_<%= resource_name %>:
21
+ <% if goma_config.modules.include?(:password_authenticatable) -%>
22
+ <% (goma_config.authentication_keys - [goma_config.email_attribute_name]).each do |key| -%>
23
+ <%= key %>: '<%= "unactivated_#{goma_scope}_#{key}" %>'
24
+ <% end -%>
25
+ <% if goma_config.email_attribute_name -%>
26
+ <%= goma_config.email_attribute_name %>: unactivated_<%= goma_scope %>@example.com
27
+ <% end -%>
28
+ <%= goma_config.encrypted_password_attribute_name %>: <%%= Goma.encryptor.encrypt('password', '<%= goma_config.pepper %>') %>
29
+ <% end -%>
30
+ <% end -%>
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ class <%= class_name %>Test < ActiveSupport::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ <% end -%>
@@ -0,0 +1,36 @@
1
+ require 'rails/generators/test_unit/scaffold/scaffold_generator'
2
+ require 'generators/goma/helpers/helpers'
3
+
4
+ module TestUnit
5
+ module Generators
6
+ module Goma
7
+ class ScaffoldGenerator < ::TestUnit::Generators::ScaffoldGenerator
8
+ include ::Goma::Generators::Helpers
9
+ source_root File.expand_path('../templates', __FILE__)
10
+
11
+ class_option :controller_type, required: true
12
+ class_option :resource_name
13
+
14
+ def create_test_files
15
+ template "#{options[:controller_type]}_functional_test.rb",
16
+ File.join("test/controllers", controller_class_path, "#{controller_file_name}_controller_test.rb")
17
+ end
18
+
19
+ def inject_controller_test_helpers
20
+ path = File.expand_path('test/test_helper.rb', destination_root)
21
+ File.open path do |f|
22
+ unless f.read =~ /class\s+ActionController::TestCase/
23
+ append_to_file path do
24
+ <<-RUBY.strip_heredoc
25
+ class ActionController::TestCase
26
+ end
27
+ RUBY
28
+ end
29
+ end
30
+ end
31
+ inject_into_class('test/test_helper.rb', 'ActionController::TestCase', " include Goma::ControllerTestHelpers\n")
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,137 @@
1
+ require 'test_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
5
+ setup do
6
+ @<%= resource_name %> = <%= resource_name.pluralize %>(:unactivated_<%= resource_name %>)
7
+ end
8
+
9
+ test "should get new" do
10
+ get :new
11
+ assert_response :success
12
+ end
13
+
14
+ test "should create <%= singular_table_name %>" do
15
+ <%= resource_name %> = <%= resource_class_name %>.create(<%= new_resource_attributes.inspect19 %>)
16
+ assert_difference 'ActionMailer::Base.deliveries.size', 1 do
17
+ post :create, <%= goma_config.authentication_keys.to_field_name %>: <%= resource_name %>.<%= goma_config.email_attribute_name %>
18
+ end
19
+ assert_redirected_to <%= login_url %>
20
+ assert_match /You will receive new activation email/, flash[:notice]
21
+ end
22
+
23
+ test "should activate <%= resource_name %>" do
24
+ <%= resource_name %> = <%= resource_class_name %>.create(<%= new_resource_attributes.inspect19 %>)
25
+ <% if goma_config.activation_success_email_method_name -%>
26
+ assert_difference 'ActionMailer::Base.deliveries.size', 1 do
27
+ <% else -%>
28
+ assert_no_difference 'ActionMailer::Base.deliveries.size' do
29
+ <% end -%>
30
+ get :show, id: <%= resource_name %>.<%= goma_config.confirmation_token_to_send_attribute_name %>
31
+ end
32
+ assert_redirected_to <%= login_url %>
33
+ assert_match /Your account was successfully activated/, flash[:notice]
34
+ <%= resource_name %>.reload
35
+ assert <%= resource_name %>.activated?
36
+ end
37
+
38
+ test "should not activate <%= resource_name %> with wrong token" do
39
+ <%= resource_name %> = <%= resource_class_name %>.create(<%= new_resource_attributes.inspect19 %>)
40
+ assert_no_difference 'ActionMailer::Base.deliveries.size' do
41
+ get :show, id: 'oops'
42
+ end
43
+ assert_response :success
44
+ assert_template :new
45
+ assert_match /Not found any account by this URL/, flash[:alert]
46
+ <%= resource_name %>.reload
47
+ refute <%= resource_name %>.activated?
48
+ end
49
+
50
+ test "should not activate <%= resource_name %> with expired token" do
51
+ <%= resource_name %> = <%= resource_class_name %>.create(<%= new_resource_attributes.inspect19 %>)
52
+ <%= resource_name %>.update_column(:<%= goma_config.confirmation_token_sent_at_attribute_name %>, <%= expire(goma_config.activate_within) %>.ago)
53
+ assert_no_difference 'ActionMailer::Base.deliveries.size' do
54
+ get :show, id: <%= resource_name %>.<%= goma_config.confirmation_token_to_send_attribute_name %>
55
+ end
56
+ assert_response :success
57
+ assert_template :new
58
+ assert_match /Your activation URL has expired/, flash[:alert]
59
+ <%= resource_name %>.reload
60
+ refute <%= resource_name %>.activated?
61
+ end
62
+
63
+ test "should confirm email" do
64
+ <%= resource_name %> = <%= resource_name.pluralize %>(:one)
65
+ <%= goma_config.email_attribute_name %> = <%= resource_name %>.<%= goma_config.email_attribute_name %>
66
+ <%= resource_name %>.update(<%= goma_config.email_attribute_name %>: 'new@example.com')
67
+ assert_equal 'new@example.com', <%= resource_name %>.<%= goma_config.unconfirmed_email_attribute_name %>
68
+ assert_equal <%= goma_config.email_attribute_name %>, <%= resource_name %>.<%= goma_config.email_attribute_name %>
69
+ <% if goma_config.activation_success_email_method_name -%>
70
+ assert_difference 'ActionMailer::Base.deliveries.size', 1 do
71
+ <% else -%>
72
+ assert_no_difference 'ActionMailer::Base.deliveries.size' do
73
+ <% end -%>
74
+ get :email, id: <%= resource_name %>.<%= goma_config.confirmation_token_to_send_attribute_name %>
75
+ end
76
+ assert_redirected_to root_path
77
+ assert_match /Your new email was successfully confirmed/, flash[:notice]
78
+ <%= resource_name %>.reload
79
+ assert_equal 'new@example.com', <%= resource_name %>.<%= goma_config.email_attribute_name %>
80
+ assert_nil <%= resource_name %>.<%= goma_config.unconfirmed_email_attribute_name %>
81
+ end
82
+
83
+ test "should not confirm email with wrong token" do
84
+ <%= resource_name %> = <%= resource_name.pluralize %>(:one)
85
+ <%= goma_config.email_attribute_name %> = <%= resource_name %>.<%= goma_config.email_attribute_name %>
86
+ <%= resource_name %>.update(<%= goma_config.email_attribute_name %>: 'new@example.com')
87
+ assert_equal 'new@example.com', <%= resource_name %>.<%= goma_config.unconfirmed_email_attribute_name %>
88
+ assert_equal <%= goma_config.email_attribute_name %>, <%= resource_name %>.<%= goma_config.email_attribute_name %>
89
+ assert_no_difference 'ActionMailer::Base.deliveries.size' do
90
+ get :email, id: 'oops'
91
+ end
92
+ assert_redirected_to root_path
93
+ assert_match /Please make sure you used the full URL provided/, flash[:alert]
94
+ <%= resource_name %>.reload
95
+ assert_equal <%= goma_config.email_attribute_name %>, <%= resource_name %>.<%= goma_config.email_attribute_name %>
96
+ assert_equal 'new@example.com', <%= resource_name %>.<%= goma_config.unconfirmed_email_attribute_name %>
97
+ end
98
+
99
+ test "should not confirm email with expired token" do
100
+ <%= resource_name %> = <%= resource_name.pluralize %>(:one)
101
+ <%= goma_config.email_attribute_name %> = <%= resource_name %>.<%= goma_config.email_attribute_name %>
102
+ <%= resource_name %>.update(<%= goma_config.email_attribute_name %>: 'new@example.com')
103
+ <%= resource_name %>.update_column(:<%= goma_config.confirmation_token_sent_at_attribute_name %>, <%= expire(goma_config.confirm_email_within) %>.ago)
104
+ assert_equal 'new@example.com', <%= resource_name %>.<%= goma_config.unconfirmed_email_attribute_name %>
105
+ assert_equal <%= goma_config.email_attribute_name %>, <%= resource_name %>.<%= goma_config.email_attribute_name %>
106
+ assert_no_difference 'ActionMailer::Base.deliveries.size' do
107
+ get :email, id: <%= resource_name %>.<%= goma_config.confirmation_token_to_send_attribute_name %>
108
+ end
109
+ assert_redirected_to root_path
110
+ assert_match /Your email confirmation URL has expired/, flash[:alert]
111
+ <%= resource_name %>.reload
112
+ assert_equal <%= goma_config.email_attribute_name %>, <%= resource_name %>.<%= goma_config.email_attribute_name %>
113
+ assert_equal 'new@example.com', <%= resource_name %>.<%= goma_config.unconfirmed_email_attribute_name %>
114
+ end
115
+
116
+ test "should be redirected to edit_user_url when failed to confirm email with wrong token if logged in" do
117
+ <%= resource_name %> = <%= resource_name.pluralize %>(:one)
118
+ force_login(<%= resource_name %>)
119
+ <%= resource_name %>.update(<%= goma_config.email_attribute_name %>: 'new@example.com')
120
+ get :email, id: 'oops'
121
+ assert_redirected_to edit_user_url(<%= resource_name %>)
122
+ assert_match /Please make sure you used the full URL provided/, flash[:alert]
123
+ <%= resource_name %>.reload
124
+ end
125
+
126
+ test "should be redirected to edit_user_url when failed to confirm email with expired token if logged in" do
127
+ <%= resource_name %> = <%= resource_name.pluralize %>(:one)
128
+ force_login(<%= resource_name %>)
129
+ <%= resource_name %>.update(<%= goma_config.email_attribute_name %>: 'new@example.com')
130
+ <%= resource_name %>.update_column(:<%= goma_config.confirmation_token_sent_at_attribute_name %>, <%= expire(goma_config.confirm_email_within) %>.ago)
131
+ get :email, id: <%= resource_name %>.<%= goma_config.confirmation_token_to_send_attribute_name %>
132
+ assert_redirected_to edit_user_url(<%= resource_name %>)
133
+ assert_match /Your email confirmation URL has expired/, flash[:alert]
134
+ end
135
+
136
+ end
137
+ <% end -%>