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

Fabricator of a model that has a column named `klass' #92

Closed
irohiroki opened this issue Mar 7, 2012 · 4 comments
Closed

Fabricator of a model that has a column named `klass' #92

irohiroki opened this issue Mar 7, 2012 · 4 comments

Comments

@irohiroki
Copy link

the snippet below spills an ArgumentError (wrong number of arguments (1 for 0)).

require 'fabrication'

class Foo
  attr_accessor :klass
end

Fabricator(:foo) do
  klass 'value'
end

is there any means to avoid that?

@irohiroki
Copy link
Author

ah,

Fabricator(:foo) do
  after_build {|foo| foo.klass = 'value' }
end

works around the issue.
any brighter idea?

@mattreduce
Copy link
Contributor

In the context of the Fabricator block, Ruby thinks you're referring to the klass attribute on Fabrication::Schematic, which is the constant Foo. The after_build works because you're able to specify the Foo class as your target.

I can't think of a better solution than yours, or to treat klass as a reserved word and not use it in this case. Perhaps @paulelliott will have better suggestions. :)

@paulelliott
Copy link
Owner

This is definitely a bug in fabrication. In the mean time, you can either use Matt's workaround with the after_build callback or name your attribute something else.

-- Paul

On Wednesday, March 7, 2012 at 12:09 PM, Matthew Conway wrote:

In the context of the Fabricator block, Ruby thinks you're referring to the klass attribute on Fabrication::Schematic, which is the constant Foo. The after_build works because you're able to specify the Foo class as your target.

I can't think of a better solution than yours, or to treat klass as a reserved word and not use it in this case. Perhaps @paulelliott will have better suggestions. :)


Reply to this email directly or view it on GitHub:
#92 (comment)

@ijcd
Copy link

ijcd commented Aug 26, 2012

It seems there are a lot of methods that can collide when in the context of a Fabricator:

(rdb:1) self.methods.sort
[:!, :!=, :!, :<=>, :==, :===, :=, :id, :send, :`, :acts_like?, :after_build, :after_create, :append_or_update_attribute, :as_json, :attribute, :attributes, :attributes=, :binding_n, :blank?, :breakpoint, :build, :callbacks, :callbacks=, :capture, :class, :class_eval, :clone, :dbg_print, :dbg_puts, :debugger, :define_singleton_method, :display, :dup, :duplicable?, :enable_warnings, :enum_for, :eql?, :equal?, :extend, :fabricate, :freeze, :frozen?, :gem, :generator, :hash, :html_safe?, :in?, :init_with, :initialize_clone, :initialize_dup, :initialize_with, :inspect, :instance_eval, :instance_exec, :instance_of?, :instance_values, :instance_variable_defined?, :instance_variable_get, :instance_variable_names, :instance_variable_set, :instance_variables, :is_a?, :is_haml?, :kind_of?, :klass, :klass=, :load, :load_dependency, :merge, :meta_class, :method, :method_missing, :methods, :nil?, :object_id, :on_init, :parse_method_name, :presence, :present?, :pretty_inspect, :pretty_print, :pretty_print_cycle, :pretty_print_inspect, :pretty_print_instance_variables, :private_methods, :protected_methods, :psych_to_yaml, :psych_y, :public_method, :public_methods, :public_send, :quietly, :require, :require_association, :require_dependency, :require_or_load, :respond_to?, :respond_to_missing?, :send, :sequence, :share_as, :share_examples_for, :shared_context, :shared_examples, :shared_examples_for, :should, :should_not, :silence, :silence_stderr, :silence_stream, :silence_warnings, :singleton_class, :singleton_methods, :suppress, :suppress_warnings, :taint, :tainted?, :tap, :to_attributes, :to_enum, :to_json, :to_param, :to_query, :to_s, :to_yaml, :to_yaml_properties, :transient, :trust, :try, :unloadable, :untaint, :untrust, :untrusted?, :with_options, :with_warnings]

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

4 participants