isyairazu
(isyairazu)
1
Hello,
$ ruby script/generate model balance plus:integer minus:integer
equal:integer
$ cat app/models/balance.rb
class Balance < ActiveRecord::Base
def save
self.equal = self.plus - self.minus
super
end
end
$ cat test/fixtures/balances.yml
_10-1:
plus: 10
minus: 1
$ rake db:fixtures:load
$ sqlite3 db/development.sqlite3
select * from balances;
//=> |xxx|10|1||...
// equal is not 9
Even create_or_update() was the same.
Should I write it as
equal: 9
in the fixture-file?
It's not DRY.
Thanks.
$ sqlite3 db/development.sqlite3
> select * from balances;
//=> |xxx|10|1||...
// equal is not 9
Even create_or_update() was the same.
fixtures are directly inserted into the db
Should I write it as
equal: 9
in the fixture-file?
It's not DRY.
It isn't, but then again your data just isn't dry. You can use erb in
your fixtures ( <%= %>) if it's bothering you that much.
Fred
isyairazu
(isyairazu)
3
Fred, thank for the reply!
I was able to understand very well.
Thakyou very much!
11155
(-- --)
4
isyairazu wrote:
Fred, thank for the reply!
I was able to understand very well.
Thakyou very much!
You do understand fixtures are in most cases a bad idea to use.
isyairazu
(isyairazu)
6
Thankyou Fernando and Marnen!
I forget fixtures.
I will learn Machinist.
Thankyou very much!