diff --git a/app/controllers/custom_workflows_controller.rb b/app/controllers/custom_workflows_controller.rb index 399e4b2..347b4cc 100644 --- a/app/controllers/custom_workflows_controller.rb +++ b/app/controllers/custom_workflows_controller.rb @@ -65,8 +65,6 @@ class CustomWorkflowsController < ApplicationController end end - def edit; end - def new @workflow = CustomWorkflow.new @workflow.author = cookies[:custom_workflows_author] @@ -75,6 +73,8 @@ class CustomWorkflowsController < ApplicationController end end + def edit; end + def import xml = params[:file].read begin diff --git a/app/models/custom_workflow.rb b/app/models/custom_workflow.rb index 6513395..6f8e483 100644 --- a/app/models/custom_workflow.rb +++ b/app/models/custom_workflow.rb @@ -15,7 +15,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License +# You should have received a copy of the GN73U General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -70,7 +70,7 @@ class CustomWorkflow < ApplicationRecord end def self.log_message(str, object) - Rails.logger.info "#{str} for #{object.class} (\##{object.id}) \"#{object}\"" + Rails.logger.info "#{str} for #{object.class} (##{object.id}) \"#{object}\"" end def self.run_shared_code(object) diff --git a/db/migrate/20110915084858_create_custom_workflows.rb b/db/migrate/20110915084858_create_custom_workflows.rb index d5d6ad3..2d7d485 100644 --- a/db/migrate/20110915084858_create_custom_workflows.rb +++ b/db/migrate/20110915084858_create_custom_workflows.rb @@ -25,7 +25,7 @@ class CreateCustomWorkflows < ActiveRecord::Migration[4.2] create_table :custom_workflows, force: true do |t| t.references :project t.text :script, null: true, default: nil - t.boolean :is_enabled + t.boolean :is_enabled, null: false, default: false t.timestamps t.index :project_id, unique: true end diff --git a/db/migrate/20120601054047_alter_custom_workflows.rb b/db/migrate/20120601054047_alter_custom_workflows.rb index 5fc2b3a..a7cf08a 100644 --- a/db/migrate/20120601054047_alter_custom_workflows.rb +++ b/db/migrate/20120601054047_alter_custom_workflows.rb @@ -34,7 +34,7 @@ class AlterCustomWorkflows < ActiveRecord::Migration[4.2] def down change_table(:custom_workflows, bulk: true) do |t| t.references :project - t.boolean :is_enabled + t.boolean :is_enabled, null: false, default: false t.remove :name t.remove :description t.remove :position diff --git a/lib/redmine_custom_workflows/patches/controllers/attachments_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/attachments_controller_patch.rb index 335686c..4ec9742 100644 --- a/lib/redmine_custom_workflows/patches/controllers/attachments_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/attachments_controller_patch.rb @@ -52,7 +52,7 @@ module RedmineCustomWorkflows next if o&.custom_workflow_messages&.empty? o.custom_workflow_messages.each do |key, value| - if value&.present? + if value.present? flash[key] = value else flash.delete key diff --git a/lib/redmine_custom_workflows/patches/controllers/groups_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/groups_controller_patch.rb index e872731..e28fc87 100644 --- a/lib/redmine_custom_workflows/patches/controllers/groups_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/groups_controller_patch.rb @@ -52,7 +52,7 @@ module RedmineCustomWorkflows next if o&.custom_workflow_messages&.empty? o.custom_workflow_messages.each do |key, value| - if value&.present? + if value.present? flash[key] = value else flash.delete key diff --git a/lib/redmine_custom_workflows/patches/controllers/issue_relations_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/issue_relations_controller_patch.rb index 1fef439..d8e785d 100644 --- a/lib/redmine_custom_workflows/patches/controllers/issue_relations_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/issue_relations_controller_patch.rb @@ -52,7 +52,7 @@ module RedmineCustomWorkflows next if o&.custom_workflow_messages&.empty? o.custom_workflow_messages.each do |key, value| - if value&.present? + if value.present? flash[key] = value else flash.delete key diff --git a/lib/redmine_custom_workflows/patches/controllers/issues_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/issues_controller_patch.rb index 6ac894f..e0e1a62 100644 --- a/lib/redmine_custom_workflows/patches/controllers/issues_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/issues_controller_patch.rb @@ -52,7 +52,7 @@ module RedmineCustomWorkflows next if o&.custom_workflow_messages&.empty? o.custom_workflow_messages.each do |key, value| - if value&.present? + if value.present? flash[key] = value else flash.delete key diff --git a/lib/redmine_custom_workflows/patches/controllers/members_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/members_controller_patch.rb index 73af62b..6a51da4 100644 --- a/lib/redmine_custom_workflows/patches/controllers/members_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/members_controller_patch.rb @@ -52,7 +52,7 @@ module RedmineCustomWorkflows next if o&.custom_workflow_messages&.empty? o.custom_workflow_messages.each do |key, value| - if value&.present? + if value.present? flash[key] = value else flash.delete key diff --git a/lib/redmine_custom_workflows/patches/controllers/projects_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/projects_controller_patch.rb index 732cf09..b172ea6 100644 --- a/lib/redmine_custom_workflows/patches/controllers/projects_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/projects_controller_patch.rb @@ -52,7 +52,7 @@ module RedmineCustomWorkflows next if o&.custom_workflow_messages&.empty? o.custom_workflow_messages.each do |key, value| - if value&.present? + if value.present? flash[key] = value else flash.delete key diff --git a/lib/redmine_custom_workflows/patches/controllers/timelog_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/timelog_controller_patch.rb index 0ae4311..df0218a 100644 --- a/lib/redmine_custom_workflows/patches/controllers/timelog_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/timelog_controller_patch.rb @@ -52,7 +52,7 @@ module RedmineCustomWorkflows next if o&.custom_workflow_messages&.empty? o.custom_workflow_messages.each do |key, value| - if value&.present? + if value.present? flash[key] = value else flash.delete key diff --git a/lib/redmine_custom_workflows/patches/controllers/users_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/users_controller_patch.rb index 597382a..2fa4e1d 100644 --- a/lib/redmine_custom_workflows/patches/controllers/users_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/users_controller_patch.rb @@ -52,7 +52,7 @@ module RedmineCustomWorkflows next if o&.custom_workflow_messages&.empty? o.custom_workflow_messages.each do |key, value| - if value&.present? + if value.present? flash[key] = value else flash.delete key diff --git a/lib/redmine_custom_workflows/patches/controllers/versions_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/versions_controller_patch.rb index feb8038..a6abcb1 100644 --- a/lib/redmine_custom_workflows/patches/controllers/versions_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/versions_controller_patch.rb @@ -52,7 +52,7 @@ module RedmineCustomWorkflows next if o&.custom_workflow_messages&.empty? o.custom_workflow_messages.each do |key, value| - if value&.present? + if value.present? flash[key] = value else flash.delete key diff --git a/lib/redmine_custom_workflows/patches/controllers/wiki_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/wiki_controller_patch.rb index 7613782..b013632 100644 --- a/lib/redmine_custom_workflows/patches/controllers/wiki_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/wiki_controller_patch.rb @@ -52,7 +52,7 @@ module RedmineCustomWorkflows next if o&.custom_workflow_messages&.empty? o.custom_workflow_messages.each do |key, value| - if value&.present? + if value.present? flash[key] = value else flash.delete key diff --git a/test/functional/attachments_controller_patch_test.rb b/test/functional/attachments_controller_patch_test.rb index 915c636..eaf6c11 100644 --- a/test/functional/attachments_controller_patch_test.rb +++ b/test/functional/attachments_controller_patch_test.rb @@ -28,18 +28,18 @@ class AttachmentsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase def setup super @attachment8 = Attachment.find 8 - @request.session[:user_id] = @jsmith.id + post '/login', params: { username: 'jsmith', password: 'jsmith' } @controller = AttachmentsController.new end def test_delete_with_cw - delete :destroy, params: { id: @attachment8.id } + delete "/attachments/#{@attachment8.id}" assert_response :redirect assert_equal 'Custom workflow', @controller.flash[:notice] end def test_cw_env - delete :destroy, params: { id: @attachment8.id } + delete "/attachments/#{@attachment8.id}" assert_response :redirect assert_equal request.remote_ip, @controller.flash[:warning] end diff --git a/test/functional/custom_workflows_controller_test.rb b/test/functional/custom_workflows_controller_test.rb index ca3a3c4..c26e05e 100644 --- a/test/functional/custom_workflows_controller_test.rb +++ b/test/functional/custom_workflows_controller_test.rb @@ -28,8 +28,6 @@ class CustomWorkflowsControllerTest < RedmineCustomWorkflows::Test::TestCase def setup super @cw1 = CustomWorkflow.find 1 - User.current = nil - @request.session[:user_id] = @admin.id end def test_truth @@ -37,13 +35,14 @@ class CustomWorkflowsControllerTest < RedmineCustomWorkflows::Test::TestCase end def test_index_admin - get :index + post '/login', params: { username: 'admin', password: 'admin' } + get '/custom_workflows' assert_response :success end def test_index_non_admin - @request.session[:user_id] = @jsmith.id - get :index + post '/login', params: { username: 'jsmith', password: 'jsmith' } + get '/custom_workflows' assert_response :forbidden end end diff --git a/test/functional/groups_controller_patch_test.rb b/test/functional/groups_controller_patch_test.rb index 63c8f72..8fc4d3b 100644 --- a/test/functional/groups_controller_patch_test.rb +++ b/test/functional/groups_controller_patch_test.rb @@ -28,22 +28,22 @@ class GroupControllerPatchTest < RedmineCustomWorkflows::Test::TestCase def setup super @group10 = Group.find 10 - @request.session[:user_id] = @admin.id + post '/login', params: { username: 'admin', password: 'admin' } @controller = GroupsController.new - default_url_options[:host] = 'test.host' + default_url_options[:host] = 'www.example.com' end def test_update_with_cw @request.headers['Referer'] = edit_group_path(id: @group10.id) - put :update, params: { id: @group10.id, group: { name: 'Updated name' } } - assert_redirected_to edit_group_path(id: @group10.id) + put "/groups/#{@group10.id}", params: { group: { name: 'Updated name' } } + assert_redirected_to groups_path assert_equal 'Custom workflow', @controller.flash[:notice] end def test_cw_env @request.headers['Referer'] = edit_group_path(id: @group10.id) - put :update, params: { id: @group10.id, group: { name: 'Updated name' } } - assert_redirected_to edit_group_path(id: @group10.id) + put "/groups/#{@group10.id}/", params: { group: { name: 'Updated name' } } + assert_redirected_to groups_path assert_equal request.remote_ip, @controller.flash[:warning] end end diff --git a/test/functional/issue_relations_controller_patch_test.rb b/test/functional/issue_relations_controller_patch_test.rb index b2387de..b74c817 100644 --- a/test/functional/issue_relations_controller_patch_test.rb +++ b/test/functional/issue_relations_controller_patch_test.rb @@ -29,18 +29,18 @@ class IssueRelationsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase def setup super @ir1 = IssueRelation.find 1 - @request.session[:user_id] = @jsmith.id + post '/login', params: { username: 'jsmith', password: 'jsmith' } @controller = AttachmentsController.new end def test_delete_with_cw - delete :destroy, params: { id: @ir1 } + delete "/relations/#{@ir1.id}" assert_response :redirect assert_equal 'Custom workflow', @controller.flash[:notice] end def test_cw_env - delete :destroy, params: { id: @ir1 } + delete "/relations/#{@ir1.id}" assert_response :redirect assert_equal request.remote_ip, @controller.flash[:warning] end diff --git a/test/functional/issues_controller_patch_test.rb b/test/functional/issues_controller_patch_test.rb index bfb91af..3fe8216 100644 --- a/test/functional/issues_controller_patch_test.rb +++ b/test/functional/issues_controller_patch_test.rb @@ -29,26 +29,26 @@ class IssuesControllerPatchTest < RedmineCustomWorkflows::Test::TestCase def setup super @issue1 = Issue.find 1 - @request.session[:user_id] = @jsmith.id + post '/login', params: { username: 'jsmith', password: 'jsmith' } @controller = IssuesController.new end def test_update_with_cw - put :update, params: { id: @issue1.id, issue: { subject: 'Updated subject' } } - assert_redirected_to action: 'show', id: @issue1.id + put "/issues/#{@issue1.id}", params: { issue: { subject: 'Updated subject' } } + assert_redirected_to issue_path(@issue1) assert_equal 'Custom workflow', @controller.flash[:notice] end def test_delete_with_cw - delete :destroy, params: { id: @issue1.id, todo: 'destroy' } + delete "/issues/#{@issue1.id}", params: { todo: 'destroy' } assert_response :redirect assert_equal 'Issue cannot be deleted', @controller.flash[:error] assert Issue.find_by(id: @issue1.id) end def test_cw_env - put :update, params: { id: @issue1.id, issue: { subject: 'Updated subject' } } - assert_redirected_to action: 'show', id: @issue1.id + put "/issues/#{@issue1.id}", params: { issue: { subject: 'Updated subject' } } + assert_redirected_to issue_path(@issue1) assert_equal request.remote_ip, @controller.flash[:warning] end end diff --git a/test/functional/members_controller_patch_test.rb b/test/functional/members_controller_patch_test.rb index 8100115..cd964ff 100644 --- a/test/functional/members_controller_patch_test.rb +++ b/test/functional/members_controller_patch_test.rb @@ -27,18 +27,18 @@ class MembersControllerPatchTest < RedmineCustomWorkflows::Test::TestCase def setup super @member1 = Member.find 1 - @request.session[:user_id] = @jsmith.id + post '/login', params: { username: 'jsmith', password: 'jsmith' } @controller = MembersController.new end def test_delete_with_cw - delete :destroy, params: { id: @member1 } + delete "/memberships/#{@member1.id}" assert_response :redirect assert_equal 'Custom workflow', @controller.flash[:notice] end def test_cw_env - delete :destroy, params: { id: @member1 } + delete "/memberships/#{@member1.id}" assert_response :redirect assert_equal request.remote_ip, @controller.flash[:warning] end diff --git a/test/functional/projects_controller_patch_test.rb b/test/functional/projects_controller_patch_test.rb index bdae4e7..74c703e 100644 --- a/test/functional/projects_controller_patch_test.rb +++ b/test/functional/projects_controller_patch_test.rb @@ -27,18 +27,18 @@ class ProjectsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase def setup super - @request.session[:user_id] = @jsmith.id + post '/login', params: { username: 'jsmith', password: 'jsmith' } @controller = ProjectsController.new end def test_update_with_cw - post :update, params: { id: @project1.id, project: { name: 'Updated name' } } + patch "/projects/#{@project1.id}", params: { project: { name: 'Updated name' } } assert_redirected_to settings_project_path(@project1) assert_equal 'Custom workflow', @controller.flash[:notice] end def test_cw_env - post :update, params: { id: @project1.id, project: { name: 'Updated name' } } + patch "/projects/#{@project1.id}", params: { project: { name: 'Updated name' } } assert_redirected_to settings_project_path(@project1) assert_equal request.remote_ip, @controller.flash[:warning] end diff --git a/test/functional/timelog_controller_patch_test.rb b/test/functional/timelog_controller_patch_test.rb index 2b7d97a..123c9d1 100644 --- a/test/functional/timelog_controller_patch_test.rb +++ b/test/functional/timelog_controller_patch_test.rb @@ -29,18 +29,18 @@ class TimelogControllerPatchTest < RedmineCustomWorkflows::Test::TestCase def setup super @te1 = TimeEntry.find 1 - @request.session[:user_id] = @jsmith.id + post '/login', params: { username: 'jsmith', password: 'jsmith' } @controller = TimelogController.new end def test_delete_with_cw - delete :destroy, params: { id: @te1 } + delete "/time_entries/#{@te1.id}" assert_response :redirect assert_equal 'Custom workflow', @controller.flash[:notice] end def test_cw_env - delete :destroy, params: { id: @te1 } + delete "/time_entries/#{@te1.id}" assert_response :redirect assert_equal request.remote_ip, @controller.flash[:warning] end diff --git a/test/functional/users_controller_patch_test.rb b/test/functional/users_controller_patch_test.rb index 9c8444d..3d3a7d0 100644 --- a/test/functional/users_controller_patch_test.rb +++ b/test/functional/users_controller_patch_test.rb @@ -26,19 +26,19 @@ class UsersControllerPatchTest < RedmineCustomWorkflows::Test::TestCase def setup super - @request.session[:user_id] = @admin.id + post '/login', params: { username: 'admin', password: 'admin' } @controller = UsersController.new end def test_update_with_cw - put :update, params: { id: @jsmith.id, user: { lastname: 'updated_lastname' } } - assert_redirected_to edit_user_path(id: @jsmith.id) + put "/users/#{@jsmith.id}", params: { user: { lastname: 'updated_lastname' } } + assert_redirected_to edit_user_path(@jsmith) assert_equal 'Custom workflow', @controller.flash[:notice] end def test_cw_env - put :update, params: { id: @jsmith.id, user: { lastname: 'updated_lastname' } } - assert_redirected_to edit_user_path(id: @jsmith.id) + put "/users/#{@jsmith.id}", params: { user: { lastname: 'updated_lastname' } } + assert_redirected_to edit_user_path(@jsmith) assert_equal request.remote_ip, @controller.flash[:warning] end end diff --git a/test/functional/versions_controller_patch_test.rb b/test/functional/versions_controller_patch_test.rb index 372c397..b533ef4 100644 --- a/test/functional/versions_controller_patch_test.rb +++ b/test/functional/versions_controller_patch_test.rb @@ -27,18 +27,18 @@ class VersionsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase def setup super @version1 = Version.find 1 - @request.session[:user_id] = @jsmith.id + post '/login', params: { username: 'jsmith', password: 'jsmith' } @controller = VersionsController.new end def test_update_with_cw - put :update, params: { id: @version1.id, version: { name: 'Updated version' } } + put "/versions/#{@version1.id}", params: { version: { name: 'Updated version' } } assert_redirected_to settings_project_path(id: @project1, tab: 'versions') assert_equal 'Custom workflow', @controller.flash[:notice] end def test_cw_env - put :update, params: { id: @version1.id, version: { name: 'Updated version' } } + put "/versions/#{@version1.id}", params: { version: { name: 'Updated version' } } assert_redirected_to settings_project_path(id: @project1, tab: 'versions') assert_equal request.remote_ip, @controller.flash[:warning] end diff --git a/test/functional/wiki_controller_patch_test.rb b/test/functional/wiki_controller_patch_test.rb index eb7b322..e066ee7 100644 --- a/test/functional/wiki_controller_patch_test.rb +++ b/test/functional/wiki_controller_patch_test.rb @@ -29,15 +29,13 @@ class WikiControllerPatchTest < RedmineCustomWorkflows::Test::TestCase def setup super @wp1 = WikiPage.find 1 - @request.session[:user_id] = @jsmith.id + post '/login', params: { username: 'jsmith', password: 'jsmith' } @controller = WikiController.new end def test_update_with_cw - put :update, + put "/projects/#{@projects1.id}/wiki/Another_page", params: { - project_id: @project1.id, - id: 'Another_page', content: { comments: 'my comments', text: 'edited', version: 1 } } assert_response :redirect diff --git a/test/test_case.rb b/test/test_case.rb index 6849c57..d4cecb7 100644 --- a/test/test_case.rb +++ b/test/test_case.rb @@ -22,7 +22,7 @@ module RedmineCustomWorkflows module Test # Test case base class - class TestCase < ActionController::TestCase + class TestCase < ActionDispatch::IntegrationTest fixtures :users, :email_addresses, :projects # Allow us to override the fixtures method to implement fixtures for our plugin.