Skip to content

Commit

Permalink
Add editor_image spec for private user case
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonasAapro committed Jun 18, 2024
1 parent 10e713e commit 7e42f67
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions spec/commands/decidim/create_editor_image_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
describe CreateEditorImage do
subject { described_class.new(form) }

let(:form) do
EditorImageForm.from_params(attributes).with_context(context)
end
let(:attributes) do
{
"editor_image" => {
organization: organization,
author_id: user.id,
file: file
}
}
end
let(:context) do
{
current_organization: organization,
current_user: user
}
end
let(:user) { create(:user, :admin, :confirmed) }
let(:organization) { user.organization }
let(:file) { Decidim::Dev.test_file("city.jpeg", "image/jpeg") }

context "when the user is private" do
it "broadcasts ok" do
expect { subject.call }.to broadcast(:ok)
expect(user.public?).to be(false)
end

it "creates an editor image" do
expect { subject.call }.to change(Decidim::EditorImage, :count).by(1)
end
end

context "when the user is public" do
let(:user) { create(:user, :admin, :published, :confirmed) }

it "broadcasts ok" do
expect { subject.call }.to broadcast(:ok)
expect(user.public?).to be(true)
end

it "creates an editor image" do
expect { subject.call }.to change(Decidim::EditorImage, :count).by(1)
end
end
end
end

0 comments on commit 7e42f67

Please sign in to comment.