diff --git a/app/controllers/assignments/toggles_controller.rb b/app/controllers/assignments/toggles_controller.rb
index a2285b35e..08562dde4 100644
--- a/app/controllers/assignments/toggles_controller.rb
+++ b/app/controllers/assignments/toggles_controller.rb
@@ -1,6 +1,10 @@
class Assignments::TogglesController < ApplicationController
include BubbleScoped, BucketScoped
+ def new
+ render partial: "bubbles/sidebar/assignment", locals: { bubble: @bubble }
+ end
+
def create
new_assignee_ids = Array(params[:assignee_id])
current_assignees = @bubble.assignees
@@ -14,7 +18,15 @@ class Assignments::TogglesController < ApplicationController
@bubble.toggle_assignment(assignee) unless current_assignees.include?(assignee)
end
- redirect_to @bubble
+ @bubble.assignees.reload
+
+ respond_to do |format|
+ format.turbo_stream do
+ render turbo_stream: turbo_stream.replace([ @bubble, :assignees ],
+ partial: "bubbles/assignees",
+ locals: { bubble: @bubble })
+ end
+ end
end
private
diff --git a/app/views/bubbles/_assignees.html.erb b/app/views/bubbles/_assignees.html.erb
index f054bb3ed..d6af2a636 100644
--- a/app/views/bubbles/_assignees.html.erb
+++ b/app/views/bubbles/_assignees.html.erb
@@ -10,9 +10,7 @@
Assign
-
- <%= render "bubbles/sidebar/assignment", bubble: bubble %>
-
+ <%= turbo_frame_tag bubble, :assignment, src: new_bucket_bubble_assignment_toggle_path(bubble.bucket, bubble) %>
<% end %>
diff --git a/app/views/bubbles/sidebar/_assignment.html.erb b/app/views/bubbles/sidebar/_assignment.html.erb
index 72dc42976..1c6f223b4 100644
--- a/app/views/bubbles/sidebar/_assignment.html.erb
+++ b/app/views/bubbles/sidebar/_assignment.html.erb
@@ -1,21 +1,23 @@
-<%= turbo_frame_tag bubble, :assignment do %>
-
+ <% end %>
<% end %>
diff --git a/test/controllers/assignments/toggles_controller_test.rb b/test/controllers/assignments/toggles_controller_test.rb
index 6579ad0df..3a1d4fcdb 100644
--- a/test/controllers/assignments/toggles_controller_test.rb
+++ b/test/controllers/assignments/toggles_controller_test.rb
@@ -5,15 +5,21 @@ class Assignments::TogglesControllerTest < ActionDispatch::IntegrationTest
sign_in_as :kevin
end
+ test "new" do
+ get new_bucket_bubble_assignment_toggle_url(buckets(:writebook), bubbles(:logo))
+
+ assert_response :success
+ end
+
test "create" do
assert_changes "bubbles(:logo).assigned_to?(users(:david))", from: false, to: true do
- post bucket_bubble_assignment_toggles_url(buckets(:writebook), bubbles(:logo)), params: { assignee_id: users(:david).id }
+ post bucket_bubble_assignment_toggles_url(buckets(:writebook), bubbles(:logo)), params: { assignee_id: users(:david).id }, as: :turbo_stream
end
- assert_redirected_to bubbles(:logo)
+ assert_response :success
assert_changes "bubbles(:logo).assigned_to?(users(:david))", from: true, to: false do
- post bucket_bubble_assignment_toggles_url(buckets(:writebook), bubbles(:logo)), params: { assignee_id: users(:kevin).id }
+ post bucket_bubble_assignment_toggles_url(buckets(:writebook), bubbles(:logo)), params: { assignee_id: users(:kevin).id }, as: :turbo_stream
end
- assert_redirected_to bubbles(:logo)
+ assert_response :success
end
end