diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index bb600ff83..559599297 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -319,7 +319,8 @@ .legislation-process-edit, .milestone-new, .milestone-edit, -.image-form { +.image-form, +.dashboard-action-form { @include direct-uploads; } diff --git a/app/models/dashboard/action.rb b/app/models/dashboard/action.rb index 88f94704d..84772c9e0 100644 --- a/app/models/dashboard/action.rb +++ b/app/models/dashboard/action.rb @@ -2,7 +2,11 @@ class Dashboard::Action < ActiveRecord::Base include Documentable documentable max_documents_allowed: 3, max_file_size: 3.megabytes, - accepted_content_types: [ 'application/pdf' ] + accepted_content_types: [ "application/pdf", + "image/jpeg", + "image/jpg", + "image/png", + "application/zip" ] include Linkable @@ -14,7 +18,7 @@ class Dashboard::Action < ActiveRecord::Base enum action_type: [:proposed_action, :resource] - validates :title, + validates :title, presence: true, allow_blank: false, length: { in: 4..80 } @@ -40,7 +44,7 @@ class Dashboard::Action < ActiveRecord::Base scope :resources, -> { where(action_type: 1) } scope :proposed_actions, -> { where(action_type: 0) } - def self.active_for(proposal) + def self.active_for(proposal) published_at = proposal.published_at&.to_date || Date.today active diff --git a/app/views/admin/dashboard/actions/edit.html.erb b/app/views/admin/dashboard/actions/edit.html.erb index d3361524c..5a94ec443 100644 --- a/app/views/admin/dashboard/actions/edit.html.erb +++ b/app/views/admin/dashboard/actions/edit.html.erb @@ -3,6 +3,8 @@

<%= t("admin.dashboard.actions.edit.editing") %>

-<%= form_for dashboard_action, url: { action: 'update' } do |f| %> - <%= render 'form', f: f %> -<% end %> +
+ <%= form_for dashboard_action, url: { action: 'update' } do |f| %> + <%= render 'form', f: f %> + <% end %> +
diff --git a/app/views/admin/dashboard/actions/new.html.erb b/app/views/admin/dashboard/actions/new.html.erb index adcb1a9a1..0ef2c672c 100644 --- a/app/views/admin/dashboard/actions/new.html.erb +++ b/app/views/admin/dashboard/actions/new.html.erb @@ -3,6 +3,8 @@

<%= t("admin.dashboard.actions.new.creating") %>

-<%= form_for dashboard_action, url: { action: 'create' } do |f| %> - <%= render 'form', f: f %> -<% end %> +
+ <%= form_for dashboard_action, url: { action: 'create' } do |f| %> + <%= render 'form', f: f %> + <% end %> +
diff --git a/spec/features/admin/dashboard/actions_spec.rb b/spec/features/admin/dashboard/actions_spec.rb index 4246ca845..4462a32c9 100644 --- a/spec/features/admin/dashboard/actions_spec.rb +++ b/spec/features/admin/dashboard/actions_spec.rb @@ -7,6 +7,15 @@ feature 'Admin dashboard actions' do login_as(admin.user) end + it_behaves_like "nested documentable", + "administrator", + "dashboard_action", + "new_admin_dashboard_action_path", + { }, + "documentable_fill_new_valid_dashboard_action", + "Save", + "Action created successfully" + context 'when visiting index' do context 'and no actions defined' do before do diff --git a/spec/shared/features/nested_documentable.rb b/spec/shared/features/nested_documentable.rb index 6d1700347..298f61fe9 100644 --- a/spec/shared/features/nested_documentable.rb +++ b/spec/shared/features/nested_documentable.rb @@ -9,7 +9,11 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na let!(:administrator) { create(:user) } let!(:user) { create(:user, :level_two) } let!(:arguments) { {} } - let!(:documentable) { create(documentable_factory_name, author: user) } + if documentable_factory_name == "dashboard_action" + let!(:documentable) { create(documentable_factory_name) } + else + let!(:documentable) { create(documentable_factory_name, author: user) } + end let!(:user_to_login) { send(login_as_name)} before do @@ -133,7 +137,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na visit send(path, arguments) documentable_attach_new_file( - Rails.root.join('spec/fixtures/files/logo_header.png'), + Rails.root.join("spec/fixtures/files/logo_header.gif"), false ) @@ -154,7 +158,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na visit send(path, arguments) documentable_attach_new_file( - Rails.root.join('spec/fixtures/files/logo_header.png'), + Rails.root.join("spec/fixtures/files/logo_header.gif"), false ) @@ -208,6 +212,9 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na end scenario "Should show new document after successful creation with one uploaded file", :js do + if documentable_factory_name == "dashboard_action" + skip("Not render Documents count on dashboard_actions") + end login_as user_to_login visit send(path, arguments) send(fill_resource_method_name) if fill_resource_method_name @@ -227,6 +234,9 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na scenario "Should show resource with new document after successful creation with maximum allowed uploaded files", :js do + if documentable_factory_name == "dashboard_action" + skip("Not render Documents count on dashboard_actions") + end login_as user_to_login visit send(path, arguments) FILENAMES ||= %w(clippy empty logo).freeze @@ -359,6 +369,11 @@ def documentable_fill_new_valid_proposal check :proposal_terms_of_service end +def documentable_fill_new_valid_dashboard_action + fill_in :dashboard_action_title, with: "Dashboard title" + fill_in :dashboard_action_short_description, with: "Dashboard description" +end + def documentable_fill_new_valid_budget_investment page.select documentable.heading.name_scoped_by_group, from: :budget_investment_heading_id fill_in :budget_investment_title, with: "Budget investment title"