Skip to content

Commit 5cf54b0

Browse files
committed
Conversations: render validation errors with 422 on disallowed participants for create/update; update request specs
1 parent ff82b19 commit 5cf54b0

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

app/controllers/better_together/conversations_controller.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def create # rubocop:todo Metrics/MethodLength, Metrics/AbcSize
4242
'form_errors',
4343
partial: 'layouts/better_together/errors',
4444
locals: { object: @conversation }
45-
)
45+
), status: :unprocessable_entity
4646
end
47-
format.html { render :new }
47+
format.html { render :new, status: :unprocessable_entity }
4848
end
4949
elsif @conversation.save
5050
@conversation.participants << helpers.current_person
@@ -82,9 +82,9 @@ def update # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
8282
'form_errors',
8383
partial: 'layouts/better_together/errors',
8484
locals: { object: @conversation }
85-
)
85+
), status: :unprocessable_entity
8686
end
87-
format.html { redirect_to conversations_path, alert: t('better_together.conversations.errors.no_permitted_participants') }
87+
format.html { render :show, status: :unprocessable_entity }
8888
end
8989
elsif @conversation.update(filtered_params)
9090
@messages = @conversation.messages.with_all_rich_text.includes(sender: [:string_translations])

spec/requests/better_together/conversations_request_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
before { login(regular_user.email, 'password12345') }
5959

60-
it 'filters out non-permitted participant_ids on create' do
60+
it 'creates conversation with permitted participants (opted-in) and excludes non-permitted' do
6161
post better_together.conversations_path(locale: I18n.default_locale), params: {
6262
conversation: {
6363
title: 'Hello',
@@ -81,7 +81,7 @@
8181
participant_ids: [non_opted_person.id]
8282
}
8383
}
84-
expect(response).to have_http_status(:ok)
84+
expect(response).to have_http_status(:unprocessable_entity)
8585
expect(BetterTogether::Conversation.count).to eq(before_count)
8686
expect(response.body).to include(I18n.t('better_together.conversations.errors.no_permitted_participants'))
8787
end
@@ -120,8 +120,7 @@
120120
participant_ids: [non_opted_person.id]
121121
}
122122
}
123-
expect(response).to have_http_status(:found)
124-
follow_redirect!
123+
expect(response).to have_http_status(:unprocessable_entity)
125124
expect(response.body).to include(I18n.t('better_together.conversations.errors.no_permitted_participants'))
126125
end
127126
end

0 commit comments

Comments
 (0)