Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6088685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:00:48+00:00 2026-05-23T12:00:48+00:00

My model has a method that will update several attributes in a model from

  • 0

My model has a method that will update several attributes in a model from a remote resource. I want to test that with Rspec, but cannot find how to test whether a field was created or updated.

Some pseudocode to explain the question

def update_from_remote
  attributes = {}
  fields.each_key do |field_name|
    attributes[field_name] = scrape_from_remote field_name
  end
  update_attributes(attributes)
end

In reality this code is a lot more complex, but that will only clutter my question. A create_from_remote is rather similar, only that it does not call update_attributes but simply sets them and then saves the object.

I would like to test this. What I want, is a spec that tests whether the fields were updated or filled:

it 'should fill or set all local attributes on a new profile' do
  #how to test if a list of fields were updated in the Database?
end
it 'should update all local attributes on an existing profile' do
  #how to test if a list of fields were created in the Database?
end

I am using mongoId, but AFAIK that should not make much difference.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:00:48+00:00Added an answer on May 23, 2026 at 12:00 pm

    I should have dug deeper in the MongoID documentation. There is a chapter on Dirty tracking which can be used:

    it "should be updated"
      @something.field.should be_changed
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Invoice model has an address_id attribute, and I don't want this address_id to
The standard model has been that OpenGL is for professional apps (CAD) and Direct3D
I have a Person model that has a foreign key relationship to Book ,
Specifically, I have a model that has a field like this pub_date = models.DateField(date
My application has a plug-in model that allows third-party developers to write assemblies that
I have a class that has a Generic type G In my class model
I make a distributed embedded application that will make use of several micro-controllers. The
The GoDiagram object model has a GoDocument. GoViews have a reference to a GoDocument.
So I have a User model that :has_many other models like Documents, Videos, Posts
I have a problem. Imagine this data model: [Person] table has: PersonId, Name1 [Tag]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.