Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Rename :writeable to :writable

Dombi Attila92a7f1ffdae1
diff --git a/app/contracts/base_contract.rb b/app/contracts/base_contract.rb
index bea08680ea5..bc27867c1c2 100644
--- a/app/contracts/base_contract.rb
+++ b/app/contracts/base_contract.rb
@@ -82,7 +82,7 @@ class BaseContract < Disposable::Twin
def attribute(attribute, options = {}, &block)
property attribute, options.slice(:readable)
- add_writable(attribute, options[:writeable])
+ add_writable(attribute, options[:writable])
attribute_permission(attribute, options[:permission])
validate(attribute, &block) if block
@@ -100,17 +100,17 @@ class BaseContract < Disposable::Twin
private
- def add_writable(attribute, writeable)
+ def add_writable(attribute, writable)
attribute_name = attribute.to_s.gsub /_id\z/, ''
- unless writeable == false
+ unless writable == false
writable_attributes << attribute_name
# allow the _id variant as well
writable_attributes << "#{attribute_name}_id"
end
- if writeable.respond_to?(:call)
- writable_conditions << [attribute_name, writeable]
+ if writable.respond_to?(:call)
+ writable_conditions << [attribute_name, writable]
end
end
end
@@ -181,7 +181,7 @@ class BaseContract < Disposable::Twin
protected
- def collect_ancestor_attribute_aliases
+ def ancestor_attribute_aliases
@ancestor_attribute_aliases ||= collect_ancestor_attributes(:attribute_aliases)
end
@@ -221,8 +221,8 @@ class BaseContract < Disposable::Twin
writable = collect_ancestor_attributes(:writable_attributes)
writable.each do |attribute|
- if collect_ancestor_attribute_aliases[attribute]
- writable << collect_ancestor_attribute_aliases[attribute].to_s
+ if ancestor_attribute_aliases[attribute]
+ writable << ancestor_attribute_aliases[attribute].to_s
end
end
diff --git a/app/contracts/model_contract.rb b/app/contracts/model_contract.rb
index 05f0678e38e..9dbc267af58 100644
--- a/app/contracts/model_contract.rb
+++ b/app/contracts/model_contract.rb
@@ -66,7 +66,7 @@ class ModelContract < BaseContract
def readonly_attributes_unchanged
unauthenticated_changed.each do |attribute|
- outside_attribute = collect_ancestor_attribute_aliases[attribute] || attribute
+ outside_attribute = ancestor_attribute_aliases[attribute] || attribute
errors.add outside_attribute, :error_readonly
end
diff --git a/app/contracts/users/base_contract.rb b/app/contracts/users/base_contract.rb
index 55a3696d6be..558b15162f0 100644
--- a/app/contracts/users/base_contract.rb
+++ b/app/contracts/users/base_contract.rb
@@ -31,25 +31,25 @@ module Users
include AssignableCustomFieldValues
attribute :login,
- writeable: ->(*) { user.allowed_to_globally?(:manage_user) && model.id != user.id }
+ writable: ->(*) { user.allowed_to_globally?(:manage_user) && model.id != user.id }
attribute :firstname
attribute :lastname
attribute :mail
attribute :admin,
- writeable: ->(*) { user.admin? && model.id != user.id }
+ writable: ->(*) { user.admin? && model.id != user.id }
attribute :language
attribute :auth_source_id,
- writeable: ->(*) { user.allowed_to_globally?(:manage_user) }
+ writable: ->(*) { user.allowed_to_globally?(:manage_user) }
attribute :status,
- writeable: ->(*) { user.allowed_to_globally?(:manage_user) }
+ writable: ->(*) { user.allowed_to_globally?(:manage_user) }
attribute :identity_url,
- writeable: ->(*) { user.admin? }
+ writable: ->(*) { user.admin? }
attribute :force_password_change,
- writeable: ->(*) { user.admin? }
+ writable: ->(*) { user.admin? }
def self.model
User
@@ -86,10 +86,12 @@ module Users
errors.add :password, :error_readonly if model.password.present?
end
+ # rubocop:disable Rails/DynamicFindBy
def existing_auth_source
if auth_source_id && AuthSource.find_by_unique(auth_source_id).nil?
errors.add :auth_source, :error_not_found
end
end
+ # rubocop:enable Rails/DynamicFindBy
end
end
diff --git a/app/contracts/work_packages/base_contract.rb b/app/contracts/work_packages/base_contract.rb
index 2dd08b1c573..a44a7a66c70 100644
--- a/app/contracts/work_packages/base_contract.rb
+++ b/app/contracts/work_packages/base_contract.rb
@@ -34,7 +34,7 @@ module WorkPackages
attribute :subject
attribute :description
attribute :status_id,
- writeable: ->(*) {
+ writable: ->(*) {
# If we did not change into the status,
# mark unwritable if status and version is closed
model.status_id_change || !closed_version_and_status?
@@ -52,13 +52,13 @@ module WorkPackages
attribute :project_id
attribute :done_ratio,
- writeable: ->(*) {
+ writable: ->(*) {
model.leaf? && Setting.work_package_done_ratio == 'field'
}
attribute :estimated_hours
attribute :derived_estimated_hours,
- writeable: false
+ writable: false
attribute :parent_id,
permission: :manage_subtasks
@@ -81,12 +81,12 @@ module WorkPackages
attribute :schedule_manually
attribute :ignore_non_working_days,
- writeable: ->(*) {
+ writable: ->(*) {
OpenProject::FeatureDecisions.work_packages_duration_field_active?
}
attribute :start_date,
- writeable: ->(*) {
+ writable: ->(*) {
model.leaf? || model.schedule_manually?
} do
if !model.schedule_manually? && start_before_soonest_start?
@@ -98,12 +98,12 @@ module WorkPackages
end
attribute :due_date,
- writeable: ->(*) {
+ writable: ->(*) {
model.leaf? || model.schedule_manually?
}
attribute :duration,
- writeable: ->(*) {
+ writable: ->(*) {
OpenProject::FeatureDecisions.work_packages_duration_field_active?
}
@@ -153,7 +153,7 @@ module WorkPackages
@can = WorkPackagePolicy.new(user)
end
- def assignable_statuses(include_default = false)
+ def assignable_statuses(include_default: false)
# Do not allow skipping statuses without intermediately saving the work package.
# We therefore take the original status of the work_package, while preserving all
# other changes to it (e.g. type, assignee, etc.)
diff --git a/app/contracts/work_packages/create_contract.rb b/app/contracts/work_packages/create_contract.rb
index 528fac1ab51..88ddcfd3158 100644
--- a/app/contracts/work_packages/create_contract.rb
+++ b/app/contracts/work_packages/create_contract.rb
@@ -31,7 +31,7 @@ require 'work_packages/base_contract'
module WorkPackages
class CreateContract < BaseContract
attribute :author_id,
- writeable: false do
+ writable: false do
errors.add :author_id, :invalid if model.author != user
end
diff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rb
index ad5d20adc78..a8a6ef0eda5 100644
--- a/app/services/work_packages/set_attributes_service.rb
+++ b/app/services/work_packages/set_attributes_service.rb
@@ -278,7 +278,7 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributes
end
def assignable_statuses
- instantiate_contract(work_package, user).assignable_statuses(true)
+ instantiate_contract(work_package, user).assignable_statuses(include_default: true)
end
def min_child_date
diff --git a/docs/api/apiv3/components/schemas/relation_edit_form_model.yml b/docs/api/apiv3/components/schemas/relation_edit_form_model.yml
index e633a83527c..1b9fccde69a 100644
--- a/docs/api/apiv3/components/schemas/relation_edit_form_model.yml
+++ b/docs/api/apiv3/components/schemas/relation_edit_form_model.yml
@@ -59,7 +59,7 @@ example:
from:
name: From work package
type: WorkPackage
- writeable: false
+ writable: false
to:
name: To work package
type: WorkPackage
diff --git a/docs/api/apiv3/paths/relation_form.yml b/docs/api/apiv3/paths/relation_form.yml
index 185fd0f88ce..558d2bbb2e4 100644
--- a/docs/api/apiv3/paths/relation_form.yml
+++ b/docs/api/apiv3/paths/relation_form.yml
@@ -43,7 +43,7 @@ post:
from:
name: From work package
type: WorkPackage
- writeable: false
+ writable: false
id:
name: ID
type: Integer
diff --git a/lib/api/decorators/link_object.rb b/lib/api/decorators/link_object.rb
index 9471e4e343c..e402a3817ea 100644
--- a/lib/api/decorators/link_object.rb
+++ b/lib/api/decorators/link_object.rb
@@ -52,7 +52,7 @@ module API
property :title,
exec_context: :decorator,
- writeable: false,
+ writable: false,
render_nil: false
def href
diff --git a/lib/api/decorators/single.rb b/lib/api/decorators/single.rb
index 2d1dcb2c684..a72b1b7d246 100644
--- a/lib/api/decorators/single.rb
+++ b/lib/api/decorators/single.rb
@@ -62,7 +62,7 @@ module API
property :_type,
exec_context: :decorator,
render_nil: false,
- writeable: false
+ writable: false
def self.self_link(path: nil, id_attribute: :id, title_getter: ->(*) { represented.name })
link :self do
diff --git a/lib/api/utilities/payload_representer.rb b/lib/api/utilities/payload_representer.rb
index c09214d2c7a..c17cd1292cc 100644
--- a/lib/api/utilities/payload_representer.rb
+++ b/lib/api/utilities/payload_representer.rb
@@ -29,7 +29,7 @@
module API
module Utilities
# PayloadRepresenter responsibility is to parse user params input and render
- # only the writeable attributes.
+ # only the writable attributes.
#
# The `UpdateContract` or the `CreateContract` is used to filter out read
# only attributes from the input parameters. Guessing is done by checking if
@@ -49,24 +49,25 @@ module API
next
end
- writeable = property[:writeable]
- if writeable == false
+ # Note: `:writeable` is not a typo, it's used by declarative gem
+ writable = property[:writeable]
+ if writable == false
property.merge!(readable: false)
end
# Only filter unwritable if not a lambda
- unless writeable.respond_to?(:call)
- add_filter(property, UnwriteablePropertyFilter)
+ unless writable.respond_to?(:call)
+ add_filter(property, UnwritablePropertyFilter)
end
end
end
- class UnwriteablePropertyFilter
+ class UnwritablePropertyFilter
def self.call(input, options)
- writeable_attr = options[:decorator].writeable_attributes
+ writable_attr = options[:decorator].writable_attributes
as = options[:binding][:as].()
- if writeable_attr.include?(as)
+ if writable_attr.include?(as)
input
else
::Representable::Pipeline::Stop
@@ -76,10 +77,10 @@ module API
class LinkRenderBlock
def self.call(input, options)
- writeable_attr = options[:decorator].writeable_attributes
+ writable_attr = options[:decorator].writable_attributes
input.reject do |link|
- link.rel && writeable_attr.exclude?(link.rel.to_s)
+ link.rel && writable_attr.exclude?(link.rel.to_s)
end
end
end
@@ -103,8 +104,8 @@ module API
contract_class(represented).present?
end
- def writeable_attributes
- @writeable_attributes ||= begin
+ def writable_attributes
+ @writable_attributes ||= begin
contract = contract_class(represented)
if contract
diff --git a/lib/api/v3/attachments/attachable_payload_representer_mixin.rb b/lib/api/v3/attachments/attachable_payload_representer_mixin.rb
index 4964874aa70..7a2b34131cd 100644
--- a/lib/api/v3/attachments/attachable_payload_representer_mixin.rb
+++ b/lib/api/v3/attachments/attachable_payload_representer_mixin.rb
@@ -33,7 +33,7 @@ module API
extend ActiveSupport::Concern
included do
- def writeable_attributes
+ def writable_attributes
super + %w[attachments]
end
diff --git a/lib/api/v3/projects/project_representer.rb b/lib/api/v3/projects/project_representer.rb
index 7be89f7c23a..f94a48925a7 100644
--- a/lib/api/v3/projects/project_representer.rb
+++ b/lib/api/v3/projects/project_representer.rb
@@ -238,7 +238,7 @@ module API
}
property :status_explanation,
- writeable: -> { represented.writable?(:status) },
+ writable: -> { represented.writable?(:status) },
getter: ->(*) {
::API::Decorators::Formattable.new(status&.explanation,
object: self,
diff --git a/lib/api/v3/queries/filters/query_filter_instance_representer.rb b/lib/api/v3/queries/filters/query_filter_instance_representer.rb
index d06c13099ec..3145df4e014 100644
--- a/lib/api/v3/queries/filters/query_filter_instance_representer.rb
+++ b/lib/api/v3/queries/filters/query_filter_instance_representer.rb
@@ -122,7 +122,7 @@ module API
property :name,
exec_context: :decorator,
- writeable: false
+ writable: false
def _type
"#{converted_name.camelize}QueryFilter"
diff --git a/lib/api/v3/queries/query_representer.rb b/lib/api/v3/queries/query_representer.rb
index f1a69a3f2f0..575df3c21c7 100644
--- a/lib/api/v3/queries/query_representer.rb
+++ b/lib/api/v3/queries/query_representer.rb
@@ -258,7 +258,7 @@ module API
skip_render: true
property :starred,
- writeable: true
+ writable: true
property :results,
exec_context: :decorator,
@@ -269,7 +269,7 @@ module API
}
property :id,
- writeable: false
+ writable: false
property :name
date_time_property :created_at
@@ -390,7 +390,7 @@ module API
::API::Utilities::ResourceLinkParser.parse_id(
href,
- property: (expected_namespace && expected_namespace.split("/").last) || "filter_value",
+ property: expected_namespace&.split("/")&.last || "filter_value",
expected_version: "3",
expected_namespace:
)
diff --git a/lib/api/v3/versions/version_payload_representer.rb b/lib/api/v3/versions/version_payload_representer.rb
index 2ed3269b8fe..aa3f8612209 100644
--- a/lib/api/v3/versions/version_payload_representer.rb
+++ b/lib/api/v3/versions/version_payload_representer.rb
@@ -34,8 +34,8 @@ module API
cached_representer disabled: true
- def writeable_attributes
- @writeable_attributes ||= begin
+ def writable_attributes
+ @writable_attributes ||= begin
static = if represented.new_record?
%w[endDate definingProject]
else
diff --git a/lib/api/v3/versions/version_representer.rb b/lib/api/v3/versions/version_representer.rb
index 46328a9626a..7fa3adf96d7 100644
--- a/lib/api/v3/versions/version_representer.rb
+++ b/lib/api/v3/versions/version_representer.rb
@@ -96,7 +96,7 @@ module API
date_property :effective_date,
as: 'endDate',
- writeable: true
+ writable: true
property :status
diff --git a/lib/api/v3/work_packages/work_package_payload_representer.rb b/lib/api/v3/work_packages/work_package_payload_representer.rb
index df9edd8149b..3ac0fd449e3 100644
--- a/lib/api/v3/work_packages/work_package_payload_representer.rb
+++ b/lib/api/v3/work_packages/work_package_payload_representer.rb
@@ -35,7 +35,7 @@ module API
cached_representer disabled: true
- def writeable_attributes
+ def writable_attributes
super + %w[date]
end
diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rb
index f42facf88e2..d73da740f72 100644
--- a/lib/api/v3/work_packages/work_package_representer.rb
+++ b/lib/api/v3/work_packages/work_package_representer.rb
@@ -433,7 +433,7 @@ module API
uncacheable: true
property :readonly,
- writeable: false,
+ writable: false,
render_nil: false,
if: ->(*) { ::Status.can_readonly? },
getter: ->(*) do
diff --git a/lib/open_project/patches/representable.rb b/lib/open_project/patches/representable.rb
index 58299e2053c..c3e5cbea48c 100644
--- a/lib/open_project/patches/representable.rb
+++ b/lib/open_project/patches/representable.rb
@@ -44,6 +44,8 @@ module OpenProject::Patches::Representable
end
def self.property(name, options = {}, &)
+ # Note: `:writeable` is required by declarative gem
+ options[:writeable] = options.delete :writable if options.has_key?(:writable)
options = { as: as_strategy.call(name.to_s) }.merge(options) if as_strategy
super
diff --git a/lib/open_project/plugins/acts_as_op_engine.rb b/lib/open_project/plugins/acts_as_op_engine.rb
index 23d14f25cf0..bc7707e54d0 100644
--- a/lib/open_project/plugins/acts_as_op_engine.rb
+++ b/lib/open_project/plugins/acts_as_op_engine.rb
@@ -71,7 +71,7 @@ module OpenProject::Plugins
# adds our factories to factory girl's load path
initializer "#{engine_name}.register_factories", after: 'factory_bot.set_factory_paths' do |_app|
- FactoryBot.definition_file_paths << File.expand_path(root.to_s + '/spec/factories') if defined?(FactoryBot)
+ FactoryBot.definition_file_paths << File.expand_path("#{root}/spec/factories") if defined?(FactoryBot)
end
initializer "#{engine_name}.append_migrations" do |app|
@@ -128,6 +128,7 @@ module OpenProject::Plugins
rescue NameError
"#{plugin_module}::Patches::#{klass_name}Patch".constantize
end
+
qualified_class_name = args.map(&:to_s).join('::')
klass = qualified_class_name.to_s.constantize
klass.send(:include, patch) unless klass.included_modules.include?(patch)
@@ -146,7 +147,7 @@ module OpenProject::Plugins
def override_core_views!
config.after_initialize do
paths = ActionController::Base.view_paths.map(&:to_s)
- my_view_path = config.root.to_s + '/app/views'
+ my_view_path = "#{config.root}/app/views"
# Move item to the front
paths.delete(my_view_path)
@@ -238,7 +239,7 @@ module OpenProject::Plugins
def add_api_attribute(on:,
ar_name:, writable_for: %i[create update],
- writeable: true,
+ writable: true,
&block)
config.to_prepare do
model_name = on.to_s.camelize
@@ -247,7 +248,7 @@ module OpenProject::Plugins
# attribute is generally writable
# overrides might be defined in the more specific contract implementations
contract_class = "::#{namespace}::#{action.to_s.camelize}Contract".constantize
- contract_class.attribute ar_name, { writeable: }, &block
+ contract_class.attribute ar_name, { writable: }, &block
end
end
end
@@ -288,7 +289,8 @@ module OpenProject::Plugins
# @param event_type [Symbol]
#
# Options:
- # * <tt>:class_name</tt> - one or more model(s) that provide these events, those need to inherit from Activities::BaseActivityProvider
+ # * <tt>:class_name</tt> - one or more model(s) that provide these events, those need to inherit
+ # from Activities::BaseActivityProvider
# * <tt>:default</tt> - setting this option to false will make the events not displayed by default
#
# Example
diff --git a/modules/backlogs/lib/open_project/backlogs/engine.rb b/modules/backlogs/lib/open_project/backlogs/engine.rb
index 3b535f6be0e..5bd25127751 100644
--- a/modules/backlogs/lib/open_project/backlogs/engine.rb
+++ b/modules/backlogs/lib/open_project/backlogs/engine.rb
@@ -170,7 +170,7 @@ module OpenProject::Backlogs
&::OpenProject::Backlogs::Patches::API::WorkPackageSchemaRepresenter.extension)
add_api_attribute on: :work_package, ar_name: :story_points
- add_api_attribute on: :work_package, ar_name: :remaining_hours, writeable: ->(*) { model.leaf? }
+ add_api_attribute on: :work_package, ar_name: :remaining_hours, writable: ->(*) { model.leaf? }
add_api_path :backlogs_type do |id|
# There is no api endpoint for this url
diff --git a/modules/bim/app/representers/bim/bcf/api/v2_1/topics/authorization_representer.rb b/modules/bim/app/representers/bim/bcf/api/v2_1/topics/authorization_representer.rb
index 496d41cce3d..3fd65032347 100644
--- a/modules/bim/app/representers/bim/bcf/api/v2_1/topics/authorization_representer.rb
+++ b/modules/bim/app/representers/bim/bcf/api/v2_1/topics/authorization_representer.rb
@@ -40,7 +40,7 @@ module Bim::Bcf::API::V2_1
property :topic_status,
getter: ->(decorator:, **) {
if decorator.manage_bcf_allowed?
- assignable_statuses(model.new_record?).pluck(:name)
+ assignable_statuses(include_default: model.new_record?).pluck(:name)
else
[]
end
diff --git a/modules/boards/spec/requests/api/v3/grids/grids_update_form_resource_spec.rb b/modules/boards/spec/requests/api/v3/grids/grids_update_form_resource_spec.rb
index 150e2c91531..fa16313f3c3 100644
--- a/modules/boards/spec/requests/api/v3/grids/grids_update_form_resource_spec.rb
+++ b/modules/boards/spec/requests/api/v3/grids/grids_update_form_resource_spec.rb
@@ -120,7 +120,7 @@ describe "PATCH /api/v3/grids/:id/form for Board Grids", type: :request, content
}
end
- it 'has a validation error on scope as the value is not writeable' do
+ it 'has a validation error on scope as the value is not writable' do
expect(subject.body)
.to be_json_eql("Scope was attempted to be written but is not writable.".to_json)
.at_path('_embedded/validationErrors/scope/message')
diff --git a/modules/grids/app/contracts/grids/create_contract.rb b/modules/grids/app/contracts/grids/create_contract.rb
index 13b6668fa66..20f3961ba28 100644
--- a/modules/grids/app/contracts/grids/create_contract.rb
+++ b/modules/grids/app/contracts/grids/create_contract.rb
@@ -31,10 +31,10 @@ require 'grids/base_contract'
module Grids
class CreateContract < BaseContract
attribute :user_id,
- writeable: -> { !!model.class.reflect_on_association(:user) }
+ writable: -> { !!model.class.reflect_on_association(:user) }
attribute :project_id,
- writeable: -> { !!model.class.reflect_on_association(:project) }
+ writable: -> { !!model.class.reflect_on_association(:project) }
attribute :type
diff --git a/modules/grids/app/representers/api/v3/grids/grid_representer.rb b/modules/grids/app/representers/api/v3/grids/grid_representer.rb
index 0ac166c602b..54907f083b9 100644
--- a/modules/grids/app/representers/api/v3/grids/grid_representer.rb
+++ b/modules/grids/app/representers/api/v3/grids/grid_representer.rb
@@ -104,11 +104,11 @@ module API
end
date_time_property :created_at,
- writeable: false,
+ writable: false,
render_nil: false
date_time_property :updated_at,
- writeable: false,
+ writable: false,
render_nil: false
def _type
diff --git a/modules/my_page/spec/requests/api/v3/grids/grids_update_form_resource_spec.rb b/modules/my_page/spec/requests/api/v3/grids/grids_update_form_resource_spec.rb
index 7720aa3c3de..5b2120dbd71 100644
--- a/modules/my_page/spec/requests/api/v3/grids/grids_update_form_resource_spec.rb
+++ b/modules/my_page/spec/requests/api/v3/grids/grids_update_form_resource_spec.rb
@@ -54,29 +54,8 @@ describe "PATCH /api/v3/grids/:id/form", type: :request, content_type: :json do
post path, params.to_json, 'CONTENT_TYPE' => 'application/json'
end
- it 'returns 200 OK' do
- expect(subject.status)
- .to be 200
- end
-
- it 'is of type form' do
- expect(subject.body)
- .to be_json_eql("Form".to_json)
- .at_path('_type')
- end
-
- it 'contains a Schema disallowing setting scope' do
- expect(subject.body)
- .to be_json_eql("Schema".to_json)
- .at_path('_embedded/schema/_type')
-
- expect(subject.body)
- .to be_json_eql(false.to_json)
- .at_path('_embedded/schema/scope/writable')
- end
-
- it 'contains the current data in the payload' do
- expected = {
+ let(:expected_payload) do
+ {
rowCount: 7,
columnCount: 4,
options: {},
@@ -108,9 +87,32 @@ describe "PATCH /api/v3/grids/:id/form", type: :request, content_type: :json do
}
}
}
+ end
+ it 'returns 200 OK' do
+ expect(subject.status)
+ .to be 200
+ end
+
+ it 'is of type form' do
+ expect(subject.body)
+ .to be_json_eql("Form".to_json)
+ .at_path('_type')
+ end
+
+ it 'contains a Schema disallowing setting scope' do
+ expect(subject.body)
+ .to be_json_eql("Schema".to_json)
+ .at_path('_embedded/schema/_type')
+
+ expect(subject.body)
+ .to be_json_eql(false.to_json)
+ .at_path('_embedded/schema/scope/writable')
+ end
+
+ it 'contains the current data in the payload' do
expect(subject.body)
- .to be_json_eql(expected.to_json)
+ .to be_json_eql(expected_payload.to_json)
.at_path('_embedded/payload')
end
@@ -131,7 +133,7 @@ describe "PATCH /api/v3/grids/:id/form", type: :request, content_type: :json do
}
end
- it 'has a validation error on scope as the value is not writeable' do
+ it 'has a validation error on scope as the value is not writable' do
expect(subject.body)
.to be_json_eql("Scope was attempted to be written but is not writable.".to_json)
.at_path('_embedded/validationErrors/scope/message')
diff --git a/spec/requests/api/v3/memberships/update_form_resource_spec.rb b/spec/requests/api/v3/memberships/update_form_resource_spec.rb
index e15baf08068..0300fd55bb2 100644
--- a/spec/requests/api/v3/memberships/update_form_resource_spec.rb
+++ b/spec/requests/api/v3/memberships/update_form_resource_spec.rb
@@ -44,7 +44,6 @@ describe ::API::V3::Memberships::UpdateFormAPI, content_type: :json do
let(:another_role) { create(:role) }
let(:other_user) { create(:user) }
let(:permissions) { [:manage_members] }
- let(:project) { create(:project) }
let(:path) { api_v3_paths.membership_form(member.id) }
let(:parameters) do
{
@@ -170,7 +169,7 @@ describe ::API::V3::Memberships::UpdateFormAPI, content_type: :json do
expect(subject.body).to have_json_path('_embedded/validationErrors/project')
end
- it 'notes project to not be writeable' do
+ it 'notes project to not be writable' do
expect(subject.body)
.to be_json_eql(false)
.at_path('_embedded/schema/project/writable')
@@ -204,7 +203,7 @@ describe ::API::V3::Memberships::UpdateFormAPI, content_type: :json do
expect(subject.body).to have_json_path('_embedded/validationErrors/user')
end
- it 'notes principal to not be writeable' do
+ it 'notes principal to not be writable' do
expect(subject.body)
.to be_json_eql(false)
.at_path('_embedded/schema/principal/writable')
diff --git a/spec/requests/api/v3/versions/update_form_resource_spec.rb b/spec/requests/api/v3/versions/update_form_resource_spec.rb
index 95df4ef5c63..ed1c08be561 100644
--- a/spec/requests/api/v3/versions/update_form_resource_spec.rb
+++ b/spec/requests/api/v3/versions/update_form_resource_spec.rb
@@ -126,7 +126,7 @@ describe ::API::V3::Versions::UpdateFormAPI, content_type: :json do
expect(subject.body).to have_json_path('_embedded/validationErrors/project')
end
- it 'notes definingProject to not be writeable' do
+ it 'notes definingProject to not be writable' do
expect(subject.body)
.to be_json_eql(false)
.at_path('_embedded/schema/definingProject/writable')
@@ -191,10 +191,6 @@ describe ::API::V3::Versions::UpdateFormAPI, content_type: :json do
.to be_json_eql('descendants'.to_json)
.at_path('_embedded/payload/sharing')
- # As the definingProject is not writeable
- expect(body)
- .not_to have_json_path('_embedded/payload/_links/definingProject')
-
expect(last_response.body)
.to be_json_eql(api_v3_paths.custom_option(list_cf.custom_options.first.id).to_json)
.at_path("_embedded/payload/_links/customField#{list_cf.id}/href")
@@ -204,6 +200,12 @@ describe ::API::V3::Versions::UpdateFormAPI, content_type: :json do
.at_path("_embedded/payload/customField#{int_cf.id}")
end
+ it 'has no definingProject path' do
+ # As the definingProject is not writable
+ expect(body)
+ .not_to have_json_path('_embedded/payload/_links/definingProject')
+ end
+
it 'has a commit link' do
expect(subject.body)
.to be_json_eql(api_v3_paths.version(version.id).to_json)
diff --git a/spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb b/spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb
index b9df7101d51..5a0e2defb5b 100644
--- a/spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb
@@ -63,17 +63,17 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
subject(:response) { last_response }
- shared_context 'post request' do
+ shared_context 'with post request' do
before do
login_as(current_user)
post post_path, (params ? params.to_json : nil), 'CONTENT_TYPE' => 'application/json'
end
end
- context 'user without needed permissions' do
+ context 'for a user without needed permissions' do
let(:params) { {} }
- include_context 'post request' do
+ include_context 'with post request' do
let(:current_user) { unauthorized_user }
end
@@ -81,14 +81,14 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
I18n.t('api_v3.errors.not_found.work_package')
end
- context 'user with all edit permissions' do
- let(:params) {}
+ context 'for a user with all edit permissions' do
+ let(:params) { nil }
let(:current_user) { authorized_user }
- context 'non-existing work package' do
+ context 'with non-existing work package' do
let(:post_path) { api_v3_paths.work_package_form 'eeek' }
- include_context 'post request'
+ include_context 'with post request'
it_behaves_like 'param validation error' do
let(:id) { 'eeek' }
@@ -96,7 +96,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
end
- context 'existing work package' do
+ context 'with existing work package' do
shared_examples_for 'valid payload' do
subject { last_response.body }
@@ -112,7 +112,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
let(:format) { 'markdown' }
let(:raw) { defined?(raw_value) ? raw_value : work_package.description.to_s }
let(:html) do
- defined?(html_value) ? html_value : ('<p class="op-uc-p">' + work_package.description.to_s + '</p>')
+ defined?(html_value) ? html_value : "<p class=\"op-uc-p\">#{work_package.description}</p>"
end
end
end
@@ -149,8 +149,8 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
describe 'body' do
- context 'empty' do
- include_context 'post request'
+ context 'as empty' do
+ include_context 'with post request'
it_behaves_like 'valid payload'
@@ -159,7 +159,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
it_behaves_like 'having no errors'
end
- context 'filled' do
+ context 'for filled' do
let(:valid_params) do
{
_type: 'WorkPackage',
@@ -170,7 +170,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
describe 'no change' do
let(:params) { valid_params }
- include_context 'post request'
+ include_context 'with post request'
it_behaves_like 'valid payload'
@@ -179,7 +179,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
it_behaves_like 'having no errors'
end
- context 'invalid content' do
+ context 'for invalid content' do
before do
allow(User).to receive(:current).and_return current_user
post post_path, '{ ,', 'CONTENT_TYPE' => 'application/json; charset=utf-8'
@@ -190,15 +190,15 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
describe 'lock version' do
- context 'missing lock version' do
+ context 'with missing lock version' do
let(:params) { valid_params.except(:lockVersion) }
- include_context 'post request'
+ include_context 'with post request'
it_behaves_like 'update conflict'
end
- context 'stale object' do
+ context 'with stale object' do
let(:params) { valid_params.merge(subject: 'Updated subject') }
before do
@@ -206,11 +206,11 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
work_package.subject = 'I am the first!'
work_package.save!
-
- expect(valid_params[:lockVersion]).not_to eq(work_package.lock_version)
end
- include_context 'post request'
+ it { expect(valid_params[:lockVersion]).not_to eq(work_package.lock_version) }
+
+ include_context 'with post request'
it { expect(last_response.status).to eq(409) }
@@ -219,9 +219,9 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
describe 'subject' do
- include_context 'post request'
+ include_context 'with post request'
- context 'valid subject' do
+ context 'for valid subject' do
let(:params) { valid_params.merge(subject: 'Updated subject') }
it_behaves_like 'valid payload'
@@ -234,7 +234,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
end
- context 'invalid subject' do
+ context 'for invalid subject' do
let(:params) { valid_params.merge(subject: nil) }
it_behaves_like 'valid payload'
@@ -253,7 +253,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
let(:description) { '**Some text** *describing* **something**...' }
let(:params) { valid_params.merge(description: { raw: description }) }
- include_context 'post request'
+ include_context 'with post request'
it_behaves_like 'valid payload' do
let(:raw_value) { description }
@@ -267,9 +267,9 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
describe 'start date' do
- include_context 'post request'
+ include_context 'with post request'
- context 'valid date' do
+ context 'for valid date' do
let(:params) { valid_params.merge(startDate: '2015-01-31') }
it_behaves_like 'valid payload'
@@ -282,7 +282,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
end
- context 'invalid date' do
+ context 'for invalid date' do
let(:params) { valid_params.merge(startDate: 'not a date') }
it_behaves_like 'format error',
@@ -294,9 +294,9 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
describe 'finish date' do
- include_context 'post request'
+ include_context 'with post request'
- context 'valid date' do
+ context 'for valid date' do
let(:params) { valid_params.merge(dueDate: '2015-01-31') }
it_behaves_like 'valid payload'
@@ -309,7 +309,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
end
- context 'invalid date' do
+ context 'for invalid date' do
let(:params) { valid_params.merge(dueDate: 'not a date') }
it_behaves_like 'format error',
@@ -327,7 +327,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
let(:status_parameter) { { _links: { status: { href: status_link } } } }
let(:params) { valid_params.merge(status_parameter) }
- context 'valid status' do
+ context 'for valid status' do
let!(:workflow) do
create(:workflow,
type_id: work_package.type.id,
@@ -336,7 +336,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
role: current_user.memberships[0].roles[0])
end
- include_context 'post request'
+ include_context 'with post request'
it_behaves_like 'valid payload'
@@ -352,9 +352,9 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
end
- context 'invalid status' do
- context 'no transition' do
- include_context 'post request'
+ context 'for invalid status' do
+ context 'when no transition' do
+ include_context 'with post request'
it_behaves_like 'valid payload'
@@ -365,13 +365,13 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
end
- context 'status does not exist' do
+ context 'when status does not exist' do
let(:error_id) do
'urn:openproject-org:api:v3:errors:MultipleErrors'.to_json
end
let(:status_link) { api_v3_paths.status -1 }
- include_context 'post request'
+ include_context 'with post request'
it_behaves_like 'valid payload'
@@ -382,10 +382,10 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
end
- context 'wrong resource' do
+ context 'for wrong resource' do
let(:status_link) { api_v3_paths.user authorized_user.id }
- include_context 'post request'
+ include_context 'with post request'
it_behaves_like 'invalid resource link' do
let(:message) do
@@ -418,7 +418,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
context "valid #{property}" do
shared_examples_for 'valid user assignment' do
- include_context 'post request'
+ include_context 'with post request'
it_behaves_like 'valid payload'
@@ -427,19 +427,19 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
it_behaves_like 'having updated work package principal'
end
- context 'empty user' do
+ context 'for empty user' do
let(:user_link) { nil }
it_behaves_like 'valid user assignment'
end
- context 'existing user' do
+ context 'for existing user' do
let(:user_link) { api_v3_paths.user visible_user.id }
it_behaves_like 'valid user assignment'
end
- context 'existing group' do
+ context 'for existing group' do
let(:user_link) { api_v3_paths.group group.id }
let(:group) { create(:group) }
let(:role) { create(:role, permissions: %i[work_package_assigned]) }
@@ -457,7 +457,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
it_behaves_like 'valid user assignment'
end
- context 'existing placeholder_user' do
+ context 'for existing placeholder_user' do
let(:user_link) { api_v3_paths.placeholder_user placeholder_user.id }
let(:placeholder_user) do
create(:placeholder_user,
@@ -470,10 +470,10 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
context "invalid #{property}" do
- context 'non-existing user' do
+ context 'for non-existing user' do
let(:user_link) { api_v3_paths.user 4200 }
- include_context 'post request'
+ include_context 'with post request'
it_behaves_like 'valid payload'
@@ -482,10 +482,10 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
it_behaves_like 'having updated work package principal'
end
- context 'wrong resource' do
+ context 'for wrong resource' do
let(:user_link) { api_v3_paths.status work_package.status.id }
- include_context 'post request'
+ include_context 'with post request'
it_behaves_like 'invalid resource link' do
let(:message) do
@@ -506,8 +506,8 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
describe 'version' do
let(:path) { '_embedded/payload/_links/version/href' }
- let(:target_version) { create(:version, project:, start_date: Date.today - 2.days) }
- let(:other_version) { create(:version, project:, start_date: Date.today - 1.day) }
+ let(:target_version) { create(:version, project:, start_date: Time.zone.today - 2.days) }
+ let(:other_version) { create(:version, project:, start_date: Time.zone.today - 1.day) }
let(:version_link) { api_v3_paths.version target_version.id }
let(:version_parameter) { { _links: { version: { href: version_link } } } }
let(:params) { valid_params.merge(version_parameter) }
@@ -517,7 +517,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
other_version
end
- include_context 'post request'
+ include_context 'with post request'
it 'lists all versions available for the project' do
[target_version, other_version].sort.each_with_index do |v, i|
@@ -527,8 +527,8 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
end
- context 'valid version' do
- include_context 'post request'
+ context 'for valid version' do
+ include_context 'with post request'
it_behaves_like 'valid payload'
@@ -554,7 +554,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
other_category
end
- include_context 'post request'
+ include_context 'with post request'
it 'lists the categories' do
[target_category, other_category].sort.each_with_index do |c, i|
@@ -564,8 +564,8 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
end
- context 'valid category' do
- include_context 'post request'
+ context 'for valid category' do
+ include_context 'with post request'
it_behaves_like 'valid payload'
@@ -592,7 +592,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
other_priority
end
- include_context 'post request'
+ include_context 'with post request'
it 'lists the priorities' do
expect(subject.body).to be_json_eql(priority_link.to_json)
@@ -602,8 +602,8 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
end
- context 'valid priority' do
- include_context 'post request'
+ context 'for valid priority' do
+ include_context 'with post request'
it_behaves_like 'valid payload'
@@ -634,7 +634,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
other_type
end
- include_context 'post request'
+ include_context 'with post request'
it 'lists the types' do
expect(subject.body).to be_json_eql(type_link.to_json)
@@ -644,8 +644,8 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
end
- context 'valid type' do
- include_context 'post request'
+ context 'for valid type' do
+ include_context 'with post request'
it_behaves_like 'valid payload'
@@ -671,7 +671,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
other_budget
end
- include_context 'post request'
+ include_context 'with post request'
it 'lists the budgets' do
budgets = project.budgets
@@ -683,8 +683,8 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
end
- context 'valid budget' do
- include_context 'post request'
+ context 'for valid budget' do
+ include_context 'with post request'
it_behaves_like 'having no errors'
@@ -693,10 +693,10 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
end
- context 'invalid budget' do
+ context 'for invalid budget' do
let(:target_budget) { create(:budget) }
- include_context 'post request'
+ include_context 'with post request'
it_behaves_like 'having an error', 'budget'
@@ -720,7 +720,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
let(:params) { valid_params.merge(subject: nil).merge(links) }
- include_context 'post request'
+ include_context 'with post request'
it_behaves_like 'valid payload'
@@ -766,14 +766,14 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
end
end
- context 'user with assign version permissions' do
+ context 'for user with assign version permissions' do
let(:params) do
{
lockVersion: work_package.lock_version
}
end
- include_context 'post request' do
+ include_context 'with post request' do
let(:current_user) { authorized_assign_user }
end
@@ -793,13 +793,13 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
it_behaves_like 'valid payload'
- it 'denotes subject to not be writeable' do
+ it 'denotes subject to not be writable' do
expect(subject)
.to be_json_eql(false)
.at_path('_embedded/schema/subject/writable')
end
- it 'denotes version to be writeable' do
+ it 'denotes version to be writable' do
expect(subject)
.to be_json_eql(true)
.at_path('_embedded/schema/version/writable')