Skip to content

Commit 6f714df

Browse files
committed
Improve code design after code review
1 parent 2749e7a commit 6f714df

File tree

11 files changed

+24
-21
lines changed

11 files changed

+24
-21
lines changed

app/controllers/profiles/chat_names_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def create
1313
new_chat_name = current_user.chat_names.new(chat_name_params)
1414

1515
if new_chat_name.save
16-
flash[:notice] = "Authorized chat nickname #{new_chat_name.chat_name}"
16+
flash[:notice] = "Authorized #{new_chat_name.chat_name}"
1717
else
1818
flash[:alert] = "Could not authorize chat nickname. Try again!"
1919
end
@@ -34,7 +34,7 @@ def destroy
3434
@chat_name = chat_names.find(params[:id])
3535

3636
if @chat_name.destroy
37-
flash[:notice] = "Delete chat nickname: #{@chat_name.chat_name}!"
37+
flash[:notice] = "Deleted chat nickname: #{@chat_name.chat_name}!"
3838
else
3939
flash[:alert] = "Could not delete chat nickname #{@chat_name.chat_name}."
4040
end

app/services/chat_names/find_user_service.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def execute
99
chat_name = find_chat_name
1010
return unless chat_name
1111

12-
chat_name.update(used_at: Time.now)
12+
chat_name.update(last_used_at: Time.now)
1313
chat_name.user
1414
end
1515

app/views/profiles/chat_names/index.html.haml

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
%h4.prepend-top-0
77
= page_title
88
%p
9-
You can see your Chat integrations.
9+
You can see your Chat accounts.
1010

1111
.col-lg-9
1212
%h5 Active chat names (#{@chat_names.length})
@@ -39,11 +39,13 @@
3939
= link_to service.title, edit_namespace_project_service_path(project.namespace, project, service)
4040
- else
4141
= chat_name.service.title
42-
%td= chat_name.team_domain
43-
%td= chat_name.chat_name
44-
%td=
45-
- if chat_name.used_at
46-
time_ago_with_tooltip(chat_name.used_at)
42+
%td
43+
= chat_name.team_domain
44+
%td
45+
= chat_name.chat_name
46+
%td
47+
- if chat_name.last_used_at
48+
time_ago_with_tooltip(chat_name.last_used_at)
4749
- else
4850
Never
4951

app/views/profiles/chat_names/new.html.haml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
%h3.page-title Authorization required
22
%main{:role => "main"}
33
%p.h4
4-
Authorize the chat user
4+
Authorize
55
%strong.text-info= @chat_name_params[:chat_name]
66
to use your account?
77

8-
%hr/
8+
%hr
99
.actions
1010
= form_tag profile_chat_names_path, method: :post do
1111
= hidden_field_tag :token, @chat_name_token.token

db/migrate/20161113184239_create_user_chat_names_table.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def change
1111
t.string :team_domain
1212
t.string :chat_id, null: false
1313
t.string :chat_name
14-
t.datetime :used_at
14+
t.datetime :last_used_at
1515
t.timestamps null: false
1616
end
1717

db/schema.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
t.string "team_domain"
160160
t.string "chat_id", null: false
161161
t.string "chat_name"
162-
t.datetime "used_at"
162+
t.datetime "last_used_at"
163163
t.datetime "created_at", null: false
164164
t.datetime "updated_at", null: false
165165
end

lib/gitlab/chat_name_token.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class ChatNameToken
55
attr_reader :token
66

77
TOKEN_LENGTH = 50
8-
EXPIRY_TIME = 10.minutes # 10 minutes
8+
EXPIRY_TIME = 10.minutes
99

1010
def initialize(token = new_token)
1111
@token = token

spec/lib/gitlab/chat_name_token_spec.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
end
1313

1414
context 'when storing data' do
15-
let(:data) {
16-
{ key: 'value' }
17-
}
15+
let(:data) { { key: 'value' } }
1816

1917
subject { described_class.new(@token) }
2018

spec/services/chat_names/authorize_user_service_spec.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
let(:params) { { team_id: 'T0001', team_domain: 'myteam', user_id: 'U0001', user_name: 'user' } }
1111

1212
it 'requests a new token' do
13-
is_expected.to include('http')
14-
is_expected.to include('://')
15-
is_expected.to include('token=')
13+
is_expected.to be_url
1614
end
1715
end
1816

spec/services/chat_names/find_user_service_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
it 'updates when last time chat name was used' do
2121
subject
2222

23-
expect(chat_name.reload.used_at).to be_like_time(Time.now)
23+
expect(chat_name.reload.last_used_at).to be_like_time(Time.now)
2424
end
2525
end
2626

spec/support/matchers/be_url.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RSpec::Matchers.define :be_url do |_|
2+
match do |actual|
3+
URI.parse(actual) rescue false
4+
end
5+
end

0 commit comments

Comments
 (0)