Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruby2_0_0_compatibility.rb#required Breaks FactoryGirl on models that have a required attribute. #45

Open
mful opened this issue Aug 1, 2016 · 3 comments · Fixed by firehydrant/ruby-asana#1 · May be fixed by #168
Open

Comments

@mful
Copy link

mful commented Aug 1, 2016

Hi there,

Trying to integrate the asana API client into a project I am working on. Simply adding the gem to my Gemfile and bundling breaks my test suite, because I have factories that create models with a required attribute, and the the #required method in ruby-asana/lib/asana/ruby2_0_0_compatibility.rb interferes.

Stack Trace (note line 4):

$ rspec
/Users/me/.rvm/gems/ruby-2.3.1/gems/factory_girl-4.5.0/lib/factory_girl/definition_proxy.rb:42:in `add_attribute': wrong number of arguments (given 3, expected 1..2) (ArgumentError)
from /Users/me/.rvm/gems/ruby-2.3.1/gems/factory_girl-4.5.0/lib/factory_girl/definition_proxy.rb:102:in `method_missing'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/asana-0.5.0/lib/asana/ruby2_0_0_compatibility.rb:2:in `required'
from /Users/me/projects/project/spec/factories/content_block_factories.rb:5:in `block (2 levels) in <top (required)>'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:18:in `instance_eval'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:18:in `factory'
from /Users/me/projects/project/spec/factories/content_block_factories.rb:3:in `block in <top (required)>'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:49:in `instance_eval'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:49:in `run'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/factory_girl-4.5.0/lib/factory_girl/syntax/default.rb:7:in `define'
from /Users/me/projects/project/spec/factories/content_block_factories.rb:1:in `<top (required)>'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `block in load'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/factory_girl-4.5.0/lib/factory_girl/find_definitions.rb:20:in `block (2 levels) in find_definitions'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/factory_girl-4.5.0/lib/factory_girl/find_definitions.rb:19:in `each'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/factory_girl-4.5.0/lib/factory_girl/find_definitions.rb:19:in `block in find_definitions'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/factory_girl-4.5.0/lib/factory_girl/find_definitions.rb:15:in `each'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/factory_girl-4.5.0/lib/factory_girl/find_definitions.rb:15:in `find_definitions'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/factory_girl_rails-4.5.0/lib/factory_girl_rails/railtie.rb:21:in `block in <class:Railtie>'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/railties-4.2.6/lib/rails/application/finisher.rb:62:in `block in <module:Finisher>'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `run'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/railties-4.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/me/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
from /Users/me/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /Users/me/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /Users/me/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /Users/me/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each'
from /Users/me/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call'
from /Users/me/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
from /Users/me/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
from /Users/me/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/railties-4.2.6/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/railties-4.2.6/lib/rails/application.rb:352:in `initialize!'
from /Users/me/projects/project/config/environment.rb:5:in `<top (required)>'
from /Users/me/projects/project/spec/rails_helper.rb:3:in `require'
from /Users/me/projects/project/spec/rails_helper.rb:3:in `<top (required)>'
from /Users/me/projects/project/spec/controllers/api/comments_controller_spec.rb:1:in `require'
from /Users/me/projects/project/spec/controllers/api/comments_controller_spec.rb:1:in `<top (required)>'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in `load'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in `block in load_spec_files'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in `each'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in `load_spec_files'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:102:in `setup'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:88:in `run'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:73:in `run'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:41:in `invoke'
from /Users/me/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.3.2/exe/rspec:4:in `<top (required)>'
from /Users/me/.rvm/gems/ruby-2.3.1/bin/rspec:23:in `load'
from /Users/me/.rvm/gems/ruby-2.3.1/bin/rspec:23:in `<main>'
from /Users/me/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
from /Users/me/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'

To quickly reproduce, create a model with a boolean required attribute in a rails project that uses FactoryGirl, and create a simple Factory for it, then try to run rspec:


# spec/factories/my_model_factories.rb
FactoryGirl.define do

factory :my_model do
 required true
 end

end

Is there a way I can work around this?

Thanks!

┆Issue is synchronized with this Asana task

@mful
Copy link
Author

mful commented Aug 1, 2016

Found a workaround, though the underlying issue is still there. In my Factories, I replaced all instances of required true and required false with add_attribute :required, <value>.

So an updated factory definition looks as follows:

# spec/factories/my_model_factories.rb

FactoryGirl.define do

  factory :my_model do
    # was 'required true'
    add_attribute :required, true
  end

end

@agnoster
Copy link
Contributor

I'm not really up in the ruby code at the moment and haven't had a chance to look at this yet - do you have any suggestions/proposals to fix this? I'm sure we'll get to this eventually but obviously suggestions (or, heh, best case pull requests I suppose) would help accelerate that timeline ;-)

@czeise
Copy link

czeise commented Sep 8, 2023

I've got a PR that should fix this without modifying any generated code.

As noted in the PR, the scope of this bug isn't just compatibility with FactoryBot. The required method is introduced globally and will conflict with any codebase that has a method named required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants