Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 464
Dragonfly Avatar asked Oct 02 '13 18:10

Dragonfly


1 Answers

This works

@model.attributes.except("id", "created_at").should == @another_model.attributes.except("id", "created_at")
like image 93
Abhinaya Avatar answered Sep 30 '22 02:09

Abhinaya