@@ -222,6 +222,16 @@ class Planet < ActiveRecord::Base
222222 belongs_to :planet_type
223223
224224 has_and_belongs_to_many :tags , join_table : :planets_tags
225+
226+ # Test model callback cancelling save
227+ before_save :check_not_pluto
228+
229+ def check_not_pluto
230+ # Pluto can't be a planet, so cancel the save
231+ if name . downcase == 'pluto'
232+ return false
233+ end
234+ end
225235end
226236
227237class PlanetType < ActiveRecord ::Base
@@ -969,7 +979,7 @@ class BadlyNamedAttributesResource < JSONAPI::Resource
969979 description : 'Saturn is the sixth planet from the Sun and the second largest planet in the Solar System, after Jupiter.' ,
970980 planet_type_id : planetoid . id )
971981titan = Moon . create ( name :'Titan' , description : 'Best known of the Saturn moons.' , planet_id : saturn . id )
972- pluto = Planet . create ( name : 'Pluto ' , description : 'Pluto is the smallest planet .' , planet_type_id : planetoid . id )
982+ makemake = Planet . create ( name : 'Makemake ' , description : 'A small planetoid in the Kuiperbelt .' , planet_type_id : planetoid . id )
973983uranus = Planet . create ( name : 'Uranus' , description : 'Insert adolescent jokes here.' , planet_type_id : gas_giant . id )
974984jupiter = Planet . create ( name : 'Jupiter' , description : 'A gas giant.' , planet_type_id : gas_giant . id )
975985betax = Planet . create ( name : 'Beta X' , description : 'Newly discovered Planet X' , planet_type_id : unknown . id )
0 commit comments