Commit b7df604dcd49be6f950d2cec48b7fb75421bcb44

Disallow nameless metas

Commit diff

lib/strokedb/document/meta.rb

 
254254 values = @args.clone.select{|a| a.is_a?(Hash) }.first
255255 values[:meta] = Meta.document(store)
256256 values[:name] ||= name.demodulize
257
258 raise ArgumentError, "meta can't be nameless" if values[:name].blank?
259
257260 values[:nsurl] ||= name.modulize.empty? ? Module.nsurl : name.modulize.constantize.nsurl
258 values[:uuid] ||= Meta.make_uuid(values[:nsurl],values[:name]) if values[:name]
261 values[:uuid] ||= Meta.make_uuid(values[:nsurl],values[:name])
262
259263
260264 if meta_doc = find_meta_doc(values, store)
261265 values[:version] = meta_doc.version
toggle raw diff

spec/lib/strokedb/document/meta_spec.rb

 
161161 @some_meta = Meta.new(:nsurl => "http://some/")
162162 end
163163
164 it "should not have document's UUID v5 based on nsurl and name" do
165 @some_meta.document.uuid.should_not == Util.sha1_uuid('http://some/#SomeName')
164 it "should not be able to create a document" do
165 lambda do
166 @some_meta.document
167 end.should raise_error(ArgumentError)
166168 end
167169end
168170
toggle raw diff

spec/lib/strokedb/document/validations_spec.rb

 
1212end
1313
1414def erroneous_stuff
15 Meta.new do
15 Meta.new(:name => "ErroneousStuff") do
1616 on_validation do |doc|
1717 doc.errors.add(:something, "123")
1818 doc.errors.add(:other, "456")
383383 end
384384
385385 it "should treat accepted value as valid" do
386 Meta.new { validates_acceptance_of :eula, :accept => "yep" }.new(:eula => "yep").should be_valid
386 Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep" }.new(:eula => "yep").should be_valid
387387 end
388388
389389 it "should treat not accepted value as invalid" do
390 Meta.new { validates_acceptance_of :eula, :accept => "yep" }.new(:eula => "nope").should_not be_valid
390 Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep" }.new(:eula => "nope").should_not be_valid
391391 end
392392
393393 it "should respect allow_nil" do
394 Meta.new { validates_acceptance_of :eula, :accept => "yep", :allow_nil => true }.new.should be_valid
395 Meta.new { validates_acceptance_of :eula, :accept => "yep", :allow_nil => false }.new.should_not be_valid
394 Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep", :allow_nil => true }.new.should be_valid
395 Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep", :allow_nil => false }.new.should_not be_valid
396396 end
397397
398398 it "should set :allow_nil to true by default" do
399 Meta.new { validates_acceptance_of :eula, :accept => "yep" }.new.should be_valid
399 Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep" }.new.should be_valid
400400 end
401401
402402 it "should set :accept to \"1\" by default" do
403 Meta.new { validates_acceptance_of :eula }.new(:eula => "1").should be_valid
403 Meta.new(:name => 'some') { validates_acceptance_of :eula }.new(:eula => "1").should be_valid
404404 end
405405
406406 it "should make a slot virtual" do
407 Foo = Meta.new { validates_acceptance_of :eula, :accept => "yep" }
407 Foo = Meta.new{ validates_acceptance_of :eula, :accept => "yep" }
408408 f = Foo.create!(:eula => "yep")
409409 Foo.find(f.uuid).has_slot?("eula").should_not be_true
410410 end
417417
418418 describe "options handling" do
419419 it "should raise ArgumentError when more than one range option is specified" do
420 arg_bang { Meta.new { validates_length_of :name, :is => 10, :maximum => 20 } }
421 arg_bang { Meta.new { validates_length_of :name, :is => 10, :within => 1..20 } }
420 arg_bang { Meta.new(:name => 'some') { validates_length_of :name, :is => 10, :maximum => 20 } }
421 arg_bang { Meta.new(:name => 'some') { validates_length_of :name, :is => 10, :within => 1..20 } }
422422 end
423423
424424 it "should raise ArgumentError when no range option is specified" do
425 arg_bang { Meta.new { validates_length_of :name } }
425 arg_bang { Meta.new(:name => 'some') { validates_length_of :name } }
426426 end
427427
428428 it "should raise ArgumentError when not Range given to :in or :within" do
429 arg_bang { Meta.new { validates_length_of :name, :in => 10 } }
430 arg_bang { Meta.new { validates_length_of :name, :within => "somewhere between one and a million" } }
429 arg_bang { Meta.new(:name => 'some') { validates_length_of :name, :in => 10 } }
430 arg_bang { Meta.new(:name => 'some') { validates_length_of :name, :within => "somewhere between one and a million" } }
431431 end
432432
433433 it "should raise ArgumentError when something other than nonnegative Integer is given to :is, :minimum, :maximum" do
434434 %w(is minimum maximum).each do |arg|
435 arg_bang { Meta.new { validates_length_of :name, arg => "blah" } }
436 arg_bang { Meta.new { validates_length_of :name, arg => -1 } }
435 arg_bang { Meta.new(:name => 'some') { validates_length_of :name, arg => "blah" } }
436 arg_bang { Meta.new(:name => 'some') { validates_length_of :name, arg => -1 } }
437437 end
438438 end
439439
564564 end
565565
566566 it "should respect :allow_nil" do
567 Meta.new { validates_length_of :bar, :is => 10, :allow_nil => false }.new.should_not be_valid
568 Meta.new { validates_length_of :bar, :is => 10, :allow_nil => true }.new.should be_valid
567 Meta.new(:name => 'some') { validates_length_of :bar, :is => 10, :allow_nil => false }.new.should_not be_valid
568 Meta.new(:name => 'some') { validates_length_of :bar, :is => 10, :allow_nil => true }.new.should be_valid
569569 end
570570
571571 it "should respect :allow_blank" do
10271027 end
10281028
10291029 it "should respect :allow_nil" do
1030 Meta.new { validates_numericality_of :number, :allow_nil => true }.new.should be_valid
1030 Meta.new(:name => 'some') { validates_numericality_of :number, :allow_nil => true }.new.should be_valid
10311031 end
10321032
10331033 describe "should allow for option combinations" do
toggle raw diff