[rspec-users] fixtures and associations
Daniel Lopes
danielvlopes at gmail.com
Thu Dec 18 10:24:22 EST 2008
I really don't know what's going on with those hell fixtures, and start
thinking I will never find... I will try migrate all my fixtures to
factory-girl, the only problem are my six hundred examples and no time to
change all. Somebody have any link about rspec + factory-girl ? or maybe
link to any project on github that use factory-girl and rspec ?
Thanks for all help.
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
On Thu, Dec 18, 2008 at 12:36 AM, Daniel Lopes <danielvlopes at gmail.com>wrote:
> I think I was misunderstood. I am not saying to use create rather than
> create! ... In this case, I just use it because will help me with puts for
> debug my own error in spec.
> In this case a really don't know what is going on, if I use create! I can't
> store the value in a var and then try to look what is the message of the
> failed attribute with puts.
> I using puts to print the error object to debug who is the wrong attribute.
> If I use create! I will have this message:
> Validation failed: Property is not valid => and cant use puts to know the
> content of @errors
>
> If I use create and print the result of fixture I will get:
>
> <ActiveRecord::Errors:0x23af4b0 @errors={"user"=>["não pode ser vazio"]},
> @base=#<Property id: 996332877, user_id: 317248456, ...
>
> And find the problem, it is just for debugging and help me to find where is
> the problem, after fix this I will change to create! again.
>
> --
>
> Anyone can figure why even property_id and owner_id are defined still raise
> "can't be blank" ?
>
> Thanks a lot for all help.
>
> 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
>
>
> On Thu, Dec 18, 2008 at 12:10 AM, aslak hellesoy <aslak.hellesoy at gmail.com
> > wrote:
>
>>
>>
>> On Thu, Dec 18, 2008 at 2:02 AM, Daniel Lopes <danielvlopes at gmail.com>wrote:
>>
>>> I know... I just don't use create!, in this special case, because it will
>>> be more complicate to know what field have the error .
>>>
>>
>> No it won't. The error message tells you what field has the error, and if
>> creation is unsuccessful you *need* to know about it. Otherwise you'll get
>> tons of false positives. I can't think of a single case where it makes sense
>> to use create inside a spec.
>>
>> Aslak
>>
>>
>>> I'm still scratching my head, my @tenant instance var on spec has values
>>> for user_id and owner_id and don't understand why my validates_associated
>>> :property raise an error.
>>>
>>> And if I mock model on model spec will not be a good thing.
>>>
>>> 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
>>>
>>>
>>> On Wed, Dec 17, 2008 at 10:45 PM, aslak hellesoy <
>>> aslak.hellesoy at gmail.com> wrote:
>>>
>>>>
>>>>
>>>> On Thu, Dec 18, 2008 at 1:38 AM, Daniel Lopes <danielvlopes at gmail.com>wrote:
>>>>
>>>>> Hello Pat, the error still the same. at errors={"user"=>["can't be
>>>>> blank"]}
>>>>>
>>>>> But if we look on @base we have user:
>>>>> @base=#<Property id: 996332877, user_id: 317248456, owner_id:
>>>>> 465176508, ... >
>>>>>
>>>>> And my code is:
>>>>> describe Tenant do
>>>>> fixtures :properties, :users ,:owners
>>>>>
>>>>> def create_tenant(options = {})
>>>>> record = Tenant.create({
>>>>>
>>>>
>>>> Just a small tip. Always, always use create! in specs. You want an error
>>>> to be raised in case creation is unsuccessful, and create doesn't do that -
>>>> it just returns false.
>>>>
>>>> Aslak
>>>>
>>>>
>>>>> :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
>>>>> properties(:two).valid?
>>>>> p properties(:two).errors
>>>>> # @tenant.errors.should be_empty
>>>>> end
>>>>>
>>>>> And my fixtures still the same... I don't know what's happening, when I
>>>>> try run on console or in browser everything ok... I think is something
>>>>> strange with fixtures.
>>>>>
>>>>> 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
>>>>>
>>>>>
>>>>> On Wed, Dec 17, 2008 at 10:14 PM, Pat Maddox <pergesu at gmail.com>wrote:
>>>>>
>>>>>> On Wed, Dec 17, 2008 at 2:13 PM, Daniel Lopes <danielvlopes at gmail.com>
>>>>>> wrote:
>>>>>> > Hello Pat, even I load all my fixtures it still not reading anything
>>>>>> from
>>>>>> > users.yml ...
>>>>>> > I will look at factory_girl but before I need understand what
>>>>>> happening.
>>>>>> > I try this:
>>>>>> > require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
>>>>>> > describe Tenant do
>>>>>> > fixtures :properties, :users , :owners
>>>>>> > 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
>>>>>> > p properties(:two).errors
>>>>>> > properties(:two).should be_valid
>>>>>> > # @tenant.errors.should be_empty
>>>>>> > end
>>>>>> > end
>>>>>>
>>>>>> What error are you getting now? Please post whatever error you're
>>>>>> experiencing...when we change this code, I expect a different error,
>>>>>> and would not know what it is. If it's the same, that's strange.
>>>>>>
>>>>>> Also, I noticed you have
>>>>>> p properties(:two).errors
>>>>>> properties(:two).should be_valid
>>>>>>
>>>>>> That's not going to show you anything, because errors don't get added
>>>>>> until you call #valid? So change that to
>>>>>>
>>>>>> properties(:two).valid?
>>>>>> p properties(:two).errors
>>>>>>
>>>>>> Pat
>>>>>> _______________________________________________
>>>>>> rspec-users mailing list
>>>>>> rspec-users at rubyforge.org
>>>>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> rspec-users mailing list
>>>>> rspec-users at rubyforge.org
>>>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> rspec-users mailing list
>>>> rspec-users at rubyforge.org
>>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>>>
>>>
>>>
>>> _______________________________________________
>>> rspec-users mailing list
>>> rspec-users at rubyforge.org
>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>>
>>
>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081218/8939a8c9/attachment-0001.html>
More information about the rspec-users
mailing list