clearance 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of clearance might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +1 -3
- data/Gemfile.lock +4 -28
- data/NEWS.md +12 -0
- data/README.md +8 -1
- data/Rakefile +11 -8
- data/app/controllers/clearance/passwords_controller.rb +1 -0
- data/app/controllers/clearance/sessions_controller.rb +14 -2
- data/app/controllers/clearance/users_controller.rb +15 -4
- data/bin/appraisal +16 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/clearance.gemspec +1 -1
- data/gemfiles/rails3.2.gemfile +1 -3
- data/gemfiles/rails4.0.gemfile +1 -3
- data/gemfiles/rails4.1.gemfile +1 -3
- data/gemfiles/rails4.2.gemfile +1 -3
- data/lib/clearance/configuration.rb +2 -0
- data/lib/clearance/session.rb +12 -6
- data/lib/clearance/version.rb +1 -1
- data/spec/acceptance/clearance_installation_spec.rb +75 -0
- data/spec/{support/app_templates → app_templates}/app/controllers/application_controller.rb +0 -0
- data/spec/{support/app_templates → app_templates}/app/models/user.rb +0 -0
- data/spec/{support/app_templates → app_templates}/config/routes.rb +0 -0
- data/spec/app_templates/testapp/Gemfile +7 -0
- data/spec/app_templates/testapp/app/controllers/home_controller.rb +5 -0
- data/spec/app_templates/testapp/config/initializers/action_mailer.rb +3 -0
- data/spec/app_templates/testapp/config/routes.rb +3 -0
- data/spec/clearance/session_spec.rb +13 -0
- data/spec/controllers/passwords_controller_spec.rb +100 -131
- data/spec/controllers/sessions_controller_spec.rb +66 -52
- data/spec/controllers/users_controller_spec.rb +47 -60
- data/spec/dummy/app/models/user.rb +3 -0
- data/spec/dummy/app/models/user_with_optional_password.rb +7 -0
- data/spec/dummy/application.rb +2 -0
- data/spec/factories.rb +4 -0
- data/spec/{models → password_strategies}/bcrypt_migration_from_sha1_spec.rb +1 -0
- data/spec/password_strategies/bcrypt_spec.rb +81 -0
- data/spec/password_strategies/blowfish_spec.rb +55 -0
- data/spec/password_strategies/password_strategies_spec.rb +28 -0
- data/spec/password_strategies/sha1_spec.rb +53 -0
- data/spec/support/clearance.rb +0 -16
- data/spec/support/fake_model_with_password_strategy.rb +0 -4
- data/spec/support/fake_model_without_password_strategy.rb +19 -0
- data/spec/support/generator_spec_helpers.rb +1 -1
- data/spec/support/request_with_remember_token.rb +1 -1
- data/spec/user_spec.rb +186 -0
- metadata +23 -67
- data/cucumber.yml +0 -1
- data/features/integration_with_rspec.feature +0 -23
- data/features/integration_with_test_unit.feature +0 -16
- data/features/step_definitions/configuration_steps.rb +0 -153
- data/features/step_definitions/gem_file_steps.rb +0 -15
- data/features/support/aruba.rb +0 -3
- data/features/support/env.rb +0 -27
- data/spec/models/bcrypt_spec.rb +0 -66
- data/spec/models/blowfish_spec.rb +0 -42
- data/spec/models/password_strategies_spec.rb +0 -41
- data/spec/models/sha1_spec.rb +0 -43
- data/spec/models/user_spec.rb +0 -196
@@ -3,7 +3,7 @@ require "ammeter/rspec/generator/matchers.rb"
|
|
3
3
|
require "ammeter/init"
|
4
4
|
|
5
5
|
module GeneratorSpecHelpers
|
6
|
-
TEMPLATE_PATH = File.expand_path("
|
6
|
+
TEMPLATE_PATH = File.expand_path("../../app_templates", __FILE__)
|
7
7
|
|
8
8
|
def provide_existing_routes_file
|
9
9
|
copy_to_generator_root("config", "routes.rb")
|
@@ -2,7 +2,7 @@ module RememberTokenHelpers
|
|
2
2
|
def request_with_remember_token(remember_token)
|
3
3
|
cookies = {
|
4
4
|
'action_dispatch.cookies' => {
|
5
|
-
Clearance
|
5
|
+
Clearance.configuration.cookie_name => remember_token
|
6
6
|
}
|
7
7
|
}
|
8
8
|
env = { clearance: Clearance::Session.new(cookies) }
|
data/spec/user_spec.rb
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe User do
|
4
|
+
it { is_expected.to have_db_index(:email) }
|
5
|
+
it { is_expected.to have_db_index(:remember_token) }
|
6
|
+
it { is_expected.to validate_presence_of(:email) }
|
7
|
+
it { is_expected.to validate_presence_of(:password) }
|
8
|
+
it { is_expected.to allow_value("foo@example.co.uk").for(:email) }
|
9
|
+
it { is_expected.to allow_value("foo@example.com").for(:email) }
|
10
|
+
it { is_expected.to allow_value("foo+bar@example.com").for(:email) }
|
11
|
+
it { is_expected.not_to allow_value("foo@").for(:email) }
|
12
|
+
it { is_expected.not_to allow_value("foo@example..com").for(:email) }
|
13
|
+
it { is_expected.not_to allow_value("foo@.example.com").for(:email) }
|
14
|
+
it { is_expected.not_to allow_value("foo").for(:email) }
|
15
|
+
it { is_expected.not_to allow_value("example.com").for(:email) }
|
16
|
+
it { is_expected.not_to allow_value("foo;@example.com").for(:email) }
|
17
|
+
|
18
|
+
describe "#email" do
|
19
|
+
it "stores email in down case and removes whitespace" do
|
20
|
+
user = create(:user, email: "Jo hn.Do e @exa mp le.c om")
|
21
|
+
|
22
|
+
expect(user.email).to eq "john.doe@example.com"
|
23
|
+
end
|
24
|
+
|
25
|
+
subject { create(:user) }
|
26
|
+
it { is_expected.to validate_uniqueness_of(:email) }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe ".authenticate" do
|
30
|
+
it "is authenticated with correct email and password" do
|
31
|
+
user = create(:user)
|
32
|
+
password = user.password
|
33
|
+
|
34
|
+
expect(User.authenticate(user.email, password)).to eq(user)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "is authenticated with correct uppercased email and correct password" do
|
38
|
+
user = create(:user)
|
39
|
+
password = user.password
|
40
|
+
|
41
|
+
expect(User.authenticate(user.email.upcase, password)).to eq(user)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "is not authenticated with incorrect credentials" do
|
45
|
+
user = create(:user)
|
46
|
+
|
47
|
+
expect(User.authenticate(user.email, "bad_password")).to be_nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it "is retrieved via a case-insensitive search" do
|
51
|
+
user = create(:user)
|
52
|
+
|
53
|
+
expect(User.find_by_normalized_email(user.email.upcase)).to eq(user)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe ".reset_remember_token" do
|
58
|
+
context "when resetting authentication with reset_remember_token!" do
|
59
|
+
it "changes the remember token" do
|
60
|
+
old_token = "old_token"
|
61
|
+
user = create(:user, remember_token: old_token)
|
62
|
+
|
63
|
+
user.reset_remember_token!
|
64
|
+
|
65
|
+
expect(user.remember_token).not_to eq old_token
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#update_password" do
|
71
|
+
context "with a valid password" do
|
72
|
+
it "changes the encrypted password" do
|
73
|
+
user = create(:user, :with_forgotten_password)
|
74
|
+
old_encrypted_password = user.encrypted_password
|
75
|
+
|
76
|
+
user.update_password("new_password")
|
77
|
+
|
78
|
+
expect(user.encrypted_password).not_to eq old_encrypted_password
|
79
|
+
end
|
80
|
+
|
81
|
+
it "clears the confirmation token" do
|
82
|
+
user = create(:user, :with_forgotten_password)
|
83
|
+
|
84
|
+
user.update_password("new_password")
|
85
|
+
|
86
|
+
expect(user.confirmation_token).to be_nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "with blank password" do
|
91
|
+
it "does not change the encrypted password" do
|
92
|
+
user = create(:user, :with_forgotten_password)
|
93
|
+
old_encrypted_password = user.encrypted_password
|
94
|
+
|
95
|
+
user.update_password("")
|
96
|
+
|
97
|
+
expect(user.encrypted_password.to_s).to eq old_encrypted_password
|
98
|
+
end
|
99
|
+
|
100
|
+
it "does not clear the confirmation token" do
|
101
|
+
user = create(:user, :with_forgotten_password)
|
102
|
+
|
103
|
+
user.update_password("")
|
104
|
+
|
105
|
+
expect(user.confirmation_token).not_to be_nil
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "before_create callbacks" do
|
111
|
+
describe "#generate_remember_token" do
|
112
|
+
it "does not generate same remember token for users with same password" do
|
113
|
+
allow(Time).to receive(:now).and_return(Time.now)
|
114
|
+
password = "secret"
|
115
|
+
first_user = create(:user, password: password)
|
116
|
+
second_user = create(:user, password: password)
|
117
|
+
|
118
|
+
expect(second_user.remember_token).not_to eq first_user.remember_token
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "#forgot_password!" do
|
124
|
+
it "generates the confirmation token" do
|
125
|
+
user = create(:user, confirmation_token: nil)
|
126
|
+
|
127
|
+
user.forgot_password!
|
128
|
+
|
129
|
+
expect(user.confirmation_token).not_to be_nil
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "a user with an optional email" do
|
134
|
+
subject { user }
|
135
|
+
|
136
|
+
it { is_expected.to allow_value(nil).for(:email) }
|
137
|
+
it { is_expected.to allow_value("").for(:email) }
|
138
|
+
|
139
|
+
def user
|
140
|
+
@user ||= User.new
|
141
|
+
allow(@user).to receive(:email_optional?).and_return(true)
|
142
|
+
@user
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "user factory" do
|
147
|
+
it "should create a valid user with just an overridden password" do
|
148
|
+
expect(build(:user, password: "test")).to be_valid
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "email address normalization" do
|
153
|
+
it "downcases the address and strips spaces" do
|
154
|
+
email = "Jo hn.Do e @exa mp le.c om"
|
155
|
+
|
156
|
+
expect(User.normalize_email(email)).to eq "john.doe@example.com"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "the password setter on a User" do
|
161
|
+
it "sets password to the plain-text password" do
|
162
|
+
password = "password"
|
163
|
+
subject.send(:password=, password)
|
164
|
+
|
165
|
+
expect(subject.password).to eq password
|
166
|
+
end
|
167
|
+
|
168
|
+
it "also sets encrypted_password" do
|
169
|
+
password = "password"
|
170
|
+
subject.send(:password=, password)
|
171
|
+
|
172
|
+
expect(subject.encrypted_password).to_not be_nil
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe UserWithOptionalPassword do
|
178
|
+
it { is_expected.to allow_value(nil).for(:password) }
|
179
|
+
it { is_expected.to allow_value("").for(:password) }
|
180
|
+
|
181
|
+
it "cannot authenticate with blank password" do
|
182
|
+
user = create(:user_with_optional_password)
|
183
|
+
|
184
|
+
expect(UserWithOptionalPassword.authenticate(user.email, "")).to be_nil
|
185
|
+
end
|
186
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clearance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Croak
|
@@ -25,7 +25,7 @@ authors:
|
|
25
25
|
autorequire:
|
26
26
|
bindir: bin
|
27
27
|
cert_chain: []
|
28
|
-
date: 2015-01-
|
28
|
+
date: 2015-01-23 00:00:00.000000000 Z
|
29
29
|
dependencies:
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bcrypt
|
@@ -101,19 +101,15 @@ files:
|
|
101
101
|
- app/views/sessions/new.html.erb
|
102
102
|
- app/views/users/_form.html.erb
|
103
103
|
- app/views/users/new.html.erb
|
104
|
+
- bin/appraisal
|
105
|
+
- bin/rake
|
106
|
+
- bin/rspec
|
104
107
|
- bin/setup
|
105
108
|
- clearance.gemspec
|
106
109
|
- config/locales/clearance.en.yml
|
107
110
|
- config/routes.rb
|
108
|
-
- cucumber.yml
|
109
111
|
- db/migrate/20110111224543_create_clearance_users.rb
|
110
112
|
- db/schema.rb
|
111
|
-
- features/integration_with_rspec.feature
|
112
|
-
- features/integration_with_test_unit.feature
|
113
|
-
- features/step_definitions/configuration_steps.rb
|
114
|
-
- features/step_definitions/gem_file_steps.rb
|
115
|
-
- features/support/aruba.rb
|
116
|
-
- features/support/env.rb
|
117
113
|
- gemfiles/rails3.2.gemfile
|
118
114
|
- gemfiles/rails4.0.gemfile
|
119
115
|
- gemfiles/rails4.1.gemfile
|
@@ -166,6 +162,14 @@ files:
|
|
166
162
|
- lib/generators/clearance/specs/templates/support/features/clearance_helpers.rb
|
167
163
|
- lib/generators/clearance/views/USAGE
|
168
164
|
- lib/generators/clearance/views/views_generator.rb
|
165
|
+
- spec/acceptance/clearance_installation_spec.rb
|
166
|
+
- spec/app_templates/app/controllers/application_controller.rb
|
167
|
+
- spec/app_templates/app/models/user.rb
|
168
|
+
- spec/app_templates/config/routes.rb
|
169
|
+
- spec/app_templates/testapp/Gemfile
|
170
|
+
- spec/app_templates/testapp/app/controllers/home_controller.rb
|
171
|
+
- spec/app_templates/testapp/config/initializers/action_mailer.rb
|
172
|
+
- spec/app_templates/testapp/config/routes.rb
|
169
173
|
- spec/clearance/back_door_spec.rb
|
170
174
|
- spec/clearance/constraints/signed_in_spec.rb
|
171
175
|
- spec/clearance/constraints/signed_out_spec.rb
|
@@ -183,6 +187,8 @@ files:
|
|
183
187
|
- spec/controllers/sessions_controller_spec.rb
|
184
188
|
- spec/controllers/users_controller_spec.rb
|
185
189
|
- spec/dummy/app/controllers/application_controller.rb
|
190
|
+
- spec/dummy/app/models/user.rb
|
191
|
+
- spec/dummy/app/models/user_with_optional_password.rb
|
186
192
|
- spec/dummy/application.rb
|
187
193
|
- spec/dummy/config/database.yml
|
188
194
|
- spec/dummy/config/routes.rb
|
@@ -192,22 +198,20 @@ files:
|
|
192
198
|
- spec/generators/clearance/specs/specs_generator_spec.rb
|
193
199
|
- spec/generators/clearance/views/views_generator_spec.rb
|
194
200
|
- spec/mailers/clearance_mailer_spec.rb
|
195
|
-
- spec/
|
196
|
-
- spec/
|
197
|
-
- spec/
|
198
|
-
- spec/
|
199
|
-
- spec/
|
200
|
-
- spec/models/user_spec.rb
|
201
|
+
- spec/password_strategies/bcrypt_migration_from_sha1_spec.rb
|
202
|
+
- spec/password_strategies/bcrypt_spec.rb
|
203
|
+
- spec/password_strategies/blowfish_spec.rb
|
204
|
+
- spec/password_strategies/password_strategies_spec.rb
|
205
|
+
- spec/password_strategies/sha1_spec.rb
|
201
206
|
- spec/routing/clearance_routes_spec.rb
|
202
207
|
- spec/spec_helper.rb
|
203
|
-
- spec/support/app_templates/app/controllers/application_controller.rb
|
204
|
-
- spec/support/app_templates/app/models/user.rb
|
205
|
-
- spec/support/app_templates/config/routes.rb
|
206
208
|
- spec/support/clearance.rb
|
207
209
|
- spec/support/cookies.rb
|
208
210
|
- spec/support/fake_model_with_password_strategy.rb
|
211
|
+
- spec/support/fake_model_without_password_strategy.rb
|
209
212
|
- spec/support/generator_spec_helpers.rb
|
210
213
|
- spec/support/request_with_remember_token.rb
|
214
|
+
- spec/user_spec.rb
|
211
215
|
homepage: http://github.com/thoughtbot/clearance
|
212
216
|
licenses:
|
213
217
|
- MIT
|
@@ -233,52 +237,4 @@ rubygems_version: 2.4.5
|
|
233
237
|
signing_key:
|
234
238
|
specification_version: 4
|
235
239
|
summary: Rails authentication & authorization with email & password.
|
236
|
-
test_files:
|
237
|
-
- features/integration_with_rspec.feature
|
238
|
-
- features/integration_with_test_unit.feature
|
239
|
-
- features/step_definitions/configuration_steps.rb
|
240
|
-
- features/step_definitions/gem_file_steps.rb
|
241
|
-
- features/support/aruba.rb
|
242
|
-
- features/support/env.rb
|
243
|
-
- spec/clearance/back_door_spec.rb
|
244
|
-
- spec/clearance/constraints/signed_in_spec.rb
|
245
|
-
- spec/clearance/constraints/signed_out_spec.rb
|
246
|
-
- spec/clearance/default_sign_in_guard_spec.rb
|
247
|
-
- spec/clearance/rack_session_spec.rb
|
248
|
-
- spec/clearance/session_spec.rb
|
249
|
-
- spec/clearance/sign_in_guard_spec.rb
|
250
|
-
- spec/clearance/testing/helpers_spec.rb
|
251
|
-
- spec/clearance/token_spec.rb
|
252
|
-
- spec/configuration_spec.rb
|
253
|
-
- spec/controllers/apis_controller_spec.rb
|
254
|
-
- spec/controllers/forgeries_controller_spec.rb
|
255
|
-
- spec/controllers/passwords_controller_spec.rb
|
256
|
-
- spec/controllers/permissions_controller_spec.rb
|
257
|
-
- spec/controllers/sessions_controller_spec.rb
|
258
|
-
- spec/controllers/users_controller_spec.rb
|
259
|
-
- spec/dummy/app/controllers/application_controller.rb
|
260
|
-
- spec/dummy/application.rb
|
261
|
-
- spec/dummy/config/database.yml
|
262
|
-
- spec/dummy/config/routes.rb
|
263
|
-
- spec/factories.rb
|
264
|
-
- spec/generators/clearance/install/install_generator_spec.rb
|
265
|
-
- spec/generators/clearance/routes/routes_generator_spec.rb
|
266
|
-
- spec/generators/clearance/specs/specs_generator_spec.rb
|
267
|
-
- spec/generators/clearance/views/views_generator_spec.rb
|
268
|
-
- spec/mailers/clearance_mailer_spec.rb
|
269
|
-
- spec/models/bcrypt_migration_from_sha1_spec.rb
|
270
|
-
- spec/models/bcrypt_spec.rb
|
271
|
-
- spec/models/blowfish_spec.rb
|
272
|
-
- spec/models/password_strategies_spec.rb
|
273
|
-
- spec/models/sha1_spec.rb
|
274
|
-
- spec/models/user_spec.rb
|
275
|
-
- spec/routing/clearance_routes_spec.rb
|
276
|
-
- spec/spec_helper.rb
|
277
|
-
- spec/support/app_templates/app/controllers/application_controller.rb
|
278
|
-
- spec/support/app_templates/app/models/user.rb
|
279
|
-
- spec/support/app_templates/config/routes.rb
|
280
|
-
- spec/support/clearance.rb
|
281
|
-
- spec/support/cookies.rb
|
282
|
-
- spec/support/fake_model_with_password_strategy.rb
|
283
|
-
- spec/support/generator_spec_helpers.rb
|
284
|
-
- spec/support/request_with_remember_token.rb
|
240
|
+
test_files: []
|
data/cucumber.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
default: -r features
|
@@ -1,23 +0,0 @@
|
|
1
|
-
Feature: generate rspec integration tests with application
|
2
|
-
|
3
|
-
Background:
|
4
|
-
Given I have a project with clearance and the following gems:
|
5
|
-
| gem |
|
6
|
-
| capybara |
|
7
|
-
| rspec-rails |
|
8
|
-
| factory_girl_rails |
|
9
|
-
| database_cleaner |
|
10
|
-
| test-unit |
|
11
|
-
|
12
|
-
Scenario: generate a Rails app, run the generators, and run the tests
|
13
|
-
When I install dependencies
|
14
|
-
And I successfully run `bundle exec rails generate rspec:install`
|
15
|
-
And I successfully run `bundle exec rails generate clearance:specs`
|
16
|
-
And I successfully run `bundle exec rails generate clearance:install`
|
17
|
-
Then the output should contain "Next steps"
|
18
|
-
When I successfully run `bundle exec rake db:migrate`
|
19
|
-
And I successfully run `bundle exec rake db:test:prepare`
|
20
|
-
And I successfully run `bundle exec rspec`
|
21
|
-
Then the output should contain "Finished"
|
22
|
-
And the output should not contain "Failed examples"
|
23
|
-
And the output should not contain "Could not find generator"
|
@@ -1,16 +0,0 @@
|
|
1
|
-
Feature: integrate with test-unit
|
2
|
-
|
3
|
-
Background:
|
4
|
-
Given I have a project with clearance and the following gems:
|
5
|
-
| gem |
|
6
|
-
| factory_girl_rails |
|
7
|
-
| cucumber-rails |
|
8
|
-
|
9
|
-
Scenario: generate a Rails app, run the generators, and run the tests
|
10
|
-
When I install dependencies
|
11
|
-
And I successfully run `bundle exec rails generate clearance:install`
|
12
|
-
And I successfully run `bundle exec rake db:migrate`
|
13
|
-
And I successfully run `bundle exec rails generate controller posts index`
|
14
|
-
And I configure test-unit
|
15
|
-
And I successfully run `bundle exec rake`
|
16
|
-
Then the output should match /1 (tests|runs).+1 assertions/
|
@@ -1,153 +0,0 @@
|
|
1
|
-
When /^I install dependencies$/ do
|
2
|
-
step "I successfully run `bundle install --local`"
|
3
|
-
end
|
4
|
-
|
5
|
-
When "I have a project with clearance and the following gems:" do |table|
|
6
|
-
step "I have a project with clearance"
|
7
|
-
|
8
|
-
table.rows.flatten.each do |gem|
|
9
|
-
step %Q{I add the "#{gem}" gem}
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
When "I have a project with clearance" do
|
14
|
-
Bundler.with_original_env do
|
15
|
-
step "I successfully run `bundle exec rails new testapp --skip-bundle --skip-javascript --skip-sprockets`"
|
16
|
-
end
|
17
|
-
|
18
|
-
step 'I cd to "testapp"'
|
19
|
-
|
20
|
-
unless Dummy.rails4?
|
21
|
-
step 'I remove the file "public/index.html"'
|
22
|
-
end
|
23
|
-
|
24
|
-
steps %Q{
|
25
|
-
And I remove the file "app/views/layouts/application.html.erb"
|
26
|
-
And I configure ActionMailer to use "localhost" as a host
|
27
|
-
And I configure a root route
|
28
|
-
And I remove the "turn" gem from this project
|
29
|
-
And I remove the "web-console" gem from this project
|
30
|
-
And I remove the "jbuilder" gem from this project
|
31
|
-
And I remove the "sdoc" gem from this project
|
32
|
-
And I remove the "byebug" gem from this project
|
33
|
-
And I remove the "debugger" gem from this project
|
34
|
-
And I remove the "spring" gem from this project
|
35
|
-
And I add the "clearance" gem from this project
|
36
|
-
}
|
37
|
-
end
|
38
|
-
|
39
|
-
When /^I configure ActionMailer to use "([^"]+)" as a host$/ do |host|
|
40
|
-
mailer_config = "config.action_mailer.default_url_options = { host: '#{host}' }"
|
41
|
-
path = 'config/application.rb'
|
42
|
-
|
43
|
-
in_current_dir do
|
44
|
-
contents = IO.read(path)
|
45
|
-
contents.sub!(/(class .* < Rails::Application)/, "\\1\n#{mailer_config}")
|
46
|
-
File.open(path, "w") { |file| file.write(contents) }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
When /^I configure a root route$/ do
|
51
|
-
route = "root to: 'home#show'"
|
52
|
-
path = 'config/routes.rb'
|
53
|
-
|
54
|
-
in_current_dir do
|
55
|
-
contents = IO.read(path)
|
56
|
-
contents.sub!(/(\.routes\.draw do)/, "\\1\n#{route}\n")
|
57
|
-
File.open(path, 'w') { |file| file.write(contents) }
|
58
|
-
end
|
59
|
-
|
60
|
-
write_file('app/controllers/home_controller.rb', <<-CONTROLLER)
|
61
|
-
class HomeController < ApplicationController
|
62
|
-
def show
|
63
|
-
render text: '', layout: 'application'
|
64
|
-
end
|
65
|
-
end
|
66
|
-
CONTROLLER
|
67
|
-
end
|
68
|
-
|
69
|
-
When /^I configure test-unit$/ do
|
70
|
-
factories_path = File.join(
|
71
|
-
'lib', 'generators', 'clearance', 'specs', 'templates', 'factories',
|
72
|
-
'clearance.rb'
|
73
|
-
)
|
74
|
-
steps %Q{
|
75
|
-
When I append to "test/test_helper.rb" with:
|
76
|
-
"""
|
77
|
-
require 'clearance/test_unit'
|
78
|
-
"""
|
79
|
-
And I overwrite "test/#{controller_test_dir}/posts_controller_test.rb" with:
|
80
|
-
"""
|
81
|
-
require 'test_helper'
|
82
|
-
|
83
|
-
class PostsControllerTest < ActionController::TestCase
|
84
|
-
test 'should get index' do
|
85
|
-
sign_in
|
86
|
-
get :index
|
87
|
-
assert_response :success
|
88
|
-
end
|
89
|
-
end
|
90
|
-
"""
|
91
|
-
And I write to "test/factories.rb" with:
|
92
|
-
"""
|
93
|
-
#{File.read(factories_path)}
|
94
|
-
"""
|
95
|
-
}
|
96
|
-
end
|
97
|
-
|
98
|
-
When /^I create a simple user model$/ do
|
99
|
-
steps %Q{
|
100
|
-
When I successfully run `rails generate model user email:string name:string`
|
101
|
-
And I successfully run `bundle exec rake db:migrate`
|
102
|
-
}
|
103
|
-
end
|
104
|
-
|
105
|
-
When /^I add an existing user$/ do
|
106
|
-
command = %q{rails runner "User.create!(email: 'a@b.com', name: 'foo')"}
|
107
|
-
|
108
|
-
steps %Q{
|
109
|
-
When I successfully run `#{command}`
|
110
|
-
}
|
111
|
-
end
|
112
|
-
|
113
|
-
When /existing user should have a remember token$/ do
|
114
|
-
command = 'rails runner "exit(1) unless User.first.remember_token"'
|
115
|
-
|
116
|
-
steps %Q{
|
117
|
-
When I successfully run `#{command}`
|
118
|
-
}
|
119
|
-
end
|
120
|
-
|
121
|
-
When /^I create a migration with clearance fields$/ do
|
122
|
-
steps %Q{
|
123
|
-
When I write to "db/migrate/001_create_users.rb" with:
|
124
|
-
"""
|
125
|
-
class CreateUsers < ActiveRecord::Migration
|
126
|
-
def self.up
|
127
|
-
create_table :users do |t|
|
128
|
-
t.timestamps null: false
|
129
|
-
t.string :email, null: false
|
130
|
-
t.string :encrypted_password, limit: 128, null: false
|
131
|
-
t.string :confirmation_token, limit: 128
|
132
|
-
t.string :remember_token, limit: 128, null: false
|
133
|
-
end
|
134
|
-
|
135
|
-
add_index :users, :email
|
136
|
-
add_index :users, :remember_token
|
137
|
-
end
|
138
|
-
|
139
|
-
def self.down
|
140
|
-
drop_table :users
|
141
|
-
end
|
142
|
-
end
|
143
|
-
"""
|
144
|
-
}
|
145
|
-
end
|
146
|
-
|
147
|
-
def controller_test_dir
|
148
|
-
if Dummy.rails4?
|
149
|
-
'controllers'
|
150
|
-
else
|
151
|
-
'functional'
|
152
|
-
end
|
153
|
-
end
|