Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions app/views/issues/_select_projects.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
<!-- this condition to avoid calling @issue.allowed_target_projects ,in the pages (show/edit "open link in new tab" /new),
call this method only for edit by "render_form_by_ajax" -->
<% allowed_projects = @allowed_target_projects.present? ? @allowed_target_projects : @issue.allowed_target_projects %>
<% select_options = project_tree_options_for_select((allowed_projects | @issue.projects) - [@issue.project], :selected => [@issue.project] | @issue.projects) %>

<!-- In case of fail validation @issue.projects are assignable_projects , and assignable_projects is not nill, see issue_patch file (assignable_projects #List related projects before save) -->
<% if @issue.assignable_projects.nil? %>
<% select_options = project_tree_options_for_select((allowed_projects | @issue.projects) - [@issue.project], :selected => [@issue.project] | @issue.projects) %>
<%= render 'projects_list', issue: @issue, selected_projects: @issue.projects, allowed_target_projects: allowed_projects %>
<% else %>
<% select_options = project_tree_options_for_select((allowed_projects | @issue.assignable_projects) - [@issue.project], :selected => [@issue.project] | @issue.assignable_projects) %>
<%= render 'projects_list', issue: @issue, selected_projects: @issue.assignable_projects, allowed_target_projects: allowed_projects %>
<% end %>
<%= f.select :project_ids, select_options, {:label => l("related_projects")},
{:multiple => true, style: "display:none;"} %>
<%= render 'projects_list', issue: @issue, selected_projects: @issue.projects, allowed_target_projects: allowed_projects %>
<a href="#" class="load-modal-projects-selection" id="loadModalProjectsSelection"><%= l('modify_projects')%></a>
<label id=answers-on-secondary-projects class="inline answers-on-secondary-projects" style="<%= "display:none;" if @issue.projects.none? %>"><%= f.check_box :answers_on_secondary_projects, :no_label => true %><%= l(:field_answers_on_secondary_projects) %></label>
</p>
Expand Down
3 changes: 2 additions & 1 deletion lib/redmine_multiprojects_issue/issues_controller_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def load_projects_selection
issue_project_attribute = [@issue.project.id, @issue.project.name, @issue.project.status, @issue.project.lft, @issue.project.rgt]
@issue_projects_attributes_array = issue_projects_attributes_array | [issue_project_attribute]

vals = Rails.env.test? ? JSON.parse(params[:allowed_projects]) : params[:allowed_projects].permit!.to_h.values
# This condition(Rails.env.test? && params[:format] == 'js') for the IssuesController test, by post method
vals = Rails.env.test? && params[:format] == 'js' ? JSON.parse(params[:allowed_projects]) : params[:allowed_projects].permit!.to_h.values
# convert to int
allowed_target_projects_attributes_array = vals.map do |id, name, status, lft, rgt|
[id.to_i, name, status.to_i, lft.to_i, rgt.to_i]
Expand Down
65 changes: 65 additions & 0 deletions spec/system/issue_system_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require "spec_helper"
require "active_support/testing/assertions"

RSpec.describe "/issue/id/edit", type: :system do
include ActiveSupport::Testing::Assertions

fixtures :projects, :users, :issues, :workflows, :members, :member_roles, :roles

def log_user(login, password)
visit '/my/page'
expect(current_path).to eq '/login'

if Redmine::Plugin.installed?(:redmine_scn)
click_on("ou s'authentifier par login / mot de passe")
end

within('#login-form form') do
fill_in 'username', with: login
fill_in 'password', with: password
find('input[name=login]').click
end
expect(current_path).to eq '/my/page'
end

before do
log_user('admin', 'admin')
end

describe "Fail validation of issue" do
let!(:issue) { Issue.first }

it "Should keep the selected projects" do
# Related projects 0
expect(issue.projects.count).to eq(0)

visit edit_issue_path( id: issue.id)
# open Related projects modal
find('#loadModalProjectsSelection').click

within '#ajax-modal' do
# select projects with id 3 , 5
find("input[value='5']").click
find("input[value='3']").click

find("input[id='button_apply_projects']").click
end

# Make fail validation
fill_in 'issue_subject', with: ''

find("input[name='commit']").click

expect(page).to have_selector("span", text: "#{Project.find(3).name}")
expect(page).to have_selector("span", text: "#{Project.find(5).name}")

# Remake succes validation
fill_in 'issue_subject', with: 'test'
find("input[name='commit']").click

# Related projects 2
expect(issue.projects.count).to eq(2)
end

end
end