@@ -928,6 +928,17 @@ def log_message
928928 end . to change { d . reload . name } . to ( '[Updated]' )
929929 end
930930
931+ it 'raises an UnknownAttribute error when adding an attribute that is not on the model' do
932+ klass = new_class do
933+ field :name
934+ end
935+
936+ obj = klass . create ( name : 'Alex' )
937+ expect {
938+ klass . update! ( obj . id , age : 26 )
939+ } . to raise_error Dynamoid ::Errors ::UnknownAttribute
940+ end
941+
931942 describe 'timestamps' do
932943 it 'sets updated_at if Config.timestamps=true' , config : { timestamps : true } do
933944 d = document_class . create ( name : 'Document#1' )
@@ -1047,6 +1058,18 @@ def log_message
10471058 end . to change { d . reload . name } . to ( '[Updated]' )
10481059 end
10491060
1061+ it 'raises an UnknownAttribute error when adding an attribute that is not on the model' do
1062+ klass = new_class do
1063+ field :name
1064+ end
1065+
1066+ obj = klass . create ( name : 'Alex' )
1067+
1068+ expect do
1069+ klass . update ( obj . id , name : 'New name' , age : 26 )
1070+ end . to raise_error Dynamoid ::Errors ::UnknownAttribute
1071+ end
1072+
10501073 describe 'timestamps' do
10511074 it 'sets updated_at if Config.timestamps=true' , config : { timestamps : true } do
10521075 d = document_class . create ( name : 'Document#1' )
@@ -1278,6 +1301,14 @@ def log_message
12781301 expect ( klass . find ( a . id ) [ :hash ] ) . to eql ( '1' : 'b' )
12791302 end
12801303 end
1304+
1305+ it 'raises an UnknownAttribute error when adding an attribute that is not on the model' do
1306+ obj = document_class . create ( title : 'New Document' )
1307+
1308+ expect {
1309+ document_class . update_fields ( obj . id , { title : 'New title' , publisher : 'New publisher' } )
1310+ } . to raise_error Dynamoid ::Errors ::UnknownAttribute
1311+ end
12811312 end
12821313
12831314 describe '.upsert' do
@@ -1455,6 +1486,14 @@ def log_message
14551486 expect ( klass . find ( a . id ) [ :hash ] ) . to eql ( '1' : 'b' )
14561487 end
14571488 end
1489+
1490+ it 'raises an UnknownAttribute error when adding an attribute that is not on the model' do
1491+ obj = document_class . create ( title : 'New Document' )
1492+
1493+ expect {
1494+ document_class . upsert ( obj . id , { title : 'New title' , publisher : 'New publisher' } )
1495+ } . to raise_error Dynamoid ::Errors ::UnknownAttribute
1496+ end
14581497 end
14591498
14601499 describe '.inc' do
@@ -1977,6 +2016,19 @@ def log_message
19772016 end . not_to raise_error
19782017 end
19792018 end
2019+
2020+ it 'raises an UnknownAttribute error when adding an attribute that is not on the model' do
2021+ klass = new_class do
2022+ field :age , :integer
2023+ field :name , :string
2024+ end
2025+
2026+ obj = klass . create! ( name : 'Alex' , age : 26 )
2027+
2028+ expect {
2029+ obj . update_attribute ( :city , 'Dublin' )
2030+ } . to raise_error ( Dynamoid ::Errors ::UnknownAttribute )
2031+ end
19802032 end
19812033
19822034 describe '#update_attributes' do
@@ -2068,6 +2120,14 @@ def log_message
20682120 end . not_to raise_error
20692121 end
20702122 end
2123+
2124+ it 'raises an UnknownAttribute error when adding an attribute that is not on the model' do
2125+ obj = klass . create! ( name : 'Alex' , age : 26 )
2126+
2127+ expect {
2128+ obj . update_attributes! ( city : 'Dublin' , age : 27 )
2129+ } . to raise_error ( Dynamoid ::Errors ::UnknownAttribute )
2130+ end
20712131 end
20722132
20732133 describe '#update_attributes!' do
@@ -2110,6 +2170,14 @@ def log_message
21102170 expect ( klass . find ( obj . id ) . age ) . to eql 26
21112171 end
21122172
2173+ it 'raises an UnknownAttribute error when adding an attribute that is not on the model' do
2174+ obj = klass . create! ( name : 'Alex' , age : 26 )
2175+
2176+ expect {
2177+ obj . update_attributes! ( city : 'Dublin' , age : 27 )
2178+ } . to raise_error ( Dynamoid ::Errors ::UnknownAttribute )
2179+ end
2180+
21132181 describe 'type casting' do
21142182 it 'type casts attributes' do
21152183 klass = new_class do
0 commit comments