-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add editor_image spec for private user case
- Loading branch information
1 parent
10e713e
commit 7e42f67
Showing
1 changed file
with
55 additions
and
0 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
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 |