docbrown/spec/models/notification_spec.rb
rhymes e588fa7ece Code cleanups (#659)
* Initial automatic cleanup with rubocop

* Fix syntax error introduced by rubocop

* Cleanup seeds file

* Cleanup lib folder

* Exclude bin folder because it contains auto generated files

* Make Rubocop a little bit more chatty

* Block length should not include comments in the count

* Cleanup config folder

* Cleanup specs

* Updated Rubocop version and generated a todo file

* Fix broken ArticlesApi spec

* Fix tests

* Restored rubocop pre-commit hook
2018-08-07 11:00:13 -04:00

35 lines
1.1 KiB
Ruby

require "rails_helper"
RSpec.describe Notification, type: :model do
let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:user3) { create(:user) }
let(:article) { create(:article, user_id: user.id) }
it "sends notifications to all followers of article user" do
user2.follow(user)
user3.follow(user)
Notification.send_all_without_delay(article, "Published")
expect(Notification.all.size).to eq(2)
end
# rubocop:disable RSpec/ExampleLength
it "sends sends a broadcast to everyone" do
user2.follow(user)
user3.follow(user)
broadcast = Broadcast.create!(
processed_html: "Hello", title: "test broadcast", type_of: "Announcement",
)
Notification.send_all_without_delay(broadcast, "Announcement")
expect(Notification.all.size).to eq(3)
end
# rubocop:enable RSpec/ExampleLength
it "removes all notifications" do
user2.follow(user)
user3.follow(user)
Notification.send_all_without_delay(article, "Published")
Notification.remove_all_without_delay(article, "Published")
expect(Notification.all.size).to eq(0)
end
end