test/unit/orm/mongoid_test.rb in has_constant-0.4.7 vs test/unit/orm/mongoid_test.rb in has_constant-0.4.8

- old
+ new

@@ -29,9 +29,15 @@ should 'add the field automatically' do MongoUserWithout.has_constant :salutations, ['Mr', 'Mrs'] assert MongoUserWithout.fields.map(&:first).include?('salutation') end + should 'not add the field if it is already there' do + MongoUserWithout.send(:field, :salutation, :type => Integer, :default => 0) + MongoUserWithout.has_constant :salutations, ['Mr', 'Mrs'] + assert_equal 'Mr', MongoUserWithout.new.salutation + end + should 'take the accessor into account when adding the field' do MongoUserWithout.has_constant :salutations, ['Mr', 'Mrs'], :accessor => :sal assert MongoUserWithout.fields.map(&:first).include?('sal') end