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

Demonstrate how to stub current_user in controller spec #103

Open
eliotsykes opened this issue Dec 10, 2015 · 0 comments
Open

Demonstrate how to stub current_user in controller spec #103

eliotsykes opened this issue Dec 10, 2015 · 0 comments

Comments

@eliotsykes
Copy link
Owner

E.g.

    it "..." do
      user = create(:user)
      foo = instance_double(Foo)
      foo_id = "123"

      allow(controller).to receive(:current_user).and_return(user)
      expect(user.foos).to receive(:find).with(foo_id).and_return(foo)
      expect(foo).to receive(:destroy).and_return(false)

      sign_in(user)

      delete :destroy, id: foo_id

      expect(flash[:error]).to eq("There was an error.")
    end
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

1 participant