Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/models/step.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
class Step < ApplicationRecord
belongs_to :account, default: -> { card.account }
belongs_to :card, touch: true
belongs_to :card

after_save -> { card.touch_last_active_at }
after_destroy -> { card.touch_last_active_at unless destroyed_by_association }
Comment thread
Klar marked this conversation as resolved.
Outdated

scope :completed, -> { where(completed: true) }

Expand Down
24 changes: 16 additions & 8 deletions test/controllers/cards/steps_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ class Cards::StepsControllerTest < ActionDispatch::IntegrationTest
card = cards(:logo)

assert_difference -> { card.steps.count }, +1 do
post card_steps_path(card), params: { step: { content: "Research alternatives" } }, as: :turbo_stream
assert_turbo_stream action: :before, target: dom_id(card, :new_step)
assert_changes -> { card.reload.last_active_at } do
post card_steps_path(card), params: { step: { content: "Research alternatives" } }, as: :turbo_stream
assert_turbo_stream action: :before, target: dom_id(card, :new_step)
end
end

assert_equal "Research alternatives", card.steps.last.content
Expand All @@ -21,8 +23,10 @@ class Cards::StepsControllerTest < ActionDispatch::IntegrationTest
step = card.steps.create!(content: "Original content")

assert_changes -> { step.reload.content }, from: "Original content", to: "Updated content" do
put card_step_path(card, step), params: { step: { content: "Updated content" } }, as: :turbo_stream
assert_turbo_stream action: :replace, target: dom_id(step)
assert_changes -> { card.reload.last_active_at } do
Comment thread
Klar marked this conversation as resolved.
put card_step_path(card, step), params: { step: { content: "Updated content" } }, as: :turbo_stream
assert_turbo_stream action: :replace, target: dom_id(step)
end
end
end

Expand All @@ -31,8 +35,10 @@ class Cards::StepsControllerTest < ActionDispatch::IntegrationTest
step = card.steps.create!(content: "Step to delete")

assert_difference -> { card.steps.count }, -1 do
delete card_step_path(card, step), as: :turbo_stream
assert_turbo_stream action: :remove, target: dom_id(step)
assert_changes -> { card.reload.last_active_at } do
Comment thread
Klar marked this conversation as resolved.
delete card_step_path(card, step), as: :turbo_stream
assert_turbo_stream action: :remove, target: dom_id(step)
end
end
end

Expand All @@ -42,8 +48,10 @@ class Cards::StepsControllerTest < ActionDispatch::IntegrationTest

# Toggle to completed
assert_changes -> { step.reload.completed? }, from: false, to: true do
put card_step_path(card, step), params: { step: { completed: "1" } }, as: :turbo_stream
assert_turbo_stream action: :replace, target: dom_id(step)
assert_changes -> { card.reload.last_active_at } do
put card_step_path(card, step), params: { step: { completed: "1" } }, as: :turbo_stream
assert_turbo_stream action: :replace, target: dom_id(step)
Comment thread
Klar marked this conversation as resolved.
end
Comment thread
Klar marked this conversation as resolved.
end

# Toggle back to incomplete
Expand Down