Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rspec run_callbacks(:commit) for create action is not working ? #2395

Closed
cis-sourabh opened this issue Jul 5, 2014 · 8 comments
Closed

rspec run_callbacks(:commit) for create action is not working ? #2395

cis-sourabh opened this issue Jul 5, 2014 · 8 comments

Comments

@cis-sourabh
Copy link

I am writing a test case for after_commit callback:

after_commit :notify_user, :on => :create

When I am executing test case without putting condition :on => :create, it works. But when try to run with condition :on => :create then after_commit callback is not executing, it skipped.

Here below is the testcase which is not working

describe "after commit" do
 after do
   subject.run_callbacks(:commit)
 end
 it "should receive notify_user when created" do
   subject.should_receive(:notify_user)
 end
end
@JonRowe
Copy link
Member

JonRowe commented Jul 5, 2014

This looks like something you're running against Rails, if so this is the wrong repo to raise this issue against but it looks like you have transactional fixtures turned on (so you'd never receive an on commit as it's never committed).

Regardless you've not provided anything like enough information to reproduce this, vanilla RSpec (of which rspec-core is apart of) has no idea about callback execution.

@JonRowe JonRowe closed this as completed Jul 5, 2014
@nandini-klocrix
Copy link

I am writing a test case for after_commit callback:

after_commit :notify_user, :on => :create

When I am executing test case without putting condition :on => :create, it works. But when try to run with condition :on => :create then after_commit callback is not executing, it skipped.

Here below is the testcase which is not working

describe "after commit" do
 after do
   subject.run_callbacks(:commit)
 end
 it "should receive notify_user when created" do
   subject.should_receive(:notify_user)
 end
end

Hi @cis-sourabh how did you solve this? I am also facing the same issue.

@pirj
Copy link
Member

pirj commented Oct 8, 2020

Which version of Rails are you using?
Typically, you should use https://github.com/grosser/test_after_commit for Rails 4, and the same is baked in Rails 5+ rails/rails#18458

@pirj pirj transferred this issue from rspec/rspec-core Oct 8, 2020
@pirj
Copy link
Member

pirj commented Oct 8, 2020

And which version of RSpec?
I can't remember if we have should_receive, is this coming from Mocha?

@nandini-klocrix
Copy link

nandini-klocrix commented Oct 8, 2020 via email

@nandini-klocrix
Copy link

nandini-klocrix commented Oct 8, 2020 via email

@pirj
Copy link
Member

pirj commented Oct 8, 2020

I'd say give test_after_commit a shot.
Provide a snippet of the model/spec.
Anyway, this question is more suitable for StackOverflow, not our bug tracker.

@nandini-klocrix
Copy link

nandini-klocrix commented Oct 8, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants