Merge pull request #3257 from Platoniq/dashboard-actions-attachments

Dashboard actions attachments
This commit is contained in:
Raimond Garcia
2019-02-28 13:33:38 +01:00
committed by GitHub
6 changed files with 46 additions and 13 deletions

View File

@@ -319,7 +319,8 @@
.legislation-process-edit,
.milestone-new,
.milestone-edit,
.image-form {
.image-form,
.dashboard-action-form {
@include direct-uploads;
}

View File

@@ -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

View File

@@ -3,6 +3,8 @@
<h2><%= t("admin.dashboard.actions.edit.editing") %></h2>
</div>
<%= form_for dashboard_action, url: { action: 'update' } do |f| %>
<%= render 'form', f: f %>
<% end %>
<div class="dashboard-action-form ">
<%= form_for dashboard_action, url: { action: 'update' } do |f| %>
<%= render 'form', f: f %>
<% end %>
</div>

View File

@@ -3,6 +3,8 @@
<h2><%= t("admin.dashboard.actions.new.creating") %></h2>
</div>
<%= form_for dashboard_action, url: { action: 'create' } do |f| %>
<%= render 'form', f: f %>
<% end %>
<div class="dashboard-action-form ">
<%= form_for dashboard_action, url: { action: 'create' } do |f| %>
<%= render 'form', f: f %>
<% end %>
</div>

View File

@@ -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

View File

@@ -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"