From 755ba96709e60c194e834da065f525da02dc3606 Mon Sep 17 00:00:00 2001 From: ur5us Date: Wed, 3 Jun 2026 17:16:25 +1200 Subject: [PATCH 1/3] Fix ArgumentError after invoking setter Fix `add_accessors': wrong number of arguments (given 1, expected 0) (ArgumentError)`. The issue was the lack of `[]=` operator method definition which resulted in the `method_missing` hook redefining `[]` method. --- lib/hubspot/resource.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/hubspot/resource.rb b/lib/hubspot/resource.rb index a21c8d19..be22da36 100644 --- a/lib/hubspot/resource.rb +++ b/lib/hubspot/resource.rb @@ -95,6 +95,10 @@ def [](name) @changes[name] || @properties.dig(name, 'value') end + def []=(name, value) + @changes[name] = value unless @changes[name] == value + end + def reload raise(Hubspot::InvalidParams.new("Resource must have an ID")) if @id.nil? From ad08bf7141594a6525be77a29bccfce0094cf4e4 Mon Sep 17 00:00:00 2001 From: ur5us Date: Thu, 4 Jun 2026 09:51:32 +1200 Subject: [PATCH 2/3] Add spec for Resource#[]= method --- spec/lib/hubspot/resource_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/lib/hubspot/resource_spec.rb b/spec/lib/hubspot/resource_spec.rb index 1fdcf08d..55cdca2b 100644 --- a/spec/lib/hubspot/resource_spec.rb +++ b/spec/lib/hubspot/resource_spec.rb @@ -73,6 +73,18 @@ end end + describe '#[]=' do + let(:resource) { described_class.from_result({ properties: }) } + let(:properties) { { id: { 'value' => 1 }, firstname: { 'value' => 'John' }, lastname: { 'value' => 'Wayne' } } } + + it "stages a change to a property" do + resource[:firstname] = 'Jon' + + expect(resource[:firstname]).to eq 'Jon' + expect(resource.changes).to include(firstname: 'Jon') + end + end + describe '#adding_accessors' do describe 'getters' do context 'using new' do From e9e2445daa4b2b6a54b34129bb7e503ad6d721f9 Mon Sep 17 00:00:00 2001 From: ur5us Date: Thu, 4 Jun 2026 20:08:47 +1200 Subject: [PATCH 3/3] Address PR feedback --- spec/lib/hubspot/resource_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/lib/hubspot/resource_spec.rb b/spec/lib/hubspot/resource_spec.rb index 55cdca2b..9199a2ab 100644 --- a/spec/lib/hubspot/resource_spec.rb +++ b/spec/lib/hubspot/resource_spec.rb @@ -77,10 +77,10 @@ let(:resource) { described_class.from_result({ properties: }) } let(:properties) { { id: { 'value' => 1 }, firstname: { 'value' => 'John' }, lastname: { 'value' => 'Wayne' } } } - it "stages a change to a property" do + it 'stages a change to a property' do resource[:firstname] = 'Jon' - expect(resource[:firstname]).to eq 'Jon' + expect(resource[:firstname]).to eq 'Jon' expect(resource.changes).to include(firstname: 'Jon') end end