Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic attachment uploads #8681

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
0305b5b
Initial
lahdeero Dec 17, 2021
ef95e5f
Can upload attachments
lahdeero Dec 20, 2021
af05f8d
Can download attachment
lahdeero Dec 21, 2021
639070c
Upload modal contract
lahdeero Dec 21, 2021
57e0978
Add multiple attachments with titles
lahdeero Dec 22, 2021
af5d839
Add npm depenency and change variable names
lahdeero Dec 23, 2021
bc77948
Fix show new file fields and click to upload
lahdeero Dec 23, 2021
caf16b8
Edit attachment title and remove attachment
lahdeero Dec 23, 2021
afe9148
Can upload photos
lahdeero Dec 27, 2021
f90579e
Rewrite form.upload so dynamic uploads are used everywhere
lahdeero Dec 27, 2021
c95e975
Field acceps single or multiple files
lahdeero Dec 28, 2021
c0f1ae8
Can change avatar
lahdeero Dec 29, 2021
41c6b5a
Refactoring and fix proposal uploads
lahdeero Dec 30, 2021
62a5b33
Fix untitled uploads
lahdeero Dec 30, 2021
1914257
Validates uploads (just console messages for now)
lahdeero Dec 30, 2021
d0d55e8
Upload validations and show current image
lahdeero Jan 3, 2022
4bdca16
Fix title change and locales
lahdeero Jan 4, 2022
0089b2b
Fix form update when not changing attachment
lahdeero Jan 4, 2022
c25e5ac
Fix edit button label
lahdeero Jan 4, 2022
9782803
Validate file size before uploading
lahdeero Jan 5, 2022
3234088
Move activestorage to core/package.json
lahdeero Jan 5, 2022
1fe175a
Downgrade activestorage npm package
lahdeero Jan 5, 2022
0a98768
Fix some tests and deduce button label
lahdeero Jan 5, 2022
f3720fd
Get resource class from validator
lahdeero Jan 10, 2022
98e0958
Fix form builder specs
lahdeero Jan 10, 2022
f3d16db
Fix upload item css
lahdeero Jan 11, 2022
9b5afe2
Fixing tests
lahdeero Jan 11, 2022
bf1e021
remove byebug
lahdeero Jan 11, 2022
ec7cc85
Fetch the resouce class from the PassthruValidator
ahukkanen Jan 11, 2022
53f8daa
Make the resource_class method private
ahukkanen Jan 11, 2022
5d026fa
Move the object attribute fetching outside of the validators check
ahukkanen Jan 11, 2022
6d72d49
Add "Private" to the method description
ahukkanen Jan 11, 2022
0288a99
Revert the passthrough validator organization setting to original
ahukkanen Jan 11, 2022
d48d558
Do not use the resource_class option if not present or nil
ahukkanen Jan 11, 2022
92f03c0
Fix upload progress bar percentages
lahdeero Jan 11, 2022
4e9f17b
Add option to delete file before upload
lahdeero Jan 12, 2022
0ba53af
Update import form
lahdeero Jan 12, 2022
c6ba44a
Attach_file -> dynamically_attach_file
lahdeero Jan 12, 2022
6e22fa9
Add token to modal and fix form test
lahdeero Jan 12, 2022
1da2d95
Update proposals tests
lahdeero Jan 12, 2022
1ef097f
Validate OAuthApplication organization logo manually
lahdeero Jan 12, 2022
9ffbc9c
Add with option when creating passthruvalidator
lahdeero Jan 13, 2022
6c0f27f
Fix attachment messages and improve validations
lahdeero Jan 13, 2022
3ce63b5
Debug form error
lahdeero Jan 13, 2022
6ae1e71
Show empty file error next to button
lahdeero Jan 13, 2022
f2fc702
Add hidden field for existing titled attachments
lahdeero Jan 14, 2022
0493a5b
Dont require attachment in admin new proposal form
lahdeero Jan 14, 2022
e72d774
Fix participatory texts attachments
lahdeero Jan 14, 2022
7b68a82
Fix proposal import tests
lahdeero Jan 14, 2022
a7afff5
Fixing tests
lahdeero Jan 14, 2022
6afc49d
Remove file before adding new
lahdeero Jan 14, 2022
b7bb938
Get paths from blobs
lahdeero Jan 14, 2022
d827143
Add fileblob concern and upload_test_file helper
lahdeero Jan 18, 2022
624f0ed
Merge develop
lahdeero Jan 19, 2022
1953e91
Change module name
lahdeero Jan 19, 2022
4791639
Attribute name cant be attribute
lahdeero Jan 19, 2022
9c51185
Add passthruvalidation with to dynamical validations
lahdeero Jan 19, 2022
519b963
Dont raise if record doesnt respond to attached_uploader
lahdeero Jan 19, 2022
79f5810
Check if responds before calling
lahdeero Jan 19, 2022
7275513
Merge branch 'develop' into feature/dynamical_attachment_uploads
lahdeero Jan 20, 2022
c98eb94
Fix erb linter errors
lahdeero Jan 20, 2022
86e2ef1
Handle titleable attachments without title
lahdeero Jan 20, 2022
56c129a
Rescue when klass is Class:xxx
lahdeero Jan 20, 2022
821ce9c
Update test files
lahdeero Jan 20, 2022
50cb21e
Extra check for button label
lahdeero Jan 21, 2022
a9efabb
Update tests
lahdeero Jan 21, 2022
5a9c5a1
Rescue when choosing button label
lahdeero Jan 21, 2022
0b5537c
Update elections view, form and command
lahdeero Jan 21, 2022
4a03cfa
Update gallery methods and some tests
lahdeero Jan 21, 2022
f664313
Add comments and remove useless(?) stuff
lahdeero Jan 24, 2022
9a2ef24
Merge develop
lahdeero Jan 24, 2022
24554f5
Divide cell and change passthru condition
lahdeero Jan 25, 2022
a7cd848
Fix admin css and wrap default image to a link
lahdeero Jan 25, 2022
9fdca58
Truncate long filenames
lahdeero Jan 25, 2022
432a02b
Edit comments and remove unused methods
lahdeero Jan 25, 2022
386f6f9
Merge develop
lahdeero Jan 25, 2022
6c9ee11
npm i
lahdeero Jan 25, 2022
513c63c
Bring back extension and dimensions helps
lahdeero Jan 26, 2022
ca9c429
Fix long avatar filename
lahdeero Jan 26, 2022
ce207ba
Add tests for new files
lahdeero Jan 26, 2022
4ce10cd
Add presence validations to upload form
lahdeero Jan 26, 2022
c6f7c0d
Change upload validation param names
lahdeero Jan 26, 2022
ab136a6
Merge branch 'develop' into feature/dynamical_attachment_uploads
ahukkanen Feb 4, 2022
505dc5f
Merge branch 'develop' into feature/dynamical_attachment_uploads
ahukkanen Feb 7, 2022
b9f1ded
Modal requireds titles for attachments
lahdeero Feb 7, 2022
a71789b
Merge branch 'develop' into feature/dynamical_attachment_uploads
lahdeero Feb 8, 2022
a9d4100
Proposal image documents shown in documents
lahdeero Feb 8, 2022
742a999
Check if form responds to documents
lahdeero Feb 8, 2022
0d2bf4b
Fix issue with changing proposal photo
ahukkanen Feb 10, 2022
f0584db
Rename `dynamical-uploads` to `dynamic-uploads`
ahukkanen Feb 10, 2022
c6998b8
Test that the card photo field works correctly for proposals
ahukkanen Feb 10, 2022
02a7048
Rename CreateUploadValidation command to ValidateUpload
ahukkanen Feb 10, 2022
28072fc
Call the correct command in the upload validations controller
ahukkanen Feb 10, 2022
15da875
Small refactoring in the UploadValidationForm
ahukkanen Feb 10, 2022
c8fbf03
Merge branch 'develop' into feature/dynamical_attachment_uploads
ahukkanen Feb 10, 2022
f48b0bd
Fix the attachment weights for photo and file in proposals edit spec
ahukkanen Feb 10, 2022
c830033
Correct the first attachment weight
ahukkanen Feb 10, 2022
8f8e578
Fix proposal admin attachment weights on create and update
ahukkanen Feb 10, 2022
30792d8
Rename the dynamical_attach.rb RSpec support file to dynamic_attach.rb
ahukkanen Feb 10, 2022
86397f4
Fix the account spec after core merge
ahukkanen Feb 10, 2022
4af04d6
Clarify the path variable in the importer_for method
ahukkanen Feb 10, 2022
9088652
Clarify the text example names
ahukkanen Feb 10, 2022
0c377e1
Consistent reference for the upload buttons
ahukkanen Feb 10, 2022
90dd182
Bring back important comments that got removed during the implementation
ahukkanen Feb 10, 2022
76f5868
Explain why validates_upload is not used for OauthApplication
ahukkanen Feb 10, 2022
61eadf7
Improve the content processor translations in the upload modal
ahukkanen Feb 10, 2022
b0e9b79
Fix the :dimensions_info spec for the form builder upload
ahukkanen Feb 10, 2022
a4107c0
Improve method naming in few places
ahukkanen Feb 10, 2022
1d36f2f
Add back admin manages votings spec for invalid banner image
ahukkanen Feb 10, 2022
371074a
Fix the unallowed characters in the failure artefact names
ahukkanen Feb 10, 2022
cdca145
Use native driver for Capybara to `send_keys` in the admin organizati…
ahukkanen Feb 10, 2022
5190046
Merge branch 'develop' into feature/dynamical_attachment_uploads
ahukkanen Feb 11, 2022
b1f5eff
Rename the upload modal "attachments" to "files"
ahukkanen Feb 11, 2022
c6b0b6f
Change the upload options as a JSON in a single data-attribute
ahukkanen Feb 11, 2022
dca04f2
Fix the ID prefix in the dynamic upload button
ahukkanen Feb 11, 2022
a0692ab
Fix the ID references for the dynamic uploads in the specs
ahukkanen Feb 11, 2022
dd133eb
Fix the UploadModal cell spec
ahukkanen Feb 11, 2022
8d3e2b9
Fix the button ID in the manage votings spec
ahukkanen Feb 11, 2022
0f3d724
Merge branch 'develop' into feature/dynamical_attachment_uploads
ahukkanen Feb 15, 2022
0046afa
Merge branch 'develop' into feature/dynamical_attachment_uploads
ahukkanen Feb 16, 2022
a4b1a81
Merge branch 'develop' into feature/dynamical_attachment_uploads
ahukkanen Feb 24, 2022
92536e1
Remove 'remove'-button from optional attachments
lahdeero Feb 28, 2022
a9d4f34
Swap dropzone and upload-items order
lahdeero Feb 28, 2022
cd106e4
Make button color white in admin panel
lahdeero Feb 28, 2022
c99e39a
Fix styling in admin side
lahdeero Feb 28, 2022
5b00f32
Remove unused locale
lahdeero Feb 28, 2022
67808cc
Update test
lahdeero Feb 28, 2022
7c1ba15
Fix css linter errors
lahdeero Feb 28, 2022
b747a7b
Merge branch 'develop' into feature/dynamical_attachment_uploads
lahdeero Mar 1, 2022
b1c218d
Fix remove of untitled attachment
lahdeero Mar 1, 2022
d9589d4
Update decidim-core/app/commands/decidim/validate_upload.rb
lahdeero Mar 2, 2022
169668a
Change @rails/activestorage version
lahdeero Mar 2, 2022
1e40c47
Update decidim-proposals/config/locales/en.yml
lahdeero Mar 2, 2022
f512700
Merge branch 'feature/dynamical_attachment_uploads' of github.com:mai…
lahdeero Mar 2, 2022
e032691
Update decidim-core/app/cells/decidim/upload_modal/modal.erb
lahdeero Mar 2, 2022
e1310ce
Merge branch 'feature/dynamical_attachment_uploads' of github.com:mai…
lahdeero Mar 2, 2022
25b3039
Update static labels to i18n
lahdeero Mar 2, 2022
efde026
Dont downgrade emoji-button
lahdeero Mar 2, 2022
78be8a2
Merge branch 'develop' into feature/dynamical_attachment_uploads
lahdeero Mar 2, 2022
cfe75d5
Add changelog entry
lahdeero Mar 2, 2022
5c8f58f
Fix typo
lahdeero Mar 2, 2022
f40058b
Copy package-lock to app design
lahdeero Mar 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,19 @@ In the next version (v0.28.0) it will be fully removed from the database.

### Added

#### Dynamic attachment uploads
PR [\#8681] https://github.com/decidim/decidim/pull/8681 Changes the way file uploads work in Decidim. Files are now dynamically uploaded inside the modal so we can give the user immediate feedback on validation. There are now two different types of file fields: titled and untitled. Titled file fields related to ```Decidim::Attachment``` internally.

**To update your module** you probably have to update forms and commands related to upload field (also views should be updated in case of titled attachments). After successful a upload and submitting a form, request params should contain signed_id of [ActiveStorage::Blob](https://api.rubyonrails.org/classes/ActiveStorage/Blob.html) which you need to find the blob at the backend.

To update view with titled file field see example: [edit_form_fields.html.erb](https://github.com/decidim/decidim/pull/8681/files#diff-17a22480fdfa3d439edcb26eb0a1a52bed5521d61ba36e0cc6ca83e838f03e9b)

To update untitled form example: [import_form.rb](https://github.com/decidim/decidim/pull/8681/files#diff-5ce71b5873906c6f8919f4bc1f8c330bd97e8757760705a66c789f375eb743c1)

To update untitled command example: [update_account.rb](https://github.com/decidim/decidim/pull/8681/files#diff-ed1274f76cd0ac1d5b223648dcdae670c2127c7dffa0d38540c1536a86f36abb)

[Learn more about direct uploads](https://edgeguides.rubyonrails.org/active_storage_overview.html#direct-uploads)

#### Moderated content can now be removed from search index
PR [\#8811](https://github.com/decidim/decidim/pull/8811) is addressing an issue when the moderated resources are not removed from the general search index.

Expand Down
Expand Up @@ -47,7 +47,7 @@ def build_attachment
weight: form.weight,
attachment_collection: form.attachment_collection,
file: form.file, # Define attached_to before this
content_type: form.file.content_type
content_type: blob(form.file).content_type
)
end

Expand All @@ -61,6 +61,10 @@ def notify_followers
followers: @attachment.attached_to.followers
)
end

def blob(signed_id)
ActiveStorage::Blob.find_signed(signed_id)
end
end
end
end
Expand Up @@ -5,6 +5,8 @@
module Decidim
module Admin
class ProcessParticipatorySpacePrivateUserImportCsv < Decidim::Command
include Decidim::HasBlobFile

# Public: Initializes the command.
#
# form - the form object containing the uploaded file
Expand Down Expand Up @@ -32,7 +34,7 @@ def call
private

def process_csv
CSV.foreach(@form.file.path, encoding: "BOM|UTF-8") do |email, user_name|
CSV.foreach(blob_path, encoding: "BOM|UTF-8") do |email, user_name|
ImportParticipatorySpacePrivateUserCsvJob.perform_later(email, user_name, @private_users_to, @current_user) if email.present? && user_name.present?
end
end
Expand Down
Expand Up @@ -7,6 +7,8 @@ module Admin
# A command with all the business logic when processing the CSV to verify
# user groups.
class ProcessUserGroupVerificationCsv < Decidim::Command
include Decidim::HasBlobFile

# Public: Initializes the command.
#
# form - the form object containing the uploaded file
Expand All @@ -33,7 +35,7 @@ def process_csv
verifier = @form.current_user
organization = @form.current_organization

CSV.foreach(@form.file.path) do |row|
CSV.foreach(blob_path) do |row|
email = row[0]
VerifyUserGroupFromCsvJob.perform_later(email, verifier, organization) if email.present?
end
Expand Down
12 changes: 8 additions & 4 deletions decidim-admin/app/forms/decidim/admin/import_form.rb
Expand Up @@ -50,26 +50,30 @@ def verify_import
end

def file_path
file&.path
ActiveStorage::Blob.service.path_for(blob.key) if blob.respond_to? :key
end

def mime_type
file&.content_type
blob&.content_type
end

def creator_class
manifest.creator
end

def importer_for(filepath, mime_type)
def importer_for(path, mime_type)
Import::ImporterFactory.build(
filepath,
path,
mime_type,
context: importer_context,
creator: creator_class
)
end

def blob
@blob ||= ActiveStorage::Blob.find_signed(file) if file.presence.is_a?(String)
end

protected

def accepted_mime_type?
Expand Down
Expand Up @@ -8,6 +8,7 @@ module Admin
#
class ParticipatorySpacePrivateUserCsvImportForm < Form
include Decidim::HasUploadValidations
include Decidim::HasBlobFile

attribute :file
attribute :user_name, String
Expand All @@ -19,7 +20,7 @@ class ParticipatorySpacePrivateUserCsvImportForm < Form
def validate_csv
return if file.blank?

CSV.foreach(file.path) do |_email, user_name|
CSV.foreach(blob_path) do |_email, user_name|
errors.add(:user_name, :invalid) unless user_name.match?(UserBaseEntity::REGEXP_NAME)
end
end
Expand Down
1 change: 1 addition & 0 deletions decidim-admin/app/packs/entrypoints/decidim_admin.js
Expand Up @@ -33,6 +33,7 @@ import "src/decidim/ajax_modals"
import "src/decidim/admin/officializations"
import "src/decidim/session_timeouter"
import "src/decidim/slug_form"
import "src/decidim/direct_uploads/upload_field"
import "src/decidim/admin/admin_autocomplete"

// CSS
Expand Down
Expand Up @@ -32,6 +32,7 @@
@import "stylesheets/decidim/admin/modules/loading-spinner";
@import "stylesheets/decidim/admin/modules/import_result";
@import "stylesheets/decidim/admin/modules/reveal";
@import "stylesheets/decidim/admin/modules/upload_modal";

// mentions__container
@import "stylesheets/decidim/modules/tags";
Expand Down
@@ -0,0 +1,42 @@
@import "stylesheets/decidim/modules/upload_modal";

.upload-modal{
button{
cursor: pointer;
}

.upload-items{
.upload-item-first-row{
display: flex;

.file-name-span{
flex: 4 1 0;
}

.title-container{
flex: 3.5 1 0;
}
}

.upload-item-second-row{
display: flex;

.progress-bar-wrapper{
flex: 4 1 0;
margin-right: 1rem;

.progress-bar-border{
border: 1px solid map-get($foundation-palette, primary);

.progress-bar{
background-color: map-get($foundation-palette, primary);
}
}
}

.remove-upload-item{
flex: 1 1 0;
}
}
}
}
Expand Up @@ -15,7 +15,12 @@
<% end %>

<div class="row column">
<%= form.file_field :add_photos, multiple: true, label: t(".add_images") %>
<%= form.attachment :photos,
multiple: true,
label: t(".add_images"),
button_label: t(".add_images"),
button_edit_label: t(".edit_images"),
help_i18n_scope: "decidim.forms.file_help.image" %>
</div>
</fieldset>
</div>
1 change: 1 addition & 0 deletions decidim-admin/config/locales/en.yml
Expand Up @@ -902,6 +902,7 @@ en:
gallery:
add_images: Add images
delete_image: Delete Image
edit_images: Edit images
gallery_legend: Add an image gallery (Optional)
static_page_topics:
create:
Expand Down
Expand Up @@ -48,8 +48,11 @@
es: "Este documento contiene información importante",
ca: "Aquest document conté informació important"
)
end

dynamically_attach_file(:attachment_file, Decidim::Dev.asset("Exampledocument.pdf"))

attach_file :attachment_file, Decidim::Dev.asset("Exampledocument.pdf")
within ".new_attachment" do
find("*[type=submit]").click
end

Expand Down Expand Up @@ -81,7 +84,11 @@
)

select translated(attachment_collection.name, locale: :en), from: "attachment_attachment_collection_id"
attach_file :attachment_file, Decidim::Dev.asset("Exampledocument.pdf")
end

dynamically_attach_file(:attachment_file, Decidim::Dev.asset("Exampledocument.pdf"))

within ".new_attachment" do
find("*[type=submit]").click
end

Expand Down
Expand Up @@ -24,12 +24,7 @@ module Decidim::Admin
weight: 0
)
end
let(:file) do
Rack::Test::UploadedFile.new(
Decidim::Dev.test_file("city.jpeg", "image/jpeg"),
"image/jpeg"
)
end
let(:file) { upload_test_file(Decidim::Dev.test_file("city.jpeg", "image/jpeg")) }
let(:attached_to) { create(:participatory_process) }

describe "when valid" do
Expand Down
Expand Up @@ -10,7 +10,7 @@ module Decidim::Admin
let(:organization) { create(:organization) }
let(:participatory_space) { create(:participatory_process, organization: organization) }
let!(:component) { create(:dummy_component, organization: organization) }
let(:file) { Decidim::Dev.test_file("verify_user_groups.csv", "text/csv") }
let(:file) { upload_test_file(Decidim::Dev.test_file("verify_user_groups.csv", "text/csv")) }

let(:form) do
Decidim::Admin::ImportForm.from_params(
Expand Down
Expand Up @@ -9,7 +9,7 @@ module Decidim::Admin
let(:current_user) { create(:user, :admin, organization: organization) }
let(:organization) { create(:organization) }
let(:private_users_to) { create :participatory_process, organization: organization }
let(:file) { File.new Decidim::Dev.asset("import_participatory_space_private_users.csv") }
let(:file) { upload_test_file(Decidim::Dev.test_file("import_participatory_space_private_users.csv", "text/csv")) }
let(:validity) { true }

let(:form) do
Expand Down Expand Up @@ -37,7 +37,7 @@ module Decidim::Admin
end

context "when the CSV file has BOM" do
let(:file) { File.new Decidim::Dev.asset("import_participatory_space_private_users_with_bom.csv") }
let(:file) { upload_test_file(Decidim::Dev.test_file("import_participatory_space_private_users_with_bom.csv", "text/csv")) }
let(:email) { "my_user@example.org" }

it "broadcasts ok" do
Expand Down
Expand Up @@ -8,7 +8,7 @@ module Decidim::Admin

let(:user) { create(:user, :admin, organization: organization) }
let(:organization) { create(:organization) }
let(:file) { File.new Decidim::Dev.asset("verify_user_groups.csv") }
let(:file) { upload_test_file(Decidim::Dev.test_file("verify_user_groups.csv", "text/csv")) }
let(:validity) { true }

let(:form) do
Expand Down
8 changes: 4 additions & 4 deletions decidim-admin/spec/forms/decidim/admin/import_form_spec.rb
Expand Up @@ -10,7 +10,7 @@ module Admin
let(:organization) { create(:organization) }
let!(:component) { create(:dummy_component, organization: organization) }
let(:user) { create(:user, :confirmed, :admin, organization: organization) }
let(:file) { Decidim::Dev.test_file("import_proposals.csv", "text/csv") }
let(:file) { upload_test_file(Decidim::Dev.test_file("import_proposals.csv", "text/csv")) }
let(:name) { "dummies" }

let(:params) { { file: file, name: name } }
Expand All @@ -28,17 +28,17 @@ module Admin
end

context "when content type is not accepted" do
let(:file) { Decidim::Dev.test_file("city.jpeg", "image/jpeg") }
let(:file) { upload_test_file(Decidim::Dev.test_file("city.jpeg", "image/jpeg")) }

it { is_expected.not_to be_valid }
end

context "when the file is not a valid file" do
let(:file) { Decidim::Dev.test_file("Exampledocument.pdf", Decidim::Admin::Import::Readers::XLSX::MIME_TYPE) }
let(:file) { upload_test_file(Decidim::Dev.test_file("Exampledocument.pdf", Decidim::Admin::Import::Readers::XLSX::MIME_TYPE)) }

it "reports invalid and adds the correct error for the file field" do
expect(subject).not_to be_valid
expect(subject.errors[:file]).to include("Invalid file provided, please check that the file is correctly formatted")
expect(subject.errors[:file]).to include("Invalid mime type")
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions decidim-admin/spec/forms/organization_appearance_form_spec.rb
Expand Up @@ -101,7 +101,7 @@ module Admin
let(:highlighted_content_banner_action_title) { Decidim::Faker::Localized.sentence(word_count: 2) }
let(:highlighted_content_banner_action_subtitle) { Decidim::Faker::Localized.sentence(word_count: 2) }
let(:highlighted_content_banner_action_url) { ::Faker::Internet.url }
let(:highlighted_content_banner_image) { Decidim::Dev.test_file("city.jpeg", "image/jpeg") }
let(:highlighted_content_banner_image) { upload_test_file(Decidim::Dev.test_file("city.jpeg", "image/jpeg")) }

it { is_expected.to be_valid }

Expand Down Expand Up @@ -130,12 +130,12 @@ module Admin
end

context "and highlighted_content_banner_image is blank" do
let(:highlighted_content_banner_image) { "" }
let(:highlighted_content_banner_image) { nil }

it { is_expected.not_to be_valid }

context "and the organization already has an image set" do
let(:organization) { create :organization, highlighted_content_banner_image: Decidim::Dev.test_file("city.jpeg", "image/jpeg") }
let(:organization) { create :organization, highlighted_content_banner_image: upload_test_file(Decidim::Dev.test_file("city.jpeg", "image/jpeg")) }
let(:highlighted_content_banner_image) { nil }

it { is_expected.to be_valid }
Expand Down
Expand Up @@ -22,7 +22,7 @@ module Admin
"file" => file
}
end
let(:file) { File.new Decidim::Dev.asset("import_participatory_space_private_users.csv") }
let(:file) { upload_test_file(Decidim::Dev.asset("import_participatory_space_private_users.csv")) }

context "when everything is OK" do
it { is_expected.to be_valid }
Expand All @@ -35,7 +35,7 @@ module Admin
end

context "when user name contains invalid chars" do
let(:file) { File.new Decidim::Dev.asset("import_participatory_space_private_users_nok.csv") }
let(:file) { upload_test_file(Decidim::Dev.asset("import_participatory_space_private_users_nok.csv")) }

it { is_expected.to be_invalid }
end
Expand Down
7 changes: 3 additions & 4 deletions decidim-admin/spec/system/admin_manages_newsletters_spec.rb
Expand Up @@ -75,12 +75,11 @@
es: "Hola, %{name}! Contenido relevante.",
ca: "Hola, %{name}! Contingut rellevant."
)
end

attach_file(
"Main image",
Decidim::Dev.asset("city2.jpeg")
)
dynamically_attach_file(:newsletter_images_main_image, Decidim::Dev.asset("city2.jpeg"))

within ".new_newsletter" do
find("*[type=submit]").click
end

Expand Down
Expand Up @@ -47,10 +47,10 @@

fill_in "Official organization URL", with: "http://www.example.com"

attach_file "Logo", Decidim::Dev.asset("city2.jpeg")
attach_file "Icon", Decidim::Dev.asset("icon.png")
attach_file "Official logo header", Decidim::Dev.asset("city2.jpeg")
attach_file "Official logo footer", Decidim::Dev.asset("city3.jpeg")
dynamically_attach_file(:organization_logo, Decidim::Dev.asset("city2.jpeg"))
dynamically_attach_file(:organization_favicon, Decidim::Dev.asset("city3.jpeg"), remove_before: true)
dynamically_attach_file(:organization_official_img_header, Decidim::Dev.asset("city2.jpeg"), remove_before: true)
dynamically_attach_file(:organization_official_img_footer, Decidim::Dev.asset("city3.jpeg"), remove_before: true)

fill_in :organization_theme_color, with: "#a0a0a0"

Expand Down
Expand Up @@ -46,10 +46,7 @@
it "updates the images of the content block" do
visit decidim_admin.edit_organization_homepage_content_block_path(:hero)

attach_file(
:content_block_images_background_image,
Decidim::Dev.asset("city2.jpeg")
)
dynamically_attach_file(:content_block_images_background_image, Decidim::Dev.asset("city2.jpeg"))

click_button "Update"
visit decidim.root_path
Expand Down