Sha256: 014edc4852dcd23468dcd0b62d4976a1081b5cae54b2e88605adb536db0838e1

Contents?: true

Size: 1.8 KB

Versions: 9

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

require "spec_helper"

module Decidim
  module Admin
    describe UpdateNewsletter, :db 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

9 entries across 9 versions & 1 rubygems

Version Path
decidim-0.4.4 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.4.3 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.4.2 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.4.1 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.4.0 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.3.2 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.3.1 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.3.0 decidim-admin/spec/commands/update_newsletter_spec.rb
decidim-0.2.0 decidim-admin/spec/commands/update_newsletter_spec.rb