Skip to content

Commit

Permalink
add tests for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-koba-mobidev committed Mar 28, 2018
1 parent 5009113 commit ce7a6b3
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
boxroom (0.0.4)
boxroom (0.0.5)
acts_as_tree (~> 2.7)
bulma-rails (~> 0.6.2)
cells-erb (~> 0.1.0)
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ ActionMailer::Base.default from: 'Boxroom <[email protected]>'
The engine is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).

## Roadmap:
- tests for notifications
- support s3
- batch actions
- tag files
Expand Down
3 changes: 3 additions & 0 deletions test/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
config.active_job.queue_adapter = :inline
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
ActionMailer::Base.default from: 'Boxroom <[email protected]>'
end
6 changes: 5 additions & 1 deletion test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180316203125) do
ActiveRecord::Schema.define(version: 20180323134701) do

create_table "boxroom_folders", force: :cascade do |t|
t.string "name"
t.integer "parent_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "notify_emails"
t.boolean "notify_create"
t.boolean "notify_update"
t.boolean "notify_remove"
t.index ["parent_id"], name: "index_boxroom_folders_on_parent_id"
end

Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ def clear_root_folder
def do_cleanup
DatabaseCleaner.clean
FileUtils.rm_rf(Dir["#{Rails.root}/#{Boxroom.configuration.uploads_path}"])
ActionMailer::Base.deliveries.clear
end
end
80 changes: 80 additions & 0 deletions test/unit/notification_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require 'test_helper'

class NotificationTest < ActiveSupport::TestCase
def setup
clear_root_folder
do_cleanup
end

test 'notify file was created in folder' do
folder = create(:folder, notify_emails: '[email protected]')
file = create(:user_file, folder: folder)

Boxroom::UserFile::NotifyCreate.(params: {id: file.id})
email = ActionMailer::Base.deliveries.last
assert_nil email

folder.update_attribute :notify_create, true

Boxroom::UserFile::NotifyCreate.(params: {id: file.id})

email = ActionMailer::Base.deliveries.last

assert email != nil
assert_equal ['[email protected]'], email.to
assert_equal I18n.t(:file_added), email.subject
assert_equal true, email.body.to_s.include?(file.attachment_file_name)
assert_equal true, email.body.to_s.include?(folder.name)
end

test 'notify file was updated in folder' do
folder = create(:folder, notify_emails: '[email protected]')
file = create(:user_file, folder: folder)

Boxroom::UserFile::NotifyUpdate.(params: {id: file.id})
email = ActionMailer::Base.deliveries.last
assert_nil email

folder.update_attribute :notify_update, true

Boxroom::UserFile::NotifyUpdate.(params: {id: file.id})

email = ActionMailer::Base.deliveries.last

assert email != nil
assert_equal ['[email protected]'], email.to
assert_equal I18n.t(:file_updated), email.subject
assert_equal true, email.body.to_s.include?(file.attachment_file_name)
assert_equal true, email.body.to_s.include?(folder.name)
end

test 'notify file was deleted in folder' do
folder = create(:folder, notify_emails: '[email protected]')
file = create(:user_file, folder: folder)

Boxroom::UserFile::NotifyRemove.(params: {id: file.id})
email = ActionMailer::Base.deliveries.last
assert_nil email

folder.update_attribute :notify_remove, true

Boxroom::UserFile::NotifyRemove.(params: {id: file.id})

email = ActionMailer::Base.deliveries.last

assert email != nil
assert_equal ['[email protected]'], email.to
assert_equal I18n.t(:file_removed), email.subject
assert_equal true, email.body.to_s.include?(file.attachment_file_name)
assert_equal true, email.body.to_s.include?(folder.name)
end

test 'notification sent to many recipients' do
folder = create(:folder, notify_emails: '[email protected], [email protected]', notify_create: true)
file = create(:user_file, folder: folder)

Boxroom::UserFile::NotifyCreate.(params: {id: file.id})

assert_equal 2, ActionMailer::Base.deliveries.size
end
end

0 comments on commit ce7a6b3

Please sign in to comment.