Sha256: cda21c82269f553d8f2c332c8f5f86acf76e06e695d8e01d1d046107f4580178

Contents?: true

Size: 1.79 KB

Versions: 11

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

require "spec_helper"

module Decidim
  module Admin
    describe UpdateNewsletter do
      describe "call" do
        let(:user) { create(:user, organization: organization) }
        let(:organization) { create(:organization) }
        let(:newsletter) { create(:newsletter, organization: organization) }

        let(:form) do
          double(
            subject: Decidim::Faker::Localized.paragraph(3),
            body: Decidim::Faker::Localized.paragraph(3),
            valid?: true
          )
        end

        let(:command) { described_class.new(newsletter, form, user) }

        describe "when the form is not valid" do
          before do
            expect(form).to receive(:valid?).and_return(false)
          end

          it "broadcasts invalid" do
            expect { command.call }.to broadcast(:invalid)
          end

          it "doesn't create a newsletter" do
            expect do
              command.call
            end.not_to change { newsletter.reload.updated_at }
          end
        end

        describe "when the newsletter can't be edited by this user" do
          let(:user) { create(:user) }

          it "broadcasts invalid" do
            expect { command.call }.to broadcast(:invalid)
          end
        end

        describe "when the form is valid" do
          it "broadcasts ok" do
            expect { command.call }.to broadcast(:ok)
          end

          it "updates the newsletter" do
            command.call
            newsletter.reload

            expect(newsletter.author).to eq(user)
            expect(newsletter.subject).to eq(form.subject.stringify_keys)
            expect(newsletter.sent?).to eq(false)
            expect(newsletter.body).to eq(form.body.stringify_keys)
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
decidim-0.6.8 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.6.7 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.6.6 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.6.5 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.6.4 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.6.3 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.6.2 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.6.1 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.6.0 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.5.1 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.5.0 decidim-admin/spec/commands/update_newsletter_spec.rb