NoBrainerORM / nobrainer

Ruby ORM for RethinkDB
http://nobrainer.io/
Other
387 stars 49 forks source link

before_save doesn't work? #191

Closed radicaled closed 8 years ago

radicaled commented 8 years ago
class Derp
  include NoBrainer::Document
  include NoBrainer::Document::Timestamps

  before_save :nuclear_strike_detected
end
> $ rails c                                                                                                                                                            ⬡ 3.1.0 [±feature/spam_detection ●●]
Running via Spring preloader in process 15737
Loading development environment (Rails 5.0.0.beta1)
2.3.0 :001 > d = Derp.new
 => #<Derp id: "30UbI4GLvdZHuj"> 
2.3.0 :002 > d.save
Connected to rethinkdb://localhost:28015/remy_development
[   4.2ms] r.table("derps").insert( {"id" => "30UbI4GLvdZHuj", "created_at" => r.expr(2016-02-13 03:27:59 +0000), "updated_at" => r.expr(2016-02-13 03:27:59 +0000)})
 => true 
2.3.0 :003 > 

Defining

def nuclear_strike_detected
   raise "Hide under a desk, because surely that will work."
end

is equally disappointing, in that nothing happens.

nviennot commented 8 years ago

Just tried. It works. Probably a problem with the Spring preloader.

radicaled commented 8 years ago

I just restarted Spring and I'm seeing the same thing.

I'm on Rails 5.0 beta2 (gem 'rails', '>= 5.0.0.beta2', '< 5.1') -- I didn't see any notes in the CHANGELOG about changes to before_save though.

This repo reproduces my error: https://github.com/radicaled/nobrainer_error

The first commit is bog-standard Rails 5.0 generation, the second commit -- https://github.com/radicaled/nobrainer_error/commit/4d03763f457c82939363d4f97fe94b55077d62d2 -- is the code I've added.

arron@XXXG-SHENLONG ~/Projects/nb-bug                                                                                                                                                            [18:45:07] 
> $ bin/spring stop                                                                                                                                                                       ⬡ 3.1.0 [±master]
Spring stopped.

arron@XXXG-SHENLONG ~/Projects/nb-bug                                                                                                                                                            [18:45:08] 
> $ rails c                                                                                                                                                                               ⬡ 3.1.0 [±master]
Running via Spring preloader in process 7827
Loading development environment (Rails 5.0.0.beta2)
2.3.0 :001 > Derp.new.save
[NoBrainer] ActiveRecord is loaded which is probably not what you want.
[NoBrainer] Follow the instructions on http://nobrainer.io/docs/configuration/#removing_activerecord
[NoBrainer] Configure NoBrainer with 'config.warn_on_active_record = false' to disable with warning.
Connected to rethinkdb://localhost:28015/nb_bug_development
[   7.7ms] r.table("derps").insert({"id" => "31B9aFk2PXVhMR"})
 => true 
2.3.0 :002 > 
nviennot commented 8 years ago

I can reproduce the problem.

Let me see...

nviennot commented 8 years ago

The issue was introduced with the new callback behavior: http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#halting-callback-chains-via-throw-abort

Fixed :)

radicaled commented 8 years ago

Verified working now, thanks!