A Rails 4.2 app has a table with about a dozen fields. Two have similar
names:
create_table :transactions do |t|
...
t.decimal :shares, precision: 12, scale: 5
...
t.decimal :shares_change, precision: 12, scale: 5
...
end
In tests the code assigns a scalar such as 12.4 or BigDecimal("12.4") to
shares_change, but a puts statement shows that it has been set to an array
(first element nil, second element a BigDecimal). Later puts statements
just show it as nil.
Here's a snippet:
self.shares_change = -self.shares
puts ">>>>> 2 /compute_shares_change/ self.shares=#{self.shares}
self.shares_change=#{self.shares_change}"
and the output:
* >>>>> 2 /compute_shares_change/ self.shares=31.0
self.shares_change=[nil, #<BigDecimal:7f7fe3ba9158,'0.31E2',9(36)>]*
But if I change the name of the first field to 'sharez' or move the
declaration of the 'shares' field to right after the 'shares_change' field
in the migration, the problem goes away:
* >>>>> 2 /compute_shares_change/ self.shares=31.0
self.shares_change=-31.0*
This happens with SQLite and with MySQL (version 5.1.58). It happens
whether I use a factory (I'm using Fabrication in Minitest) to create the
Transaction object or not. In all cases the declaration changes fix the
problem.
ActiveRecord bug? Just wondered if anyone else has encountered this.
Thanks,
Scott
--
--
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
---
You received this message because you are subscribed to the Google Groups "SD
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.