Skip to content

Commit

Permalink
Merge branch 'master' into new-views
Browse files Browse the repository at this point in the history
  • Loading branch information
yrashk committed Apr 30, 2008
2 parents c573eaf + b7df604 commit 599c3ba
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
6 changes: 5 additions & 1 deletion lib/strokedb/document/meta.rb
Expand Up @@ -254,8 +254,12 @@ def make_document(store=nil)
values = @args.clone.select{|a| a.is_a?(Hash) }.first
values[:meta] = Meta.document(store)
values[:name] ||= name.demodulize

raise ArgumentError, "meta can't be nameless" if values[:name].blank?

values[:nsurl] ||= name.modulize.empty? ? Module.nsurl : name.modulize.constantize.nsurl
values[:uuid] ||= Meta.make_uuid(values[:nsurl],values[:name]) if values[:name]
values[:uuid] ||= Meta.make_uuid(values[:nsurl],values[:name])


if meta_doc = find_meta_doc(values, store)
values[:version] = meta_doc.version
Expand Down
6 changes: 4 additions & 2 deletions spec/lib/strokedb/document/meta_spec.rb
Expand Up @@ -161,8 +161,10 @@
@some_meta = Meta.new(:nsurl => "http://some/")
end

it "should not have document's UUID v5 based on nsurl and name" do
@some_meta.document.uuid.should_not == Util.sha1_uuid('http://some/#SomeName')
it "should not be able to create a document" do
lambda do
@some_meta.document
end.should raise_error(ArgumentError)
end
end

Expand Down
36 changes: 18 additions & 18 deletions spec/lib/strokedb/document/validations_spec.rb
Expand Up @@ -12,7 +12,7 @@ def validations_setup
end

def erroneous_stuff
Meta.new do
Meta.new(:name => "ErroneousStuff") do
on_validation do |doc|
doc.errors.add(:something, "123")
doc.errors.add(:other, "456")
Expand Down Expand Up @@ -383,28 +383,28 @@ def no_bang
end

it "should treat accepted value as valid" do
Meta.new { validates_acceptance_of :eula, :accept => "yep" }.new(:eula => "yep").should be_valid
Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep" }.new(:eula => "yep").should be_valid
end

it "should treat not accepted value as invalid" do
Meta.new { validates_acceptance_of :eula, :accept => "yep" }.new(:eula => "nope").should_not be_valid
Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep" }.new(:eula => "nope").should_not be_valid
end

it "should respect allow_nil" do
Meta.new { validates_acceptance_of :eula, :accept => "yep", :allow_nil => true }.new.should be_valid
Meta.new { validates_acceptance_of :eula, :accept => "yep", :allow_nil => false }.new.should_not be_valid
Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep", :allow_nil => true }.new.should be_valid
Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep", :allow_nil => false }.new.should_not be_valid
end

it "should set :allow_nil to true by default" do
Meta.new { validates_acceptance_of :eula, :accept => "yep" }.new.should be_valid
Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep" }.new.should be_valid
end

it "should set :accept to \"1\" by default" do
Meta.new { validates_acceptance_of :eula }.new(:eula => "1").should be_valid
Meta.new(:name => 'some') { validates_acceptance_of :eula }.new(:eula => "1").should be_valid
end

it "should make a slot virtual" do
Foo = Meta.new { validates_acceptance_of :eula, :accept => "yep" }
Foo = Meta.new{ validates_acceptance_of :eula, :accept => "yep" }
f = Foo.create!(:eula => "yep")
Foo.find(f.uuid).has_slot?("eula").should_not be_true
end
Expand All @@ -417,23 +417,23 @@ def no_bang

describe "options handling" do
it "should raise ArgumentError when more than one range option is specified" do
arg_bang { Meta.new { validates_length_of :name, :is => 10, :maximum => 20 } }
arg_bang { Meta.new { validates_length_of :name, :is => 10, :within => 1..20 } }
arg_bang { Meta.new(:name => 'some') { validates_length_of :name, :is => 10, :maximum => 20 } }
arg_bang { Meta.new(:name => 'some') { validates_length_of :name, :is => 10, :within => 1..20 } }
end

it "should raise ArgumentError when no range option is specified" do
arg_bang { Meta.new { validates_length_of :name } }
arg_bang { Meta.new(:name => 'some') { validates_length_of :name } }
end

it "should raise ArgumentError when not Range given to :in or :within" do
arg_bang { Meta.new { validates_length_of :name, :in => 10 } }
arg_bang { Meta.new { validates_length_of :name, :within => "somewhere between one and a million" } }
arg_bang { Meta.new(:name => 'some') { validates_length_of :name, :in => 10 } }
arg_bang { Meta.new(:name => 'some') { validates_length_of :name, :within => "somewhere between one and a million" } }
end

it "should raise ArgumentError when something other than nonnegative Integer is given to :is, :minimum, :maximum" do
%w(is minimum maximum).each do |arg|
arg_bang { Meta.new { validates_length_of :name, arg => "blah" } }
arg_bang { Meta.new { validates_length_of :name, arg => -1 } }
arg_bang { Meta.new(:name => 'some') { validates_length_of :name, arg => "blah" } }
arg_bang { Meta.new(:name => 'some') { validates_length_of :name, arg => -1 } }
end
end

Expand Down Expand Up @@ -564,8 +564,8 @@ def arg_bang
end

it "should respect :allow_nil" do
Meta.new { validates_length_of :bar, :is => 10, :allow_nil => false }.new.should_not be_valid
Meta.new { validates_length_of :bar, :is => 10, :allow_nil => true }.new.should be_valid
Meta.new(:name => 'some') { validates_length_of :bar, :is => 10, :allow_nil => false }.new.should_not be_valid
Meta.new(:name => 'some') { validates_length_of :bar, :is => 10, :allow_nil => true }.new.should be_valid
end

it "should respect :allow_blank" do
Expand Down Expand Up @@ -1027,7 +1027,7 @@ def arg_bang
end

it "should respect :allow_nil" do
Meta.new { validates_numericality_of :number, :allow_nil => true }.new.should be_valid
Meta.new(:name => 'some') { validates_numericality_of :number, :allow_nil => true }.new.should be_valid
end

describe "should allow for option combinations" do
Expand Down

0 comments on commit 599c3ba

Please sign in to comment.