Skip to content

Commit

Permalink
FIX: add translations and check for message and if assignment is succ…
Browse files Browse the repository at this point in the history
…essful in spec (#22)
  • Loading branch information
mrfinch authored and SamSaffron committed Dec 6, 2018
1 parent a2e7fc4 commit b20b4c0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/discourse_assign/assign_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def assign
raise Discourse::NotFound unless assign_to

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

assigner = TopicAssigner.new(topic, current_user)
Expand Down
1 change: 1 addition & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ en:
assigned_to: "Topic assigned to @%{username}"
unassigned: "Topic was unassigned"
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_unclaimed: "You must claim that topic before acting on the flag"
topic_assigned_excerpt: "assigned you the topic '%{title}'"
Expand Down
7 changes: 5 additions & 2 deletions spec/requests/assign_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
let(:post) { Fabricate(:post) }
let(:user2) { Fabricate(:active_user) }

context 'assign' do
context '#assign' do

it 'assigns topic to a user' do
sign_in(user)

put '/assign/assign', params: {
put '/assign/assign.json', params: {
topic_id: post.topic_id, username: user2.username
}

expect(response.status).to eq(200)
expect(post.topic.reload.custom_fields['assigned_to_id']).to eq(user2.id.to_s)
end

it 'fails to assign topic to the user if its already assigned to the same user' do
Expand All @@ -26,12 +27,14 @@
}

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: {
topic_id: post.topic_id, username: user2.username
}

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
Expand Down

0 comments on commit b20b4c0

Please sign in to comment.