Create a "published" event if a card is created published
This isn't the normal workflow in the app, but this problem will show up if we create cards programmatically (e.g., the seeds)
This commit is contained in:
@@ -4,6 +4,8 @@ module Card::Statuses
|
||||
included do
|
||||
enum :status, %w[ creating drafted published ].index_by(&:itself)
|
||||
|
||||
after_create -> { track_event :published }, if: :published?
|
||||
|
||||
scope :published_or_drafted_by, ->(user) { where(status: :published).or(where(status: :drafted, creator: user)) }
|
||||
end
|
||||
|
||||
|
||||
@@ -25,6 +25,33 @@ class Card::StatusesTest < ActiveSupport::TestCase
|
||||
assert_includes Card.published_or_drafted_by(users(:jz)), card
|
||||
end
|
||||
|
||||
test "an event is created when a card is created in the published state" do
|
||||
Current.session = sessions(:david)
|
||||
|
||||
assert_no_difference(-> { Event.count }) do
|
||||
collections(:writebook).cards.create! creator: users(:kevin), title: "Draft Card"
|
||||
end
|
||||
|
||||
assert_difference(-> { Event.count } => +1) do
|
||||
@card = collections(:writebook).cards.create! creator: users(:kevin), title: "Published Card", status: :published
|
||||
end
|
||||
|
||||
assert_equal @card, Event.last.eventable
|
||||
assert_equal "card_published", Event.last.action
|
||||
end
|
||||
|
||||
test "an event is created when a card is published" do
|
||||
Current.session = sessions(:david)
|
||||
|
||||
card = collections(:writebook).cards.create! creator: users(:kevin), title: "Published Card"
|
||||
assert_difference(-> { Event.count } => +1) do
|
||||
card.publish
|
||||
end
|
||||
|
||||
assert_equal card, Event.last.eventable
|
||||
assert_equal "card_published", Event.last.action
|
||||
end
|
||||
|
||||
test "can_recover_abandoned_creation?" do
|
||||
card = collections(:writebook).cards.create! creator: users(:kevin)
|
||||
unsaved_card = collections(:writebook).cards.new creator: users(:kevin)
|
||||
|
||||
Reference in New Issue
Block a user