ruby-on-railsrspecmongoid

How do I get all attributes of a Model minus a few


So I'm writing a rspec test. It will test if a model is duplicated correctly. So the spec is something like this:

  it "should copy the data" do
    @model = build(:model)
    @another_model.copy_data(@model)
    @model.data.should == @another_model.data
  end

The data is a embedded document so it is duplicated when I do this. All the attributes on the model is copied over successfully minus the id and the created_at date. Is there a way I can do something like this?

    @model.data.attributes.without(:_id, :created_at).should == @another_model.data.attributes.without(:_id, :created_at)

Or the other way around where I select all the other fields without the id and created_at?

Thanks!


Solution

  • This works

    @model.attributes.except("id", "created_at").should == @another_model.attributes.except("id", "created_at")