require 'spec_helper' describe "Rad Mongoid basics" do with_mongoid after(:all){remove_constants :ToRsonTest} it "to_rson" do class ToRsonTest include Mongoid::Document field :name, type: String field :text, type: String validates_presence_of :name end ToRsonTest.delete_all ToRsonTest.create! name: 'a' ToRsonTest.create! name: 'b' # model.to_rson o = ToRsonTest.first r = o.to_rson r.delete 'id' r.should == {"name" => "a"} o.to_rson(only: :name).should == {"name" => "a"} # collections.to_rson r = ToRsonTest.all.to_rson r.collect!{|h| h.delete('id'); h} r.should == [{"name" => "a"}, {"name" => "b"}] ToRsonTest.all.to_rson(only: :name).should == [{"name" => "a"}, {"name" => "b"}] end end