Topic: Overriding mutator methods

Hi all,

I've come across a confusing situation in my Rails 2.3/Hobo 1.0 app.

I have the overridden the mutator methods for a belongs_to field:

  def country=(country)
    if( country.id.nil? )
      country_id = nil
    else
      country_id = country.id
    end

    self.currency = self.country.currency if( not self.country.nil? )
  end

  def country_id=(country_id)
    super(country_id)
    self.currency_id = self.country.currency_id if( not self.country.nil? )
  end

The confusion arises because this appears to work in the application (if I change the country on the company page, the currency is changed for the company as well). This does not work in unit testing, though, so I assume there must be something wrong with it.

Any ideas?

Thanks in advance.