Michael Guterl
2011-Jan-14 16:15 UTC
[rspec-users] Rails 3 / RSpec 2 use_transactional_fixtures and after_commit
We''re migrating a Rails 2.3.x application to Rails 3 and RSpec 2.x. In Rails 2.3.x we were using https://github.com/freelancing-god/after_commit to provide after_commit functionality (now provided by Rails 3). The plugin version of after_commit came with some helpers to make testing with `use_transactional_fixtures = true` work. From: https://github.com/freelancing-god/after_commit "Keep in mind that transactions are finicky at best in tests, and so there?s a helper module to make after_commit play nicely in your testing context. You?ll need to add these two lines to your spec/test helper:" ActiveRecord::Base.send(:include, AfterCommit::AfterSavepoint) ActiveRecord::Base.include_after_savepoint_extensions Anyone else ran into this? Best, Michael Guterl
Kurt
2011-Feb-09 01:32 UTC
[rspec-users] Rails 3 / RSpec 2 use_transactional_fixtures and after_commit
We''re just running into it now, but we''re using after_commit in Rails 3 for the first time. The callback appears not to fire in our specs -- I noticed your posting but have not had luck getting the gem to load. Bundler 1.0.7 requires the gem, and it generates this: /Users/kurtsnyder/.rvm/gems/ree-1.8.7-2010.02 at rails3/gems/after_commit-1.0.7/lib/after_commit/active_record.rb:15:in `include_after_commit_extensions'': undefined method `subclasses_of'' for Object:Class (NoMethodError) from /Users/kurtsnyder/.rvm/gems/ree-1.8.7-2010.02 at rails3/gems/after_commit-1.0.7/lib/after_commit.rb:81 Did you add these two lines to your spec_helper.rb file or somewhere else? ActiveRecord::Base.send(:include, AfterCommit::AfterSavepoint) ActiveRecord::Base.include_after_savepoint_extensions I''d be interested in helping to get this to work, but not sure where to start as we''re new to after_commit. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110208/c8a7a859/attachment.html>
Michael Guterl
2011-Feb-09 13:46 UTC
[rspec-users] Rails 3 / RSpec 2 use_transactional_fixtures and after_commit
Hi Kurt, On Tue, Feb 8, 2011 at 8:32 PM, Kurt <ks at cissor.com> wrote:> We''re just running into it now, but we''re using after_commit in Rails 3 for > the first time.? The callback appears not to fire in our specs -- I noticed > your posting but have not had luck getting the gem to load.? Bundler 1.0.7 > requires the gem, and it generates this: > > /Users/kurtsnyder/.rvm/gems/ree-1.8.7-2010.02 at rails3/gems/after_commit-1.0.7/lib/after_commit/active_record.rb:15:in > `include_after_commit_extensions'': undefined method `subclasses_of'' for > Object:Class (NoMethodError) > ??? from > /Users/kurtsnyder/.rvm/gems/ree-1.8.7-2010.02 at rails3/gems/after_commit-1.0.7/lib/after_commit.rb:81 > > Did you add these two lines to your spec_helper.rb file or somewhere else? > > ActiveRecord::Base.send(:include, AfterCommit::AfterSavepoint) > ActiveRecord::Base.include_after_savepoint_extensions > > I''d be interested in helping to get this to work, but not sure where to > start as we''re new to after_commit. >after_commit is built-in to Rails 3, so you don''t need the gem. Rails 3 does not include any type of AfterSavepoint helper for running with transactional fixtures turned on. That is the piece that needs to be ported over to Rails 3. Best, Michael Guterl
Kurt
2011-Feb-09 18:10 UTC
[rspec-users] Rails 3 / RSpec 2 use_transactional_fixtures and after_commit
Thanks -- that confirms the results of our experiments. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110209/f9467a9f/attachment.html>
Mat B.
2011-Apr-20 15:30 UTC
[rspec-users] Rails 3 / RSpec 2 use_transactional_fixtures and after_commit
Michael Guterl wrote in post #980563:> Hi Kurt, > > On Tue, Feb 8, 2011 at 8:32 PM, Kurt <ks at cissor.com> wrote: >> >> Did you add these two lines to your spec_helper.rb file or somewhere else? >> >> ActiveRecord::Base.send(:include, AfterCommit::AfterSavepoint) >> ActiveRecord::Base.include_after_savepoint_extensions >> >> I''d be interested in helping to get this to work, but not sure where to >> start as we''re new to after_commit. >> > > after_commit is built-in to Rails 3, so you don''t need the gem. Rails > 3 does not include any type of AfterSavepoint helper for running with > transactional fixtures turned on. That is the piece that needs to be > ported over to Rails 3. > > Best, > Michael GuterlHi guys, Just wanted to let you know that I had the same problem and ended up writing a monkey-patch for it: http://outofti.me/post/4777884779/test-after-commit-hooks-with-transactional-fixtures Pretty straightforward, fairly clean as monkey patches go, if I may. Mat -- Posted via http://www.ruby-forum.com/.
Possibly Parallel Threads
- Rails 3 Observer: No support for after_commit?
- Testable after_commit hooks for rails 4?
- db:migrate fails after upgrade to Rails 2.3.5
- Suggestion: `before_save on: :create` should either work or raise an exception
- callback executed like after_save but after transaction