Skip to content

Commit 06025c6

Browse files
committed
Refactoring authentications controller
1 parent 8a5f8d0 commit 06025c6

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

volume/blog-backend/spec/requests/authentication_request_spec.rb

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@
55
let!(:user) { create :user }
66

77
context 'When receive matching username and password' do
8-
before do
9-
post '/auth/login', params: { username: user.username, password: user.password }
10-
end
8+
before { post '/auth/login', params: { username: user.username, password: user.password } }
119

12-
it 'responds :created' do
13-
expect(response).to have_http_status(:ok)
14-
end
10+
it { expect(response).to have_http_status(:ok) }
1511

1612
it "responds with user's username" do
1713
json_response = JSON.parse(response.body)
@@ -33,30 +29,21 @@
3329

3430
context 'When receive NOT matching username and password' do
3531
context 'when invalid username and password' do
36-
before do
37-
post '/auth/login', params: { username: 'invalid username', password: 'invalid passowrd' }
38-
end
39-
it 'responds :unauthorized' do
40-
expect(response).to have_http_status(:unauthorized)
41-
end
32+
before { post '/auth/login', params: { username: 'invalid username', password: 'invalid passowrd' } }
33+
34+
it { expect(response).to have_http_status(:unauthorized) }
4235
end
4336

4437
context 'when valid username and invalid password' do
45-
before do
46-
post '/auth/login', params: { username: user.username, password: 'invalid passowrd' }
47-
end
48-
it 'responds :unauthorized' do
49-
expect(response).to have_http_status(:unauthorized)
50-
end
38+
before { post '/auth/login', params: { username: user.username, password: 'invalid passowrd' } }
39+
40+
it { expect(response).to have_http_status(:unauthorized) }
5141
end
5242

5343
context 'when invalid username and valid password' do
54-
before do
55-
post '/auth/login', params: { username: 'invalid username', password: user.password }
56-
end
57-
it 'responds :unauthorized' do
58-
expect(response).to have_http_status(:unauthorized)
59-
end
44+
before { post '/auth/login', params: { username: 'invalid username', password: user.password } }
45+
46+
it { expect(response).to have_http_status(:unauthorized) }
6047
end
6148
end
6249
end

0 commit comments

Comments
 (0)