spec/mongoid_spec.rb in machinist_mongo-1.1.1 vs spec/mongoid_spec.rb in machinist_mongo-1.2.0

- old
+ new

@@ -7,22 +7,21 @@ include Mongoid::Document field :street field :zip field :country - belongs_to :person, :inverse_of => :address + embedded_in :person, :inverse_of => :address end class Person include Mongoid::Document - field :name - field :type + field :name, :accessible => false field :password field :admin, :type => Boolean, :default => false - has_one :address + embeds_one :address end class Post include Mongoid::Document @@ -57,30 +56,37 @@ Person.blueprint { } person = Person.make person.should_not be_new_record end - it "should create an object through belongs_to association" do + it "should create an object through embedded_in association" do Post.blueprint { } Comment.blueprint { post } Comment.make.post.class.should == Post end - it "should create an object through belongs_to association with a class_name attribute" do + it "should create an object through embedded_in association with a class_name attribute" do Person.blueprint { } Comment.blueprint { author } Comment.make.author.class.should == Person end - it "should create an object through belongs_to association using a named blueprint" do + it "should create an object through embedded_in association using a named blueprint" do Post.blueprint { } Post.blueprint(:dummy) do title { 'Dummy Post' } end Comment.blueprint { post(:dummy) } Comment.make.post.title.should == 'Dummy Post' end + + it "should be able to set attributes which are marked as inaccessible" do + Person.blueprint do + name { 'Foobar User' } + end + Person.make.name.should == 'Foobar User' + end end describe "plan method" do it "should not save the constructed object" do person_count = Person.count @@ -93,11 +99,11 @@ Post.blueprint { title "Test" } post = Post.plan post[:title].should == "Test" end - it "should create an object through a belongs_to association, and return its id" do + it "should create an object through a embedded_in association, and return its id" do Post.blueprint { } Comment.blueprint { post } post_count = Post.count comment = Comment.plan Post.count.should == post_count + 1 @@ -165,6 +171,6 @@ addr = Address.make addr.foo.should == "bar" end end -end \ No newline at end of file +end