before_save doesn't work? #191

Closed
radicaled opened this Issue Feb 13, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@radicaled
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

This comment has been minimized.

Show comment
Hide comment
@nviennot

nviennot Feb 15, 2016

Owner

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

Owner

nviennot commented Feb 15, 2016

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

@radicaled

This comment has been minimized.

Show comment
Hide comment
@radicaled

radicaled Feb 15, 2016

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 -- radicaled/nobrainer_error@4d03763 -- 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 > 

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 -- radicaled/nobrainer_error@4d03763 -- 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

This comment has been minimized.

Show comment
Hide comment
@nviennot

nviennot Feb 16, 2016

Owner

I can reproduce the problem.

Let me see...

Owner

nviennot commented Feb 16, 2016

I can reproduce the problem.

Let me see...

@nviennot nviennot closed this in f827778 Feb 16, 2016

@nviennot

This comment has been minimized.

Show comment
Hide comment
Owner

nviennot commented Feb 16, 2016

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 :)

nviennot added a commit that referenced this issue Feb 16, 2016

nviennot added a commit that referenced this issue Feb 16, 2016

nviennot added a commit that referenced this issue Feb 16, 2016

@radicaled

This comment has been minimized.

Show comment
Hide comment
@radicaled

radicaled Feb 16, 2016

Verified working now, thanks!

Verified working now, thanks!

nviennot added a commit that referenced this issue Feb 16, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment