mac_generators 0.2.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +12 -16
  3. data/lib/generators/authentication/email/email_generator.rb +62 -63
  4. data/lib/generators/authentication/email/templates/create_identities.rb +1 -2
  5. data/lib/generators/authentication/email/templates/database_authentication.rb +2 -0
  6. data/lib/generators/authentication/email/templates/identities_controller.rb +4 -2
  7. data/lib/generators/authentication/email/templates/identity.rb +2 -0
  8. data/lib/generators/authentication/email/templates/sessions_controller.rb +2 -0
  9. data/lib/generators/authentication/email/templates/warden.rb +3 -1
  10. data/lib/generators/authentication/omniauth/omniauth_generator.rb +69 -68
  11. data/lib/generators/authentication/omniauth/templates/authentication_domain.rb +1 -1
  12. data/lib/generators/authentication/omniauth/templates/create_identities.rb +1 -1
  13. data/lib/generators/bootstrap/bootstrap_generator.rb +13 -13
  14. data/lib/mac_generators/version.rb +1 -1
  15. data/test/dummy/Rakefile +1 -1
  16. data/test/dummy/app/assets/config/manifest.js +3 -0
  17. data/test/dummy/app/controllers/application_controller.rb +4 -4
  18. data/test/dummy/config.ru +1 -1
  19. data/test/dummy/config/application.rb +3 -4
  20. data/test/dummy/config/boot.rb +4 -4
  21. data/test/dummy/config/environment.rb +1 -1
  22. data/test/dummy/config/environments/development.rb +1 -1
  23. data/test/dummy/config/environments/production.rb +2 -2
  24. data/test/dummy/config/environments/test.rb +1 -1
  25. data/test/dummy/config/initializers/secret_token.rb +1 -1
  26. data/test/dummy/config/initializers/session_store.rb +1 -1
  27. data/test/dummy/config/routes.rb +3 -3
  28. data/test/dummy/log/test.log +2981 -0
  29. data/test/dummy/script/rails +3 -3
  30. data/test/dummy/tmp/Gemfile +2 -2
  31. data/test/dummy/tmp/app/controllers/application_controller.rb +17 -16
  32. data/test/dummy/tmp/config/initializers/authentication_domain.rb +1 -1
  33. data/test/dummy/tmp/config/routes.rb +2 -2
  34. data/test/dummy/tmp/db/migrate/create_identities.rb +1 -1
  35. data/test/generators/authentication_email_generator_test.rb +64 -66
  36. data/test/generators/authentication_omniauth_generator_test.rb +46 -46
  37. data/test/support/generators_test_helper.rb +4 -4
  38. data/test/test_helper.rb +2 -24
  39. metadata +39 -54
  40. data/test/dummy/db/development.sqlite3 +0 -0
  41. data/test/dummy/db/test.sqlite3 +0 -0
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
3
 
4
- APP_PATH = File.expand_path('../../config/application', __FILE__)
5
- require File.expand_path('../../config/boot', __FILE__)
6
- require 'rails/commands'
4
+ APP_PATH = File.expand_path("../../config/application", __FILE__)
5
+ require File.expand_path("../../config/boot", __FILE__)
6
+ require "rails/commands"
@@ -1,3 +1,3 @@
1
1
 
2
- gem "warden", "~> 1.2.0"
3
- gem "omniauth"
2
+ gem 'warden', '~> 1.2.0'
3
+ gem 'omniauth'
@@ -1,27 +1,28 @@
1
1
  class ApplicationController < ActionController::Base
2
2
  protect_from_forgery with: :exception
3
3
 
4
- helper_method :current_identity, :identity_signed_in?, :warden_message
4
+ helper_method :current_identity, :identity_signed_in?, :warden_message
5
5
 
6
6
  protected
7
- def current_identity
8
- warden.user(scope: :identity)
9
- end
10
7
 
11
- def identity_signed_in?
12
- warden.authenticate?(scope: :identity)
13
- end
8
+ def current_identity
9
+ warden.user(scope: :identity)
10
+ end
11
+
12
+ def identity_signed_in?
13
+ warden.authenticate?(scope: :identity)
14
+ end
14
15
 
15
- def authenticate!
16
- redirect_to root_path, notice: t('.not_logged') unless identity_signed_in?
17
- end
16
+ def authenticate!
17
+ redirect_to root_path, notice: t('.not_logged') unless identity_signed_in?
18
+ end
18
19
 
19
- def warden_message
20
- warden.message
21
- end
20
+ def warden_message
21
+ warden.message
22
+ end
22
23
 
23
- def warden
24
- request.env['warden']
25
- end
24
+ def warden
25
+ request.env['warden']
26
+ end
26
27
 
27
28
  end
@@ -1 +1 @@
1
- Rails.application.config.authentication_domain = ''
1
+ Rails.application.config.authentication_domain = ""
@@ -1,4 +1,4 @@
1
1
  Dummy::Application.routes.draw do
2
- delete '/sessions/destroy' => 'sessions#destroy', as: :log_out
3
- get 'auth/:provider/callback' => 'sessions#create', as: :log_in
2
+ delete '/sessions/destroy', to: 'sessions#destroy', as: :log_out
3
+ get 'auth/:provider/callback', to: 'sessions#create', as: :log_in
4
4
  end
@@ -1,4 +1,4 @@
1
- class CreateIdentities < ActiveRecord::Migration
1
+ class CreateIdentities < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  create_table :identities do |t|
4
4
  t.string :provider
@@ -1,10 +1,10 @@
1
- require 'test_helper'
2
- require 'generators/authentication/email/email_generator'
1
+ require "test_helper"
2
+ require "generators/authentication/email/email_generator"
3
3
 
4
- describe Authentication::Generators::EmailGenerator do
4
+ class Authentication::Generators::EmailGeneratorTest < Rails::Generators::TestCase
5
5
  include GeneratorsTestHelper
6
6
 
7
- before do
7
+ setup do
8
8
  copy_routes
9
9
  copy_locales
10
10
  copy_gemfile
@@ -12,72 +12,72 @@ describe Authentication::Generators::EmailGenerator do
12
12
  make_migrations_dir
13
13
  end
14
14
 
15
- it 'copies controllers templates for user signup and session' do
15
+ test "it copies controllers templates for user signup and session" do
16
16
  run_generator
17
17
 
18
- assert_file 'app/controllers/identities_controller.rb' do |m|
19
- assert_match 'IdentitiesController', m
20
- assert_match 'def new', m
21
- assert_match 'def create', m
18
+ assert_file "app/controllers/identities_controller.rb" do |m|
19
+ assert_match "IdentitiesController", m
20
+ assert_match "def new", m
21
+ assert_match "def create", m
22
22
  end
23
23
 
24
- assert_file 'app/controllers/sessions_controller.rb' do |m|
25
- assert_match 'SessionsController', m
26
- assert_match 'def new', m
27
- assert_match 'def create', m
28
- assert_match 'def destroy', m
24
+ assert_file "app/controllers/sessions_controller.rb" do |m|
25
+ assert_match "SessionsController", m
26
+ assert_match "def new", m
27
+ assert_match "def create", m
28
+ assert_match "def destroy", m
29
29
  end
30
30
  end
31
31
 
32
- it 'copies user_controller template for user class' do
33
- run_generator ['user']
32
+ test "it copies user_controller template for user class" do
33
+ run_generator ["user"]
34
34
 
35
- assert_file 'app/controllers/users_controller.rb' do |m|
36
- assert_match 'UsersController', m
37
- assert_match 'def new', m
38
- assert_match 'def create', m
39
- assert_match '@user = User.new', m
35
+ assert_file "app/controllers/users_controller.rb" do |m|
36
+ assert_match "UsersController", m
37
+ assert_match "def new", m
38
+ assert_match "def create", m
39
+ assert_match "@user = User.new", m
40
40
  end
41
41
  end
42
42
 
43
- it 'copies erb templates' do
43
+ test "it copies erb templates" do
44
44
  run_generator
45
45
 
46
- assert_file 'app/views/identities/new.html.erb' do |m|
47
- assert_match 'form_for @identity, url: identity_path', m
46
+ assert_file "app/views/identities/new.html.erb" do |m|
47
+ assert_match "form_for @identity, url: identity_path", m
48
48
  end
49
49
 
50
- assert_file 'app/views/sessions/new.html.erb' do |m|
51
- assert_match 'form_for @identity, url: sessions_path', m
50
+ assert_file "app/views/sessions/new.html.erb" do |m|
51
+ assert_match "form_for @identity, url: sessions_path", m
52
52
  end
53
53
  end
54
54
 
55
- it 'copies haml templates' do
56
- run_generator ['--haml']
55
+ test "it copies haml templates" do
56
+ run_generator ["--haml"]
57
57
 
58
- assert_file 'app/views/identities/new.html.haml' do |m|
59
- assert_match 'form_for @identity, url: identity_path', m
58
+ assert_file "app/views/identities/new.html.haml" do |m|
59
+ assert_match "form_for @identity, url: identity_path", m
60
60
  end
61
61
 
62
- assert_file 'app/views/sessions/new.html.haml' do |m|
63
- assert_match 'form_for @identity, url: sessions_path', m
62
+ assert_file "app/views/sessions/new.html.haml" do |m|
63
+ assert_match "form_for @identity, url: sessions_path", m
64
64
  end
65
65
  end
66
66
 
67
- it 'add routes' do
67
+ test "it add routes" do
68
68
  run_generator
69
69
 
70
- assert_file 'config/routes.rb' do |m|
71
- assert_match "get 'sign_up' => 'identities#new'", m
72
- assert_match "get 'log_in' => 'sessions#new'", m
73
- assert_match "delete 'log_out' => 'sessions#destroy'", m
70
+ assert_file "config/routes.rb" do |m|
71
+ assert_match "get 'sign_up', to: 'identities#new', as: :sign_up", m
72
+ assert_match "get 'log_in', to: 'sessions#new', as: :log_in", m
73
+ assert_match "delete 'log_out', to: 'sessions#destroy', as: :log_out", m
74
74
 
75
75
  assert_match "resource :identity, only: [:create, :new]", m
76
76
  assert_match "resource :sessions, only: [:create, :new]", m
77
77
  end
78
78
  end
79
79
 
80
- it 'generate migration' do
80
+ test "it generate migration" do
81
81
  Authentication::Generators::EmailGenerator.class_eval do
82
82
  def migration_name
83
83
  "create_#{resource_pluralize}.rb"
@@ -86,56 +86,54 @@ describe Authentication::Generators::EmailGenerator do
86
86
 
87
87
  run_generator
88
88
 
89
- assert_file 'db/migrate/create_identities.rb' do |m|
90
- assert_match 'create_table :identities', m
91
- assert_match 't.string :email', m
92
- assert_match 't.string :password_hash', m
93
- assert_match 't.string :password_digest', m
89
+ assert_file "db/migrate/create_identities.rb" do |m|
90
+ assert_match "create_table :identities", m
91
+ assert_match "t.string :email", m
92
+ assert_match "t.string :password_digest", m
94
93
  end
95
94
 
96
- assert_file 'app/models/identity.rb' do |m|
97
- assert_match 'class Identity < ActiveRecord::Base', m
98
- assert_match 'has_secure_password validations: true', m
95
+ assert_file "app/models/identity.rb" do |m|
96
+ assert_match "class Identity < ActiveRecord::Base", m
97
+ assert_match "has_secure_password validations: true", m
99
98
  end
100
99
  end
101
100
 
102
- it 'add helper methods to application controller' do
101
+ test "it add helper methods to application controller" do
103
102
  run_generator
104
103
 
105
- assert_file 'app/controllers/application_controller.rb' do |m|
106
- assert_match 'helper_method :current_identity, :identity_signed_in?', m
107
- assert_match 'def current_identity', m
108
- assert_match 'def identity_signed_in?', m
109
- assert_match 'def authenticate!', m
104
+ assert_file "app/controllers/application_controller.rb" do |m|
105
+ assert_match "helper_method :current_identity, :identity_signed_in?", m
106
+ assert_match "def current_identity", m
107
+ assert_match "def identity_signed_in?", m
108
+ assert_match "def authenticate!", m
110
109
  end
111
110
  end
112
111
 
113
- it 'add warden gem to Gemfile' do
112
+ test "it add warden gem to Gemfile" do
114
113
  run_generator
115
114
 
116
- assert_file 'Gemfile' do |m|
117
- assert_match "gem \"warden\", \"~> 1.2.0\"", m
118
- assert_match "gem \"bcrypt-ruby\"", m
115
+ assert_file "Gemfile" do |m|
116
+ assert_match %(gem 'warden', '~> 1.2.0'), m
117
+ assert_match %(gem 'bcrypt'), m
119
118
  end
120
119
  end
121
120
 
122
- it 'copy warden configuration' do
121
+ test "it copy warden configuration" do
123
122
  run_generator
124
123
 
125
- assert_file 'config/initializers/warden.rb' do |m|
126
- assert_match 'manager.default_strategies :database_authentication', m
127
- assert_match 'Warden::Manager.serialize_into_session(:identity)', m
128
- assert_match 'Warden::Manager.serialize_from_session(:identity)', m
124
+ assert_file "config/initializers/warden.rb" do |m|
125
+ assert_match "manager.default_strategies :database_authentication", m
126
+ assert_match "Warden::Manager.serialize_into_session(:identity)", m
127
+ assert_match "Warden::Manager.serialize_from_session(:identity)", m
129
128
  end
130
129
  end
131
130
 
132
- it 'copy warden strategies' do
131
+ test "it copy warden strategies" do
133
132
  run_generator
134
133
 
135
- assert_file 'lib/strategies/database_authentication.rb' do |m|
136
- assert_match 'def valid?', m
137
- assert_match 'authenticate!', m
134
+ assert_file "lib/strategies/database_authentication.rb" do |m|
135
+ assert_match "def valid?", m
136
+ assert_match "authenticate!", m
138
137
  end
139
138
  end
140
139
  end
141
-
@@ -1,10 +1,10 @@
1
- require 'test_helper'
2
- require 'generators/authentication/omniauth/omniauth_generator'
1
+ require "test_helper"
2
+ require "generators/authentication/omniauth/omniauth_generator"
3
3
 
4
- describe Authentication::Generators::OmniauthGenerator do
4
+ class Authentication::Generators::OmniauthGeneratorTest < Rails::Generators::TestCase
5
5
  include GeneratorsTestHelper
6
6
 
7
- before do
7
+ setup do
8
8
  copy_routes
9
9
  copy_locales
10
10
  copy_gemfile
@@ -12,26 +12,26 @@ describe Authentication::Generators::OmniauthGenerator do
12
12
  make_migrations_dir
13
13
  end
14
14
 
15
- it 'copies controllers templates for session' do
15
+ test "it copies controllers templates for session" do
16
16
  run_generator
17
17
 
18
- assert_file 'app/controllers/sessions_controller.rb' do |m|
19
- assert_match 'SessionsController', m
20
- assert_match 'def create', m
21
- assert_match 'def destroy', m
18
+ assert_file "app/controllers/sessions_controller.rb" do |m|
19
+ assert_match "SessionsController", m
20
+ assert_match "def create", m
21
+ assert_match "def destroy", m
22
22
  end
23
23
  end
24
24
 
25
- it 'add routes' do
25
+ test "it add routes" do
26
26
  run_generator
27
27
 
28
- assert_file 'config/routes.rb' do |m|
29
- assert_match "get 'auth/:provider/callback' => 'sessions#create'", m
30
- assert_match "delete '/sessions/destroy' => 'sessions#destroy'", m
28
+ assert_file "config/routes.rb" do |m|
29
+ assert_match "get 'auth/:provider/callback', to: 'sessions#create', as: :log_in", m
30
+ assert_match "delete '/sessions/destroy', to: 'sessions#destroy', as: :log_out", m
31
31
  end
32
32
  end
33
33
 
34
- it 'generate migration' do
34
+ test "it generate migration" do
35
35
  Authentication::Generators::OmniauthGenerator.class_eval do
36
36
  def migration_name
37
37
  "create_#{resource_pluralize}.rb"
@@ -40,68 +40,68 @@ describe Authentication::Generators::OmniauthGenerator do
40
40
 
41
41
  run_generator
42
42
 
43
- assert_file 'db/migrate/create_identities.rb' do |m|
44
- assert_match 'create_table :identities', m
45
- assert_match 't.string :provider', m
46
- assert_match 't.string :uid', m
47
- assert_match 't.string :name', m
48
- assert_match 't.string :email', m
43
+ assert_file "db/migrate/create_identities.rb" do |m|
44
+ assert_match "create_table :identities", m
45
+ assert_match "t.string :provider", m
46
+ assert_match "t.string :uid", m
47
+ assert_match "t.string :name", m
48
+ assert_match "t.string :email", m
49
49
  end
50
50
 
51
- assert_file 'app/models/identity.rb' do |m|
52
- assert_match 'class Identity < ActiveRecord::Base', m
53
- assert_match 'def find_identity(uid, provider)', m
51
+ assert_file "app/models/identity.rb" do |m|
52
+ assert_match "class Identity < ActiveRecord::Base", m
53
+ assert_match "def find_identity(uid, provider)", m
54
54
  end
55
55
  end
56
56
 
57
- it 'add helper methods to application controller' do
57
+ test "it add helper methods to application controller" do
58
58
  run_generator
59
59
 
60
- assert_file 'app/controllers/application_controller.rb' do |m|
61
- assert_match 'helper_method :current_identity, :identity_signed_in?', m
62
- assert_match 'def current_identity', m
63
- assert_match 'def identity_signed_in?', m
64
- assert_match 'def authenticate!', m
60
+ assert_file "app/controllers/application_controller.rb" do |m|
61
+ assert_match "helper_method :current_identity, :identity_signed_in?", m
62
+ assert_match "def current_identity", m
63
+ assert_match "def identity_signed_in?", m
64
+ assert_match "def authenticate!", m
65
65
  end
66
66
  end
67
67
 
68
- it 'add warden gem to Gemfile' do
68
+ test "it add warden gem to Gemfile" do
69
69
  run_generator
70
70
 
71
- assert_file 'Gemfile' do |m|
72
- assert_match "gem \"warden\", \"~> 1.2.0\"", m
73
- assert_match "gem \"omniauth\"", m
71
+ assert_file "Gemfile" do |m|
72
+ assert_match %(gem 'warden', '~> 1.2.0'), m
73
+ assert_match %(gem 'omniauth'), m
74
74
  end
75
75
  end
76
76
 
77
- it 'copy warden configuration' do
77
+ test "it copy warden configuration" do
78
78
  run_generator
79
79
 
80
- assert_file 'config/initializers/warden.rb' do |m|
81
- assert_match 'manager.default_strategies :oauth_authentication', m
82
- assert_match 'Warden::Manager.serialize_into_session(:identity)', m
83
- assert_match 'Warden::Manager.serialize_from_session(:identity)', m
80
+ assert_file "config/initializers/warden.rb" do |m|
81
+ assert_match "manager.default_strategies :oauth_authentication", m
82
+ assert_match "Warden::Manager.serialize_into_session(:identity)", m
83
+ assert_match "Warden::Manager.serialize_from_session(:identity)", m
84
84
  end
85
85
  end
86
86
 
87
- it 'copy domain authentication configuration' do
87
+ test "it copy domain authentication configuration" do
88
88
  run_generator
89
89
 
90
- assert_file 'config/initializers/authentication_domain.rb'
90
+ assert_file "config/initializers/authentication_domain.rb"
91
91
  end
92
92
 
93
- it 'copy omniauth configuration' do
93
+ test "it copy omniauth configuration" do
94
94
  run_generator
95
95
 
96
- assert_file 'config/initializers/omniauth.rb'
96
+ assert_file "config/initializers/omniauth.rb"
97
97
  end
98
98
 
99
- it 'copy warden strategies' do
99
+ test "it copy warden strategies" do
100
100
  run_generator
101
101
 
102
- assert_file 'lib/strategies/oauth_authentication.rb' do |m|
103
- assert_match 'def valid?', m
104
- assert_match 'authenticate!', m
102
+ assert_file "lib/strategies/oauth_authentication.rb" do |m|
103
+ assert_match "def valid?", m
104
+ assert_match "authenticate!", m
105
105
  end
106
106
  end
107
107
  end
@@ -5,7 +5,7 @@ module GeneratorsTestHelper
5
5
  setup :prepare_destination
6
6
 
7
7
  begin
8
- base.tests Rails::Generators.const_get(base.name.sub(/Test$/, ''))
8
+ base.tests Rails::Generators.const_get(base.name.sub(/Test$/, ""))
9
9
  rescue
10
10
  end
11
11
  end
@@ -26,14 +26,14 @@ module GeneratorsTestHelper
26
26
 
27
27
  def copy_application_controller
28
28
  controller = File.expand_path("../../fixtures/application_controller.rb", __FILE__)
29
- destination = File.join(destination_root, 'app', 'controllers')
29
+ destination = File.join(destination_root, "app", "controllers")
30
30
 
31
31
  copy_file controller, destination
32
32
  end
33
33
 
34
34
  def copy_locales
35
35
  controller = File.expand_path("../../fixtures/en.yml", __FILE__)
36
- destination = File.join(destination_root, 'config', 'locales')
36
+ destination = File.join(destination_root, "config", "locales")
37
37
 
38
38
  copy_file controller, destination
39
39
  end
@@ -44,7 +44,7 @@ module GeneratorsTestHelper
44
44
  end
45
45
 
46
46
  def make_migrations_dir
47
- destination = File.join(destination_root, 'db', 'migrate')
47
+ destination = File.join(destination_root, "db", "migrate")
48
48
 
49
49
  FileUtils.mkdir_p(destination)
50
50
  end