[rspec-users] fixtures and associations

David Chelimsky dchelimsky at gmail.com
Wed Dec 17 14:18:03 EST 2008


On Wed, Dec 17, 2008 at 12:37 PM, Daniel Lopes <danielvlopes at gmail.com> wrote:
> Hello... I want ask for a help in error that don't understand.
> I have properties model and tenants model. Tenant belongs to Property and
> Property has many Tenants... I try this test association but allways get
> "not valid" error for association. Anyone can help? I post all my classes
> below:
> My Tenant class:
> class Tenant < ActiveRecord::Base
>   belongs_to :property
>
>   validates_associated  :property
>   validates_presence_of :property
>   ...
> My tenant_spec.rb
> describe Tenant do
>   fixtures :properties
>   def create_tenant(options = {})
>     record = Tenant.create({
>       :property => properties(:two),
>       :renters => "value for renters",
>       :guarantor => "value for guarantor",
>       :contact_name => "value for contact_name",
>       :contact_phone => "value for contact_phone",
>       :contact_email => "teste at hosttest.com",
>       :end_date => Date.today,
>       :beginning_date => Date.today,
>       :initial_value => "9.99"
>     }.merge(options))
>   end
>
>   before(:each) do
>     @tenant = create_tenant
>   end
>
>   it "should create a new instance given valid attributes" do
>     @tenant.errors.should be_blank
>   end
> ...
> My property_spec.rb
> class Property < ActiveRecord::Base
>   has_many :tenants
> ...
> My properties.yml:
> two:
>   user: aaron
>   owner: tania
>   address: Rua de teste
>   address_number: 250
>   neighborhood: Bairro ABC
>   country_state: MG
>   country: Brasil
>   city: Belo Horizonte
>   cep: 30566500
>   area: 150m
>   constructed_area: 120m
>   category: galpão
>   usage: comercial
>   owner_code: AS341ADV
>   garage: 2
>   description: Casa com 3 quartos
>   observation:
>   condominium_value: 0
>   iptu_value: 90.50

Hi Daniel,

Are both tenant_spec and property_spec failing? What are the failure
messages you're getting?

>
> Atenciosamente,
>
> Daniel Lopes    Area Criações
> Design, Websites e Sistemas Web
>
> Visite:  http://www.areacriacoes.com.br/projects
>           http://blog.areacriacoes.com.br/
>
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
> *
> 55 (31) 3077-4560  /  55 (31) 8808-8748  /  55 (31) 8737-7501


More information about the rspec-users mailing list