nifty-generators 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +17 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +110 -0
- data/Rakefile +1 -9
- data/features/nifty_authentication.feature +27 -9
- data/features/nifty_layout.feature +1 -0
- data/features/nifty_scaffold.feature +6 -3
- data/features/step_definitions/common_steps.rb +7 -0
- data/features/support/env.rb +1 -1
- data/features/support/matchers.rb +1 -1
- data/lib/generators/nifty/authentication/authentication_generator.rb +10 -2
- data/lib/generators/nifty/authentication/templates/{authentication.rb → controller_authentication.rb} +4 -3
- data/lib/generators/nifty/authentication/templates/tests/rspec/users_controller.rb +30 -0
- data/lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb +36 -2
- data/lib/generators/nifty/authentication/templates/tests/testunit/users_controller.rb +30 -0
- data/lib/generators/nifty/authentication/templates/user.rb +2 -2
- data/lib/generators/nifty/authentication/templates/users_controller.rb +16 -0
- data/lib/generators/nifty/authentication/templates/views/erb/_form.html.erb +20 -0
- data/lib/generators/nifty/authentication/templates/views/erb/edit.html.erb +3 -0
- data/lib/generators/nifty/authentication/templates/views/erb/signup.html.erb +1 -20
- data/lib/generators/nifty/authentication/templates/views/haml/_form.html.haml +20 -0
- data/lib/generators/nifty/authentication/templates/views/haml/edit.html.haml +3 -0
- data/lib/generators/nifty/authentication/templates/views/haml/signup.html.haml +1 -20
- data/lib/generators/nifty/layout/templates/layout_helper.rb +1 -1
- data/lib/generators/nifty/scaffold/scaffold_generator.rb +6 -2
- data/rails_generators/nifty_authentication/templates/fixtures.yml +4 -4
- metadata +101 -6
data/CHANGELOG
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
0.4.2 (October 15, 2010)
|
2
|
+
|
3
|
+
* adding mocha to Gemfile automatically if it's not there already
|
4
|
+
|
5
|
+
* switching to BCrypt for user password encryption on nifty:authentication - issue #53
|
6
|
+
|
7
|
+
* adding Gemfile, now just run "bunde" and "rake" to get cucumber features running - issue #56
|
8
|
+
|
9
|
+
* renaming Authentication module to ControllerAuthentication to avoid conflicts in nifty:authentication - issue #57
|
10
|
+
|
11
|
+
* automatically use RSpec when there's a spec directory - issue #50
|
12
|
+
|
13
|
+
* escaping page title in layout helper (thanks cbmeeks) - issue #52
|
14
|
+
|
15
|
+
* adding edit profile page to nifty:authentication - closes #54
|
16
|
+
|
17
|
+
|
1
18
|
0.4.1 (September 23rd, 2010)
|
2
19
|
|
3
20
|
* fixing frozen hash error when not passing additional arguments to nifty:scaffold - issue #35
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nifty-generators (0.4.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
abstract (1.0.0)
|
10
|
+
actionmailer (3.0.1)
|
11
|
+
actionpack (= 3.0.1)
|
12
|
+
mail (~> 2.2.5)
|
13
|
+
actionpack (3.0.1)
|
14
|
+
activemodel (= 3.0.1)
|
15
|
+
activesupport (= 3.0.1)
|
16
|
+
builder (~> 2.1.2)
|
17
|
+
erubis (~> 2.6.6)
|
18
|
+
i18n (~> 0.4.1)
|
19
|
+
rack (~> 1.2.1)
|
20
|
+
rack-mount (~> 0.6.12)
|
21
|
+
rack-test (~> 0.5.4)
|
22
|
+
tzinfo (~> 0.3.23)
|
23
|
+
activemodel (3.0.1)
|
24
|
+
activesupport (= 3.0.1)
|
25
|
+
builder (~> 2.1.2)
|
26
|
+
i18n (~> 0.4.1)
|
27
|
+
activerecord (3.0.1)
|
28
|
+
activemodel (= 3.0.1)
|
29
|
+
activesupport (= 3.0.1)
|
30
|
+
arel (~> 1.0.0)
|
31
|
+
tzinfo (~> 0.3.23)
|
32
|
+
activeresource (3.0.1)
|
33
|
+
activemodel (= 3.0.1)
|
34
|
+
activesupport (= 3.0.1)
|
35
|
+
activesupport (3.0.1)
|
36
|
+
arel (1.0.1)
|
37
|
+
activesupport (~> 3.0.0)
|
38
|
+
bcrypt-ruby (2.1.2)
|
39
|
+
builder (2.1.2)
|
40
|
+
cucumber (0.9.2)
|
41
|
+
builder (~> 2.1.2)
|
42
|
+
diff-lcs (~> 1.1.2)
|
43
|
+
gherkin (~> 2.2.5)
|
44
|
+
json (~> 1.4.6)
|
45
|
+
term-ansicolor (~> 1.0.5)
|
46
|
+
diff-lcs (1.1.2)
|
47
|
+
erubis (2.6.6)
|
48
|
+
abstract (>= 1.0.0)
|
49
|
+
gherkin (2.2.9)
|
50
|
+
json (~> 1.4.6)
|
51
|
+
term-ansicolor (~> 1.0.5)
|
52
|
+
i18n (0.4.1)
|
53
|
+
json (1.4.6)
|
54
|
+
mail (2.2.7)
|
55
|
+
activesupport (>= 2.3.6)
|
56
|
+
mime-types
|
57
|
+
treetop (>= 1.4.5)
|
58
|
+
mime-types (1.16)
|
59
|
+
mocha (0.9.8)
|
60
|
+
rake
|
61
|
+
polyglot (0.3.1)
|
62
|
+
rack (1.2.1)
|
63
|
+
rack-mount (0.6.13)
|
64
|
+
rack (>= 1.0.0)
|
65
|
+
rack-test (0.5.6)
|
66
|
+
rack (>= 1.0)
|
67
|
+
rails (3.0.1)
|
68
|
+
actionmailer (= 3.0.1)
|
69
|
+
actionpack (= 3.0.1)
|
70
|
+
activerecord (= 3.0.1)
|
71
|
+
activeresource (= 3.0.1)
|
72
|
+
activesupport (= 3.0.1)
|
73
|
+
bundler (~> 1.0.0)
|
74
|
+
railties (= 3.0.1)
|
75
|
+
railties (3.0.1)
|
76
|
+
actionpack (= 3.0.1)
|
77
|
+
activesupport (= 3.0.1)
|
78
|
+
rake (>= 0.8.4)
|
79
|
+
thor (~> 0.14.0)
|
80
|
+
rake (0.8.7)
|
81
|
+
rspec (2.0.0)
|
82
|
+
rspec-core (= 2.0.0)
|
83
|
+
rspec-expectations (= 2.0.0)
|
84
|
+
rspec-mocks (= 2.0.0)
|
85
|
+
rspec-core (2.0.0)
|
86
|
+
rspec-expectations (2.0.0)
|
87
|
+
diff-lcs (>= 1.1.2)
|
88
|
+
rspec-mocks (2.0.0)
|
89
|
+
rspec-core (= 2.0.0)
|
90
|
+
rspec-expectations (= 2.0.0)
|
91
|
+
rspec-rails (2.0.1)
|
92
|
+
rspec (~> 2.0.0)
|
93
|
+
sqlite3-ruby (1.3.1)
|
94
|
+
term-ansicolor (1.0.5)
|
95
|
+
thor (0.14.3)
|
96
|
+
treetop (1.4.8)
|
97
|
+
polyglot (>= 0.3.1)
|
98
|
+
tzinfo (0.3.23)
|
99
|
+
|
100
|
+
PLATFORMS
|
101
|
+
ruby
|
102
|
+
|
103
|
+
DEPENDENCIES
|
104
|
+
bcrypt-ruby (~> 2.1.2)
|
105
|
+
cucumber (~> 0.9.2)
|
106
|
+
mocha (~> 0.9.8)
|
107
|
+
nifty-generators!
|
108
|
+
rails (~> 3.0.0)
|
109
|
+
rspec-rails (~> 2.0.1)
|
110
|
+
sqlite3-ruby (~> 1.3.1)
|
data/Rakefile
CHANGED
@@ -1,18 +1,10 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
|
-
require 'rake/testtask'
|
4
3
|
require 'cucumber'
|
5
4
|
require 'cucumber/rake/task'
|
6
5
|
|
7
|
-
desc "Run tests."
|
8
|
-
Rake::TestTask.new do |t|
|
9
|
-
t.libs << "test"
|
10
|
-
t.test_files = FileList['test/test*.rb']
|
11
|
-
t.verbose = true
|
12
|
-
end
|
13
|
-
|
14
6
|
Cucumber::Rake::Task.new(:features) do |t|
|
15
7
|
t.cucumber_opts = "features --format progress"
|
16
8
|
end
|
17
9
|
|
18
|
-
task :default =>
|
10
|
+
task :default => :features
|
@@ -11,10 +11,11 @@ Feature: Nifty Authentication Generator
|
|
11
11
|
| app/controllers/users_controller.rb |
|
12
12
|
| app/helpers/users_helper.rb |
|
13
13
|
| app/views/users/new.html.erb |
|
14
|
+
| app/views/users/edit.html.erb |
|
14
15
|
| app/controllers/sessions_controller.rb |
|
15
16
|
| app/helpers/sessions_helper.rb |
|
16
17
|
| app/views/sessions/new.html.erb |
|
17
|
-
| lib/
|
18
|
+
| lib/controller_authentication.rb |
|
18
19
|
| test/fixtures/users.yml |
|
19
20
|
| test/unit/user_test.rb |
|
20
21
|
| test/functional/users_controller_test.rb |
|
@@ -26,10 +27,12 @@ Feature: Nifty Authentication Generator
|
|
26
27
|
| match 'login' => 'sessions#new', :as => :login |
|
27
28
|
| match 'logout' => 'sessions#destroy', :as => :logout |
|
28
29
|
| match 'signup' => 'users#new', :as => :signup |
|
29
|
-
|
30
|
+
| match 'user/edit' => 'users#edit', :as => :edit_user |
|
31
|
+
And I should see "include ControllerAuthentication" in file "app/controllers/application_controller.rb"
|
32
|
+
And I should see "gem "mocha", :group => :test" in file "Gemfile"
|
33
|
+
And I should see "gem "bcrypt-ruby", :require => "bcrypt"" in file "Gemfile"
|
30
34
|
When I run "rails g nifty:layout -f"
|
31
35
|
And I run "rake db:migrate"
|
32
|
-
And I add "gem 'mocha', :group => :test" to file "Gemfile"
|
33
36
|
Then I should successfully run "rake test"
|
34
37
|
|
35
38
|
Scenario: Generate named authentication
|
@@ -40,6 +43,7 @@ Feature: Nifty Authentication Generator
|
|
40
43
|
| app/controllers/accounts_controller.rb |
|
41
44
|
| app/helpers/accounts_helper.rb |
|
42
45
|
| app/views/accounts/new.html.erb |
|
46
|
+
| app/views/accounts/edit.html.erb |
|
43
47
|
| app/controllers/current_sessions_controller.rb |
|
44
48
|
| app/helpers/current_sessions_helper.rb |
|
45
49
|
| app/views/current_sessions/new.html.erb |
|
@@ -48,12 +52,26 @@ Feature: Nifty Authentication Generator
|
|
48
52
|
| test/functional/accounts_controller_test.rb |
|
49
53
|
| test/functional/current_sessions_controller_test.rb |
|
50
54
|
And I should see the following in file "config/routes.rb"
|
51
|
-
| resources :current_sessions
|
52
|
-
| resources :accounts
|
53
|
-
| match 'login' => 'current_sessions#new', :as => :login
|
54
|
-
| match 'logout' => 'current_sessions#destroy', :as => :logout
|
55
|
-
| match 'signup' => 'accounts#new', :as => :signup
|
55
|
+
| resources :current_sessions |
|
56
|
+
| resources :accounts |
|
57
|
+
| match 'login' => 'current_sessions#new', :as => :login |
|
58
|
+
| match 'logout' => 'current_sessions#destroy', :as => :logout |
|
59
|
+
| match 'signup' => 'accounts#new', :as => :signup |
|
60
|
+
| match 'account/edit' => 'accounts#edit', :as => :edit_account |
|
56
61
|
When I run "rails g nifty:layout -f"
|
57
62
|
And I run "rake db:migrate"
|
58
|
-
And I add "gem 'mocha', :group => :test" to file "Gemfile"
|
59
63
|
Then I should successfully run "rake test"
|
64
|
+
|
65
|
+
Scenario: Generate named authentication with rspec
|
66
|
+
Given a new Rails app
|
67
|
+
When I run "rails g nifty:authentication Account CurrentSession --rspec"
|
68
|
+
Then I should see the following files
|
69
|
+
| spec/models/account_spec.rb |
|
70
|
+
| spec/controllers/accounts_controller_spec.rb |
|
71
|
+
| spec/controllers/current_sessions_controller_spec.rb |
|
72
|
+
When I run "rails g nifty:layout -f"
|
73
|
+
And I run "rake db:migrate"
|
74
|
+
And I add "gem 'rspec-rails', '>= 2.0.1'" to file "Gemfile"
|
75
|
+
And I run "rails g rspec:install"
|
76
|
+
And I replace "mock_with :rspec" with "mock_with :mocha" in file "spec/spec_helper.rb"
|
77
|
+
Then I should successfully run "rake spec"
|
@@ -7,6 +7,7 @@ Feature: Nifty Layout Generator
|
|
7
7
|
Given a new Rails app
|
8
8
|
When I run "rails g nifty:layout -f"
|
9
9
|
Then I should see "stylesheet_link_tag "application"" in file "app/views/layouts/application.html.erb"
|
10
|
+
Then I should see "h(page_title" in file "app/helpers/layout_helper.rb"
|
10
11
|
And I should see file "app/helpers/layout_helper.rb"
|
11
12
|
And I should see file "app/helpers/error_messages_helper.rb"
|
12
13
|
And I should see file "public/stylesheets/application.css"
|
@@ -16,10 +16,10 @@ Feature: Nifty Scaffold Generator
|
|
16
16
|
| app/views/projects/edit.html.erb |
|
17
17
|
| db/migrate |
|
18
18
|
And I should see "resources :projects" in file "config/routes.rb"
|
19
|
+
And I should see "gem "mocha", :group => :test" in file "Gemfile"
|
19
20
|
When I run "rails g nifty:layout -f"
|
20
21
|
And I run "rake db:migrate"
|
21
22
|
And I should successfully run "rails g nifty:scaffold Project -f"
|
22
|
-
And I add "gem 'mocha', :group => :test" to file "Gemfile"
|
23
23
|
Then I should successfully run "rake test"
|
24
24
|
|
25
25
|
Scenario: Generate scaffold with rspec tests
|
@@ -28,10 +28,13 @@ Feature: Nifty Scaffold Generator
|
|
28
28
|
Then I should see the following files
|
29
29
|
| spec/models/project_spec.rb |
|
30
30
|
| spec/controllers/projects_controller_spec.rb |
|
31
|
-
|
31
|
+
When I run "rails g nifty:scaffold Task project_id:integer"
|
32
|
+
Then I should see the following files
|
33
|
+
| spec/models/task_spec.rb |
|
34
|
+
| spec/controllers/tasks_controller_spec.rb |
|
32
35
|
When I run "rails g nifty:layout -f"
|
33
36
|
And I run "rake db:migrate"
|
34
|
-
And I add "gem 'mocha', :group => :test" to file "Gemfile"
|
35
37
|
And I add "gem 'rspec-rails', '>= 2.0.0.beta.19'" to file "Gemfile"
|
36
38
|
And I run "rails g rspec:install"
|
39
|
+
And I replace "mock_with :rspec" with "mock_with :mocha" in file "spec/spec_helper.rb"
|
37
40
|
Then I should successfully run "rake spec"
|
@@ -8,6 +8,13 @@ When /^I add "([^\"]*)" to file "([^\"]*)"$/ do |content, short_path|
|
|
8
8
|
File.open(path, 'a') { |f| f.write(content + "\n") }
|
9
9
|
end
|
10
10
|
|
11
|
+
When /^I replace "([^\"]*)" with "([^\"]*)" in file "([^\"]*)"$/ do |old_content, new_content, short_path|
|
12
|
+
path = File.join(@current_directory, short_path)
|
13
|
+
File.should exist(path)
|
14
|
+
content = File.read(path).gsub(old_content, new_content)
|
15
|
+
File.open(path, 'w') { |f| f.write(content) }
|
16
|
+
end
|
17
|
+
|
11
18
|
Then /^I should see file "([^\"]*)"$/ do |path|
|
12
19
|
File.should exist(File.join(@current_directory, path))
|
13
20
|
end
|
data/features/support/env.rb
CHANGED
@@ -16,6 +16,11 @@ module Nifty
|
|
16
16
|
class_option :haml, :desc => 'Generate HAML views instead of ERB.', :type => :boolean
|
17
17
|
class_option :authlogic, :desc => 'Use Authlogic for authentication.', :type => :boolean
|
18
18
|
|
19
|
+
def add_gems
|
20
|
+
gem "bcrypt-ruby", :require => "bcrypt" unless File.read(destination_path("Gemfile")).include? "bcrypt"
|
21
|
+
gem "mocha", :group => :test unless File.read(destination_path("Gemfile")).include? "mocha"
|
22
|
+
end
|
23
|
+
|
19
24
|
def create_model_files
|
20
25
|
template 'user.rb', "app/models/#{user_singular_name}.rb"
|
21
26
|
template 'authlogic_session.rb', "app/models/#{user_singular_name}_session.rb" if options.authlogic?
|
@@ -33,11 +38,13 @@ module Nifty
|
|
33
38
|
|
34
39
|
def create_view_files
|
35
40
|
template "views/#{view_language}/signup.html.#{view_language}", "app/views/#{user_plural_name}/new.html.#{view_language}"
|
41
|
+
template "views/#{view_language}/edit.html.#{view_language}", "app/views/#{user_plural_name}/edit.html.#{view_language}"
|
42
|
+
template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{user_plural_name}/_form.html.#{view_language}"
|
36
43
|
template "views/#{view_language}/login.html.#{view_language}", "app/views/#{session_plural_name}/new.html.#{view_language}"
|
37
44
|
end
|
38
45
|
|
39
46
|
def create_lib_files
|
40
|
-
template '
|
47
|
+
template 'controller_authentication.rb', 'lib/controller_authentication.rb'
|
41
48
|
end
|
42
49
|
|
43
50
|
def create_routes
|
@@ -46,6 +53,7 @@ module Nifty
|
|
46
53
|
route "match 'login' => '#{session_plural_name}#new', :as => :login"
|
47
54
|
route "match 'logout' => '#{session_plural_name}#destroy', :as => :logout"
|
48
55
|
route "match 'signup' => '#{user_plural_name}#new', :as => :signup"
|
56
|
+
route "match '#{user_singular_name}/edit' => '#{user_plural_name}#edit', :as => :edit_#{user_singular_name}"
|
49
57
|
end
|
50
58
|
|
51
59
|
def create_migration
|
@@ -54,7 +62,7 @@ module Nifty
|
|
54
62
|
|
55
63
|
def load_and_include_authentication
|
56
64
|
inject_into_class "config/application.rb", "Application", " config.autoload_paths << \"\#{config.root}/lib\""
|
57
|
-
inject_into_class "app/controllers/application_controller.rb", "ApplicationController", " include
|
65
|
+
inject_into_class "app/controllers/application_controller.rb", "ApplicationController", " include ControllerAuthentication\n"
|
58
66
|
end
|
59
67
|
|
60
68
|
def create_test_files
|
@@ -3,7 +3,8 @@
|
|
3
3
|
# common example you might add to your application layout file.
|
4
4
|
#
|
5
5
|
# <%% if logged_in? %>
|
6
|
-
# Welcome <%%= current_<%= user_singular_name %>.username
|
6
|
+
# Welcome <%%= current_<%= user_singular_name %>.username %>.
|
7
|
+
# <%%= link_to "Edit profile", edit_<%= user_singular_name %>_path %> or
|
7
8
|
# <%%= link_to "Log out", logout_path %>
|
8
9
|
# <%% else %>
|
9
10
|
# <%%= link_to "Sign up", signup_path %> or
|
@@ -14,7 +15,7 @@
|
|
14
15
|
# a before filter. For example.
|
15
16
|
#
|
16
17
|
# before_filter :login_required, :except => [:index, :show]
|
17
|
-
module
|
18
|
+
module ControllerAuthentication
|
18
19
|
def self.included(controller)
|
19
20
|
controller.send :helper_method, :current_<%= user_singular_name %>, :logged_in?, :redirect_to_target_or_default
|
20
21
|
end
|
@@ -55,6 +56,6 @@ module Authentication
|
|
55
56
|
private
|
56
57
|
|
57
58
|
def store_target_location
|
58
|
-
session[:return_to] = request.
|
59
|
+
session[:return_to] = request.url
|
59
60
|
end
|
60
61
|
end
|
@@ -23,4 +23,34 @@ describe <%= user_plural_class_name %>Controller do
|
|
23
23
|
session['<%= user_singular_name %>_id'].should == assigns['<%= user_singular_name %>'].id
|
24
24
|
<%- end -%>
|
25
25
|
end
|
26
|
+
|
27
|
+
it "edit action should redirect when not logged in" do
|
28
|
+
get :edit, :id => "ignored"
|
29
|
+
response.should redirect_to(login_url)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "edit action should render edit template" do
|
33
|
+
@controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
|
34
|
+
get :edit, :id => "ignored"
|
35
|
+
response.should render_template(:edit)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "update action should redirect when not logged in" do
|
39
|
+
put :update, :id => "ignored"
|
40
|
+
response.should redirect_to(login_url)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "update action should render edit template when <%= user_singular_name %> is invalid" do
|
44
|
+
@controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
|
45
|
+
<%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
|
46
|
+
put :update, :id => "ignored"
|
47
|
+
response.should render_template(:edit)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "update action should redirect when <%= user_singular_name %> is valid" do
|
51
|
+
@controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
|
52
|
+
<%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
|
53
|
+
put :update, :id => "ignored"
|
54
|
+
response.should redirect_to("/")
|
55
|
+
end
|
26
56
|
end
|
@@ -9,13 +9,13 @@ class <%= user_plural_class_name %>ControllerTest < ActionController::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
context "create action" do
|
12
|
-
should "render new template when
|
12
|
+
should "render new template when <%= user_singular_name %> is invalid" do
|
13
13
|
<%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
|
14
14
|
post :create
|
15
15
|
assert_template 'new'
|
16
16
|
end
|
17
17
|
|
18
|
-
should "redirect when
|
18
|
+
should "redirect when <%= user_singular_name %> is valid" do
|
19
19
|
<%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
|
20
20
|
post :create
|
21
21
|
assert_redirected_to "/"
|
@@ -24,4 +24,38 @@ class <%= user_plural_class_name %>ControllerTest < ActionController::TestCase
|
|
24
24
|
<%- end -%>
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
context "edit action" do
|
29
|
+
should "redirect when not logged in" do
|
30
|
+
get :edit, :id => "ignored"
|
31
|
+
assert_redirected_to login_url
|
32
|
+
end
|
33
|
+
|
34
|
+
should "render edit template" do
|
35
|
+
@controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
|
36
|
+
get :edit, :id => "ignored"
|
37
|
+
assert_template 'edit'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "update action" do
|
42
|
+
should "redirect when not logged in" do
|
43
|
+
put :update, :id => "ignored"
|
44
|
+
assert_redirected_to login_url
|
45
|
+
end
|
46
|
+
|
47
|
+
should "render edit template when <%= user_singular_name %> is invalid" do
|
48
|
+
@controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
|
49
|
+
<%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
|
50
|
+
put :update, :id => "ignored"
|
51
|
+
assert_template 'edit'
|
52
|
+
end
|
53
|
+
|
54
|
+
should "redirect when <%= user_singular_name %> is valid" do
|
55
|
+
@controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
|
56
|
+
<%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
|
57
|
+
put :update, :id => "ignored"
|
58
|
+
assert_redirected_to "/"
|
59
|
+
end
|
60
|
+
end
|
27
61
|
end
|
@@ -20,4 +20,34 @@ class <%= user_plural_class_name %>ControllerTest < ActionController::TestCase
|
|
20
20
|
assert_equal assigns['<%= user_singular_name %>'].id, session['<%= user_singular_name %>_id']
|
21
21
|
<%- end -%>
|
22
22
|
end
|
23
|
+
|
24
|
+
def test_edit_without_user
|
25
|
+
get :edit, :id => "ignored"
|
26
|
+
assert_redirected_to login_url
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_edit
|
30
|
+
@controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
|
31
|
+
get :edit, :id => "ignored"
|
32
|
+
assert_template 'edit'
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_update_without_user
|
36
|
+
put :update, :id => "ignored"
|
37
|
+
assert_redirected_to login_url
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_update_invalid
|
41
|
+
@controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
|
42
|
+
<%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
|
43
|
+
put :update, :id => "ignored"
|
44
|
+
assert_template 'edit'
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_update_valid
|
48
|
+
@controller.stubs(:current_<%= user_singular_name %>).returns(<%= user_class_name %>.first)
|
49
|
+
<%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
|
50
|
+
put :update, :id => "ignored"
|
51
|
+
assert_redirected_to "/"
|
52
|
+
end
|
23
53
|
end
|
@@ -30,13 +30,13 @@ class <%= user_class_name %> < ActiveRecord::Base
|
|
30
30
|
|
31
31
|
def prepare_password
|
32
32
|
unless password.blank?
|
33
|
-
self.password_salt =
|
33
|
+
self.password_salt = BCrypt::Engine.generate_salt
|
34
34
|
self.password_hash = encrypt_password(password)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def encrypt_password(pass)
|
39
|
-
|
39
|
+
BCrypt::Engine.hash_secret(pass, password_salt)
|
40
40
|
end
|
41
41
|
<%- end -%>
|
42
42
|
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
class <%= user_plural_class_name %>Controller < ApplicationController
|
2
|
+
before_filter :login_required, :except => [:new, :create]
|
3
|
+
|
2
4
|
def new
|
3
5
|
@<%= user_singular_name %> = <%= user_class_name %>.new
|
4
6
|
end
|
@@ -15,4 +17,18 @@ class <%= user_plural_class_name %>Controller < ApplicationController
|
|
15
17
|
render :action => 'new'
|
16
18
|
end
|
17
19
|
end
|
20
|
+
|
21
|
+
def edit
|
22
|
+
@<%= user_singular_name %> = current_<%= user_singular_name %>
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
@<%= user_singular_name %> = current_<%= user_singular_name %>
|
27
|
+
if @<%= user_singular_name %>.update_attributes(params[:<%= user_singular_name %>])
|
28
|
+
flash[:notice] = "Your profile has been updated."
|
29
|
+
redirect_to "/"
|
30
|
+
else
|
31
|
+
render :action => 'edit'
|
32
|
+
end
|
33
|
+
end
|
18
34
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<%%= form_for @<%= user_singular_name %> do |f| %>
|
2
|
+
<%%= f.error_messages %>
|
3
|
+
<p>
|
4
|
+
<%%= f.label :username %><br />
|
5
|
+
<%%= f.text_field :username %>
|
6
|
+
</p>
|
7
|
+
<p>
|
8
|
+
<%%= f.label :email, "Email Address" %><br />
|
9
|
+
<%%= f.text_field :email %>
|
10
|
+
</p>
|
11
|
+
<p>
|
12
|
+
<%%= f.label :password %><br />
|
13
|
+
<%%= f.password_field :password %>
|
14
|
+
</p>
|
15
|
+
<p>
|
16
|
+
<%%= f.label :password_confirmation, "Confirm Password" %><br />
|
17
|
+
<%%= f.password_field :password_confirmation %>
|
18
|
+
</p>
|
19
|
+
<p><%%= f.submit (@<%= user_singular_name %>.new_record? ? "Sign up" : "Update") %></p>
|
20
|
+
<%% end %>
|
@@ -2,23 +2,4 @@
|
|
2
2
|
|
3
3
|
<p>Already have an account? <%%= link_to "Log in", login_path %>.</p>
|
4
4
|
|
5
|
-
<%%=
|
6
|
-
<%%= f.error_messages %>
|
7
|
-
<p>
|
8
|
-
<%%= f.label :username %><br />
|
9
|
-
<%%= f.text_field :username %>
|
10
|
-
</p>
|
11
|
-
<p>
|
12
|
-
<%%= f.label :email, "Email Address" %><br />
|
13
|
-
<%%= f.text_field :email %>
|
14
|
-
</p>
|
15
|
-
<p>
|
16
|
-
<%%= f.label :password %><br />
|
17
|
-
<%%= f.password_field :password %>
|
18
|
-
</p>
|
19
|
-
<p>
|
20
|
-
<%%= f.label :password_confirmation, "Confirm Password" %><br />
|
21
|
-
<%%= f.password_field :password_confirmation %>
|
22
|
-
</p>
|
23
|
-
<p><%%= f.submit "Sign up" %></p>
|
24
|
-
<%% end %>
|
5
|
+
<%%= render 'form' %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
- form_for @<%= user_singular_name %> do |f|
|
2
|
+
= f.error_messages
|
3
|
+
%p
|
4
|
+
= f.label :username
|
5
|
+
%br
|
6
|
+
= f.text_field :username
|
7
|
+
%p
|
8
|
+
= f.label :email, "Email Address"
|
9
|
+
%br
|
10
|
+
= f.text_field :email
|
11
|
+
%p
|
12
|
+
= f.label :password
|
13
|
+
%br
|
14
|
+
= f.password_field :password
|
15
|
+
%p
|
16
|
+
= f.label :password_confirmation, "Confirm Password"
|
17
|
+
%br
|
18
|
+
= f.password_field :password_confirmation
|
19
|
+
%p
|
20
|
+
= f.submit (@<%= user_singular_name %>.new_record? ? "Sign up" : "Update")
|
@@ -2,23 +2,4 @@
|
|
2
2
|
|
3
3
|
%p== Already have an account? #{link_to "Log in", login_path}.
|
4
4
|
|
5
|
-
|
6
|
-
= f.error_messages
|
7
|
-
%p
|
8
|
-
= f.label :username
|
9
|
-
%br
|
10
|
-
= f.text_field :username
|
11
|
-
%p
|
12
|
-
= f.label :email, "Email Address"
|
13
|
-
%br
|
14
|
-
= f.text_field :email
|
15
|
-
%p
|
16
|
-
= f.label :password
|
17
|
-
%br
|
18
|
-
= f.password_field :password
|
19
|
-
%p
|
20
|
-
= f.label :password_confirmation, "Confirm Password"
|
21
|
-
%br
|
22
|
-
= f.password_field :password_confirmation
|
23
|
-
%p
|
24
|
-
= f.submit "Sign up"
|
5
|
+
= render 'form'
|
@@ -61,10 +61,14 @@ module Nifty
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
def add_gems
|
65
|
+
gem "mocha", :group => :test unless File.read(destination_path("Gemfile")).include? "mocha"
|
66
|
+
end
|
67
|
+
|
64
68
|
def create_model
|
65
69
|
unless @skip_model
|
66
70
|
template 'model.rb', "app/models/#{singular_name}.rb"
|
67
|
-
if
|
71
|
+
if test_framework == :rspec
|
68
72
|
template "tests/rspec/model.rb", "spec/models/#{singular_name}_spec.rb"
|
69
73
|
template 'fixtures.yml', "spec/fixtures/#{plural_name}.yml"
|
70
74
|
else
|
@@ -98,7 +102,7 @@ module Nifty
|
|
98
102
|
|
99
103
|
route "resources #{plural_name.to_sym.inspect}"
|
100
104
|
|
101
|
-
if
|
105
|
+
if test_framework == :rspec
|
102
106
|
template "tests/#{test_framework}/controller.rb", "spec/controllers/#{plural_name}_controller_spec.rb"
|
103
107
|
else
|
104
108
|
template "tests/#{test_framework}/controller.rb", "test/functional/#{plural_name}_controller_test.rb"
|
@@ -7,8 +7,8 @@ foo:
|
|
7
7
|
crypted_password: 3d16c326648cccafe3d4b4cb024475c381dda92f430dfedf6f933e1f61203bacb6bae2437849bdb43b06be335e23790e4aa03902b3c28c3bbbbe27d501e521f3
|
8
8
|
password_salt: n6z_wtpWoIsHgQb5IcFd
|
9
9
|
<%- else -%>
|
10
|
-
password_hash:
|
11
|
-
password_salt:
|
10
|
+
password_hash: "$2a$10$tUpEtZKDRfgosDmX2cUIFeCvHAHn9VT/0ZvmUhXiZCxSIrSdRiLhu"
|
11
|
+
password_salt: "$2a$10$tUpEtZKDRfgosDmX2cUIFe"
|
12
12
|
<%- end -%>
|
13
13
|
|
14
14
|
bar:
|
@@ -19,6 +19,6 @@ bar:
|
|
19
19
|
crypted_password: 3bc9f4113ca645a186765df3d31a9352d0067bf2304ba0cdd6b08a7f3d58c6668ab1762fa3e76aef466ea2ff188399d8e6c40244fa59312bb4112292dac9f7f0
|
20
20
|
password_salt: UiAh9ejabnKRxqsiK0xO
|
21
21
|
<%- else -%>
|
22
|
-
password_hash:
|
23
|
-
password_salt:
|
22
|
+
password_hash: "$2a$10$tUpEtZKDRfgosDmX2cUIFeCvHAHn9VT/0ZvmUhXiZCxSIrSdRiLhu"
|
23
|
+
password_salt: "$2a$10$tUpEtZKDRfgosDmX2cUIFe"
|
24
24
|
<%- end -%>
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 2
|
9
|
+
version: 0.4.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ryan Bates
|
@@ -14,10 +14,99 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-10-15 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec-rails
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 0
|
31
|
+
- 1
|
32
|
+
version: 2.0.1
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: cucumber
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
- 9
|
46
|
+
- 2
|
47
|
+
version: 0.9.2
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rails
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 3
|
60
|
+
- 0
|
61
|
+
- 0
|
62
|
+
version: 3.0.0
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: mocha
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ~>
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
- 9
|
76
|
+
- 8
|
77
|
+
version: 0.9.8
|
78
|
+
type: :development
|
79
|
+
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: bcrypt-ruby
|
82
|
+
prerelease: false
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
segments:
|
89
|
+
- 2
|
90
|
+
- 1
|
91
|
+
- 2
|
92
|
+
version: 2.1.2
|
93
|
+
type: :development
|
94
|
+
version_requirements: *id005
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: sqlite3-ruby
|
97
|
+
prerelease: false
|
98
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
segments:
|
104
|
+
- 1
|
105
|
+
- 3
|
106
|
+
- 1
|
107
|
+
version: 1.3.1
|
108
|
+
type: :development
|
109
|
+
version_requirements: *id006
|
21
110
|
description: A collection of useful Rails generator scripts for scaffolding, layout files, authentication, and more.
|
22
111
|
email: ryan@railscasts.com
|
23
112
|
executables: []
|
@@ -28,8 +117,8 @@ extra_rdoc_files: []
|
|
28
117
|
|
29
118
|
files:
|
30
119
|
- lib/generators/nifty/authentication/authentication_generator.rb
|
31
|
-
- lib/generators/nifty/authentication/templates/authentication.rb
|
32
120
|
- lib/generators/nifty/authentication/templates/authlogic_session.rb
|
121
|
+
- lib/generators/nifty/authentication/templates/controller_authentication.rb
|
33
122
|
- lib/generators/nifty/authentication/templates/fixtures.yml
|
34
123
|
- lib/generators/nifty/authentication/templates/migration.rb
|
35
124
|
- lib/generators/nifty/authentication/templates/sessions_controller.rb
|
@@ -46,8 +135,12 @@ files:
|
|
46
135
|
- lib/generators/nifty/authentication/templates/user.rb
|
47
136
|
- lib/generators/nifty/authentication/templates/users_controller.rb
|
48
137
|
- lib/generators/nifty/authentication/templates/users_helper.rb
|
138
|
+
- lib/generators/nifty/authentication/templates/views/erb/_form.html.erb
|
139
|
+
- lib/generators/nifty/authentication/templates/views/erb/edit.html.erb
|
49
140
|
- lib/generators/nifty/authentication/templates/views/erb/login.html.erb
|
50
141
|
- lib/generators/nifty/authentication/templates/views/erb/signup.html.erb
|
142
|
+
- lib/generators/nifty/authentication/templates/views/haml/_form.html.haml
|
143
|
+
- lib/generators/nifty/authentication/templates/views/haml/edit.html.haml
|
51
144
|
- lib/generators/nifty/authentication/templates/views/haml/login.html.haml
|
52
145
|
- lib/generators/nifty/authentication/templates/views/haml/signup.html.haml
|
53
146
|
- lib/generators/nifty/authentication/USAGE
|
@@ -216,6 +309,8 @@ files:
|
|
216
309
|
- rails_generators/nifty_scaffold/templates/views/haml/show.html.haml
|
217
310
|
- rails_generators/nifty_scaffold/USAGE
|
218
311
|
- CHANGELOG
|
312
|
+
- Gemfile
|
313
|
+
- Gemfile.lock
|
219
314
|
- LICENSE
|
220
315
|
- Rakefile
|
221
316
|
- README.rdoc
|