diff --git a/app/controllers/cards/assignments_controller.rb b/app/controllers/cards/assignments_controller.rb index 63dce613c..0dd3d460e 100644 --- a/app/controllers/cards/assignments_controller.rb +++ b/app/controllers/cards/assignments_controller.rb @@ -6,5 +6,6 @@ class Cards::AssignmentsController < ApplicationController def create @card.toggle_assignment @collection.users.active.find(params[:assignee_id]) + render_card_replacement end end diff --git a/app/controllers/cards/closures_controller.rb b/app/controllers/cards/closures_controller.rb index 3682552ee..29dcfd30c 100644 --- a/app/controllers/cards/closures_controller.rb +++ b/app/controllers/cards/closures_controller.rb @@ -3,11 +3,11 @@ class Cards::ClosuresController < ApplicationController def create @card.close(user: Current.user, reason: params[:reason]) - redirect_to @card + render_card_replacement end def destroy @card.reopen - redirect_to @card + render_card_replacement end end diff --git a/app/controllers/cards/engagements_controller.rb b/app/controllers/cards/engagements_controller.rb index 72025d16a..50a6daa83 100644 --- a/app/controllers/cards/engagements_controller.rb +++ b/app/controllers/cards/engagements_controller.rb @@ -3,11 +3,11 @@ class Cards::EngagementsController < ApplicationController def create @card.engage - redirect_to @card + render_card_replacement end def destroy @card.reconsider - redirect_to @card + render_card_replacement end end diff --git a/app/controllers/cards/goldnesses_controller.rb b/app/controllers/cards/goldnesses_controller.rb index 4be611d14..1a0912a24 100644 --- a/app/controllers/cards/goldnesses_controller.rb +++ b/app/controllers/cards/goldnesses_controller.rb @@ -3,11 +3,11 @@ class Cards::GoldnessesController < ApplicationController def create @card.gild - redirect_to @card + render_card_replacement end def destroy @card.ungild - redirect_to @card + render_card_replacement end end diff --git a/app/controllers/cards/pins_controller.rb b/app/controllers/cards/pins_controller.rb index 76c5aa723..235393178 100644 --- a/app/controllers/cards/pins_controller.rb +++ b/app/controllers/cards/pins_controller.rb @@ -6,24 +6,20 @@ class Cards::PinsController < ApplicationController def create pin = @card.pin_by Current.user - - broadcast_my_new pin - redirect_to card_pin_path(@card) + broadcast_add_to_tray pin end def destroy pin = @card.unpin_by Current.user - - broadcast_my_removed pin - redirect_to card_pin_path(@card) + broadcast_remove_from_tray pin end private - def broadcast_my_new(pin) - pin.card.broadcast_prepend_later_to [ Current.user, :pins ], target: "pins", partial: "cards/display/preview" + def broadcast_add_to_tray(pin) + pin.broadcast_prepend_to [ Current.user, :pins_tray ], target: "pins", partial: "my/pins/pin" end - def broadcast_my_removed(pin) - pin.broadcast_remove_to [ Current.user, :pins ] + def broadcast_remove_from_tray(pin) + pin.broadcast_remove_to [ Current.user, :pins_tray ] end end diff --git a/app/controllers/cards/readings_controller.rb b/app/controllers/cards/readings_controller.rb index bbc4d53c0..2d8b51ac6 100644 --- a/app/controllers/cards/readings_controller.rb +++ b/app/controllers/cards/readings_controller.rb @@ -2,7 +2,7 @@ class Cards::ReadingsController < ApplicationController include CardScoped def create - @notification = Current.user.notifications.find_by(card: @card) - @notification.read + @notifications = Current.user.notifications.where(card: @card) + @notifications.each(&:read) end end diff --git a/app/controllers/cards/stagings_controller.rb b/app/controllers/cards/stagings_controller.rb index 071d19f5a..102c17599 100644 --- a/app/controllers/cards/stagings_controller.rb +++ b/app/controllers/cards/stagings_controller.rb @@ -9,6 +9,8 @@ class Cards::StagingsController < ApplicationController else @card.update!(stage: nil) end + + render_card_replacement end private diff --git a/app/controllers/cards/taggings_controller.rb b/app/controllers/cards/taggings_controller.rb index 710b59fdd..a8fe7ecf9 100644 --- a/app/controllers/cards/taggings_controller.rb +++ b/app/controllers/cards/taggings_controller.rb @@ -7,6 +7,7 @@ class Cards::TaggingsController < ApplicationController def create @card.toggle_tag_with sanitized_tag_title_param + render_card_replacement end private diff --git a/app/controllers/cards_controller.rb b/app/controllers/cards_controller.rb index c2c932cb5..040633646 100644 --- a/app/controllers/cards_controller.rb +++ b/app/controllers/cards_controller.rb @@ -25,16 +25,16 @@ class CardsController < ApplicationController def edit end + def update + @card.update! card_params + render_card_replacement + end + def destroy @card.destroy! redirect_to cards_path(collection_ids: [ @card.collection ]), notice: ("Card deleted" unless @card.creating?) end - def update - @card.update! card_params - redirect_to @card - end - private def set_card @card = @collection.cards.find params[:id] @@ -51,4 +51,8 @@ class CardsController < ApplicationController def card_params params.expect(card: [ :status, :title, :description, :image, tag_ids: [] ]) end + + def render_card_replacement + render turbo_stream: turbo_stream.replace([ @card, :card_container ], partial: "cards/container", locals: { card: @card.reload }) + end end diff --git a/app/controllers/concerns/card_scoped.rb b/app/controllers/concerns/card_scoped.rb index ef40d56e3..2ea4752c4 100644 --- a/app/controllers/concerns/card_scoped.rb +++ b/app/controllers/concerns/card_scoped.rb @@ -13,4 +13,8 @@ module CardScoped def set_collection @collection = @card.collection end + + def render_card_replacement + render turbo_stream: turbo_stream.replace([ @card, :card_container ], partial: "cards/container", locals: { card: @card.reload }) + end end diff --git a/app/helpers/cards_helper.rb b/app/helpers/cards_helper.rb index e13defa96..028a4e715 100644 --- a/app/helpers/cards_helper.rb +++ b/app/helpers/cards_helper.rb @@ -29,4 +29,12 @@ module CardsHelper **options, &block end + + def button_to_delete_card(card) + button_to collection_card_path(card.collection, card), + method: :delete, class: "btn", data: { turbo_confirm: "Are you sure you want to delete this?" } do + concat(icon_tag("trash")) + concat(tag.span("Delete", class: "for-screen-reader")) + end + end end diff --git a/app/views/cards/_container.html.erb b/app/views/cards/_container.html.erb new file mode 100644 index 000000000..a817a21af --- /dev/null +++ b/app/views/cards/_container.html.erb @@ -0,0 +1,43 @@ +
" style="--card-color: <%= card.color %>;"> + <%= render "cards/container/engagement", card: card %> + + + +
+ <%= card_article_tag card, class: "card" do %> +
+ <%= link_to card.collection.name, cards_path(collection_ids: [ card.collection ]), + class: "card__collection txt-uppercase overflow-ellipsis txt-reversed" %> + + <%= render "cards/display/perma/tags", card: card %> +
+ +
+ <%= render "cards/container/title", card: card %> + <%= render "cards/stagings/stages", card: card if card.doing? %> +
+ +
+ <%= render "cards/display/perma/meta", card: card %> +
+ + <%= render "cards/display/common/background", card: card %> + <% end %> +
+ + <% if card.published? %> + <%# FIXME: Let's move this aside outside of the card container section so these frames don't reload/flicker when card is replaced %> + + + <%= render "cards/container/closure", card: card %> + <% end %> +
diff --git a/app/views/cards/_description_as_draft_comment.html.erb b/app/views/cards/_description_as_draft_comment.html.erb new file mode 100644 index 000000000..5e7a1cd71 --- /dev/null +++ b/app/views/cards/_description_as_draft_comment.html.erb @@ -0,0 +1,29 @@ +
+
+ + +
+
+
+ <%= tag.house_md card.draft_comment, name: "card[draft_comment]", class: "input comment__input", + form: "card_form", + placeholder: new_comment_placeholder(card), + data: { action: "house-md:change->outlet-auto-save#change focusout->outlet-auto-save#submit", uploads_url: uploads_url(format: "json") } %> +
+ + <% if card.creating? %> +
+ <%= button_to "Create card", card_publish_path(card), class: "btn btn--reversed" %> + <%= button_to "Save as draft", collection_card_path(card.collection, card), name: "card[status]", value: "drafted", method: :put, class: "btn" %> +
+ <% end %> +
+
+
+
+ diff --git a/app/views/cards/assignments/create.turbo_stream.erb b/app/views/cards/assignments/create.turbo_stream.erb deleted file mode 100644 index f05f15d8d..000000000 --- a/app/views/cards/assignments/create.turbo_stream.erb +++ /dev/null @@ -1 +0,0 @@ -<%= turbo_stream.replace([ @card, :meta ], partial: "cards/display/perma/meta", locals: { card: @card }) %> diff --git a/app/views/cards/_closure_toggle.html.erb b/app/views/cards/container/_closure.html.erb similarity index 100% rename from app/views/cards/_closure_toggle.html.erb rename to app/views/cards/container/_closure.html.erb diff --git a/app/views/cards/_doing_toggle.html.erb b/app/views/cards/container/_engagement.html.erb similarity index 100% rename from app/views/cards/_doing_toggle.html.erb rename to app/views/cards/container/_engagement.html.erb diff --git a/app/views/cards/_golden_toggle.html.erb b/app/views/cards/container/_gild.html.erb similarity index 100% rename from app/views/cards/_golden_toggle.html.erb rename to app/views/cards/container/_gild.html.erb diff --git a/app/views/cards/_image.html.erb b/app/views/cards/container/_image.html.erb similarity index 100% rename from app/views/cards/_image.html.erb rename to app/views/cards/container/_image.html.erb diff --git a/app/views/cards/container/_title.html.erb b/app/views/cards/container/_title.html.erb new file mode 100644 index 000000000..b62eb2fb4 --- /dev/null +++ b/app/views/cards/container/_title.html.erb @@ -0,0 +1,14 @@ +

+ <% if card.published? %> + <%= turbo_frame_tag card, :edit do %> + <%= link_to card.title, edit_collection_card_path(card.collection, card), class: "card__title-link overflow-line-clamp" %> + <% end %> + <% else %> + <%= form_with model: card, url: collection_card_path(card.collection, card), id: "card_form", data: { controller: "auto-save" } do |form| %> + <%= form.text_area :title, placeholder: "Name it…", + class: "input input--textarea full-width borderless txt-align-start #{ "fill-highlight" if card.creating? }", + autofocus: card.title.blank?, + data: { action: "auto-save#change blur->auto-save#submit keydown.enter->auto-save#submit:prevent keydown.ctrl+enter->auto-save#submit:prevent" } %> + <% end %> + <% end %> +

diff --git a/app/views/cards/display/_perma.html.erb b/app/views/cards/display/_perma.html.erb deleted file mode 100644 index 9b9cc7cbd..000000000 --- a/app/views/cards/display/_perma.html.erb +++ /dev/null @@ -1,55 +0,0 @@ -<% cache card do %> - <%= card_article_tag card, class: "card" do %> -
- <%= link_to card.collection.name, cards_path(collection_ids: [card.collection]), - class: "card__collection txt-uppercase overflow-ellipsis txt-reversed" %> - - <%= render "cards/display/perma/tags", card: card %> -
- -
- <% if card.published? %> - <%= turbo_frame_tag card, :edit do %> -
-

- <%= card.title %> - <%= link_to edit_collection_card_path(card.collection, card), class: "btn txt-small margin-block-start-half" do %> - <%= icon_tag "pencil" %> - Edit - <% end %> -

-

- <%= sanitize card.description_html %> -

-
- <% end %> - <% else %> - <%= form_with model: card, url: collection_card_path(card.collection, card), id: "card_form", class: "full-width", data: { controller: "auto-save" } do |form| %> -

- <%= form.text_area :title, placeholder: "Name it…", - class: "input input--textarea full-width borderless txt-align-start #{ "fill-highlight" if card.creating? }", - autofocus: card.title.blank?, - data: { action: "auto-save#change blur->auto-save#submit keydown.enter->auto-save#submit:prevent keydown.ctrl+enter->auto-save#submit:prevent" } %> -

-
- <%= form.markdown_area :description, class: "input input--textarea full-width fill-white borderless txt-align-start card-field__description #{ "fill-highlight" if card.creating? }", - placeholder: "Add some notes, context, pictures, or video about this…", - data: { action: "auto-save#change blur->auto-save#submit keydown.ctrl+enter->form#submit:prevent keydown.meta+enter->form#submit:prevent keydown.esc->form#cancel:stop paste->paste#pasteFiles" } %> -
- <% end %> - <% end %> - - <% if card.doing? %> - <%= turbo_frame_tag dom_id(@card, :stages) do %> - <%= render "cards/stagings/stages", card: card %> - <% end %> - <% end %> -
- - - - <%= render "cards/display/common/background", card: card %> - <% end %> -<% end %> diff --git a/app/views/cards/pins/_pin_button.html.erb b/app/views/cards/pins/_pin_button.html.erb new file mode 100644 index 000000000..e08308829 --- /dev/null +++ b/app/views/cards/pins/_pin_button.html.erb @@ -0,0 +1,11 @@ +
+ <% if card.pinned_by? Current.user %> + <%= button_to card_pin_path(card), method: :delete, class: "btn btn--reversed" do %> + <%= icon_tag "pinned" %> Un-pin this card + <% end %> + <% else %> + <%= button_to card_pin_path(card), class: "btn" do %> + <%= icon_tag "unpinned" %> Pin this card + <% end %> + <% end %> +
diff --git a/app/views/cards/pins/create.turbo_stream.erb b/app/views/cards/pins/create.turbo_stream.erb new file mode 100644 index 000000000..b1dd787e9 --- /dev/null +++ b/app/views/cards/pins/create.turbo_stream.erb @@ -0,0 +1 @@ +<%= turbo_stream.replace [ @card, :pin_button ], partial: "cards/pins/pin_button", locals: { card: @card } %> diff --git a/app/views/cards/pins/destroy.turbo_stream.erb b/app/views/cards/pins/destroy.turbo_stream.erb new file mode 100644 index 000000000..d54dea5f1 --- /dev/null +++ b/app/views/cards/pins/destroy.turbo_stream.erb @@ -0,0 +1 @@ +<%= render template: "cards/pins/create" %> diff --git a/app/views/cards/pins/show.html.erb b/app/views/cards/pins/show.html.erb index 64eb1ad5c..c8ac69d7e 100644 --- a/app/views/cards/pins/show.html.erb +++ b/app/views/cards/pins/show.html.erb @@ -1,13 +1,3 @@ <%= turbo_frame_tag dom_id(@card, :pin) do %> - <% if @card.pinned_by? Current.user %> - <%= button_to card_pin_path(@card), method: :delete, class: "btn btn--reversed" do %> - <%= icon_tag "pinned" %> - Un-pin this card - <% end %> - <% else %> - <%= button_to card_pin_path(@card), class: "btn" do %> - <%= icon_tag "unpinned" %> - Pin this card - <% end %> - <% end %> + <%= render "cards/pins/pin_button", card: @card %> <% end %> diff --git a/app/views/cards/readings/create.turbo_stream.erb b/app/views/cards/readings/create.turbo_stream.erb index 1f3b07b47..5d7fe7801 100644 --- a/app/views/cards/readings/create.turbo_stream.erb +++ b/app/views/cards/readings/create.turbo_stream.erb @@ -1 +1,3 @@ -<%= turbo_stream.remove @notification %> +<% @notifications.each do |notification| %> + <%= turbo_stream.remove notification %> +<% end %> diff --git a/app/views/cards/show.html.erb b/app/views/cards/show.html.erb index af59aad87..df993c968 100644 --- a/app/views/cards/show.html.erb +++ b/app/views/cards/show.html.erb @@ -30,45 +30,11 @@ <% end %>
-
- - <%= render "cards/doing_toggle", card: @card %> - - - -
- <%= render "cards/display/perma", card: @card %> -
- - <% if @card.published? %> - - <% end %> - - <% if @card.creating? %> -
- <%= button_to "Create card", card_publish_path(@card), class: "btn btn--reversed" %> - <%= button_to "Save as draft", collection_card_path(@card.collection, @card), name: "card[status]", value: "drafted", method: :put, class: "btn" %> -
- <% elsif @card.published? %> - <%= render "cards/closure_toggle", card: @card %> - <% end %> -
- + <%= render "cards/container", card: @card %> <% if @card.published? %> <%= render "cards/messages", card: @card %> + <% else %> + <%= render "cards/description_as_draft_comment", card: @card %> <% end %>
diff --git a/app/views/cards/stagings/create.turbo_stream.erb b/app/views/cards/stagings/create.turbo_stream.erb deleted file mode 100644 index ac3942d6a..000000000 --- a/app/views/cards/stagings/create.turbo_stream.erb +++ /dev/null @@ -1,8 +0,0 @@ -<%= turbo_stream.replace dom_id(@card, "stages") do %> - <%= render partial: "cards/stagings/stages", locals: { card: @card } %> -<% end %> - -<%= turbo_stream.set_css_variable dom_id(@card, :card_closure_toggle), name: "--card-color", value: @card.color %> -<%= turbo_stream.set_css_variable dom_id(@card, :card_container), name: "--card-color", value: @card.color %> -<%= turbo_stream.set_css_variable dom_id(@card, :card_engagement_toggle), name: "--card-color", value: @card.color %> -<%= turbo_stream.set_css_variable dom_id(@card, :ticket), name: "--card-color", value: @card.color %> diff --git a/app/views/cards/taggings/create.turbo_stream.erb b/app/views/cards/taggings/create.turbo_stream.erb deleted file mode 100644 index f1775e2f8..000000000 --- a/app/views/cards/taggings/create.turbo_stream.erb +++ /dev/null @@ -1 +0,0 @@ -<%= turbo_stream.replace([ @card, :tags ], partial: "cards/display/perma/tags", locals: { card: @card }) %> diff --git a/app/views/my/pins/_pin.html.erb b/app/views/my/pins/_pin.html.erb new file mode 100644 index 000000000..66d177b28 --- /dev/null +++ b/app/views/my/pins/_pin.html.erb @@ -0,0 +1,3 @@ +
+ <%= render "cards/display/preview", card: pin.card %> +
diff --git a/app/views/my/pins/_tray.html.erb b/app/views/my/pins/_tray.html.erb index 70c1d5a16..ddd39fdfe 100644 --- a/app/views/my/pins/_tray.html.erb +++ b/app/views/my/pins/_tray.html.erb @@ -1,4 +1,4 @@ -<%= turbo_stream_from Current.user, :pins %> +<%= turbo_stream_from Current.user, :pins_tray %> <%= tag.dialog id: "pin-tray", class: "tray pin-tray", data: { controller: "dialog", turbo_permanent: true, dialog_modal_value: false, dialog_target: "dialog", action: "keydown.esc->dialog#close:stop click@document->dialog#closeOnClickOutside" } do %> diff --git a/app/views/my/pins/index.html.erb b/app/views/my/pins/index.html.erb index 519070aec..bee9fe10b 100644 --- a/app/views/my/pins/index.html.erb +++ b/app/views/my/pins/index.html.erb @@ -1,7 +1,3 @@ <%= turbo_frame_tag "pins" do %> - <% @pins.map(&:card).each do |card| %> -
- <%= render partial: "cards/display/preview", locals: { card: card } %> -
- <% end %> + <%= render partial: "my/pins/pin", collection: @pins %> <% end %> diff --git a/config/deploy.production.yml b/config/deploy.production.yml index 00a4b176e..cc05d75b5 100644 --- a/config/deploy.production.yml +++ b/config/deploy.production.yml @@ -18,3 +18,32 @@ proxy: ssh: user: app + + +x-beamer-accessory: &beamer-accessory + image: basecamp/beamer + registry: + username: bcbot + password: + - BASECAMP_REGISTRY_PASSWORD + options: + user: 1000 # Match the UID of the Rails app, for volume permissions + volumes: + - fizzy:/storage + + +accessories: + beamer-primary: + <<: *beamer-accessory + service: beamer-primary + cmd: beamer primary --remove-after=1h --dir=/storage + port: 5000:80 + roles: + - web + + beamer-replica: + <<: *beamer-accessory + service: beamer-replica + cmd: beamer replica --primary=http://fizzy-app-101:5000/ --dir=/storage + roles: + - web-replica diff --git a/config/deploy.yml b/config/deploy.yml index 29eb15ba4..9617a8b87 100644 --- a/config/deploy.yml +++ b/config/deploy.yml @@ -1,42 +1,10 @@ service: fizzy image: basecamp/fizzy - -x-basecamp-registry: &basecamp-registry - username: bcbot - password: - - BASECAMP_REGISTRY_PASSWORD - -x-beamer-accessory: &beamer-accessory - image: basecamp/beamer - registry: - <<: *basecamp-registry - options: - user: 1000 # Match the UID of the Rails app, for volume permissions - volumes: - - fizzy:/storage - - servers: jobs: cmd: bin/jobs -accessories: - beamer-primary: - <<: *beamer-accessory - service: beamer-primary - cmd: beamer primary --debug --remove-after=1h --dir=/storage - port: 5000:80 - roles: - - web - - beamer-replica: - <<: *beamer-accessory - service: beamer-replica - cmd: beamer replica --debug --primary=http://fizzy-app-101:5000/ --dir=/storage - roles: - - web-replica - volumes: - fizzy:/rails/storage @@ -44,7 +12,9 @@ proxy: ssl: true registry: - <<: *basecamp-registry + username: bcbot + password: + - BASECAMP_REGISTRY_PASSWORD builder: arch: amd64 diff --git a/test/controllers/cards/assignments_controller_test.rb b/test/controllers/cards/assignments_controller_test.rb index c92f57627..e0629aee4 100644 --- a/test/controllers/cards/assignments_controller_test.rb +++ b/test/controllers/cards/assignments_controller_test.rb @@ -13,12 +13,12 @@ class Cards::AssignmentsControllerTest < ActionDispatch::IntegrationTest test "create" do assert_changes "cards(:logo).assigned_to?(users(:david))", from: false, to: true do post card_assignments_path(cards(:logo)), params: { assignee_id: users(:david).id }, as: :turbo_stream + assert_card_container_rerendered(cards(:logo)) end - assert_response :success assert_changes "cards(:logo).assigned_to?(users(:david))", from: true, to: false do post card_assignments_path(cards(:logo)), params: { assignee_id: users(:david).id }, as: :turbo_stream + assert_card_container_rerendered(cards(:logo)) end - assert_response :success end end diff --git a/test/controllers/cards/closures_controller_test.rb b/test/controllers/cards/closures_controller_test.rb index 1729010a9..1e8f85871 100644 --- a/test/controllers/cards/closures_controller_test.rb +++ b/test/controllers/cards/closures_controller_test.rb @@ -10,11 +10,10 @@ class Cards::ClosuresControllerTest < ActionDispatch::IntegrationTest assert_changes -> { card.reload.closed? }, from: false, to: true do post card_closure_path(card, reason: "Scope too big") + assert_card_container_rerendered(card) end assert_equal "Scope too big", card.closure.reason - - assert_redirected_to collection_card_path(card.collection, card) end test "destroy" do @@ -22,8 +21,7 @@ class Cards::ClosuresControllerTest < ActionDispatch::IntegrationTest assert_changes -> { card.reload.closed? }, from: true, to: false do delete card_closure_path(card) + assert_card_container_rerendered(card) end - - assert_redirected_to collection_card_path(card.collection, card) end end diff --git a/test/controllers/cards/engagements_controller_test.rb b/test/controllers/cards/engagements_controller_test.rb index 1e966108c..6b4265b86 100644 --- a/test/controllers/cards/engagements_controller_test.rb +++ b/test/controllers/cards/engagements_controller_test.rb @@ -10,9 +10,8 @@ class Cards::EngagementsControllerTest < ActionDispatch::IntegrationTest assert_changes -> { card.reload.doing? }, from: false, to: true do post card_engagement_path(card) + assert_card_container_rerendered(card) end - - assert_redirected_to collection_card_path(card.collection, card) end test "destroy" do @@ -20,8 +19,12 @@ class Cards::EngagementsControllerTest < ActionDispatch::IntegrationTest assert_changes -> { card.reload.doing? }, from: true, to: false do delete card_engagement_path(card) + assert_card_container_rerendered(card) end - - assert_redirected_to collection_card_path(card.collection, card) end + + private + def assert_card_container_rerendered(card) + assert_turbo_stream action: :replace, target: dom_id(card, :card_container) + end end diff --git a/test/controllers/cards/goldnesses_controller_test.rb b/test/controllers/cards/goldnesses_controller_test.rb index b8cfb9469..447aa2b71 100644 --- a/test/controllers/cards/goldnesses_controller_test.rb +++ b/test/controllers/cards/goldnesses_controller_test.rb @@ -6,22 +6,16 @@ class Cards::GoldnessesControllerTest < ActionDispatch::IntegrationTest end test "create" do - card = cards(:text) - - assert_changes -> { card.reload.golden? }, from: false, to: true do - post card_goldness_path(card) + assert_changes -> { cards(:text).reload.golden? }, from: false, to: true do + post card_goldness_path(cards(:text)), as: :turbo_stream + assert_card_container_rerendered(cards(:text)) end - - assert_redirected_to collection_card_path(card.collection, card) end test "destroy" do - card = cards(:logo) - - assert_changes -> { card.reload.golden? }, from: true, to: false do - delete card_goldness_path(card) + assert_changes -> { cards(:logo).reload.golden? }, from: true, to: false do + delete card_goldness_path(cards(:logo)), as: :turbo_stream + assert_card_container_rerendered(cards(:logo)) end - - assert_redirected_to collection_card_path(card.collection, card) end end diff --git a/test/controllers/cards/pins_controller_test.rb b/test/controllers/cards/pins_controller_test.rb index 39b12a053..3bc569827 100644 --- a/test/controllers/cards/pins_controller_test.rb +++ b/test/controllers/cards/pins_controller_test.rb @@ -8,24 +8,24 @@ class Cards::PinsControllerTest < ActionDispatch::IntegrationTest test "create" do assert_changes -> { cards(:layout).pinned_by?(users(:kevin)) }, from: false, to: true do perform_enqueued_jobs do - assert_turbo_stream_broadcasts([ users(:kevin), :pins ], count: 1) do - post card_pin_path(cards(:layout)) + assert_turbo_stream_broadcasts([ users(:kevin), :pins_tray ], count: 1) do + post card_pin_path(cards(:layout)), as: :turbo_stream end end end - assert_redirected_to card_pin_path(cards(:layout)) + assert_response :success end test "destroy" do assert_changes -> { cards(:shipping).pinned_by?(users(:kevin)) }, from: true, to: false do perform_enqueued_jobs do - assert_turbo_stream_broadcasts([ users(:kevin), :pins ], count: 1) do - delete card_pin_path(cards(:shipping)) + assert_turbo_stream_broadcasts([ users(:kevin), :pins_tray ], count: 1) do + delete card_pin_path(cards(:shipping)), as: :turbo_stream end end end - assert_redirected_to card_pin_path(cards(:shipping)) + assert_response :success end end diff --git a/test/controllers/cards/readings_controller_test.rb b/test/controllers/cards/readings_controller_test.rb index c169517e2..a880e46c7 100644 --- a/test/controllers/cards/readings_controller_test.rb +++ b/test/controllers/cards/readings_controller_test.rb @@ -5,11 +5,21 @@ class Cards::ReadingsControllerTest < ActionDispatch::IntegrationTest sign_in_as :kevin end - test "index" do + test "read one notification on card visit" do assert_changes -> { notifications(:logo_published_kevin).reload.read? }, from: false, to: true do post card_reading_path(cards(:logo)), as: :turbo_stream end assert_response :success end + + test "read multiple notifications on card visit" do + assert_changes -> { notifications(:logo_published_kevin).reload.read? }, from: false, to: true do + assert_changes -> { notifications(:logo_assignment_kevin).reload.read? }, from: false, to: true do + post card_reading_path(cards(:logo)), as: :turbo_stream + end + end + + assert_response :success + end end diff --git a/test/controllers/cards/taggings_controller_test.rb b/test/controllers/cards/taggings_controller_test.rb index ad5a8fa91..60f4cf743 100644 --- a/test/controllers/cards/taggings_controller_test.rb +++ b/test/controllers/cards/taggings_controller_test.rb @@ -13,14 +13,14 @@ class Cards::TaggingsControllerTest < ActionDispatch::IntegrationTest test "toggle tag on" do assert_changes "cards(:logo).tagged_with?(tags(:mobile))", from: false, to: true do post card_taggings_path(cards(:logo)), params: { tag_title: tags(:mobile).title }, as: :turbo_stream + assert_card_container_rerendered(cards(:logo)) end - assert_response :success end test "toggle tag off" do assert_changes "cards(:logo).tagged_with?(tags(:web))", from: true, to: false do post card_taggings_path(cards(:logo)), params: { tag_title: tags(:web).title }, as: :turbo_stream + assert_card_container_rerendered(cards(:logo)) end - assert_response :success end end diff --git a/test/fixtures/notifications.yml b/test/fixtures/notifications.yml index d6db9d360..7579f8eb6 100644 --- a/test/fixtures/notifications.yml +++ b/test/fixtures/notifications.yml @@ -5,6 +5,13 @@ logo_published_kevin: resource: logo (Card) created_at: <%= 1.week.ago %> +logo_assignment_kevin: + user: kevin + event: logo_assignment_km + card: logo + resource: logo (Card) + created_at: <%= 1.week.ago %> + layout_commented_kevin: user: kevin event: layout_commented diff --git a/test/test_helper.rb b/test/test_helper.rb index f7cc1e088..1447430b1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -10,6 +10,6 @@ module ActiveSupport # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all - include ChangeTestHelper, SessionTestHelper + include CardTestHelper, ChangeTestHelper, SessionTestHelper end end diff --git a/test/test_helpers/card_test_helper.rb b/test/test_helpers/card_test_helper.rb new file mode 100644 index 000000000..6de139c86 --- /dev/null +++ b/test/test_helpers/card_test_helper.rb @@ -0,0 +1,5 @@ +module CardTestHelper + def assert_card_container_rerendered(card) + assert_turbo_stream action: :replace, target: dom_id(card, :card_container) + end +end