Merge pull request #4448 from consul/improve-management-investments

Improve create investments in Management section
This commit is contained in:
Javi Martín
2021-04-09 16:40:17 +02:00
committed by GitHub
17 changed files with 133 additions and 69 deletions

View File

@@ -1,4 +1,5 @@
class Admin::Dashboard::ActionsController < Admin::Dashboard::BaseController class Admin::Dashboard::ActionsController < Admin::Dashboard::BaseController
include DocumentAttributes
helper_method :dashboard_action, :resource helper_method :dashboard_action, :resource
def index def index
@@ -58,7 +59,7 @@ class Admin::Dashboard::ActionsController < Admin::Dashboard::BaseController
.permit( .permit(
:title, :description, :short_description, :request_to_administrators, :day_offset, :title, :description, :short_description, :request_to_administrators, :day_offset,
:required_supports, :order, :active, :action_type, :published_proposal, :required_supports, :order, :active, :action_type, :published_proposal,
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], documents_attributes: document_attributes,
links_attributes: [:id, :label, :url, :_destroy] links_attributes: [:id, :label, :url, :_destroy]
) )
end end

View File

@@ -1,6 +1,7 @@
class Admin::Legislation::ProcessesController < Admin::Legislation::BaseController class Admin::Legislation::ProcessesController < Admin::Legislation::BaseController
include Translatable include Translatable
include ImageAttributes include ImageAttributes
include DocumentAttributes
has_filters %w[active all], only: :index has_filters %w[active all], only: :index
@@ -71,7 +72,7 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll
:font_color, :font_color,
:related_sdg_list, :related_sdg_list,
translation_params(::Legislation::Process), translation_params(::Legislation::Process),
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], documents_attributes: document_attributes,
image_attributes: image_attributes image_attributes: image_attributes
] ]
end end

View File

@@ -1,6 +1,7 @@
class Admin::MilestonesController < Admin::BaseController class Admin::MilestonesController < Admin::BaseController
include Translatable include Translatable
include ImageAttributes include ImageAttributes
include DocumentAttributes
before_action :load_milestoneable, only: [:index, :new, :create, :edit, :update, :destroy] before_action :load_milestoneable, only: [:index, :new, :create, :edit, :update, :destroy]
before_action :load_milestone, only: [:edit, :update, :destroy] before_action :load_milestone, only: [:edit, :update, :destroy]
@@ -42,10 +43,9 @@ class Admin::MilestonesController < Admin::BaseController
private private
def milestone_params def milestone_params
documents_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]
attributes = [:publication_date, :status_id, attributes = [:publication_date, :status_id,
translation_params(Milestone), translation_params(Milestone),
image_attributes: image_attributes, documents_attributes: documents_attributes] image_attributes: image_attributes, documents_attributes: document_attributes]
params.require(:milestone).permit(*attributes) params.require(:milestone).permit(*attributes)
end end

View File

@@ -1,4 +1,6 @@
class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseController class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseController
include ImageAttributes
before_action :load_answer, except: :destroy before_action :load_answer, except: :destroy
def index def index
@@ -33,7 +35,7 @@ class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseContr
def images_params def images_params
params.require(:poll_question_answer).permit(:answer_id, params.require(:poll_question_answer).permit(:answer_id,
images_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) images_attributes: image_attributes)
end end
def load_answer def load_answer

View File

@@ -1,5 +1,6 @@
class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
include Translatable include Translatable
include DocumentAttributes
before_action :load_answer, only: [:show, :edit, :update, :documents] before_action :load_answer, only: [:show, :edit, :update, :documents]
@@ -50,9 +51,8 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
private private
def answer_params def answer_params
documents_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]
attributes = [:title, :description, :given_order, :question_id, attributes = [:title, :description, :given_order, :question_id,
documents_attributes: documents_attributes] documents_attributes: document_attributes]
params.require(:poll_question_answer).permit( params.require(:poll_question_answer).permit(
*attributes, translation_params(Poll::Question::Answer) *attributes, translation_params(Poll::Question::Answer)

View File

@@ -5,6 +5,8 @@ module Budgets
include FlagActions include FlagActions
include RandomSeed include RandomSeed
include ImageAttributes include ImageAttributes
include DocumentAttributes
include MapLocationAttributes
include Translatable include Translatable
include InvestmentFilters include InvestmentFilters
@@ -135,8 +137,8 @@ module Budgets
attributes = [:heading_id, :tag_list, :organization_name, :location, attributes = [:heading_id, :tag_list, :organization_name, :location,
:terms_of_service, :skip_map, :related_sdg_list, :terms_of_service, :skip_map, :related_sdg_list,
image_attributes: image_attributes, image_attributes: image_attributes,
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], documents_attributes: document_attributes,
map_location_attributes: [:latitude, :longitude, :zoom]] map_location_attributes: map_location_attributes]
params.require(:budget_investment).permit(attributes, translation_params(Budget::Investment)) params.require(:budget_investment).permit(attributes, translation_params(Budget::Investment))
end end

View File

@@ -0,0 +1,7 @@
module DocumentAttributes
extend ActiveSupport::Concern
def document_attributes
[:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]
end
end

View File

@@ -0,0 +1,7 @@
module MapLocationAttributes
extend ActiveSupport::Concern
def map_location_attributes
[:latitude, :longitude, :zoom]
end
end

View File

@@ -1,4 +1,5 @@
class Dashboard::PollsController < Dashboard::BaseController class Dashboard::PollsController < Dashboard::BaseController
include DocumentAttributes
helper_method :poll helper_method :poll
before_action :authorize_manage_polls before_action :authorize_manage_polls
@@ -70,11 +71,7 @@ class Dashboard::PollsController < Dashboard::BaseController
def question_answers_attributes def question_answers_attributes
[:id, :_destroy, :title, :description, :given_order, :question_id, [:id, :_destroy, :title, :description, :given_order, :question_id,
documents_attributes: documents_attributes] documents_attributes: document_attributes]
end
def documents_attributes
[:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]
end end
def authorize_manage_polls def authorize_manage_polls

View File

@@ -1,5 +1,8 @@
class Management::Budgets::InvestmentsController < Management::BaseController class Management::Budgets::InvestmentsController < Management::BaseController
include Translatable include Translatable
include ImageAttributes
include DocumentAttributes
include MapLocationAttributes
include FeatureFlags include FeatureFlags
feature_flag :budgets feature_flag :budgets
@@ -57,7 +60,10 @@ class Management::Budgets::InvestmentsController < Management::BaseController
end end
def investment_params def investment_params
attributes = [:external_url, :heading_id, :tag_list, :organization_name, :location, :skip_map] attributes = [:external_url, :heading_id, :tag_list, :organization_name, :location, :skip_map,
image_attributes: image_attributes,
documents_attributes: document_attributes,
map_location_attributes: map_location_attributes]
params.require(:budget_investment).permit(attributes, translation_params(Budget::Investment)) params.require(:budget_investment).permit(attributes, translation_params(Budget::Investment))
end end

View File

@@ -2,6 +2,7 @@ class Management::ProposalsController < Management::BaseController
include HasOrders include HasOrders
include CommentableActions include CommentableActions
include Translatable include Translatable
include MapLocationAttributes
before_action :only_verified_users, except: :print before_action :only_verified_users, except: :print
before_action :set_proposal, only: [:vote, :show] before_action :set_proposal, only: [:vote, :show]
@@ -56,7 +57,7 @@ class Management::ProposalsController < Management::BaseController
def proposal_params def proposal_params
attributes = [:video_url, :responsible_name, :tag_list, attributes = [:video_url, :responsible_name, :tag_list,
:terms_of_service, :geozone_id, :terms_of_service, :geozone_id,
:skip_map, map_location_attributes: [:latitude, :longitude, :zoom]] :skip_map, map_location_attributes: map_location_attributes]
params.require(:proposal).permit(attributes, translation_params(Proposal)) params.require(:proposal).permit(attributes, translation_params(Proposal))
end end

View File

@@ -3,6 +3,8 @@ class ProposalsController < ApplicationController
include CommentableActions include CommentableActions
include FlagActions include FlagActions
include ImageAttributes include ImageAttributes
include DocumentAttributes
include MapLocationAttributes
include Translatable include Translatable
before_action :load_categories, only: [:index, :new, :create, :edit, :map, :summary] before_action :load_categories, only: [:index, :new, :create, :edit, :map, :summary]
@@ -101,9 +103,8 @@ class ProposalsController < ApplicationController
attributes = [:video_url, :responsible_name, :tag_list, :terms_of_service, attributes = [:video_url, :responsible_name, :tag_list, :terms_of_service,
:geozone_id, :skip_map, :related_sdg_list, :geozone_id, :skip_map, :related_sdg_list,
image_attributes: image_attributes, image_attributes: image_attributes,
documents_attributes: [:id, :title, :attachment, :cached_attachment, documents_attributes: document_attributes,
:user_id, :_destroy], map_location_attributes: map_location_attributes]
map_location_attributes: [:latitude, :longitude, :zoom]]
translations_attributes = translation_params(Proposal, except: :retired_explanation) translations_attributes = translation_params(Proposal, except: :retired_explanation)
params.require(:proposal).permit(attributes, translations_attributes) params.require(:proposal).permit(attributes, translations_attributes)
end end

View File

@@ -43,7 +43,9 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
find("#new_map_location").click find("#new_map_location").click
send("submit_#{mappable_factory_name}_form") send("submit_#{mappable_factory_name}_form")
expect(page).to have_css(".map_location") within ".map_location" do
expect(page).to have_css(".map-icon")
end
end end
scenario "Can not display map on #{mappable_factory_name} when not fill marker on map" do scenario "Can not display map on #{mappable_factory_name} when not fill marker on map" do
@@ -319,12 +321,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end end
def do_login_for(user) def do_login_for(user)
if management common_do_login_for(user, management: management)
login_managed_user(user)
login_as_manager
else
login_as(user)
end
end end
def fill_in_proposal_form def fill_in_proposal_form

View File

@@ -1,4 +1,6 @@
shared_examples "nested documentable" do |login_as_name, documentable_factory_name, path, documentable_path_arguments, fill_resource_method_name, submit_button, documentable_success_notice| shared_examples "nested documentable" do |login_as_name, documentable_factory_name, path,
documentable_path_arguments, fill_resource_method_name,
submit_button, documentable_success_notice, management: false|
let!(:administrator) { create(:user) } let!(:administrator) { create(:user) }
let!(:user) { create(:user, :level_two) } let!(:user) { create(:user, :level_two) }
let!(:arguments) { {} } let!(:arguments) { {} }
@@ -8,6 +10,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
let!(:documentable) { create(documentable_factory_name, author: user) } let!(:documentable) { create(documentable_factory_name, author: user) }
end end
let!(:user_to_login) { send(login_as_name) } let!(:user_to_login) { send(login_as_name) }
let(:management) { management }
before do before do
create(:administrator, user: administrator) create(:administrator, user: administrator)
@@ -19,7 +22,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
describe "at #{path}" do describe "at #{path}" do
scenario "Should show new document link when max documents allowed limit is not reached" do scenario "Should show new document link when max documents allowed limit is not reached" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
expect(page).to have_css "#new_document_link" expect(page).to have_css "#new_document_link"
@@ -27,7 +30,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should not show new document link when scenario "Should not show new document link when
documentable max documents allowed limit is reached" do documentable max documents allowed limit is reached" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
documentable.class.max_documents_allowed.times.each do documentable.class.max_documents_allowed.times.each do
@@ -38,14 +41,14 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end end
scenario "Should not show max documents warning when no documents added" do scenario "Should not show max documents warning when no documents added" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
expect(page).not_to have_css ".max-documents-notice" expect(page).not_to have_css ".max-documents-notice"
end end
scenario "Should show max documents warning when max documents allowed limit is reached" do scenario "Should show max documents warning when max documents allowed limit is reached" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
documentable.class.max_documents_allowed.times.each do documentable.class.max_documents_allowed.times.each do
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf"))
@@ -56,7 +59,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end end
scenario "Should hide max documents warning after any document removal" do scenario "Should hide max documents warning after any document removal" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
documentable.class.max_documents_allowed.times.each do documentable.class.max_documents_allowed.times.each do
@@ -69,7 +72,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end end
scenario "Should update nested document file name after choosing a file" do scenario "Should update nested document file name after choosing a file" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
click_link "Add new document" click_link "Add new document"
@@ -89,7 +92,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should update nested document file title with scenario "Should update nested document file title with
file name after choosing a file when no title defined" do file name after choosing a file when no title defined" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf"))
@@ -99,7 +102,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should not update nested document file title with scenario "Should not update nested document file title with
file name after choosing a file when title already defined" do file name after choosing a file when title already defined" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
click_link "Add new document" click_link "Add new document"
@@ -120,7 +123,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end end
scenario "Should update loading bar style after valid file upload" do scenario "Should update loading bar style after valid file upload" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf"))
@@ -129,7 +132,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end end
scenario "Should update loading bar style after invalid file upload" do scenario "Should update loading bar style after invalid file upload" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
documentable_attach_new_file( documentable_attach_new_file(
@@ -141,7 +144,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end end
scenario "Should update document cached_attachment field after valid file upload" do scenario "Should update document cached_attachment field after valid file upload" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf"))
@@ -150,7 +153,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end end
scenario "Should not update document cached_attachment field after invalid file upload" do scenario "Should not update document cached_attachment field after invalid file upload" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
documentable_attach_new_file( documentable_attach_new_file(
@@ -163,7 +166,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should show document errors after documentable submit with scenario "Should show document errors after documentable submit with
empty document fields" do empty document fields" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
click_link "Add new document" click_link "Add new document"
@@ -175,7 +178,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end end
scenario "Should delete document after valid file upload and click on remove button" do scenario "Should delete document after valid file upload and click on remove button" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf")) documentable_attach_new_file(Rails.root.join("spec/fixtures/files/empty.pdf"))
@@ -186,7 +189,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should show successful notice when scenario "Should show successful notice when
resource filled correctly without any nested documents" do resource filled correctly without any nested documents" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
@@ -197,7 +200,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should show successful notice when scenario "Should show successful notice when
resource filled correctly and after valid file uploads" do resource filled correctly and after valid file uploads" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
@@ -211,7 +214,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
if documentable_factory_name == "dashboard_action" if documentable_factory_name == "dashboard_action"
skip("Not render Documents count on dashboard_actions") skip("Not render Documents count on dashboard_actions")
end end
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
@@ -233,7 +236,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
if documentable_factory_name == "dashboard_action" if documentable_factory_name == "dashboard_action"
skip("Not render Documents count on dashboard_actions") skip("Not render Documents count on dashboard_actions")
end end
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
@@ -251,7 +254,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
if path.include? "edit" if path.include? "edit"
scenario "Should show persisted documents and remove nested_field" do scenario "Should show persisted documents and remove nested_field" do
create(:document, documentable: documentable) create(:document, documentable: documentable)
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
expect(page).to have_css ".document", count: 1 expect(page).to have_css ".document", count: 1
@@ -260,7 +263,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should not show add document button when scenario "Should not show add document button when
documentable has reached maximum of documents allowed" do documentable has reached maximum of documents allowed" do
create_list(:document, documentable.class.max_documents_allowed, documentable: documentable) create_list(:document, documentable.class.max_documents_allowed, documentable: documentable)
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
expect(page).not_to have_css "#new_document_link" expect(page).not_to have_css "#new_document_link"
@@ -268,7 +271,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should show add document button after destroy one document" do scenario "Should show add document button after destroy one document" do
create_list(:document, documentable.class.max_documents_allowed, documentable: documentable) create_list(:document, documentable.class.max_documents_allowed, documentable: documentable)
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
last_document = all("#nested-documents .document").last last_document = all("#nested-documents .document").last
within last_document do within last_document do
@@ -280,7 +283,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should remove nested field after remove document" do scenario "Should remove nested field after remove document" do
create(:document, documentable: documentable) create(:document, documentable: documentable)
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
click_on "Remove document" click_on "Remove document"
@@ -294,7 +297,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end end
scenario "Add new document button should not be available" do scenario "Add new document button should not be available" do
login_as user_to_login do_login_for user_to_login
visit send(path, arguments) visit send(path, arguments)
expect(page).not_to have_content("Add new document") expect(page).not_to have_content("Add new document")
@@ -303,6 +306,10 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end end
end end
def do_login_for(user)
common_do_login_for(user, management: management)
end
def documentable_redirected_to_resource_show_or_navigate_to def documentable_redirected_to_resource_show_or_navigate_to
find("a", text: "Not now, go to my proposal") find("a", text: "Not now, go to my proposal")
click_on "Not now, go to my proposal" click_on "Not now, go to my proposal"

View File

@@ -1,7 +1,10 @@
shared_examples "nested imageable" do |imageable_factory_name, path, imageable_path_arguments, fill_resource_method_name, submit_button, imageable_success_notice, has_many_images = false| shared_examples "nested imageable" do |imageable_factory_name, path, imageable_path_arguments,
fill_resource_method_name, submit_button, imageable_success_notice,
has_many_images = false, management: false|
let!(:user) { create(:user, :level_two) } let!(:user) { create(:user, :level_two) }
let!(:arguments) { {} } let!(:arguments) { {} }
let!(:imageable) { create(imageable_factory_name) } let!(:imageable) { create(imageable_factory_name) }
let(:management) { management }
before do before do
create(:administrator, user: user) create(:administrator, user: user)
@@ -15,14 +18,14 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
describe "at #{path}" do describe "at #{path}" do
scenario "Should show new image link when imageable has not an associated image defined" do scenario "Should show new image link when imageable has not an associated image defined" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
expect(page).to have_selector "#new_image_link" expect(page).to have_selector "#new_image_link"
end end
scenario "Should hide new image link after adding one image" do scenario "Should hide new image link after adding one image" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
click_on "Add image" click_on "Add image"
@@ -31,7 +34,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should update nested image file name after choosing any file" do scenario "Should update nested image file name after choosing any file" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
click_link "Add image" click_link "Add image"
@@ -46,7 +49,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should update nested image file title with file name after choosing a file when no title defined" do scenario "Should update nested image file title with file name after choosing a file when no title defined" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(
@@ -58,7 +61,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should not update nested image file title with file name after choosing a file when title already defined" do scenario "Should not update nested image file title with file name after choosing a file when title already defined" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
click_link "Add image" click_link "Add image"
@@ -79,7 +82,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should update loading bar style after valid file upload" do scenario "Should update loading bar style after valid file upload" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(
@@ -91,7 +94,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should update loading bar style after invalid file upload" do scenario "Should update loading bar style after invalid file upload" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(
@@ -104,7 +107,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should update image cached_attachment field after valid file upload" do scenario "Should update image cached_attachment field after valid file upload" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(
@@ -116,7 +119,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should not update image cached_attachment field after invalid file upload" do scenario "Should not update image cached_attachment field after invalid file upload" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(
@@ -129,7 +132,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should show nested image errors after invalid form submit" do scenario "Should show nested image errors after invalid form submit" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
click_link "Add image" click_link "Add image"
@@ -145,7 +148,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should remove nested image after valid file upload and click on remove button" do scenario "Should remove nested image after valid file upload and click on remove button" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(
@@ -164,7 +167,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
if has_many_images if has_many_images
skip "no need to test, there are no attributes for the parent resource" skip "no need to test, there are no attributes for the parent resource"
else else
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
@@ -174,7 +177,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should show successful notice when resource filled correctly and after valid file uploads" do scenario "Should show successful notice when resource filled correctly and after valid file uploads" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
@@ -191,7 +194,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should show new image after successful creation with one uploaded file" do scenario "Should show new image after successful creation with one uploaded file" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
@@ -216,7 +219,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
if path.include? "edit" if path.include? "edit"
scenario "Should show persisted image" do scenario "Should show persisted image" do
create(:image, imageable: imageable) create(:image, imageable: imageable)
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
expect(page).to have_css ".image", count: 1 expect(page).to have_css ".image", count: 1
@@ -224,7 +227,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
scenario "Should not show add image button when image already exists" do scenario "Should not show add image button when image already exists" do
create(:image, imageable: imageable) create(:image, imageable: imageable)
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
expect(page).not_to have_css "a#new_image_link" expect(page).not_to have_css "a#new_image_link"
@@ -232,7 +235,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
scenario "Should remove nested field after remove image" do scenario "Should remove nested field after remove image" do
create(:image, imageable: imageable) create(:image, imageable: imageable)
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
click_on "Remove image" click_on "Remove image"
@@ -241,7 +244,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
scenario "Should show add image button after remove image" do scenario "Should show add image button after remove image" do
create(:image, imageable: imageable) create(:image, imageable: imageable)
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
click_on "Remove image" click_on "Remove image"
@@ -251,6 +254,10 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
end end
def do_login_for(user)
common_do_login_for(user, management: management)
end
def imageable_redirected_to_resource_show_or_navigate_to def imageable_redirected_to_resource_show_or_navigate_to
find("a", text: "Not now, go to my proposal") find("a", text: "Not now, go to my proposal")
click_on "Not now, go to my proposal" click_on "Not now, go to my proposal"

View File

@@ -81,4 +81,13 @@ module Users
def expect_not_to_be_signed_in def expect_not_to_be_signed_in
expect(find(".top-bar-right")).not_to have_content "My account" expect(find(".top-bar-right")).not_to have_content "My account"
end end
def common_do_login_for(user, management:)
if management
login_managed_user(user)
login_as_manager
else
login_as(user)
end
end
end end

View File

@@ -7,6 +7,25 @@ describe "Budget Investments" do
let(:heading) { create(:budget_heading, group: group, name: "Health") } let(:heading) { create(:budget_heading, group: group, name: "Health") }
let(:user) { create(:user, :level_two) } let(:user) { create(:user, :level_two) }
it_behaves_like "nested documentable",
"user",
"budget_investment",
"new_management_budget_investment_path",
{ "budget_id": "budget_id" },
"documentable_fill_new_valid_budget_investment",
"Create Investment",
"Investment created successfully.",
management: true
it_behaves_like "nested imageable",
"budget_investment",
"new_management_budget_investment_path",
{ "budget_id": "budget_id" },
"imageable_fill_new_valid_budget_investment",
"Create Investment",
"Investment created successfully.",
management: true
it_behaves_like "mappable", it_behaves_like "mappable",
"budget_investment", "budget_investment",
"investment", "investment",