gsterndale-warrant 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +2 -2
- data/VERSION.yml +1 -1
- data/test/rails_root/config/environment.rb +0 -4
- data/test/rails_root/test/unit/post_test.rb +18 -0
- metadata +9 -104
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/bin/redcloth +0 -3
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/doc/CHANGELOG +0 -160
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/doc/COPYING +0 -25
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/doc/README +0 -106
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/doc/REFERENCE +0 -216
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/doc/make.rb +0 -359
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/lib/redcloth.rb +0 -1130
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/run-tests.rb +0 -28
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/setup.rb +0 -1376
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/tests/code.yml +0 -105
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/tests/hard_breaks.yml +0 -26
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/tests/images.yml +0 -171
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/tests/instiki.yml +0 -39
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/tests/links.yml +0 -155
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/tests/lists.yml +0 -77
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/tests/markdown.yml +0 -218
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/tests/poignant.yml +0 -64
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/tests/table.yml +0 -198
- data/test/rails_root/vendor/gems/RedCloth-3.0.4/tests/textism.yml +0 -406
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/LICENSE +0 -21
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/README.textile +0 -204
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/Rakefile +0 -54
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/TODO.textile +0 -8
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/USAGE +0 -1
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/clearance_generator.rb +0 -92
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/lib/insert_commands.rb +0 -103
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/lib/rake_commands.rb +0 -22
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/README +0 -54
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/app/controllers/application.rb +0 -5
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/app/controllers/confirmations_controller.rb +0 -3
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/app/controllers/passwords_controller.rb +0 -3
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/app/controllers/sessions_controller.rb +0 -3
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/app/controllers/users_controller.rb +0 -3
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/app/models/clearance_mailer.rb +0 -5
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/app/models/user.rb +0 -3
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/app/views/clearance_mailer/change_password.html.erb +0 -10
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/app/views/clearance_mailer/confirmation.html.erb +0 -1
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/app/views/passwords/edit.html.erb +0 -25
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/app/views/passwords/new.html.erb +0 -15
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/app/views/sessions/new.html.erb +0 -28
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/app/views/users/_form.html.erb +0 -13
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/app/views/users/edit.html.erb +0 -6
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/app/views/users/new.html.erb +0 -6
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/db/migrate/create_users_with_clearance_columns.rb +0 -21
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/db/migrate/update_users_with_clearance_columns.rb +0 -42
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/test/factories/clearance.rb +0 -16
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/test/functional/confirmations_controller_test.rb +0 -5
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/test/functional/passwords_controller_test.rb +0 -5
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/test/functional/sessions_controller_test.rb +0 -5
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/test/functional/users_controller_test.rb +0 -5
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/test/unit/clearance_mailer_test.rb +0 -6
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/generators/clearance/templates/test/unit/user_test.rb +0 -5
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance.rb +0 -14
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance/app/controllers/application_controller.rb +0 -82
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance/app/controllers/confirmations_controller.rb +0 -42
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance/app/controllers/passwords_controller.rb +0 -68
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance/app/controllers/sessions_controller.rb +0 -68
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance/app/controllers/users_controller.rb +0 -40
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance/app/models/clearance_mailer.rb +0 -29
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance/app/models/user.rb +0 -85
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance/test/functional/confirmations_controller_test.rb +0 -44
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance/test/functional/passwords_controller_test.rb +0 -175
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance/test/functional/sessions_controller_test.rb +0 -194
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance/test/functional/users_controller_test.rb +0 -85
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance/test/test_helper.rb +0 -28
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance/test/unit/clearance_mailer_test.rb +0 -65
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance/test/unit/user_test.rb +0 -163
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/rails/init.rb +0 -1
- data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/shoulda_macros/clearance.rb +0 -173
@@ -1,85 +0,0 @@
|
|
1
|
-
module Clearance
|
2
|
-
module Test
|
3
|
-
module Functional
|
4
|
-
module UsersControllerTest
|
5
|
-
|
6
|
-
def self.included(controller_test)
|
7
|
-
controller_test.class_eval do
|
8
|
-
|
9
|
-
should_filter_params :password
|
10
|
-
|
11
|
-
public_context do
|
12
|
-
context "When getting new User view" do
|
13
|
-
setup { get :new }
|
14
|
-
|
15
|
-
should_respond_with :success
|
16
|
-
should_render_template :new
|
17
|
-
should_not_set_the_flash
|
18
|
-
|
19
|
-
should "display a form to register" do
|
20
|
-
assert_select "form[action=#{users_path}][method=post]",
|
21
|
-
true, "There must be a form to register" do
|
22
|
-
assert_select "input[type=text][name=?]",
|
23
|
-
"user[email]", true, "There must be an email field"
|
24
|
-
assert_select "input[type=password][name=?]",
|
25
|
-
"user[password]", true, "There must be a password field"
|
26
|
-
assert_select "input[type=password][name=?]",
|
27
|
-
"user[password_confirmation]", true, "There must be a password confirmation field"
|
28
|
-
assert_select "input[type=submit]", true,
|
29
|
-
"There must be a submit button"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "Given email parameter when getting new User view" do
|
35
|
-
setup do
|
36
|
-
@email = "a@example.com"
|
37
|
-
get :new, :user => { :email => @email }
|
38
|
-
end
|
39
|
-
|
40
|
-
should "set assigned user's email" do
|
41
|
-
assert_equal @email, assigns(:user).email
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "Given valid attributes when creating a new user" do
|
46
|
-
setup do
|
47
|
-
user_attributes = Factory.attributes_for(:registered_user)
|
48
|
-
post :create, :user => user_attributes
|
49
|
-
end
|
50
|
-
|
51
|
-
should_create_user_successfully
|
52
|
-
end
|
53
|
-
|
54
|
-
context "Given valid email confirmation attributes when creating a new user" do
|
55
|
-
setup do
|
56
|
-
user_attributes = Factory.attributes_for(:email_confirmed_user)
|
57
|
-
post :create, :user => user_attributes
|
58
|
-
end
|
59
|
-
|
60
|
-
should_create_user_successfully
|
61
|
-
|
62
|
-
should "not confirm email" do
|
63
|
-
assert ! assigns(:user).email_confirmed
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
signed_in_user_context do
|
69
|
-
context "GET to new" do
|
70
|
-
setup { get :new }
|
71
|
-
should_redirect_to "root_url"
|
72
|
-
end
|
73
|
-
|
74
|
-
context "POST to create" do
|
75
|
-
setup { post :create, :user => {} }
|
76
|
-
should_redirect_to "root_url"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance/test/test_helper.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
module Clearance
|
2
|
-
module Test
|
3
|
-
module TestHelper
|
4
|
-
|
5
|
-
def self.included(test_helper)
|
6
|
-
test_helper.class_eval do
|
7
|
-
|
8
|
-
def sign_in_as(user = nil)
|
9
|
-
unless user
|
10
|
-
user = Factory(:registered_user)
|
11
|
-
user.confirm_email!
|
12
|
-
end
|
13
|
-
@request.session[:user_id] = user.id
|
14
|
-
@request.session[:salt] = user.salt
|
15
|
-
return user
|
16
|
-
end
|
17
|
-
|
18
|
-
def sign_out
|
19
|
-
@request.session[:user_id] = nil
|
20
|
-
@request.session[:salt] = nil
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module Clearance
|
2
|
-
module Test
|
3
|
-
module Unit
|
4
|
-
module ClearanceMailerTest
|
5
|
-
|
6
|
-
def self.included(mailer_test)
|
7
|
-
mailer_test.class_eval do
|
8
|
-
|
9
|
-
context "A change password email" do
|
10
|
-
setup do
|
11
|
-
@user = Factory(:registered_user)
|
12
|
-
@email = ClearanceMailer.create_change_password @user
|
13
|
-
end
|
14
|
-
|
15
|
-
should "set its from address to DO_NOT_REPLY" do
|
16
|
-
assert_equal DO_NOT_REPLY, @email.from[0]
|
17
|
-
end
|
18
|
-
|
19
|
-
should "contain a link to edit the user's password" do
|
20
|
-
host = ActionMailer::Base.default_url_options[:host]
|
21
|
-
regexp = %r{http://#{host}/users/#{@user.id}/password/edit\?email=#{@user.email.gsub("@", "%40")}&password=#{@user.encrypted_password}}
|
22
|
-
assert_match regexp, @email.body
|
23
|
-
end
|
24
|
-
|
25
|
-
should "be sent to the user" do
|
26
|
-
assert_equal [@user.email], @email.to
|
27
|
-
end
|
28
|
-
|
29
|
-
should "set its subject" do
|
30
|
-
assert_match /Change your password/, @email.subject
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "A confirmation email" do
|
35
|
-
setup do
|
36
|
-
@user = Factory(:registered_user)
|
37
|
-
@email = ClearanceMailer.create_confirmation @user
|
38
|
-
end
|
39
|
-
|
40
|
-
should "set its recipient to the given user" do
|
41
|
-
assert_equal @user.email, @email.to[0]
|
42
|
-
end
|
43
|
-
|
44
|
-
should "set its subject" do
|
45
|
-
assert_match /Account confirmation/, @email.subject
|
46
|
-
end
|
47
|
-
|
48
|
-
should "set its from address to DO_NOT_REPLY" do
|
49
|
-
assert_equal DO_NOT_REPLY, @email.from[0]
|
50
|
-
end
|
51
|
-
|
52
|
-
should "contain a link to confirm the user's account" do
|
53
|
-
host = ActionMailer::Base.default_url_options[:host]
|
54
|
-
regexp = %r{http://#{host}/users/#{@user.id}/confirmation/new\?salt=#{@user.salt}}
|
55
|
-
assert_match regexp, @email.body
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
data/test/rails_root/vendor/gems/thoughtbot-clearance-0.4.0/lib/clearance/test/unit/user_test.rb
DELETED
@@ -1,163 +0,0 @@
|
|
1
|
-
module Clearance
|
2
|
-
module Test
|
3
|
-
module Unit
|
4
|
-
module UserTest
|
5
|
-
|
6
|
-
def self.included(unit_test)
|
7
|
-
unit_test.class_eval do
|
8
|
-
|
9
|
-
# registering
|
10
|
-
|
11
|
-
context "When registering" do
|
12
|
-
should_require_attributes :email
|
13
|
-
should_allow_values_for :email, "foo@example.com"
|
14
|
-
should_not_allow_values_for :email, "foo"
|
15
|
-
should_not_allow_values_for :email, "example.com"
|
16
|
-
|
17
|
-
should_validate_confirmation_of :password,
|
18
|
-
:factory => :registered_user
|
19
|
-
|
20
|
-
should "initialize salt" do
|
21
|
-
assert_not_nil Factory(:registered_user).salt
|
22
|
-
end
|
23
|
-
|
24
|
-
context "encrypt password" do
|
25
|
-
setup do
|
26
|
-
@salt = "salt"
|
27
|
-
User.any_instance.stubs(:initialize_salt)
|
28
|
-
|
29
|
-
@user = Factory(:registered_user, :salt => @salt)
|
30
|
-
@password = @user.password
|
31
|
-
|
32
|
-
@user.encrypt(@password)
|
33
|
-
@expected = Digest::SHA512.hexdigest("--#{@salt}--#{@password}--")
|
34
|
-
end
|
35
|
-
|
36
|
-
should "create an encrypted password using SHA512 encryption" do
|
37
|
-
assert_equal @expected, @user.encrypted_password
|
38
|
-
assert_not_equal @password, @user.encrypted_password
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
should "store email in lower case" do
|
43
|
-
user = Factory(:registered_user, :email => "John.Doe@example.com")
|
44
|
-
assert_equal "john.doe@example.com", user.email
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "When multiple users have registerd" do
|
49
|
-
setup { @user = Factory(:registered_user) }
|
50
|
-
|
51
|
-
should_require_unique_attributes :email
|
52
|
-
end
|
53
|
-
|
54
|
-
# confirming email
|
55
|
-
|
56
|
-
context "A registered user without email confirmation" do
|
57
|
-
setup do
|
58
|
-
@user = Factory(:registered_user)
|
59
|
-
assert ! @user.email_confirmed?
|
60
|
-
end
|
61
|
-
|
62
|
-
context "after #confirm_email!" do
|
63
|
-
setup do
|
64
|
-
assert @user.confirm_email!
|
65
|
-
@user.reload
|
66
|
-
end
|
67
|
-
|
68
|
-
should "have confirmed their email" do
|
69
|
-
assert @user.email_confirmed?
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# authenticating
|
75
|
-
|
76
|
-
context "A user" do
|
77
|
-
setup do
|
78
|
-
@user = Factory(:registered_user)
|
79
|
-
@password = @user.password
|
80
|
-
end
|
81
|
-
|
82
|
-
should "authenticate with good credentials" do
|
83
|
-
assert User.authenticate(@user.email, @password)
|
84
|
-
assert @user.authenticated?(@password)
|
85
|
-
end
|
86
|
-
|
87
|
-
should "authenticate with good credentials, email in uppercase" do
|
88
|
-
assert User.authenticate(@user.email.upcase, @password)
|
89
|
-
assert @user.authenticated?(@password)
|
90
|
-
end
|
91
|
-
|
92
|
-
should "not authenticate with bad credentials" do
|
93
|
-
assert ! User.authenticate(@user.email, 'horribly_wrong_password')
|
94
|
-
assert ! @user.authenticated?('horribly_wrong_password')
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# remember me
|
99
|
-
|
100
|
-
context "When registering with remember_me!" do
|
101
|
-
setup do
|
102
|
-
@user = Factory(:registered_user)
|
103
|
-
assert_nil @user.remember_token
|
104
|
-
assert_nil @user.remember_token_expires_at
|
105
|
-
@user.remember_me!
|
106
|
-
end
|
107
|
-
|
108
|
-
should "set the remember token and expiration date" do
|
109
|
-
assert_not_nil @user.remember_token
|
110
|
-
assert_not_nil @user.remember_token_expires_at
|
111
|
-
end
|
112
|
-
|
113
|
-
should "remember user when token expires in the future" do
|
114
|
-
@user.update_attribute :remember_token_expires_at,
|
115
|
-
2.weeks.from_now.utc
|
116
|
-
assert @user.remember?
|
117
|
-
end
|
118
|
-
|
119
|
-
should "not remember user when token has already expired" do
|
120
|
-
@user.update_attribute :remember_token_expires_at,
|
121
|
-
2.weeks.ago.utc
|
122
|
-
assert ! @user.remember?
|
123
|
-
end
|
124
|
-
|
125
|
-
# logging out
|
126
|
-
|
127
|
-
context "forget_me!" do
|
128
|
-
setup { @user.forget_me! }
|
129
|
-
|
130
|
-
should "unset the remember token and expiration date" do
|
131
|
-
assert_nil @user.remember_token
|
132
|
-
assert_nil @user.remember_token_expires_at
|
133
|
-
end
|
134
|
-
|
135
|
-
should "not remember user" do
|
136
|
-
assert ! @user.remember?
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
# updating password
|
142
|
-
|
143
|
-
context "An email confirmed user" do
|
144
|
-
setup { @user = Factory(:email_confirmed_user) }
|
145
|
-
|
146
|
-
context "who changes and confirms password" do
|
147
|
-
setup do
|
148
|
-
@user.password = "new_password"
|
149
|
-
@user.password_confirmation = "new_password"
|
150
|
-
@user.save
|
151
|
-
end
|
152
|
-
|
153
|
-
should_change "@user.encrypted_password"
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'clearance'
|
@@ -1,173 +0,0 @@
|
|
1
|
-
module Clearance
|
2
|
-
module Shoulda
|
3
|
-
|
4
|
-
# STATE OF AUTHENTICATION
|
5
|
-
|
6
|
-
def should_be_signed_in_as(&block)
|
7
|
-
should "be signed in as #{block.bind(self).call}" do
|
8
|
-
user = block.bind(self).call
|
9
|
-
assert_not_nil user,
|
10
|
-
"please pass a User. try: should_be_signed_in_as { @user }"
|
11
|
-
assert_equal user.id, session[:user_id],
|
12
|
-
"session[:user_id] is not set to User's id"
|
13
|
-
assert_equal user.salt, session[:salt],
|
14
|
-
"session[:salt] is not set to User's salt"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def should_be_signed_in_and_email_confirmed_as(&block)
|
19
|
-
should_be_signed_in_as &block
|
20
|
-
|
21
|
-
should "have confirmed email" do
|
22
|
-
user = block.bind(self).call
|
23
|
-
|
24
|
-
assert_not_nil user
|
25
|
-
assert_equal user, assigns(:user)
|
26
|
-
assert assigns(:user).email_confirmed?
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def should_not_be_signed_in
|
31
|
-
should "not be signed in" do
|
32
|
-
assert_nil session[:user_id]
|
33
|
-
assert_nil session[:salt]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def should_deny_access_on(command, opts = {})
|
38
|
-
context "on #{command}" do
|
39
|
-
setup { eval command }
|
40
|
-
should_deny_access(opts)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def should_deny_access(opts = {})
|
45
|
-
if opts[:flash]
|
46
|
-
should_set_the_flash_to opts[:flash]
|
47
|
-
else
|
48
|
-
should_not_set_the_flash
|
49
|
-
end
|
50
|
-
|
51
|
-
should "respond with 401 Unauthorized and render sign_in template" do
|
52
|
-
assert_response :unauthorized,
|
53
|
-
"access was expected to be denied (401 unauthorized)"
|
54
|
-
assert_template "sessions/new",
|
55
|
-
"template was expected to be sign in (sessions/new)"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# CONTEXTS
|
60
|
-
|
61
|
-
def signed_in_user_context(&blk)
|
62
|
-
context "A signed in user" do
|
63
|
-
setup do
|
64
|
-
@user = Factory(:registered_user)
|
65
|
-
@user.confirm_email!
|
66
|
-
sign_in_as @user
|
67
|
-
end
|
68
|
-
merge_block(&blk)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def public_context(&blk)
|
73
|
-
context "The public" do
|
74
|
-
setup { sign_out }
|
75
|
-
merge_block(&blk)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
# CREATING USERS
|
80
|
-
|
81
|
-
def should_create_user_successfully
|
82
|
-
should_assign_to :user
|
83
|
-
should_change 'User.count', :by => 1
|
84
|
-
|
85
|
-
should "send the confirmation email" do
|
86
|
-
assert_sent_email do |email|
|
87
|
-
email.subject =~ /account confirmation/i
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
should_set_the_flash_to /confirm/i
|
92
|
-
should_redirect_to_url_after_create
|
93
|
-
end
|
94
|
-
|
95
|
-
# RENDERING
|
96
|
-
|
97
|
-
def should_render_nothing
|
98
|
-
should "render nothing" do
|
99
|
-
assert @response.body.blank?
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# REDIRECTS
|
104
|
-
|
105
|
-
def should_redirect_to_url_after_create
|
106
|
-
should_redirect_to "@controller.send(:url_after_create)"
|
107
|
-
end
|
108
|
-
|
109
|
-
def should_redirect_to_url_after_update
|
110
|
-
should_redirect_to "@controller.send(:url_after_update)"
|
111
|
-
end
|
112
|
-
|
113
|
-
def should_redirect_to_url_after_destroy
|
114
|
-
should_redirect_to "@controller.send(:url_after_destroy)"
|
115
|
-
end
|
116
|
-
|
117
|
-
# VALIDATIONS
|
118
|
-
|
119
|
-
def should_validate_confirmation_of(attribute, opts = {})
|
120
|
-
raise ArgumentError if opts[:factory].nil?
|
121
|
-
|
122
|
-
context "on save" do
|
123
|
-
should_validate_confirmation_is_not_blank opts[:factory], attribute
|
124
|
-
should_validate_confirmation_is_not_bad opts[:factory], attribute
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def should_validate_confirmation_is_not_blank(factory, attribute, opts = {})
|
129
|
-
should "validate #{attribute}_confirmation is not blank" do
|
130
|
-
model = Factory.build(factory, blank_confirmation_options(attribute))
|
131
|
-
model.save
|
132
|
-
assert_confirmation_error(model, attribute,
|
133
|
-
"#{attribute}_confirmation cannot be blank")
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def should_validate_confirmation_is_not_bad(factory, attribute, opts = {})
|
138
|
-
should "validate #{attribute}_confirmation is different than #{attribute}" do
|
139
|
-
model = Factory.build(factory, bad_confirmation_options(attribute))
|
140
|
-
model.save
|
141
|
-
assert_confirmation_error(model, attribute,
|
142
|
-
"#{attribute}_confirmation cannot be different than #{attribute}")
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
module Clearance
|
150
|
-
module Shoulda
|
151
|
-
module Helpers
|
152
|
-
def blank_confirmation_options(attribute)
|
153
|
-
opts = { attribute => attribute.to_s }
|
154
|
-
opts.merge("#{attribute}_confirmation".to_sym => "")
|
155
|
-
end
|
156
|
-
|
157
|
-
def bad_confirmation_options(attribute)
|
158
|
-
opts = { attribute => attribute.to_s }
|
159
|
-
opts.merge("#{attribute}_confirmation".to_sym => "not_#{attribute}")
|
160
|
-
end
|
161
|
-
|
162
|
-
def assert_confirmation_error(model, attribute, message = "confirmation error")
|
163
|
-
assert model.errors.on(attribute).include?("doesn't match confirmation"),
|
164
|
-
message
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
class Test::Unit::TestCase
|
171
|
-
include Clearance::Shoulda::Helpers
|
172
|
-
end
|
173
|
-
Test::Unit::TestCase.extend(Clearance::Shoulda)
|