Sha256: ab427062ee7f171e25367dbae0c9e9615f573102f3ae597c92c992dcf323d4de

Contents?: true

Size: 1.38 KB

Versions: 26

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # This class is used to generate fake newsletters and data to preview
    # newsletter templates.
    class FakeNewsletter
      def initialize(organization, manifest)
        @organization = organization
        @manifest = manifest
      end

      def id
        1
      end

      def template
        @template ||= Decidim::ContentBlock.new(
          in_preview: true,
          manifest_name: manifest.name,
          scope_name: :newsletter_template,
          settings: manifest.settings.attributes.inject({}) do |acc, (name, attrs)|
            value = if attrs.preview.respond_to?(:call)
                      attrs.preview.call
                    else
                      attrs.preview
                    end

            acc.update(name => value)
          end
        )
      end

      def subject
        organization.available_locales.inject({}) do |acc, locale|
          acc.update(locale => "Lorem ipsum")
        end
      end

      def sent_at
        nil
      end

      def draft?
        true
      end

      def url(**_)
        "#"
      end

      def notifications_settings_url(**_)
        "#"
      end

      def unsubscribe_newsletters_url(**_)
        "#"
      end

      def organization_official_url
        "#"
      end

      private

      attr_reader :organization, :manifest
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
decidim-admin-0.26.8 app/models/decidim/admin/fake_newsletter.rb
decidim-admin-0.27.4 app/models/decidim/admin/fake_newsletter.rb
decidim-admin-0.27.3 app/models/decidim/admin/fake_newsletter.rb
decidim-admin-0.26.7 app/models/decidim/admin/fake_newsletter.rb
decidim-admin-0.26.5 app/models/decidim/admin/fake_newsletter.rb
decidim-admin-0.27.2 app/models/decidim/admin/fake_newsletter.rb