Commit 0945abece66b5e705db503ac3f2a1d693c9f0b9f
1 parent
4c95405b
Exists in
master
and in
27 other branches
rails3: define slug based on given name on factories
Showing
1 changed file
with
4 additions
and
0 deletions
Show diff stats
test/factories.rb
1 | 1 | module Noosfero::Factory |
2 | 2 | |
3 | 3 | def fast_create(name, attrs = {}, options = {}) |
4 | + defaults = defaults_for(name) | |
5 | + attrs[:slug] = attrs[:name].to_slug if attrs[:name].present? && attrs[:slug].blank? && defaults[:slug].present? | |
4 | 6 | data = defaults_for(name.to_s.gsub('::','')).merge(attrs) |
5 | 7 | klass = name.to_s.camelize.constantize |
6 | 8 | if klass.superclass != ActiveRecord::Base |
... | ... | @@ -36,6 +38,8 @@ module Noosfero::Factory |
36 | 38 | end |
37 | 39 | |
38 | 40 | def build(name, attrs = {}) |
41 | + defaults = defaults_for(name) | |
42 | + attrs[:slug] = attrs[:name].to_slug if attrs[:name].present? && attrs[:slug].blank? && defaults[:slug].present? | |
39 | 43 | data = defaults_for(name).merge(attrs) |
40 | 44 | object = name.to_s.camelize.constantize.new |
41 | 45 | data.each { |attribute, value| object.send(attribute.to_s+'=', value) } | ... | ... |