rethinkdb / rethinkdb

The open-source database for the realtime web.
https://rethinkdb.com
Other
26.8k stars 1.86k forks source link

RethinkDB and crypt ruby #2277

Closed alec-c4 closed 10 years ago

alec-c4 commented 10 years ago

Hi, i'm expecting some troubles with using subj. My example%

class User
  include NoBrainer::Document
  include ActiveModel::SecurePassword

  field :email
  field :password_digest

  has_secure_password
  validates_presence_of :password, :on => :create
end

on attempt to create user with

user = User.new(email: 'somebody@alec-c4.com', password: '123456', password_confirmation: '123456')

generates exception

> user.save
RethinkDB::RqlDriverError: r.expr can't handle "$2a$10$9IfobijTpfLaD.f2juPrAOmBKu8G.usPtM35kl79.ZpXc0brOIaFi" of type BCrypt::Password

How can i fix it?

coffeemug commented 10 years ago

It sounds like you're passing BCrypt::Password type to RethinkDB, but the driver isn't equipped to deal with that type. You'd have to convert it into a string for that to work.

I'm not sure how to do that with NoBrainer -- pinging @nviennot (you might want to ask on https://github.com/nviennot/nobrainer)

nviennot commented 10 years ago

It's definitely a bug in the rethinkdb driver. BCrypt::Password is a subclass of String, so it should be okay.

The recent changes in the Ruby driver made a bunch of test fails in NoBrainer. Including this one which seems to be a legit driver bug:

screenshot76

(This is after fixing NoBrainer due to changes in the internal representation of RQL queries -- not a welcoming change)

coffeemug commented 10 years ago

Got it, thanks @nviennot. Sorry we're shifting things under your feet (Rethink had a bit of a popularity spike in the past month or so, so we're still adjusting to the fact that people often care about the internals while they didn't before).

Pinging @mlucy -- Michael, could you take a look at what's going on?

nviennot commented 10 years ago

FYI, the driver in next does not have this issue, the original bug has been fixed: subclasses of String are good to go.

mlucy commented 10 years ago

I'll patch the Ruby driver in 1.12.x to work with all subclasses of String . (It's worth noting, though, that when the string is retrieved from the server it won't be of the same class as when it was inserted.)

@nviennot -- I'm having trouble parsing that error from the nobrainer tests. Is there a specific query you could paste which returns something you don't expect?

mlucy commented 10 years ago

This is fixed in the 1.13 Ruby driver.

irb(main):092:0> class A < String; end; r(A.new("abc")).run
"abc"                                                      
coffeemug commented 10 years ago

Should @AtnNn publish a new version?

mlucy commented 10 years ago

No, the version we released with 1.13 fixed this issue as a side-effect of some other changes, and I just forgot to mark it closed.