-
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.
Fix editor image upload for private user / Add spec
- Loading branch information
1 parent
803fdd4
commit c0d56db
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
app/models/concerns/decidim/privacy/editor_image_extensions.rb
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Privacy | ||
module EditorImageExtensions | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
belongs_to :author, -> { entire_collection }, foreign_key: :decidim_author_id, class_name: "Decidim::User" | ||
end | ||
end | ||
end | ||
end |
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
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,54 @@ | ||
# 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:, | ||
author_id: user.id, | ||
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 |