mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
replace usage of OpenStruct
This commit is contained in:
@@ -72,16 +72,17 @@ module API
|
||||
.from_hash(request_body)
|
||||
|
||||
deep_to_h(struct)
|
||||
.deep_symbolize_keys
|
||||
end
|
||||
|
||||
def struct
|
||||
OpenStruct.new
|
||||
Hashie::Mash.new
|
||||
end
|
||||
|
||||
def deep_to_h(value)
|
||||
# Does not yet factor in Arrays. There hasn't been the need to do that, yet.
|
||||
case value
|
||||
when OpenStruct, Hash
|
||||
when Hashie::Mash, Hash
|
||||
value.to_h.transform_values do |sub_value|
|
||||
deep_to_h(sub_value)
|
||||
end
|
||||
|
||||
@@ -46,10 +46,10 @@ module API
|
||||
end
|
||||
|
||||
def struct
|
||||
if model&.respond_to?(:available_custom_fields)
|
||||
OpenStruct.new available_custom_fields: model.available_custom_fields(model.new)
|
||||
else
|
||||
super
|
||||
super.tap do |instance|
|
||||
if model.respond_to?(:available_custom_fields)
|
||||
instance.available_custom_fields = model.available_custom_fields(model.new)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -125,7 +125,7 @@ module API
|
||||
end
|
||||
|
||||
def format_query_sums(sums)
|
||||
OpenStruct.new(format_column_keys(sums).merge(available_custom_fields: WorkPackageCustomField.summable.to_a))
|
||||
Hashie::Mash.new(format_column_keys(sums).merge(available_custom_fields: WorkPackageCustomField.summable.to_a))
|
||||
end
|
||||
|
||||
def format_column_keys(hash_by_column)
|
||||
|
||||
@@ -58,7 +58,7 @@ module API
|
||||
protected
|
||||
|
||||
def meta_representer
|
||||
meta_representer_class.create(meta || OpenStruct.new, current_user: current_user)
|
||||
meta_representer_class.create(meta || Hashie::Mash.new, current_user: current_user)
|
||||
end
|
||||
|
||||
def meta_representer_class
|
||||
|
||||
@@ -58,11 +58,11 @@ module API
|
||||
struct.status = struct.status_attributes
|
||||
|
||||
# Remove temporary attributes workaround
|
||||
struct.delete_field(:status_attributes)
|
||||
struct.delete(:status_attributes)
|
||||
|
||||
# Remove nil status_explanation when passed as nil
|
||||
if struct.respond_to?(:status_explanation)
|
||||
struct.delete_field(:status_explanation)
|
||||
struct.delete(:status_explanation)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -216,7 +216,7 @@ module API
|
||||
end
|
||||
},
|
||||
setter: ->(fragment:, represented:, **) {
|
||||
represented.status_attributes ||= OpenStruct.new
|
||||
represented.status_attributes ||= Hashie::Mash.new
|
||||
|
||||
link = ::API::Decorators::LinkObject.new(represented.status_attributes,
|
||||
path: :project_status,
|
||||
@@ -235,7 +235,7 @@ module API
|
||||
plain: false)
|
||||
},
|
||||
setter: ->(fragment:, represented:, **) {
|
||||
represented.status_attributes ||= OpenStruct.new
|
||||
represented.status_attributes ||= Hashie::Mash.new
|
||||
represented.status_attributes[:explanation] = fragment["raw"]
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ describe ::API::V3::Projects::ProjectPayloadRepresenter, 'parsing' do
|
||||
include ::API::V3::Utilities::PathHelper
|
||||
|
||||
let(:object) do
|
||||
OpenStruct.new available_custom_fields: []
|
||||
Hashie::Mash.new available_custom_fields: []
|
||||
end
|
||||
let(:user) { build_stubbed(:user) }
|
||||
let(:representer) do
|
||||
@@ -117,16 +117,16 @@ describe ::API::V3::Projects::ProjectPayloadRepresenter, 'parsing' do
|
||||
end
|
||||
|
||||
it 'does set status to nil' do
|
||||
project = representer.from_hash(hash).to_h
|
||||
project = representer.from_hash(hash)
|
||||
|
||||
expect(project)
|
||||
.to have_key(:status)
|
||||
|
||||
status = project[:status]
|
||||
expect(status.to_h)
|
||||
expect(status)
|
||||
.to have_key(:code)
|
||||
|
||||
expect(status.to_h)
|
||||
expect(status)
|
||||
.not_to have_key(:explanation)
|
||||
|
||||
expect(status[:code])
|
||||
@@ -150,7 +150,7 @@ describe ::API::V3::Projects::ProjectPayloadRepresenter, 'parsing' do
|
||||
end
|
||||
|
||||
it 'sets the parent_id to the value' do
|
||||
project = representer.from_hash(hash).to_h
|
||||
project = representer.from_hash(hash)
|
||||
|
||||
expect(project[:parent_id])
|
||||
.to eq "5"
|
||||
@@ -169,7 +169,7 @@ describe ::API::V3::Projects::ProjectPayloadRepresenter, 'parsing' do
|
||||
end
|
||||
|
||||
it 'sets the parent_id to nil' do
|
||||
project = representer.from_hash(hash).to_h
|
||||
project = representer.from_hash(hash)
|
||||
|
||||
expect(project)
|
||||
.to have_key(:parent_id)
|
||||
@@ -191,7 +191,7 @@ describe ::API::V3::Projects::ProjectPayloadRepresenter, 'parsing' do
|
||||
end
|
||||
|
||||
it 'omits the parent information' do
|
||||
project = representer.from_hash(hash).to_h
|
||||
project = representer.from_hash(hash)
|
||||
|
||||
expect(project)
|
||||
.not_to have_key(:parent_id)
|
||||
|
||||
@@ -250,7 +250,7 @@ describe ::API::V3::WorkPackageCollectionFromQueryService,
|
||||
.to receive(:summable)
|
||||
.and_return(custom_fields)
|
||||
|
||||
expected = OpenStruct.new(estimated_hours: 0.0, available_custom_fields: custom_fields)
|
||||
expected = Hashie::Mash.new(estimated_hours: 0.0, available_custom_fields: custom_fields)
|
||||
|
||||
expect(subject.total_sums)
|
||||
.to eq(expected)
|
||||
|
||||
Reference in New Issue
Block a user