Member.blueprint do
account
friends { members }
first_name { Forgery(:name).first_name }
last_name { Forgery(:name).last_name }
country { Forgery(:address).country }
city { Forgery(:address).city }
single { false }
photo_file_name { 'fixtures/photo.jpg' }
photo_content_type { 'image/jpeg' }
photo_file_size { 65536 }
photo_updated_at { Time.now - Forgery(:basic).number }
end
But now in 1.0.6 I get ;
RuntimeError: No sham defined for members
from /Library/Ruby/Gems/1.8/gems/machinist-1.0.6/lib/sham.rb:16:in
`method_missing'
from /Library/Ruby/Gems/1.8/gems/machinist-1.0.6/lib/machinist.rb:
83:in `send'
from /Library/Ruby/Gems/1.8/gems/machinist-1.0.6/lib/machinist.rb:
83:in `generate_attribute_value'
from /Library/Ruby/Gems/1.8/gems/machinist-1.0.6/lib/machinist.rb:
46:in `method_missing'
from ./test/blueprints.rb:39
from /Library/Ruby/Gems/1.8/gems/machinist-1.0.6/lib/machinist.rb:
77:in `generate_attribute_value'
from /Library/Ruby/Gems/1.8/gems/machinist-1.0.6/lib/machinist.rb:
46:in `method_missing'
from ./test/blueprints.rb:39
from /Library/Ruby/Gems/1.8/gems/machinist-1.0.6/lib/machinist.rb:
20:in `instance_eval'
from /Library/Ruby/Gems/1.8/gems/machinist-1.0.6/lib/machinist.rb:
20:in `run'
from /Library/Ruby/Gems/1.8/gems/machinist-1.0.6/lib/machinist/
active_record.rb:53:in `make'
Any ideas?
On Jan 31, 12:15 am, J2M <james2mccar...@gmail.com> wrote:
> in 1.0.3 this was working;
>
> Member.blueprint do
> account
> friends { members }
> first_name { Forgery(:name).first_name }
> last_name { Forgery(:name).last_name }
> country { Forgery(:address).country }
> city { Forgery(:address).city }
> single { false }
> photo_file_name { 'fixtures/photo.jpg' }
> photo_content_type { 'image/jpeg' }
> photo_file_size { 65536 }
> photo_updated_at { Time.now - Forgery(:basic).number }
> end
Where's "members" supposed to be coming from?
- Pete
has_many :friendships
has_many :friends, :through => :friendship
So members is referring to the Member blueprint. This was working in
1.0.3 but I was surprised it did, but has stopped in 1.0.6.
Thanks,
James
> --
> You received this message because you are subscribed to the Google Groups "Machinist Users" group.
> To post to this group, send email to machini...@googlegroups.com.
> To unsubscribe from this group, send email to machinist-use...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/machinist-users?hl=en.
>
>
--
James
I'm pretty stunned that it ever worked at all! There's no code in
Machinist to singularise "members", work out that it corresponds to
the Member class, and generate an Array of them (which is what you'd
need to populate that association.)
I strongly discourage the creation of objects through has_many or
has_and_belongs_to_many associations in blueprints. There are all
sorts of traps waiting there, thanks to ActiveRecord and implicit
saves it can do, so you can end up with objects where half the
attributes don't get saved and the like.
In general, if you have a complex object graph to construct, keep your
blueprints as simple as you can and write a helper to build the graph.
- Pete