paulelliott / fabrication

This project has moved to GitLab! Please check there for the latest updates.
https://gitlab.com/fabrication-gem/fabrication
MIT License
998 stars 97 forks source link

Rake #289

Closed jonallured closed 7 years ago

jonallured commented 7 years ago

With fd0424bf472823d9b71371a867385be48e8917c5, the Rake DSL is now included when the fabrication gem is required. I tried to follow that commit message, but wasn't able to figure out what the reason for that change was. If you could help enlighten me, I would really appreciate it!

In any event, we're having an issue where we have a model that has an attribute named link - the exception is:

ActiveAttr::DangerousAttributeError: an attribute method named "link" would conflict with an existing method

Which is super weird! With some help from my friends (@ashkan18 and @yuki24), we figured out that fabrication 2.14.0 was the version that broke things for us.

Check this out:

$ gem install rake fabrication
Successfully installed rake-12.0.0
Successfully installed fabrication-2.16.0
2 gems installed
$ irb
2.3.1 :001 > require 'rake'
 => true
2.3.1 :002 > Object.new.method(:link).source_location
NameError: undefined method `link' for class `Object'
    from (irb):2:in `method'
    from (irb):2
    from /Users/jon/.rvm/rubies/ruby-2.3.1/bin/irb:11:in `<main>'
2.3.1 :003 > require 'fabrication'
 => true
2.3.1 :004 > Object.new.method(:link).source_location
 => ["/Users/jon/.rvm/gems/ruby-2.3.1/gems/rake-12.0.0/lib/rake/file_utils_ext.rb", 33]

I think that's pretty unexpected, no? I don't know what the way forward is here, but I wanted to raise the issue and see if anyone had any good ideas about what to do.

yuki24 commented 7 years ago

Fabrication's task definition is perfectly compatible with both rake 0.9.* and 10.*. What was really deprecated was something like below, and I believe we can safely remove the include call.

#!/usr/bin/env rake

module Namespace
  desc 'description'
  task :run do
    sh 'say "Running this task shows deprecation warnings"'
  end
end

And if you run the rake task, it shows the following:

$ rake run
WARNING: Global access to Rake DSL methods is deprecated.  Please include
    ...  Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method Module#desc called at /Users/yuki/GitHub/tmp/rake-922/Rakefile:4:in `<module:Namespace>'
WARNING: DSL method Module#task called at /Users/yuki/GitHub/tmp/rake-922/Rakefile:5:in `<module:Namespace>'
WARNING: DSL method Module#sh called at /Users/yuki/GitHub/tmp/rake-922/Rakefile:6:in `block in <module:Namespace>'
say "Running this task shows deprecation warnings"

Make sure to use rake 0.9.2.2 otherwise it raises an NoMethodError