Skip to content

Commit

Permalink
add publish and unpublish conference_speakers commands spec
Browse files Browse the repository at this point in the history
  • Loading branch information
ElviaBth committed Jun 13, 2024
1 parent 89383ba commit 7f4b798
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Admin
class PublishConferenceSpeaker < Decidim::Command
# Public: Initializes the command.
#
# conference_speaker - Decidim::Meetings::Meeting
# conference_speaker - Decidim::Conferences::Admin::ConferenceSpeaker
# current_user - the user performing the action
def initialize(conference_speaker, current_user)
@conference_speaker = conference_speaker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Admin
class UnpublishConferenceSpeaker < Decidim::Command
# Public: Initializes the command.
#
# conference_speaker - Decidim::Meetings::Meeting
# conference_speaker - Decidim::Conferences::Admin::ConferenceSpeaker
# current_user - the user performing the action
def initialize(conference_speaker, current_user)
@conference_speaker = conference_speaker
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddPublishedAtToConferenceSpeakers < ActiveRecord::Migration[7.0]
def change
add_column :decidim_conference_speakers, :published_at, :datetime, index: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require "spec_helper"
module Decidim
module Conferences
module Admin
describe PublishConferenceSpeaker, type: :command do
let(:organization) { create :organization, available_locales: [:en] }
let(:conference_speaker) { create(:conference_speaker, published_at: nil) }
let(:current_user) { create(:user, :admin, :confirmed, organization:) }
let(:command) { described_class.new(conference_speaker, current_user) }

describe "call" do
context "when the conference speaker is not already published" do
it "publishes the conference speaker" do
expect(Decidim.traceability).to receive(:perform_action!).with(
:publish,
conference_speaker,
current_user
).and_call_original

expect(command).to broadcast(:ok, conference_speaker)
end
end

context "when the conference speaker is already published" do
before do
conference_speaker.update!(published_at: Time.current)
end

it "does not publish the conference speaker" do
expect { command.call }.not_to(change { conference_speaker.reload.published_at })

expect(command).to broadcast(:invalid)
end
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
module Conferences
module Admin
describe UnpublishConferenceSpeaker, type: :command do
let(:organization) { create :organization, available_locales: [:en] }
let(:conference_speaker) { create(:conference_speaker, published_at: Time.current) }
let(:current_user) { create(:user, :admin, :confirmed, organization:) }
let(:command) { described_class.new(conference_speaker, current_user) }

describe "call" do
context "when the conference speaker is published" do
it "unpublishes the conference speaker" do
expect(Decidim.traceability).to receive(:perform_action!).with(
:unpublish,
conference_speaker,
current_user
).and_call_original

expect(command).to broadcast(:ok, conference_speaker)
end
end

context "when the conference speaker is not published" do
before do
conference_speaker.update!(published_at: nil)
end

it "does not unpublish the conference speaker" do
expect { command.call }.not_to(change { conference_speaker.reload.published_at })

expect(command).to broadcast(:invalid)
end
end
end
end
end
end
end

0 comments on commit 7f4b798

Please sign in to comment.