GithubHelp home page GithubHelp logo

Comments (2)

palkan avatar palkan commented on August 20, 2024

Hey @kleber-gueriero!

Could you please provide a code example and a test example for this exception?'

P.S. Sorry for such a late response.

from abstract_notifier.

SuzukiRyuichiro avatar SuzukiRyuichiro commented on August 20, 2024

Edit

nvm, I didn't realize that you can add .twice 🙏

What I originally wrote I can see a similar issue with `have_sent_notification` matcher as well.

I have two callbacks where each of them create notifications.

Basically, when I have a test like

the test

RSpec.describe Post, type: :model do
  describe 'notifications' do
      context 'when new post is published' do
        it { expect { create(:post) }.to have_sent_notification }
      end
  end
end

example model

class Post < ActiveRecord

  after_create :notify_can_see_posts
  after_create :notify_new_post

  def notify_can_see_posts
    FromAdminNotifier.send_can_see_posts.notify_now 
  end

  def notify_new_post
    NewPostNotifier.created(self).notify_now
  end
end

example notifiers

# frozen_string_literal: true

class NewPostNotifier < ApplicationNotifier
  def created(post)
    notification(
      title: 'New post!',
      body: "#{post.title}",
    )
  end
end

class FromAdminNotifier < ApplicationNotifier
  def send_can_see_posts()
    notification(
      title: 'Thanks for your post!',
      body: 'Thank you for your submission. Now you can see what others have posted on the platform!',
    )
  end
end

So creating a post sends two notifications. One to the user who have submitted to tell them that they can now see others post (we have some exclusive thread page like that), and another to rest of the users who have already submitted a post to tell them that there's a new post in the app.

When one action sends two or more notifications, the matcher fails.

from abstract_notifier.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.