-
-
Notifications
You must be signed in to change notification settings - Fork 365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model and Test values not the same #40
Comments
Can you post the factory and the section of the db/schema.rb that creates its table? |
Here is the factory: Here is the schema.rb: In the schema.rb it says decimal but I run a migration which changes the type to float: |
If you create the model without factory girl, what happens? define Object, "with spacing set" do
subject { Object.create!(:set_spacing => 4.5) }
its(:set_spacing) { should == 4.5 }
end |
When I create the object without the factory the set_spacing is 4.5: |
When i do the following test the set_spacing is 5.0 and not 4.5: it "should give set_spacing as 4.5" do
object = Object.create!(:set_spacing => 4.5, :name => "Test Object")
objects.set_spacing.should == 4.5
object_action = ObjectAction.create( :name_past => "replaced", :object_counter => "", :object_name => "Pipe Section")
job = Job.create(:object_id => object.id)
job.object_counter_string.should == "9.0m"
end It fails on the last line and give answer as "10.0m" meaning the set_spacing in the model side gets round to 5.0 |
Have you overwritten the setter for set_spacing, per chance? When FactoryGirl assigns attributes, all it does is loop through each one and essentially call |
Can it be that the following is overwriting the value as it comes into the model |
The output of FactoryGirl.attributes_for(:object) is: |
Wonderful! That means it's not an issue with FactoryGirl. I'd look through your model code and try to trace down where the value is changing. I'd look in any callbacks, setters, or anything else that'd modify set_spacing. If you call |
Thanks for the help |
No problem - let me know what you end up finding! |
I looked at the validations but nothing, next I went and looked at my callbacks nothing the only thing that I can think of is that my database which is Microsoft SQL Server 2008 is rounding the numbers. I could not find any place where I change the set_spacing |
Hey I have a really weird problem which does not make any sense to me.
My environment is Factory_Girl_Rails(1.2.0) on jruby 1.6.3, rails 3.0.10
What the issue is I create a dummy object with factory_girl and some how the objects attributes are different within the tests and in the model.
What I mean by it is in the test the value of an attribute is 4.5 and in the model the same attribute is 5.0 on the same object.
Can some help me to determine if its a active record problem or factory_girl or something else?
Thanks
The text was updated successfully, but these errors were encountered: