FIX: add translations and check for message and if assignment is successful in spec (#22)

This commit is contained in:
Saurabh Patel 2018-12-06 14:04:31 +07:00 committed by Sam
parent a2e7fc4cac
commit b20b4c088d
3 changed files with 7 additions and 3 deletions

View File

@ -63,7 +63,7 @@ module DiscourseAssign
raise Discourse::NotFound unless assign_to raise Discourse::NotFound unless assign_to
if topic.custom_fields && topic.custom_fields['assigned_to_id'] == assign_to.id.to_s if topic.custom_fields && topic.custom_fields['assigned_to_id'] == assign_to.id.to_s
return render json: { failed: 'Already assigned to the user' }, status: 400 return render json: { failed: I18n.t('discourse_assign.already_assigned', username: username) }, status: 400
end end
assigner = TopicAssigner.new(topic, current_user) assigner = TopicAssigner.new(topic, current_user)

View File

@ -16,6 +16,7 @@ en:
assigned_to: "Topic assigned to @%{username}" assigned_to: "Topic assigned to @%{username}"
unassigned: "Topic was unassigned" unassigned: "Topic was unassigned"
already_claimed: "That topic has already been claimed." already_claimed: "That topic has already been claimed."
already_assigned: 'Topic is already assigned to @%{username}'
flag_assigned: "Sorry, that flag's topic is assigned to another user" flag_assigned: "Sorry, that flag's topic is assigned to another user"
flag_unclaimed: "You must claim that topic before acting on the flag" flag_unclaimed: "You must claim that topic before acting on the flag"
topic_assigned_excerpt: "assigned you the topic '%{title}'" topic_assigned_excerpt: "assigned you the topic '%{title}'"

View File

@ -6,16 +6,17 @@ RSpec.describe DiscourseAssign::AssignController do
let(:post) { Fabricate(:post) } let(:post) { Fabricate(:post) }
let(:user2) { Fabricate(:active_user) } let(:user2) { Fabricate(:active_user) }
context 'assign' do context '#assign' do
it 'assigns topic to a user' do it 'assigns topic to a user' do
sign_in(user) sign_in(user)
put '/assign/assign', params: { put '/assign/assign.json', params: {
topic_id: post.topic_id, username: user2.username topic_id: post.topic_id, username: user2.username
} }
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(post.topic.reload.custom_fields['assigned_to_id']).to eq(user2.id.to_s)
end end
it 'fails to assign topic to the user if its already assigned to the same user' do it 'fails to assign topic to the user if its already assigned to the same user' do
@ -26,12 +27,14 @@ RSpec.describe DiscourseAssign::AssignController do
} }
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(post.topic.reload.custom_fields['assigned_to_id']).to eq(user2.id.to_s)
put '/assign/assign.json', params: { put '/assign/assign.json', params: {
topic_id: post.topic_id, username: user2.username topic_id: post.topic_id, username: user2.username
} }
expect(response.status).to eq(400) expect(response.status).to eq(400)
expect(JSON.parse(response.body)['failed']).to eq(I18n.t('discourse_assign.already_assigned', username: user2.username))
end end
end end