Skip to content

Commit

Permalink
Use respond_to? to check if reference responds to writer when using r…
Browse files Browse the repository at this point in the history
…epresents
  • Loading branch information
andriusch committed Jan 21, 2021
1 parent b12ba1f commit 574c8e4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# master (not released yet)

# Version 0.9.7

* fix `represents` to skip not defined attributes on the reference

# Version 0.9.6

* fix gemspec to include `config` directory
Expand Down
4 changes: 1 addition & 3 deletions lib/granite/represents/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def initialize(*_args)
end

def sync
return if reference.nil?

reference.public_send(writer, read)
reference.public_send(writer, read) if reference.respond_to?(writer)
end

def typecast(value)
Expand Down
2 changes: 1 addition & 1 deletion lib/granite/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Granite
VERSION = '0.9.6'.freeze
VERSION = '0.9.7'.freeze
end
3 changes: 2 additions & 1 deletion spec/lib/granite/represents/attribute_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def user
expect { subject.sync }.to change { action.user.sign_in_count }.from(1).to(2)
end

context 'when represents attribute of nil' do
context 'when represented object does not respond to attribute name' do
before do
stub_class(:action, Granite::Action) do
allow_if { true }
Expand All @@ -80,6 +80,7 @@ def user
represents :related_ids, of: :user

def user
Object.new
end
end
end
Expand Down

0 comments on commit 574c8e4

Please sign in to comment.