jruby / jruby

JRuby, an implementation of Ruby on the JVM
https://www.jruby.org
Other
3.79k stars 922 forks source link

9000 gives private_attribute? warning #2886

Open lephyrius opened 9 years ago

lephyrius commented 9 years ago

I get this warning: /.rbenv/versions/jruby-9.0.0.0-dev/lib/ruby/gems/shared/gems/sorcery-0.9.1/lib/sorcery/model.rb:71: warning: private attribute?

But I don't get it in ruby 2.2.2. Here is the 9000 version I used: jruby 9.0.0.0-SNAPSHOT (2.2.2) 2015-04-28 a5c372d Java HotSpot(TM) 64-Bit Server VM 25.0-b70 on 1.8.0-b132 +jit [darwin-x86_64]

Should I report it to sorcery? The problem here is that I think it's related to an error I get from sorcery: NoMethodError: undefined method `password=' for #User:0x31dbe419 It's when I try to create a user:

class User < ActiveRecord::Base
  authenticates_with_sorcery!
end
User.create username: 'test', password: 'secret'
lephyrius commented 9 years ago

I dunno if I should create a new issue or not. But I tried with this version: jruby 9.0.0.0-SNAPSHOT (2.2.2) 2015-05-23 57edf61 Java HotSpot(TM) 64-Bit Server VM 25.0-b70 on 1.8.0-b132 +jit [darwin-x86_64] I created a shorter much more isolated testcase here:

module AttrModel
  def add_methods m
    attr_accessor m
  end
end

require 'active_record'
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
  require 'activerecord-jdbcsqlite3-adapter'
else
  require 'sqlite3'
end

ActiveRecord::Base.establish_connection(
  adapter: 'sqlite3',
  database: ':memory:'
)

ActiveRecord::Schema.define do
  create_table :users, force: true do |t|
    t.string :username
  end
end

ActiveRecord::Base.extend AttrModel

class User < ActiveRecord::Base
  add_methods :password
  validates :password, confirmation: true
end

attr_test = User.create password: 'Banana!', password_confirmation: 'Banana!'

puts attr_test.password

On ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14] :

-- create_table(:users, {:force=>true})
   -> 0.0056s
Banana!

On jruby 9.0.0.0-SNAPSHOT (2.2.2) 2015-05-23 57edf61 Java HotSpot(TM) 64-Bit Server VM 25.0-b70 on 1.8.0-b132 +jit [darwin-x86_64] :

ActiveRecord::UnknownAttributeError: unknown attribute: password_confirmation
           _assign_attribute at /.rbenv/versions/jruby-9.0.0.0-dev/lib/ruby/gems/shared/gems/activerecord-4.1.10/lib/active_record/attribute_assignment.rb:50
  block in assign_attributes at /.rbenv/versions/jruby-9.0.0.0-dev/lib/ruby/gems/shared/gems/activerecord-4.1.10/lib/active_record/attribute_assignment.rb:32
                        each at org/jruby/RubyHash.java:1356
           assign_attributes at /.rbenv/versions/jruby-9.0.0.0-dev/lib/ruby/gems/shared/gems/activerecord-4.1.10/lib/active_record/attribute_assignment.rb:26
             init_attributes at /.rbenv/versions/jruby-9.0.0.0-dev/lib/ruby/gems/shared/gems/activerecord-4.1.10/lib/active_record/core.rb:452
                  initialize at /.rbenv/versions/jruby-9.0.0.0-dev/lib/ruby/gems/shared/gems/activerecord-4.1.10/lib/active_record/core.rb:195
                         new at /.rbenv/versions/jruby-9.0.0.0-dev/lib/ruby/gems/shared/gems/activerecord-4.1.10/lib/active_record/inheritance.rb:30
                      create at /.rbenv/versions/jruby-9.0.0.0-dev/lib/ruby/gems/shared/gems/activerecord-4.1.10/lib/active_record/persistence.rb:33
                       <top> at attr_test.rb:32