mac_generators 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Rakefile +12 -16
- data/lib/generators/authentication/email/email_generator.rb +62 -63
- data/lib/generators/authentication/email/templates/create_identities.rb +1 -2
- data/lib/generators/authentication/email/templates/database_authentication.rb +2 -0
- data/lib/generators/authentication/email/templates/identities_controller.rb +4 -2
- data/lib/generators/authentication/email/templates/identity.rb +2 -0
- data/lib/generators/authentication/email/templates/sessions_controller.rb +2 -0
- data/lib/generators/authentication/email/templates/warden.rb +3 -1
- data/lib/generators/authentication/omniauth/omniauth_generator.rb +69 -68
- data/lib/generators/authentication/omniauth/templates/authentication_domain.rb +1 -1
- data/lib/generators/authentication/omniauth/templates/create_identities.rb +1 -1
- data/lib/generators/bootstrap/bootstrap_generator.rb +13 -13
- data/lib/mac_generators/version.rb +1 -1
- data/test/dummy/Rakefile +1 -1
- data/test/dummy/app/assets/config/manifest.js +3 -0
- data/test/dummy/app/controllers/application_controller.rb +4 -4
- data/test/dummy/config.ru +1 -1
- data/test/dummy/config/application.rb +3 -4
- data/test/dummy/config/boot.rb +4 -4
- data/test/dummy/config/environment.rb +1 -1
- data/test/dummy/config/environments/development.rb +1 -1
- data/test/dummy/config/environments/production.rb +2 -2
- data/test/dummy/config/environments/test.rb +1 -1
- data/test/dummy/config/initializers/secret_token.rb +1 -1
- data/test/dummy/config/initializers/session_store.rb +1 -1
- data/test/dummy/config/routes.rb +3 -3
- data/test/dummy/log/test.log +2981 -0
- data/test/dummy/script/rails +3 -3
- data/test/dummy/tmp/Gemfile +2 -2
- data/test/dummy/tmp/app/controllers/application_controller.rb +17 -16
- data/test/dummy/tmp/config/initializers/authentication_domain.rb +1 -1
- data/test/dummy/tmp/config/routes.rb +2 -2
- data/test/dummy/tmp/db/migrate/create_identities.rb +1 -1
- data/test/generators/authentication_email_generator_test.rb +64 -66
- data/test/generators/authentication_omniauth_generator_test.rb +46 -46
- data/test/support/generators_test_helper.rb +4 -4
- data/test/test_helper.rb +2 -24
- metadata +39 -54
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
data/test/dummy/script/rails
CHANGED
@@ -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(
|
5
|
-
require File.expand_path(
|
6
|
-
require
|
4
|
+
APP_PATH = File.expand_path("../../config/application", __FILE__)
|
5
|
+
require File.expand_path("../../config/boot", __FILE__)
|
6
|
+
require "rails/commands"
|
data/test/dummy/tmp/Gemfile
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
|
2
|
-
gem
|
3
|
-
gem
|
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
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def authenticate!
|
17
|
+
redirect_to root_path, notice: t('.not_logged') unless identity_signed_in?
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def warden_message
|
21
|
+
warden.message
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
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'
|
3
|
-
get 'auth/:provider/callback'
|
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,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "test_helper"
|
2
|
+
require "generators/authentication/email/email_generator"
|
3
3
|
|
4
|
-
|
4
|
+
class Authentication::Generators::EmailGeneratorTest < Rails::Generators::TestCase
|
5
5
|
include GeneratorsTestHelper
|
6
6
|
|
7
|
-
|
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
|
15
|
+
test "it copies controllers templates for user signup and session" do
|
16
16
|
run_generator
|
17
17
|
|
18
|
-
assert_file
|
19
|
-
assert_match
|
20
|
-
assert_match
|
21
|
-
assert_match
|
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
|
25
|
-
assert_match
|
26
|
-
assert_match
|
27
|
-
assert_match
|
28
|
-
assert_match
|
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
|
33
|
-
run_generator [
|
32
|
+
test "it copies user_controller template for user class" do
|
33
|
+
run_generator ["user"]
|
34
34
|
|
35
|
-
assert_file
|
36
|
-
assert_match
|
37
|
-
assert_match
|
38
|
-
assert_match
|
39
|
-
assert_match
|
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
|
43
|
+
test "it copies erb templates" do
|
44
44
|
run_generator
|
45
45
|
|
46
|
-
assert_file
|
47
|
-
assert_match
|
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
|
51
|
-
assert_match
|
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
|
56
|
-
run_generator [
|
55
|
+
test "it copies haml templates" do
|
56
|
+
run_generator ["--haml"]
|
57
57
|
|
58
|
-
assert_file
|
59
|
-
assert_match
|
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
|
63
|
-
assert_match
|
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
|
67
|
+
test "it add routes" do
|
68
68
|
run_generator
|
69
69
|
|
70
|
-
assert_file
|
71
|
-
assert_match "get 'sign_up'
|
72
|
-
assert_match "get 'log_in'
|
73
|
-
assert_match "delete 'log_out'
|
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
|
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
|
90
|
-
assert_match
|
91
|
-
assert_match
|
92
|
-
assert_match
|
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
|
97
|
-
assert_match
|
98
|
-
assert_match
|
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
|
101
|
+
test "it add helper methods to application controller" do
|
103
102
|
run_generator
|
104
103
|
|
105
|
-
assert_file
|
106
|
-
assert_match
|
107
|
-
assert_match
|
108
|
-
assert_match
|
109
|
-
assert_match
|
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
|
112
|
+
test "it add warden gem to Gemfile" do
|
114
113
|
run_generator
|
115
114
|
|
116
|
-
assert_file
|
117
|
-
assert_match
|
118
|
-
assert_match
|
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
|
121
|
+
test "it copy warden configuration" do
|
123
122
|
run_generator
|
124
123
|
|
125
|
-
assert_file
|
126
|
-
assert_match
|
127
|
-
assert_match
|
128
|
-
assert_match
|
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
|
131
|
+
test "it copy warden strategies" do
|
133
132
|
run_generator
|
134
133
|
|
135
|
-
assert_file
|
136
|
-
assert_match
|
137
|
-
assert_match
|
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
|
2
|
-
require
|
1
|
+
require "test_helper"
|
2
|
+
require "generators/authentication/omniauth/omniauth_generator"
|
3
3
|
|
4
|
-
|
4
|
+
class Authentication::Generators::OmniauthGeneratorTest < Rails::Generators::TestCase
|
5
5
|
include GeneratorsTestHelper
|
6
6
|
|
7
|
-
|
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
|
15
|
+
test "it copies controllers templates for session" do
|
16
16
|
run_generator
|
17
17
|
|
18
|
-
assert_file
|
19
|
-
assert_match
|
20
|
-
assert_match
|
21
|
-
assert_match
|
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
|
25
|
+
test "it add routes" do
|
26
26
|
run_generator
|
27
27
|
|
28
|
-
assert_file
|
29
|
-
assert_match "get 'auth/:provider/callback'
|
30
|
-
assert_match "delete '/sessions/destroy'
|
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
|
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
|
44
|
-
assert_match
|
45
|
-
assert_match
|
46
|
-
assert_match
|
47
|
-
assert_match
|
48
|
-
assert_match
|
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
|
52
|
-
assert_match
|
53
|
-
assert_match
|
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
|
57
|
+
test "it add helper methods to application controller" do
|
58
58
|
run_generator
|
59
59
|
|
60
|
-
assert_file
|
61
|
-
assert_match
|
62
|
-
assert_match
|
63
|
-
assert_match
|
64
|
-
assert_match
|
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
|
68
|
+
test "it add warden gem to Gemfile" do
|
69
69
|
run_generator
|
70
70
|
|
71
|
-
assert_file
|
72
|
-
assert_match
|
73
|
-
assert_match
|
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
|
77
|
+
test "it copy warden configuration" do
|
78
78
|
run_generator
|
79
79
|
|
80
|
-
assert_file
|
81
|
-
assert_match
|
82
|
-
assert_match
|
83
|
-
assert_match
|
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
|
87
|
+
test "it copy domain authentication configuration" do
|
88
88
|
run_generator
|
89
89
|
|
90
|
-
assert_file
|
90
|
+
assert_file "config/initializers/authentication_domain.rb"
|
91
91
|
end
|
92
92
|
|
93
|
-
it
|
93
|
+
test "it copy omniauth configuration" do
|
94
94
|
run_generator
|
95
95
|
|
96
|
-
assert_file
|
96
|
+
assert_file "config/initializers/omniauth.rb"
|
97
97
|
end
|
98
98
|
|
99
|
-
it
|
99
|
+
test "it copy warden strategies" do
|
100
100
|
run_generator
|
101
101
|
|
102
|
-
assert_file
|
103
|
-
assert_match
|
104
|
-
assert_match
|
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,
|
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,
|
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,
|
47
|
+
destination = File.join(destination_root, "db", "migrate")
|
48
48
|
|
49
49
|
FileUtils.mkdir_p(destination)
|
50
50
|
end
|