Skip to content

Commit 9fd409c

Browse files
committed
Fix issue with frozen string literals
Close #73
1 parent 51889ef commit 9fd409c

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/hawk/model/base.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ def initialize(attributes = {}, params = {})
2424
end
2525

2626
def inspect
27-
attributes = schema.inject('') do |s, (k, _v)|
28-
s << " #{k}=#{read_attribute(k).inspect}"
27+
result = "#<#{self.class.name}"
28+
29+
schema.each_key do |k|
30+
result << " #{k}=#{read_attribute(k).inspect}"
2931
end
30-
"#<#{self.class.name}#{attributes}>"
32+
33+
result << '>'
34+
35+
result
3136
end
3237
end
3338
end

spec/basic_operations_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,16 @@ class Person < Hawk::Model::Base
124124
expect(person).to be_a(Person)
125125
end
126126
end
127+
128+
describe '#inspect' do
129+
it 'returns a string representation of the model' do
130+
stub_request(:GET, 'https://example.org/people/2')
131+
.with(headers: { 'User-Agent' => 'Foobar' })
132+
.to_return(status: 200, body: person_attributes.to_json, headers: {})
133+
134+
person = Person.find(2)
135+
136+
expect(person.inspect).to eq('#<Person id=2 name="Woody Allen">')
137+
end
138+
end
127139
end

0 commit comments

Comments
 (0)