forked from decidim/decidim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add publish and unpublish conference_speakers commands spec
- Loading branch information
Showing
5 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
decidim-conferences/db/migrate/20240613095855_add_published_at_to_conference_speakers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
decidim-conferences/spec/commands/publish_conference_speaker_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
42 changes: 42 additions & 0 deletions
42
decidim-conferences/spec/commands/unpublish_conference_speaker_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |