Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

Collisions when building Fabricator #124

Closed
ijcd opened this issue Aug 26, 2012 · 2 comments
Closed

Collisions when building Fabricator #124

ijcd opened this issue Aug 26, 2012 · 2 comments

Comments

@ijcd
Copy link

ijcd commented Aug 26, 2012

I'm trying to use Fabricator and have come across another collision (similar to the klass one in #92). Inspecting self.methods while in a Fabricator yields a whole slew of possible collisions (see below).

For me, I had a column called "display" and since there is a "display" method below, method_missing is never invoked. Perhaps the instance_eval needs to be done on a much more naked object?

https://github.com/masover/blankslate

% cat fabrication_collision_test.rb
require 'fabrication'
require 'faker'

class Store
attr_accessor :uuid, :display
end

Fabricator(:store) do
uuid { Faker::Lorem.characters(32) }
puts methods.inspect
display { "bar" }
end

% bundle exec ruby fabrication_collision_test.rb
[:klass, :klass=, :after_build, :after_create, :attribute, :append_or_update_attribute, :attributes=, :attributes, :callbacks=, :callbacks, :generator, :build, :fabricate, :to_attributes, :init_with, :merge, :method_missing, :on_init, :initialize_with, :parse_method_name, :transient, :sequence, :psych_to_yaml, :to_yaml_properties, :to_yaml, :nil?, :===, :=, :!, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :gem, :suppress_warnings, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :send, :id]

@ijcd
Copy link
Author

ijcd commented Aug 26, 2012

I think the strategy would be to instance_eval against a blank slate object, proxying your DSL methods, and leaving at least one method usable for escaping other reserved words:

Fabricator(:store) do
uuid "foo"
display "bar"
__attr :attributes "my attrs"
end

something like that...

@paulelliott
Copy link
Owner

Working on this. Stay tuned!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants