Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ class TimeEntryRepresenter < ::API::Decorators::Single
getter: ->(*) {
datetime_formatter.format_datetime(represented.end_timestamp, allow_nil: true)
},
setter: ->(*) {
# end_time is derived (start_time + hours), never its own column --
# silently accept a write attempt without touching the record, same
# as any other purely-computed read-only API property.
},
if: ->(*) { TimeEntry.can_track_start_and_end_time? }

associated_resource :activity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,29 @@
end
end

describe "endTime" do
# Regression test: end_time is purely derived (start_time + hours) and
# has no setter of its own on TimeEntry. Representable used to fall
# through to a raw `send(:end_time=, value)` when a client sent
# endTime on write, crashing with NoMethodError instead of silently
# ignoring the unwritable field.
context "when tracking start and end time" do
before do
allow(TimeEntry).to receive_messages(
can_track_start_and_end_time?: true,
must_track_start_and_end_time?: false
)

hash["endTime"] = "2017-07-28T17:30:00Z"
end

it "does not raise and does not set end_time as its own attribute" do
expect { representer.from_hash(hash) }.not_to raise_error
expect(time_entry).not_to respond_to(:end_time=)
end
end
Comment thread
myabc marked this conversation as resolved.
Outdated
end

describe "hours" do
it "updates hours" do
time_entry = representer.from_hash(hash)
Expand Down
Loading