janova-clearance 0.8.8 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +11 -2
- data/README.md +34 -35
- data/Rakefile +79 -33
- data/VERSION +1 -1
- data/app/controllers/clearance/confirmations_controller.rb +0 -2
- data/app/controllers/clearance/passwords_controller.rb +1 -2
- data/app/controllers/clearance/sessions_controller.rb +1 -2
- data/app/controllers/clearance/users_controller.rb +0 -1
- data/app/models/clearance_mailer.rb +4 -4
- data/app/views/passwords/edit.html.erb +1 -1
- data/app/views/passwords/new.html.erb +2 -2
- data/app/views/sessions/new.html.erb +1 -1
- data/app/views/users/_form.html.erb +1 -1
- data/app/views/users/new.html.erb +1 -1
- data/clearance.gemspec +207 -0
- data/config/routes.rb +23 -0
- data/cucumber.yml +4 -0
- data/{rails/init.rb → init.rb} +0 -0
- data/lib/clearance.rb +2 -1
- data/lib/clearance/authentication.rb +2 -2
- data/lib/clearance/configuration.rb +10 -3
- data/lib/clearance/engine.rb +10 -0
- data/{shoulda_macros/clearance.rb → lib/clearance/shoulda_macros.rb} +11 -23
- data/lib/clearance/user.rb +5 -6
- data/lib/rails/generators/clearance_features_generator.rb +20 -0
- data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/password_reset.feature +1 -1
- data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/sign_in.feature +0 -0
- data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/sign_out.feature +0 -0
- data/{generators/clearance_features/templates → lib/rails/generators/clearance_features_templates}/features/sign_up.feature +0 -0
- data/lib/rails/generators/clearance_features_templates/features/step_definitions/clearance_steps.rb +138 -0
- data/lib/rails/generators/clearance_generator.rb +72 -0
- data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/README +0 -0
- data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/clearance.rb +0 -0
- data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/factories.rb +0 -0
- data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/migrations/create_users.rb +0 -1
- data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/migrations/update_users.rb +0 -1
- data/{generators/clearance/templates → lib/rails/generators/clearance_templates}/user.rb +0 -0
- data/lib/rails/generators/clearance_views_generator.rb +14 -0
- data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/passwords/edit.html.erb +3 -3
- data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/passwords/new.html.erb +3 -3
- data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/sessions/new.html.erb +3 -3
- data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/users/_inputs.html.erb +1 -1
- data/{generators/clearance_views/templates/formtastic → lib/rails/generators/clearance_views_templates/formtastic/erb}/users/new.html.erb +2 -2
- data/spec/rails_root/Gemfile +15 -0
- data/spec/rails_root/README +244 -0
- data/spec/rails_root/Rakefile +10 -0
- data/spec/rails_root/app/controllers/accounts_controller.rb +10 -0
- data/spec/rails_root/app/controllers/application_controller.rb +6 -0
- data/spec/rails_root/app/helpers/application_helper.rb +2 -0
- data/spec/rails_root/app/models/user.rb +3 -0
- data/{generators/clearance_views/USAGE → spec/rails_root/app/views/accounts/edit.html.erb} +0 -0
- data/spec/rails_root/app/views/layouts/application.html.erb +24 -0
- data/spec/rails_root/config.ru +4 -0
- data/spec/rails_root/config/application.rb +46 -0
- data/spec/rails_root/config/boot.rb +6 -0
- data/spec/rails_root/config/cucumber.yml +8 -0
- data/spec/rails_root/config/database.yml +25 -0
- data/spec/rails_root/config/environment.rb +7 -0
- data/spec/rails_root/config/environments/development.rb +21 -0
- data/spec/rails_root/config/environments/production.rb +42 -0
- data/spec/rails_root/config/environments/test.rb +34 -0
- data/spec/rails_root/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails_root/config/initializers/clearance.rb +3 -0
- data/spec/rails_root/config/initializers/inflections.rb +10 -0
- data/spec/rails_root/config/initializers/mime_types.rb +5 -0
- data/spec/rails_root/config/initializers/secret_token.rb +7 -0
- data/spec/rails_root/config/initializers/session_store.rb +8 -0
- data/spec/rails_root/config/locales/en.yml +5 -0
- data/spec/rails_root/config/routes.rb +61 -0
- data/spec/rails_root/db/schema.rb +29 -0
- data/spec/rails_root/doc/README_FOR_APP +2 -0
- data/spec/rails_root/features/password_reset.feature +33 -0
- data/spec/rails_root/features/sign_in.feature +35 -0
- data/spec/rails_root/features/sign_out.feature +15 -0
- data/spec/rails_root/features/sign_up.feature +45 -0
- data/{generators/clearance_features/templates → spec/rails_root}/features/step_definitions/clearance_steps.rb +18 -7
- data/spec/rails_root/features/step_definitions/web_steps.rb +219 -0
- data/spec/rails_root/features/support/env.rb +57 -0
- data/spec/rails_root/features/support/paths.rb +45 -0
- data/spec/rails_root/lib/tasks/cucumber.rake +53 -0
- data/spec/rails_root/public/404.html +26 -0
- data/spec/rails_root/public/422.html +26 -0
- data/spec/rails_root/public/500.html +26 -0
- data/spec/rails_root/public/favicon.ico +0 -0
- data/spec/rails_root/public/images/rails.png +0 -0
- data/spec/rails_root/public/javascripts/application.js +2 -0
- data/spec/rails_root/public/javascripts/controls.js +965 -0
- data/spec/rails_root/public/javascripts/dragdrop.js +974 -0
- data/spec/rails_root/public/javascripts/effects.js +1123 -0
- data/spec/rails_root/public/javascripts/prototype.js +4874 -0
- data/spec/rails_root/public/javascripts/rails.js +118 -0
- data/spec/rails_root/public/robots.txt +5 -0
- data/spec/rails_root/script/cucumber +10 -0
- data/spec/rails_root/script/rails +9 -0
- data/spec/rails_root/spec/factories/clearance.rb +13 -0
- data/spec/rails_root/vendor/plugins/dynamic_form/MIT-LICENSE +20 -0
- data/spec/rails_root/vendor/plugins/dynamic_form/README +13 -0
- data/spec/rails_root/vendor/plugins/dynamic_form/Rakefile +10 -0
- data/spec/rails_root/vendor/plugins/dynamic_form/init.rb +5 -0
- data/spec/rails_root/vendor/plugins/dynamic_form/lib/action_view/helpers/dynamic_form.rb +300 -0
- data/spec/rails_root/vendor/plugins/dynamic_form/lib/action_view/locale/en.yml +8 -0
- data/spec/rails_root/vendor/plugins/dynamic_form/test/dynamic_form_i18n_test.rb +42 -0
- data/spec/rails_root/vendor/plugins/dynamic_form/test/dynamic_form_test.rb +370 -0
- data/spec/rails_root/vendor/plugins/dynamic_form/test/test_helper.rb +9 -0
- data/test/controllers/confirmations_controller_test.rb +10 -7
- data/test/controllers/passwords_controller_test.rb +16 -20
- data/test/controllers/sessions_controller_test.rb +59 -20
- data/test/controllers/users_controller_test.rb +19 -16
- data/test/models/clearance_mailer_test.rb +2 -2
- data/test/models/user_test.rb +14 -13
- data/test/rails_root/Gemfile +17 -0
- data/test/rails_root/README +244 -0
- data/test/rails_root/Rakefile +10 -0
- data/test/rails_root/app/helpers/application_helper.rb +0 -3
- data/test/rails_root/app/models/user.rb +3 -0
- data/test/rails_root/app/views/accounts/edit.html.erb +0 -0
- data/test/rails_root/app/views/layouts/application.html.erb +24 -0
- data/test/rails_root/config.ru +4 -0
- data/test/rails_root/config/application.rb +46 -0
- data/test/rails_root/config/boot.rb +5 -109
- data/test/rails_root/config/cucumber.yml +8 -0
- data/test/rails_root/config/database.yml +25 -0
- data/test/rails_root/config/environment.rb +5 -15
- data/test/rails_root/config/environments/development.rb +16 -14
- data/test/rails_root/config/environments/production.rb +42 -1
- data/test/rails_root/config/environments/test.rb +34 -36
- data/test/rails_root/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_root/config/initializers/inflections.rb +1 -1
- data/test/rails_root/config/initializers/secret_token.rb +7 -0
- data/test/rails_root/config/initializers/session_store.rb +8 -0
- data/test/rails_root/config/locales/en.yml +5 -0
- data/test/rails_root/config/routes.rb +59 -4
- data/test/rails_root/doc/README_FOR_APP +2 -0
- data/test/rails_root/features/step_definitions/web_steps.rb +125 -165
- data/test/rails_root/features/support/env.rb +24 -14
- data/test/rails_root/features/support/paths.rb +45 -0
- data/test/rails_root/lib/tasks/cucumber.rake +53 -0
- data/test/rails_root/public/404.html +26 -0
- data/test/rails_root/public/422.html +26 -0
- data/test/rails_root/public/500.html +26 -0
- data/test/rails_root/public/favicon.ico +0 -0
- data/test/rails_root/public/images/rails.png +0 -0
- data/test/rails_root/public/javascripts/application.js +2 -0
- data/test/rails_root/public/javascripts/controls.js +965 -0
- data/test/rails_root/public/javascripts/dragdrop.js +974 -0
- data/test/rails_root/public/javascripts/effects.js +1123 -0
- data/test/rails_root/public/javascripts/prototype.js +4874 -0
- data/test/rails_root/public/javascripts/rails.js +118 -0
- data/test/rails_root/public/robots.txt +5 -0
- data/test/rails_root/script/cucumber +10 -0
- data/test/rails_root/script/rails +9 -0
- data/test/rails_root/test/factories/clearance.rb +13 -0
- data/test/rails_root/test/functional/accounts_controller_test.rb +0 -1
- data/test/rails_root/test/performance/browsing_test.rb +9 -0
- data/test/rails_root/test/test_helper.rb +13 -0
- data/test/rails_root/vendor/plugins/dynamic_form/MIT-LICENSE +20 -0
- data/test/rails_root/vendor/plugins/dynamic_form/README +13 -0
- data/test/rails_root/vendor/plugins/dynamic_form/Rakefile +10 -0
- data/test/rails_root/vendor/plugins/dynamic_form/init.rb +5 -0
- data/test/rails_root/vendor/plugins/dynamic_form/lib/action_view/helpers/dynamic_form.rb +300 -0
- data/test/rails_root/vendor/plugins/dynamic_form/lib/action_view/locale/en.yml +8 -0
- data/test/rails_root/vendor/plugins/dynamic_form/test/dynamic_form_i18n_test.rb +42 -0
- data/test/rails_root/vendor/plugins/dynamic_form/test/dynamic_form_test.rb +370 -0
- data/test/rails_root/vendor/plugins/dynamic_form/test/test_helper.rb +9 -0
- data/test/test_helper.rb +31 -2
- metadata +273 -61
- data/generators/clearance/USAGE +0 -1
- data/generators/clearance/clearance_generator.rb +0 -68
- data/generators/clearance/lib/insert_commands.rb +0 -33
- data/generators/clearance/lib/rake_commands.rb +0 -22
- data/generators/clearance_features/USAGE +0 -1
- data/generators/clearance_features/clearance_features_generator.rb +0 -19
- data/generators/clearance_features/templates/features/support/paths.rb +0 -23
- data/generators/clearance_views/clearance_views_generator.rb +0 -27
- data/lib/clearance/routes.rb +0 -49
- data/test/rails_root/app/helpers/confirmations_helper.rb +0 -2
- data/test/rails_root/app/helpers/passwords_helper.rb +0 -2
- data/test/rails_root/config/initializers/requires.rb +0 -13
- data/test/rails_root/config/initializers/time_formats.rb +0 -4
- data/test/rails_root/public/dispatch.rb +0 -10
- data/test/rails_root/script/create_project.rb +0 -52
- data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb +0 -21
- data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/lib/formtastic.rb +0 -1236
- data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/lib/justin_french/formtastic.rb +0 -10
- data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/rails/init.rb +0 -3
- data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/spec/formtastic_spec.rb +0 -2900
- data/test/rails_root/vendor/gems/justinfrench-formtastic-0.2.1/spec/test_helper.rb +0 -14
@@ -4,8 +4,8 @@ class PasswordsControllerTest < ActionController::TestCase
|
|
4
4
|
|
5
5
|
tests Clearance::PasswordsController
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
should route(:get, '/users/1/password/edit').
|
8
|
+
to(:controller => 'clearance/passwords', :action => 'edit', :user_id => '1')
|
9
9
|
|
10
10
|
context "a signed up user" do
|
11
11
|
setup do
|
@@ -15,8 +15,8 @@ class PasswordsControllerTest < ActionController::TestCase
|
|
15
15
|
context "on GET to #new" do
|
16
16
|
setup { get :new, :user_id => @user.to_param }
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
should respond_with(:success)
|
19
|
+
should render_template(:new)
|
20
20
|
end
|
21
21
|
|
22
22
|
context "on POST to #create" do
|
@@ -30,13 +30,9 @@ class PasswordsControllerTest < ActionController::TestCase
|
|
30
30
|
assert_not_nil @user.reload.confirmation_token
|
31
31
|
end
|
32
32
|
|
33
|
-
should
|
34
|
-
assert_sent_email do |email|
|
35
|
-
email.subject =~ /change your password/i
|
36
|
-
end
|
37
|
-
end
|
33
|
+
should have_sent_email.with_subject(/change your password/i)
|
38
34
|
|
39
|
-
|
35
|
+
should set_the_flash.to(/password/i)
|
40
36
|
should_redirect_to_url_after_create
|
41
37
|
end
|
42
38
|
|
@@ -64,7 +60,7 @@ class PasswordsControllerTest < ActionController::TestCase
|
|
64
60
|
assert_match /unknown email/i, flash.now[:failure]
|
65
61
|
end
|
66
62
|
|
67
|
-
|
63
|
+
should render_template(:new)
|
68
64
|
end
|
69
65
|
end
|
70
66
|
end
|
@@ -85,9 +81,8 @@ class PasswordsControllerTest < ActionController::TestCase
|
|
85
81
|
assert_equal @user, assigns(:user)
|
86
82
|
end
|
87
83
|
|
88
|
-
|
89
|
-
|
90
|
-
should_display_a_password_update_form
|
84
|
+
should respond_with(:success)
|
85
|
+
should render_template(:edit)
|
91
86
|
end
|
92
87
|
|
93
88
|
should_forbid "on GET to #edit with correct id but blank token" do
|
@@ -127,7 +122,7 @@ class PasswordsControllerTest < ActionController::TestCase
|
|
127
122
|
assert_not_nil @user.remember_token
|
128
123
|
end
|
129
124
|
|
130
|
-
|
125
|
+
should set_the_flash.to(/signed in/i)
|
131
126
|
should_redirect_to_url_after_update
|
132
127
|
end
|
133
128
|
|
@@ -155,12 +150,13 @@ class PasswordsControllerTest < ActionController::TestCase
|
|
155
150
|
assert_not_nil @user.confirmation_token
|
156
151
|
end
|
157
152
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
should_render_template :edit
|
153
|
+
should "not be signed in" do
|
154
|
+
assert_nil cookies[:remember_token]
|
155
|
+
end
|
162
156
|
|
163
|
-
|
157
|
+
should_not set_the_flash
|
158
|
+
should respond_with(:success)
|
159
|
+
should render_template(:edit)
|
164
160
|
end
|
165
161
|
|
166
162
|
should_forbid "on PUT to #update with id but no token" do
|
@@ -1,18 +1,16 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class SessionsControllerTest < ActionController::TestCase
|
4
|
-
|
5
4
|
tests Clearance::SessionsController
|
6
5
|
|
7
|
-
|
6
|
+
should filter_param(:password)
|
8
7
|
|
9
8
|
context "on GET to /sessions/new" do
|
10
9
|
setup { get :new }
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
should_display_a_sign_in_form
|
11
|
+
should respond_with(:success)
|
12
|
+
should render_template(:new)
|
13
|
+
should_not set_the_flash
|
16
14
|
end
|
17
15
|
|
18
16
|
context "on POST to #create with unconfirmed credentials" do
|
@@ -41,11 +39,13 @@ class SessionsControllerTest < ActionController::TestCase
|
|
41
39
|
:password => @user.password }
|
42
40
|
end
|
43
41
|
|
44
|
-
|
42
|
+
should set_the_flash.to(/signed in/i)
|
45
43
|
should_redirect_to_url_after_create
|
46
44
|
|
47
|
-
|
48
|
-
|
45
|
+
should_set_cookie("remember_token", "old-token", Clearance.configuration.cookie_expiration.call)
|
46
|
+
|
47
|
+
should "have a default of 1 year from now" do
|
48
|
+
assert_in_delta Clearance.configuration.cookie_expiration.call, 1.year.from_now, 100
|
49
49
|
end
|
50
50
|
|
51
51
|
should "not change the remember token" do
|
@@ -53,6 +53,46 @@ class SessionsControllerTest < ActionController::TestCase
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
context "on POST to #create with good credentials - cookie duration set to 2 weeks" do
|
57
|
+
custom_duration = 2.weeks.from_now.utc
|
58
|
+
|
59
|
+
setup do
|
60
|
+
Clearance.configuration.cookie_expiration = lambda { custom_duration }
|
61
|
+
@user = Factory(:email_confirmed_user)
|
62
|
+
@user.update_attribute(:remember_token, "old-token2")
|
63
|
+
post :create, :session => {
|
64
|
+
:email => @user.email,
|
65
|
+
:password => @user.password }
|
66
|
+
end
|
67
|
+
|
68
|
+
should_set_cookie("remember_token", "old-token2", custom_duration)
|
69
|
+
|
70
|
+
teardown do
|
71
|
+
# restore default Clearance configuration
|
72
|
+
Clearance.configuration = nil
|
73
|
+
Clearance.configure {}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "on POST to #create with good credentials - cookie expiration set to nil (session cookie)" do
|
78
|
+
setup do
|
79
|
+
Clearance.configuration.cookie_expiration = lambda { nil }
|
80
|
+
@user = Factory(:email_confirmed_user)
|
81
|
+
@user.update_attribute(:remember_token, "old-token3")
|
82
|
+
post :create, :session => {
|
83
|
+
:email => @user.email,
|
84
|
+
:password => @user.password }
|
85
|
+
end
|
86
|
+
|
87
|
+
should_set_cookie("remember_token", "old-token3", nil)
|
88
|
+
|
89
|
+
teardown do
|
90
|
+
# restore default Clearance configuration
|
91
|
+
Clearance.configuration = nil
|
92
|
+
Clearance.configure {}
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
56
96
|
context "on POST to #create with good credentials and a session return url" do
|
57
97
|
setup do
|
58
98
|
@user = Factory(:email_confirmed_user)
|
@@ -63,7 +103,7 @@ class SessionsControllerTest < ActionController::TestCase
|
|
63
103
|
:password => @user.password }
|
64
104
|
end
|
65
105
|
|
66
|
-
|
106
|
+
should redirect_to("the return URL") { @return_url }
|
67
107
|
end
|
68
108
|
|
69
109
|
context "on POST to #create with good credentials and a request return url" do
|
@@ -76,7 +116,7 @@ class SessionsControllerTest < ActionController::TestCase
|
|
76
116
|
:return_to => @return_url
|
77
117
|
end
|
78
118
|
|
79
|
-
|
119
|
+
should redirect_to("the return URL") { @return_url }
|
80
120
|
end
|
81
121
|
|
82
122
|
context "on POST to #create with good credentials and a session return url and request return url" do
|
@@ -90,7 +130,7 @@ class SessionsControllerTest < ActionController::TestCase
|
|
90
130
|
:return_to => '/url_in_the_request'
|
91
131
|
end
|
92
132
|
|
93
|
-
|
133
|
+
should redirect_to("the return URL") { @return_url }
|
94
134
|
end
|
95
135
|
|
96
136
|
context "on POST to #create with bad credentials" do
|
@@ -100,13 +140,12 @@ class SessionsControllerTest < ActionController::TestCase
|
|
100
140
|
:password => "bad value" }
|
101
141
|
end
|
102
142
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
should_not_be_signed_in
|
143
|
+
should set_the_flash.to(/bad/i)
|
144
|
+
should respond_with(:unauthorized)
|
145
|
+
should render_template(:new)
|
107
146
|
|
108
|
-
should
|
109
|
-
assert_nil cookies[
|
147
|
+
should "not be signed in" do
|
148
|
+
assert_nil cookies[:remember_token]
|
110
149
|
end
|
111
150
|
end
|
112
151
|
|
@@ -115,7 +154,7 @@ class SessionsControllerTest < ActionController::TestCase
|
|
115
154
|
sign_out
|
116
155
|
delete :destroy
|
117
156
|
end
|
118
|
-
|
157
|
+
should set_the_flash.to(/signed out/i)
|
119
158
|
should_redirect_to_url_after_destroy
|
120
159
|
end
|
121
160
|
|
@@ -127,7 +166,7 @@ class SessionsControllerTest < ActionController::TestCase
|
|
127
166
|
delete :destroy
|
128
167
|
end
|
129
168
|
|
130
|
-
|
169
|
+
should set_the_flash.to(/signed out/i)
|
131
170
|
should_redirect_to_url_after_destroy
|
132
171
|
|
133
172
|
should "delete the cookie token" do
|
@@ -4,7 +4,7 @@ class UsersControllerTest < ActionController::TestCase
|
|
4
4
|
|
5
5
|
tests Clearance::UsersController
|
6
6
|
|
7
|
-
|
7
|
+
should filter_param(:password)
|
8
8
|
|
9
9
|
context "when signed out" do
|
10
10
|
setup { sign_out }
|
@@ -12,11 +12,9 @@ class UsersControllerTest < ActionController::TestCase
|
|
12
12
|
context "on GET to #new" do
|
13
13
|
setup { get :new }
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
should_display_a_sign_up_form
|
15
|
+
should respond_with(:success)
|
16
|
+
should render_template(:new)
|
17
|
+
should_not set_the_flash
|
20
18
|
end
|
21
19
|
|
22
20
|
context "on GET to #new with email" do
|
@@ -33,32 +31,37 @@ class UsersControllerTest < ActionController::TestCase
|
|
33
31
|
context "on POST to #create with valid attributes" do
|
34
32
|
setup do
|
35
33
|
user_attributes = Factory.attributes_for(:user)
|
34
|
+
@old_user_count = User.count
|
36
35
|
post :create, :user => user_attributes
|
37
36
|
end
|
38
37
|
|
39
|
-
|
40
|
-
should_change 'User.count', :by => 1
|
38
|
+
should assign_to(:user)
|
41
39
|
|
42
|
-
should "
|
43
|
-
|
44
|
-
email.subject =~ /account confirmation/i
|
45
|
-
end
|
40
|
+
should "create a new user" do
|
41
|
+
assert_equal @old_user_count + 1, User.count
|
46
42
|
end
|
47
43
|
|
48
|
-
|
44
|
+
should have_sent_email.with_subject(/account confirmation/i)
|
45
|
+
|
46
|
+
should set_the_flash.to(/confirm/i)
|
49
47
|
should_redirect_to_url_after_create
|
50
48
|
end
|
51
49
|
end
|
52
50
|
|
53
|
-
|
51
|
+
context "A signed-in user" do
|
52
|
+
setup do
|
53
|
+
@user = Factory(:email_confirmed_user)
|
54
|
+
sign_in_as @user
|
55
|
+
end
|
56
|
+
|
54
57
|
context "GET to new" do
|
55
58
|
setup { get :new }
|
56
|
-
|
59
|
+
should redirect_to("the home page") { root_url }
|
57
60
|
end
|
58
61
|
|
59
62
|
context "POST to create" do
|
60
63
|
setup { post :create, :user => {} }
|
61
|
-
|
64
|
+
should redirect_to("the home page") { root_url }
|
62
65
|
end
|
63
66
|
end
|
64
67
|
|
@@ -5,7 +5,7 @@ class ClearanceMailerTest < ActiveSupport::TestCase
|
|
5
5
|
context "A change password email" do
|
6
6
|
setup do
|
7
7
|
@user = Factory(:user)
|
8
|
-
@email = ClearanceMailer.
|
8
|
+
@email = ClearanceMailer.change_password @user
|
9
9
|
end
|
10
10
|
|
11
11
|
should "be from DO_NOT_REPLY" do
|
@@ -30,7 +30,7 @@ class ClearanceMailerTest < ActiveSupport::TestCase
|
|
30
30
|
context "A confirmation email" do
|
31
31
|
setup do
|
32
32
|
@user = Factory(:user)
|
33
|
-
@email = ClearanceMailer.
|
33
|
+
@email = ClearanceMailer.confirmation @user
|
34
34
|
end
|
35
35
|
|
36
36
|
should "be from DO_NOT_REPLY" do
|
data/test/models/user_test.rb
CHANGED
@@ -2,6 +2,11 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class UserTest < ActiveSupport::TestCase
|
4
4
|
|
5
|
+
# db
|
6
|
+
|
7
|
+
should have_db_index(:email)
|
8
|
+
should have_db_index(:remember_token)
|
9
|
+
|
5
10
|
# signing up
|
6
11
|
|
7
12
|
context "When signing up" do
|
@@ -19,14 +24,14 @@ class UserTest < ActiveSupport::TestCase
|
|
19
24
|
user = Factory.build(:user, :password => 'blah',
|
20
25
|
:password_confirmation => 'boogidy')
|
21
26
|
assert ! user.save
|
22
|
-
assert user.errors
|
27
|
+
assert user.errors[:password].any?
|
23
28
|
end
|
24
29
|
|
25
30
|
should "require non blank password confirmation on create" do
|
26
31
|
user = Factory.build(:user, :password => 'blah',
|
27
32
|
:password_confirmation => '')
|
28
33
|
assert ! user.save
|
29
|
-
assert user.errors
|
34
|
+
assert user.errors[:password].any?
|
30
35
|
end
|
31
36
|
|
32
37
|
should "initialize salt" do
|
@@ -59,11 +64,7 @@ class UserTest < ActiveSupport::TestCase
|
|
59
64
|
assert_equal "John.Doe@example.com", user.email
|
60
65
|
end
|
61
66
|
|
62
|
-
should
|
63
|
-
assert_sent_email do |email|
|
64
|
-
email.subject =~ /account confirmation/i
|
65
|
-
end
|
66
|
-
end
|
67
|
+
should have_sent_email.with_subject(/account confirmation/i)
|
67
68
|
end
|
68
69
|
|
69
70
|
context "When signing up with email already confirmed" do
|
@@ -72,14 +73,12 @@ class UserTest < ActiveSupport::TestCase
|
|
72
73
|
Factory(:user, :email_confirmed => true)
|
73
74
|
end
|
74
75
|
|
75
|
-
|
76
|
-
assert_did_not_send_email
|
77
|
-
end
|
76
|
+
should_not have_sent_email
|
78
77
|
end
|
79
78
|
|
80
79
|
context "When multiple users have signed up" do
|
81
80
|
setup { Factory(:user) }
|
82
|
-
|
81
|
+
should validate_uniqueness_of(:email)
|
83
82
|
end
|
84
83
|
|
85
84
|
# confirming email
|
@@ -239,7 +238,8 @@ class UserTest < ActiveSupport::TestCase
|
|
239
238
|
|
240
239
|
subject { @user }
|
241
240
|
|
242
|
-
|
241
|
+
should allow_value(nil).for(:email)
|
242
|
+
should allow_value("").for(:email)
|
243
243
|
end
|
244
244
|
|
245
245
|
context "a user with an optional password" do
|
@@ -254,7 +254,8 @@ class UserTest < ActiveSupport::TestCase
|
|
254
254
|
|
255
255
|
subject { @user }
|
256
256
|
|
257
|
-
|
257
|
+
should allow_value(nil).for(:password)
|
258
|
+
should allow_value("").for(:password)
|
258
259
|
end
|
259
260
|
|
260
261
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '3.0.0'
|
4
|
+
|
5
|
+
gem 'sqlite3-ruby', :require => 'sqlite3'
|
6
|
+
|
7
|
+
gem 'capybara', '0.3.9'
|
8
|
+
gem 'cucumber', '0.8.5'
|
9
|
+
gem 'cucumber-rails', '0.3.2'
|
10
|
+
gem 'factory_girl_rails', '1.0'
|
11
|
+
gem 'formtastic', '1.1.0.beta'
|
12
|
+
gem 'launchy', '0.3.7'
|
13
|
+
gem 'mocha', '0.9.8'
|
14
|
+
gem 'nokogiri', '1.4.1'
|
15
|
+
gem 'shoulda', '2.11.3'
|
16
|
+
|
17
|
+
gem 'clearance', :path => '../..'
|
@@ -0,0 +1,244 @@
|
|
1
|
+
== Welcome to Rails
|
2
|
+
|
3
|
+
Rails is a web-application framework that includes everything needed to create
|
4
|
+
database-backed web applications according to the Model-View-Control pattern.
|
5
|
+
|
6
|
+
This pattern splits the view (also called the presentation) into "dumb" templates
|
7
|
+
that are primarily responsible for inserting pre-built data in between HTML tags.
|
8
|
+
The model contains the "smart" domain objects (such as Account, Product, Person,
|
9
|
+
Post) that holds all the business logic and knows how to persist themselves to
|
10
|
+
a database. The controller handles the incoming requests (such as Save New Account,
|
11
|
+
Update Product, Show Post) by manipulating the model and directing data to the view.
|
12
|
+
|
13
|
+
In Rails, the model is handled by what's called an object-relational mapping
|
14
|
+
layer entitled Active Record. This layer allows you to present the data from
|
15
|
+
database rows as objects and embellish these data objects with business logic
|
16
|
+
methods. You can read more about Active Record in
|
17
|
+
link:files/vendor/rails/activerecord/README.html.
|
18
|
+
|
19
|
+
The controller and view are handled by the Action Pack, which handles both
|
20
|
+
layers by its two parts: Action View and Action Controller. These two layers
|
21
|
+
are bundled in a single package due to their heavy interdependence. This is
|
22
|
+
unlike the relationship between the Active Record and Action Pack that is much
|
23
|
+
more separate. Each of these packages can be used independently outside of
|
24
|
+
Rails. You can read more about Action Pack in
|
25
|
+
link:files/vendor/rails/actionpack/README.html.
|
26
|
+
|
27
|
+
|
28
|
+
== Getting Started
|
29
|
+
|
30
|
+
1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
|
31
|
+
and your application name. Ex: rails myapp
|
32
|
+
2. Change directory into myapp and start the web server: <tt>rails server</tt> (run with --help for options)
|
33
|
+
3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
|
34
|
+
4. Follow the guidelines to start developing your application
|
35
|
+
|
36
|
+
|
37
|
+
== Web Servers
|
38
|
+
|
39
|
+
By default, Rails will try to use Mongrel if it's installed when started with <tt>rails server</tt>, otherwise
|
40
|
+
Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
|
41
|
+
with a variety of other web servers.
|
42
|
+
|
43
|
+
Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
|
44
|
+
suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
|
45
|
+
getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
|
46
|
+
More info at: http://mongrel.rubyforge.org
|
47
|
+
|
48
|
+
Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
|
49
|
+
Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
|
50
|
+
FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
|
51
|
+
|
52
|
+
== Apache .htaccess example for FCGI/CGI
|
53
|
+
|
54
|
+
# General Apache options
|
55
|
+
AddHandler fastcgi-script .fcgi
|
56
|
+
AddHandler cgi-script .cgi
|
57
|
+
Options +FollowSymLinks +ExecCGI
|
58
|
+
|
59
|
+
# If you don't want Rails to look in certain directories,
|
60
|
+
# use the following rewrite rules so that Apache won't rewrite certain requests
|
61
|
+
#
|
62
|
+
# Example:
|
63
|
+
# RewriteCond %{REQUEST_URI} ^/notrails.*
|
64
|
+
# RewriteRule .* - [L]
|
65
|
+
|
66
|
+
# Redirect all requests not available on the filesystem to Rails
|
67
|
+
# By default the cgi dispatcher is used which is very slow
|
68
|
+
#
|
69
|
+
# For better performance replace the dispatcher with the fastcgi one
|
70
|
+
#
|
71
|
+
# Example:
|
72
|
+
# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
|
73
|
+
RewriteEngine On
|
74
|
+
|
75
|
+
# If your Rails application is accessed via an Alias directive,
|
76
|
+
# then you MUST also set the RewriteBase in this htaccess file.
|
77
|
+
#
|
78
|
+
# Example:
|
79
|
+
# Alias /myrailsapp /path/to/myrailsapp/public
|
80
|
+
# RewriteBase /myrailsapp
|
81
|
+
|
82
|
+
RewriteRule ^$ index.html [QSA]
|
83
|
+
RewriteRule ^([^.]+)$ $1.html [QSA]
|
84
|
+
RewriteCond %{REQUEST_FILENAME} !-f
|
85
|
+
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
|
86
|
+
|
87
|
+
# In case Rails experiences terminal errors
|
88
|
+
# Instead of displaying this message you can supply a file here which will be rendered instead
|
89
|
+
#
|
90
|
+
# Example:
|
91
|
+
# ErrorDocument 500 /500.html
|
92
|
+
|
93
|
+
ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
|
94
|
+
|
95
|
+
|
96
|
+
== Debugging Rails
|
97
|
+
|
98
|
+
Sometimes your application goes wrong. Fortunately there are a lot of tools that
|
99
|
+
will help you debug it and get it back on the rails.
|
100
|
+
|
101
|
+
First area to check is the application log files. Have "tail -f" commands running
|
102
|
+
on the server.log and development.log. Rails will automatically display debugging
|
103
|
+
and runtime information to these files. Debugging info will also be shown in the
|
104
|
+
browser on requests from 127.0.0.1.
|
105
|
+
|
106
|
+
You can also log your own messages directly into the log file from your code using
|
107
|
+
the Ruby logger class from inside your controllers. Example:
|
108
|
+
|
109
|
+
class WeblogController < ActionController::Base
|
110
|
+
def destroy
|
111
|
+
@weblog = Weblog.find(params[:id])
|
112
|
+
@weblog.destroy
|
113
|
+
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
The result will be a message in your log file along the lines of:
|
118
|
+
|
119
|
+
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
|
120
|
+
|
121
|
+
More information on how to use the logger is at http://www.ruby-doc.org/core/
|
122
|
+
|
123
|
+
Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
|
124
|
+
|
125
|
+
* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
|
126
|
+
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
|
127
|
+
|
128
|
+
These two online (and free) books will bring you up to speed on the Ruby language
|
129
|
+
and also on programming in general.
|
130
|
+
|
131
|
+
|
132
|
+
== Debugger
|
133
|
+
|
134
|
+
Debugger support is available through the debugger command when you start your Mongrel or
|
135
|
+
Webrick server with --debugger. This means that you can break out of execution at any point
|
136
|
+
in the code, investigate and change the model, AND then resume execution!
|
137
|
+
You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
|
138
|
+
Example:
|
139
|
+
|
140
|
+
class WeblogController < ActionController::Base
|
141
|
+
def index
|
142
|
+
@posts = Post.find(:all)
|
143
|
+
debugger
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
So the controller will accept the action, run the first line, then present you
|
148
|
+
with a IRB prompt in the server window. Here you can do things like:
|
149
|
+
|
150
|
+
>> @posts.inspect
|
151
|
+
=> "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
|
152
|
+
#<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
|
153
|
+
>> @posts.first.title = "hello from a debugger"
|
154
|
+
=> "hello from a debugger"
|
155
|
+
|
156
|
+
...and even better is that you can examine how your runtime objects actually work:
|
157
|
+
|
158
|
+
>> f = @posts.first
|
159
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
160
|
+
>> f.
|
161
|
+
Display all 152 possibilities? (y or n)
|
162
|
+
|
163
|
+
Finally, when you're ready to resume execution, you enter "cont"
|
164
|
+
|
165
|
+
|
166
|
+
== Console
|
167
|
+
|
168
|
+
You can interact with the domain model by starting the console through <tt>rails console</tt>.
|
169
|
+
Here you'll have all parts of the application configured, just like it is when the
|
170
|
+
application is running. You can inspect domain models, change values, and save to the
|
171
|
+
database. Starting the script without arguments will launch it in the development environment.
|
172
|
+
Passing an argument will specify a different environment, like <tt>rails console production</tt>.
|
173
|
+
|
174
|
+
To reload your controllers and models after launching the console run <tt>reload!</tt>
|
175
|
+
|
176
|
+
== dbconsole
|
177
|
+
|
178
|
+
You can go to the command line of your database directly through <tt>rails dbconsole</tt>.
|
179
|
+
You would be connected to the database with the credentials defined in database.yml.
|
180
|
+
Starting the script without arguments will connect you to the development database. Passing an
|
181
|
+
argument will connect you to a different database, like <tt>rails dbconsole production</tt>.
|
182
|
+
Currently works for mysql, postgresql and sqlite.
|
183
|
+
|
184
|
+
== Description of Contents
|
185
|
+
|
186
|
+
app
|
187
|
+
Holds all the code that's specific to this particular application.
|
188
|
+
|
189
|
+
app/controllers
|
190
|
+
Holds controllers that should be named like weblogs_controller.rb for
|
191
|
+
automated URL mapping. All controllers should descend from ApplicationController
|
192
|
+
which itself descends from ActionController::Base.
|
193
|
+
|
194
|
+
app/models
|
195
|
+
Holds models that should be named like post.rb.
|
196
|
+
Most models will descend from ActiveRecord::Base.
|
197
|
+
|
198
|
+
app/views
|
199
|
+
Holds the template files for the view that should be named like
|
200
|
+
weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
|
201
|
+
syntax.
|
202
|
+
|
203
|
+
app/views/layouts
|
204
|
+
Holds the template files for layouts to be used with views. This models the common
|
205
|
+
header/footer method of wrapping views. In your views, define a layout using the
|
206
|
+
<tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
|
207
|
+
call <% yield %> to render the view using this layout.
|
208
|
+
|
209
|
+
app/helpers
|
210
|
+
Holds view helpers that should be named like weblogs_helper.rb. These are generated
|
211
|
+
for you automatically when using rails generate for controllers. Helpers can be used to
|
212
|
+
wrap functionality for your views into methods.
|
213
|
+
|
214
|
+
config
|
215
|
+
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
|
216
|
+
|
217
|
+
db
|
218
|
+
Contains the database schema in schema.rb. db/migrate contains all
|
219
|
+
the sequence of Migrations for your schema.
|
220
|
+
|
221
|
+
doc
|
222
|
+
This directory is where your application documentation will be stored when generated
|
223
|
+
using <tt>rake doc:app</tt>
|
224
|
+
|
225
|
+
lib
|
226
|
+
Application specific libraries. Basically, any kind of custom code that doesn't
|
227
|
+
belong under controllers, models, or helpers. This directory is in the load path.
|
228
|
+
|
229
|
+
public
|
230
|
+
The directory available for the web server. Contains subdirectories for images, stylesheets,
|
231
|
+
and javascripts. Also contains the dispatchers and the default HTML files. This should be
|
232
|
+
set as the DOCUMENT_ROOT of your web server.
|
233
|
+
|
234
|
+
script
|
235
|
+
Helper scripts for automation and generation.
|
236
|
+
|
237
|
+
test
|
238
|
+
Unit and functional tests along with fixtures. When using the rails generate command, template
|
239
|
+
test files will be generated for you and placed in this directory.
|
240
|
+
|
241
|
+
vendor
|
242
|
+
External libraries that the application depends on. Also includes the plugins subdirectory.
|
243
|
+
If the app has frozen rails, those gems also go here, under vendor/rails/.
|
244
|
+
This directory is in the load path.
|