Merge pull request #1619 from opf/feature/13954_add_edit_quote_comments_in_wp_overview
commit
15ff42d0c9
@ -0,0 +1,56 @@ |
||||
//-- copyright
|
||||
// OpenProject is a project management system.
|
||||
// Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License version 3.
|
||||
//
|
||||
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||||
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
// Copyright (C) 2010-2013 the ChiliProject Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// 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
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// See doc/COPYRIGHT.rdoc for more details.
|
||||
//++
|
||||
|
||||
// TODO move to UI components
|
||||
angular.module('openproject.uiComponents') |
||||
|
||||
.directive('activityComment', ['I18n', 'ActivityService', 'ConfigurationService', function(I18n, ActivityService, ConfigurationService) { |
||||
return { |
||||
restrict: 'E', |
||||
replace: true, |
||||
scope: { |
||||
workPackage: '=', |
||||
activities: '=' |
||||
}, |
||||
templateUrl: '/templates/components/activity_comment.html', |
||||
link: function(scope, element, attrs) { |
||||
scope.title = I18n.t('js.label_add_comment_title'); |
||||
scope.buttonTitle = I18n.t('js.label_add_comment'); |
||||
|
||||
scope.createComment = function() { |
||||
var comment = angular.element('#add-comment-text').val(); |
||||
var descending = ConfigurationService.commentsSortedInDescendingOrder(); |
||||
ActivityService.createComment(scope.workPackage.props.id, scope.activities, descending, comment) |
||||
.then(function(response){ |
||||
angular.element('#add-comment-text').val(''); |
||||
return response; |
||||
}); |
||||
} |
||||
} |
||||
}; |
||||
}]); |
@ -0,0 +1,35 @@ |
||||
//-- copyright
|
||||
// OpenProject is a project management system.
|
||||
// Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License version 3.
|
||||
//
|
||||
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||||
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
// Copyright (C) 2010-2013 the ChiliProject Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// 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
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// See doc/COPYRIGHT.rdoc for more details.
|
||||
//++
|
||||
|
||||
angular.module('openproject.uiComponents') |
||||
|
||||
.filter('latestItems', function(){ |
||||
return function(items, isDescending, visible){ |
||||
return isDescending ? items.slice(0, visible) : items.slice(-visible).reverse(); |
||||
} |
||||
}); |
@ -0,0 +1,74 @@ |
||||
//-- copyright
|
||||
// OpenProject is a project management system.
|
||||
// Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License version 3.
|
||||
//
|
||||
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||||
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
// Copyright (C) 2010-2013 the ChiliProject Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// 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
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// See doc/COPYRIGHT.rdoc for more details.
|
||||
//++
|
||||
|
||||
angular.module('openproject.services') |
||||
|
||||
.service('ActivityService', ['HALAPIResource', |
||||
'$http', |
||||
'PathHelper', function(HALAPIResource, $http, PathHelper){ |
||||
|
||||
var ActivityService = { |
||||
createComment: function(workPackageId, activities, descending, comment) { |
||||
var resource = HALAPIResource.setup(PathHelper.activitiesPath(workPackageId)); |
||||
var options = { |
||||
ajax: { |
||||
method: "POST", |
||||
data: { comment: comment } |
||||
} |
||||
}; |
||||
|
||||
return resource.fetch(options).then(function(activity){ |
||||
// We are unable to add to the work package's embedded activities directly
|
||||
if(activity) { |
||||
if(descending){ |
||||
activities.unshift(activity); |
||||
} else { |
||||
activities.push(activity); |
||||
} |
||||
return activity; |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
updateComment: function(activityId, comment) { |
||||
var resource = HALAPIResource.setup(PathHelper.activityPath(activityId)); |
||||
var options = { |
||||
ajax: { |
||||
method: "PUT", |
||||
data: { comment: comment } |
||||
} |
||||
}; |
||||
|
||||
return resource.fetch(options).then(function(activity){ |
||||
return activity; |
||||
}); |
||||
} |
||||
} |
||||
|
||||
return ActivityService; |
||||
}]); |
@ -0,0 +1,43 @@ |
||||
//-- copyright
|
||||
// OpenProject is a project management system.
|
||||
// Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License version 3.
|
||||
//
|
||||
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||||
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
// Copyright (C) 2010-2013 the ChiliProject Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// 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
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// See doc/COPYRIGHT.rdoc for more details.
|
||||
//++
|
||||
|
||||
angular.module('openproject.workPackages.directives') |
||||
|
||||
.directive('editableComment', [function(){ |
||||
return { |
||||
restrict: 'A', |
||||
scope: { |
||||
activity: '=', |
||||
commentInEdit: '=' |
||||
}, |
||||
templateUrl: '/templates/work_packages/tabs/_editable_comment.html', |
||||
link: function(scope){ |
||||
|
||||
} |
||||
}; |
||||
}]); |
@ -0,0 +1,50 @@ |
||||
//-- copyright
|
||||
// OpenProject is a project management system.
|
||||
// Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License version 3.
|
||||
//
|
||||
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||||
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
// Copyright (C) 2010-2013 the ChiliProject Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// 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
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// See doc/COPYRIGHT.rdoc for more details.
|
||||
//++
|
||||
|
||||
angular.module('openproject.workPackages.tabs') |
||||
|
||||
.directive('exclusiveEdit', function() { |
||||
return { |
||||
restrict: 'EA', |
||||
replace: true, |
||||
transclude: true, |
||||
template: '<div class="exclusive-edit" ng-transclude></div>', |
||||
controller: function() { |
||||
var editors = []; |
||||
this.gotEditable = function(selectedEditor) { |
||||
angular.forEach(editors, function(editor) { |
||||
if (selectedEditor != editor) { |
||||
editor.inEdit = false; } |
||||
}); |
||||
}; |
||||
this.addEditable = function(editor) { |
||||
editors.push(editor); |
||||
}; |
||||
} |
||||
}; |
||||
}) |
@ -0,0 +1,41 @@ |
||||
/*-- copyright |
||||
* OpenProject is a project management system. |
||||
* Copyright (C) 2012-2014 the OpenProject Foundation (OPF) |
||||
* |
||||
* This program is free software; you can redistribute it and/or |
||||
* modify it under the terms of the GNU General Public License version 3. |
||||
* |
||||
* OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
* Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
* Copyright (C) 2010-2013 the ChiliProject Team |
||||
* |
||||
* This program is free software; you can redistribute it and/or |
||||
* modify it under the terms of the GNU General Public License |
||||
* as published by the Free Software Foundation; either version 2 |
||||
* of the License, or (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* 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 |
||||
* along with this program; if not, write to the Free Software |
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
* |
||||
* See doc/COPYRIGHT.rdoc for more details. ++ |
||||
*/ |
||||
|
||||
.activity-comment |
||||
textarea |
||||
width: 100% |
||||
height: 6em |
||||
-webkit-box-sizing: border-box |
||||
-moz-box-sizing: border-box |
||||
box-sizing: border-box |
||||
-webkit-border-radius: 3px |
||||
-moz-border-radius: 3px |
||||
border-radius: 3px |
||||
.button |
||||
float: right |
||||
margin-right: 0px |
@ -0,0 +1,55 @@ |
||||
//-- copyright
|
||||
// OpenProject is a project management system.
|
||||
// Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License version 3.
|
||||
//
|
||||
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||||
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
// Copyright (C) 2010-2013 the ChiliProject Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// 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
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// See doc/COPYRIGHT.rdoc for more details.
|
||||
//++
|
||||
|
||||
/*jshint expr: true*/ |
||||
|
||||
describe('Latest items filter', function() { |
||||
|
||||
beforeEach(module('openproject.workPackages.filters')); |
||||
|
||||
describe('latestItems', function() { |
||||
var items; |
||||
|
||||
beforeEach(function(){ |
||||
items = [1,2,3,4,5,6,7,8,9]; |
||||
}); |
||||
|
||||
it('should be defined', inject(function($filter) { |
||||
expect($filter('latestItems')).not.to.equal(null); |
||||
})); |
||||
|
||||
it('should return the first 3 items', inject(function($filter) { |
||||
expect($filter('latestItems')(items, false, 3)).to.eql([9,8,7]); |
||||
})); |
||||
|
||||
it('should return the last 3 items reversed', inject(function($filter) { |
||||
expect($filter('latestItems')(items, true, 3)).to.eql([1,2,3]); |
||||
})); |
||||
|
||||
}); |
||||
}); |
@ -0,0 +1,82 @@ |
||||
//-- copyright
|
||||
// OpenProject is a project management system.
|
||||
// Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License version 3.
|
||||
//
|
||||
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||||
// Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
// Copyright (C) 2010-2013 the ChiliProject Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// 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
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// See doc/COPYRIGHT.rdoc for more details.
|
||||
//++
|
||||
|
||||
/*jshint expr: true*/ |
||||
|
||||
describe('ActivityService', function() { |
||||
|
||||
var $httpBackend, ActivityService; |
||||
beforeEach(module('openproject.api', 'openproject.services', 'openproject.models')); |
||||
|
||||
beforeEach(inject(function(_$httpBackend_, _ActivityService_) { |
||||
$httpBackend = _$httpBackend_; |
||||
ActivityService = _ActivityService_; |
||||
})); |
||||
|
||||
describe('createComment', function() { |
||||
var setupFunction; |
||||
var workPackageId = 5; |
||||
var actvityId = 10; |
||||
var activities = []; |
||||
var descending = false; |
||||
var comment = "Jack Bauer 24 hour power shower"; |
||||
var apiResource; |
||||
var apiFetchResource; |
||||
|
||||
beforeEach(inject(function($q) { |
||||
apiResource = { |
||||
fetch: function() { |
||||
deferred = $q.defer(); |
||||
deferred.resolve({ id: actvityId, comment: comment } ); |
||||
return deferred.promise; |
||||
} |
||||
} |
||||
})); |
||||
|
||||
beforeEach(inject(function(HALAPIResource) { |
||||
setupFunction = sinon.stub(HALAPIResource, 'setup').returns(apiResource); |
||||
})); |
||||
|
||||
beforeEach(inject(function() { |
||||
apiFetchResource = ActivityService.createComment(workPackageId, activities, descending, comment); |
||||
})); |
||||
|
||||
it('makes an api setup call', function() { |
||||
expect(setupFunction).to.have.been.calledWith("/work_packages/" + workPackageId + "/activities"); |
||||
}); |
||||
|
||||
it('returns an activity', function() { |
||||
apiFetchResource.then(function(activity){ |
||||
expect(activity.id).to.equal(activityId); |
||||
expect(activity.comment).to.equal(comment); |
||||
expect(activities.length).to.equal(1); |
||||
}); |
||||
}); |
||||
|
||||
}); |
||||
}); |
@ -0,0 +1,7 @@ |
||||
<div class="activity-comment"> |
||||
<label> |
||||
<h3>{{ title }}</h3> |
||||
<textarea id="add-comment-text" name="add-comment"></textarea> |
||||
<button class="button" ng-click="createComment()">{{ buttonTitle }}</button> |
||||
</label> |
||||
</div> |
@ -0,0 +1,5 @@ |
||||
|
||||
<span class="message" |
||||
ng-show="activity.props._type == 'Activity::Comment'" |
||||
ng-bind-html="activity.props.comment"/> |
||||
<textarea ng-if="commentInEdit = activity.props.id" id="edit-comment-text"></textarea> |
@ -1,19 +1,24 @@ |
||||
<div class="detail-panel-content" > |
||||
<div class="detail-activity"> |
||||
<ul class="work-package-details-activities-list"> |
||||
<li ng-repeat="activity in activities" |
||||
class="work-package-details-activities-activity" |
||||
ng-init="activityNo = activitiesSortedInDescendingOrder && activities.length - $index || $index + 1; |
||||
currentDate = (activity.props.createdAt|date:'longDate'); |
||||
currentAnchor = 'note-' + activityNo"> |
||||
<h3 class="activity-date" |
||||
ng-if="currentDate !== (activities[$index-1].props.createdAt | date:'longDate')" |
||||
ng-bind="currentDate"/> |
||||
<user-activity activity="activity" |
||||
activity-no="activityNo" |
||||
current-anchor="currentAnchor"> |
||||
</user-activity> |
||||
</li> |
||||
</ul> |
||||
<exclusive-edit> |
||||
<ul class="work-package-details-activities-list"> |
||||
<li ng-repeat="activity in activities" |
||||
class="work-package-details-activities-activity" |
||||
ng-init="activityNo = activitiesSortedInDescendingOrder && activities.length - $index || $index + 1; |
||||
currentDate = (activity.props.createdAt|date:'longDate'); |
||||
currentAnchor = 'note-' + activityNo"> |
||||
<h3 class="activity-date" |
||||
ng-if="currentDate !== (activities[$index-1].props.createdAt | date:'longDate')" |
||||
ng-bind="currentDate"/> |
||||
<user-activity activity="activity" |
||||
activity-no="activityNo" |
||||
input-element-id="'add-comment-text'"> |
||||
</user-activity> |
||||
</li> |
||||
</ul> |
||||
</exclusive-edit> |
||||
</div> |
||||
<activity-comment work-package="workPackage" |
||||
activities="activities"> |
||||
</activity-comment> |
||||
</div> |
||||
|
@ -0,0 +1,82 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2014 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# 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 |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
require 'rack/test' |
||||
|
||||
describe API::V3::Activities::ActivitiesAPI do |
||||
let(:admin) { FactoryGirl.create(:admin) } |
||||
let(:comment) { "This is a test comment!" } |
||||
|
||||
shared_examples_for "safeguarded API" do |
||||
it { expect(response.response_code).to eq(403) } |
||||
end |
||||
|
||||
shared_examples_for "valid activity request" do |
||||
before { allow(User).to receive(:current).and_return(admin) } |
||||
|
||||
subject { JSON.parse(response.body) } |
||||
|
||||
it { expect(subject['_type']).to eq("Activity::Comment") } |
||||
|
||||
it { expect(subject['rawComment']).to eq(comment) } |
||||
end |
||||
|
||||
shared_examples_for "invalid activity request" do |
||||
before { allow(User).to receive(:current).and_return(admin) } |
||||
|
||||
it { expect(response.response_code).to eq(422) } |
||||
end |
||||
|
||||
describe "PUT /api/v3/activities/:activityId" do |
||||
let(:work_package) { FactoryGirl.create(:work_package) } |
||||
let(:wp_journal) { FactoryGirl.build(:journal_work_package_journal) } |
||||
let(:journal) { FactoryGirl.create(:work_package_journal, |
||||
data: wp_journal, |
||||
journable_id: work_package.id) } |
||||
|
||||
shared_context "edit activity" do |
||||
before { put "/api/v3/activities/#{journal.id}", |
||||
comment: comment } |
||||
end |
||||
|
||||
it_behaves_like "safeguarded API" do |
||||
include_context "edit activity" |
||||
end |
||||
|
||||
it_behaves_like "valid activity request" do |
||||
include_context "edit activity" |
||||
end |
||||
|
||||
it_behaves_like "invalid activity request" do |
||||
before { allow_any_instance_of(Journal).to receive(:save).and_return(false) } |
||||
|
||||
include_context "edit activity" |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,53 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2014 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# 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 |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
shared_examples_for "safeguarded API" do |
||||
it { expect(response.response_code).to eq(403) } |
||||
end |
||||
|
||||
shared_examples_for "valid activity request" do |
||||
let(:status_code) { 200 } |
||||
|
||||
before { allow(User).to receive(:current).and_return(admin) } |
||||
|
||||
it { expect(response.response_code).to eq(status_code) } |
||||
|
||||
describe 'response body' do |
||||
subject { JSON.parse(response.body) } |
||||
|
||||
it { expect(subject['_type']).to eq("Activity::Comment") } |
||||
|
||||
it { expect(subject['rawComment']).to eq(comment) } |
||||
end |
||||
end |
||||
|
||||
shared_examples_for "invalid activity request" do |
||||
before { allow(User).to receive(:current).and_return(admin) } |
||||
|
||||
it { expect(response.response_code).to eq(422) } |
||||
end |
@ -0,0 +1,61 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2014 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# 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 |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
require 'rack/test' |
||||
|
||||
describe API::V3::WorkPackages::WorkPackagesAPI do |
||||
describe "activities" do |
||||
let(:admin) { FactoryGirl.create(:admin) } |
||||
let(:work_package) { FactoryGirl.create(:work_package) } |
||||
let(:comment) { "This is a test comment!" } |
||||
|
||||
describe "POST /api/v3/work_packages/:id/activities" do |
||||
shared_context "create activity" do |
||||
before { post "/api/v3/work_packages/#{work_package.id}/activities", |
||||
comment: comment } |
||||
end |
||||
|
||||
it_behaves_like "safeguarded API" do |
||||
include_context "create activity" |
||||
end |
||||
|
||||
it_behaves_like "valid activity request" do |
||||
let(:status_code) { 201 } |
||||
|
||||
include_context "create activity" |
||||
end |
||||
|
||||
it_behaves_like "invalid activity request" do |
||||
before { allow_any_instance_of(WorkPackage).to receive(:save).and_return(false) } |
||||
|
||||
include_context "create activity" |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue