Commit ebcc2a5
committed
Base: read from
Prior to this commit, the `respond_to_missing?` implementation had a
conditional to supports attributes being able to be written to through
methods "did not respond to" (like `send("#{attr_name}=", value)`), as
well as `?`-suffixed predicate methods.
The `method_missing` implementation has a set of conditionals similar to
`respond_to_missing`, but with subtle variations through checking for an
attribute name's inclusion in `known_attributes` (attributes defined by
the Schema **or** assigned during `Base#load`) rather than the attribute
name's inclusion in `attributes` (the current instance's assigned
values, without any attributes declared in the Schema).
Without the implementation changes, the following tests introduced in
this commit fail:
```
1) Failure:
BaseTest#test_respond_to_known_attributes [test/cases/base_test.rb:972]:
Expected #<Person:0x000000011d0cdcf8 @attributes={}, @prefix_options={}, @persisted=false> (Person) to respond to #name=.
```
This commit changes the `respond_to_missing?` conditional to check for
the presence of the key in `known_attributes` rather than `attributes`
so that instances will respond to `=`-suffixed writers and `?`-suffixed
predicates for attributes that are declared in the resource's Schema
that have not yet been assigned to.known_attributes in respond_to_missing?
1 parent b549319 commit ebcc2a5
2 files changed
Lines changed: 47 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1653 | 1653 | | |
1654 | 1654 | | |
1655 | 1655 | | |
1656 | | - | |
| 1656 | + | |
1657 | 1657 | | |
1658 | 1658 | | |
1659 | 1659 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
960 | 960 | | |
961 | 961 | | |
962 | 962 | | |
963 | | - | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
964 | 1009 | | |
965 | 1010 | | |
966 | 1011 | | |
| |||
0 commit comments