-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
343 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Notification model for customisation & custom methods | ||
class Notification < ActivityNotification::Notification | ||
class <%= @model_name %> < ActivityNotification::Notification | ||
|
||
# Write custom methods or override methods here | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'generators/activity_notification/active_record/migration_generator' | ||
|
||
describe ActivityNotification::Generators::MigrationGenerator, type: :generator do | ||
|
||
# setup_default_destination | ||
destination File.expand_path("../../../../tmp", __FILE__) | ||
before { prepare_destination } | ||
|
||
it 'runs generating migration tasks' do | ||
gen = generator | ||
expect(gen).to receive :create_migrations | ||
gen.invoke_all | ||
end | ||
|
||
describe 'the generated files' do | ||
context 'without name argument' do | ||
before do | ||
run_generator | ||
end | ||
|
||
describe 'CreateNotifications migration file' do | ||
subject { file(Dir["tmp/db/migrate/*_create_notifications.rb"].first.gsub!('tmp/', '')) } | ||
it { is_expected.to exist } | ||
it { is_expected.to contain(/class CreateNotifications < ActiveRecord::Migration/) } | ||
end | ||
end | ||
|
||
context 'with CreateCustomNotifications as name argument' do | ||
before do | ||
run_generator %w(CreateCustomNotifications) | ||
end | ||
|
||
describe 'CreateCustomNotifications migration file' do | ||
subject { file(Dir["tmp/db/migrate/*_create_custom_notifications.rb"].first.gsub!('tmp/', '')) } | ||
it { is_expected.to exist } | ||
it { is_expected.to contain(/class CreateCustomNotifications < ActiveRecord::Migration/) } | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require 'generators/activity_notification/controllers_generator' | ||
|
||
describe ActivityNotification::Generators::ControllersGenerator, type: :generator do | ||
|
||
# setup_default_destination | ||
destination File.expand_path("../../../tmp", __FILE__) | ||
before { prepare_destination } | ||
|
||
it 'runs generating controllers tasks' do | ||
gen = generator %w(users) | ||
expect(gen).to receive :create_controllers | ||
expect(gen).to receive(:readme).and_return(true) | ||
gen.invoke_all | ||
end | ||
|
||
describe 'the generated files' do | ||
context 'without target argument' do | ||
it 'raise Thor::RequiredArgumentMissingError' do | ||
expect { run_generator } | ||
.to raise_error(Thor::RequiredArgumentMissingError) | ||
end | ||
end | ||
|
||
context 'with users as target' do | ||
context 'with target controllers as default' do | ||
before do | ||
run_generator %w(users) | ||
end | ||
|
||
describe 'the notifications_controller' do | ||
subject { file('app/controllers/users/notifications_controller.rb') } | ||
it { is_expected.to exist } | ||
it { is_expected.to contain(/class Users::NotificationsController < ActivityNotification::NotificationsController/) } | ||
end | ||
|
||
describe 'the notifications_with_devise_controller' do | ||
subject { file('app/controllers/users/notifications_with_devise_controller.rb') } | ||
it { is_expected.to exist } | ||
it { is_expected.to contain(/class Users::NotificationsWithDeviseController < ActivityNotification::NotificationsWithDeviseController/) } | ||
end | ||
end | ||
|
||
context 'with a controllers option as notifications' do | ||
before do | ||
run_generator %w(users --controllers notifications) | ||
end | ||
|
||
describe 'the notifications_controller' do | ||
subject { file('app/controllers/users/notifications_controller.rb') } | ||
it { is_expected.to exist } | ||
it { is_expected.to contain(/class Users::NotificationsController < ActivityNotification::NotificationsController/) } | ||
end | ||
|
||
describe 'the notifications_with_devise_controller' do | ||
subject { file('app/controllers/users/notifications_with_devise_controller.rb') } | ||
it { is_expected.not_to exist } | ||
end | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'generators/activity_notification/install_generator' | ||
|
||
describe ActivityNotification::Generators::InstallGenerator, type: :generator do | ||
|
||
# setup_default_destination | ||
destination File.expand_path("../../../tmp", __FILE__) | ||
before { prepare_destination } | ||
|
||
it 'runs both the initializer and locale tasks' do | ||
gen = generator | ||
expect(gen).to receive :copy_initializer | ||
expect(gen).to receive :copy_locale | ||
expect(gen).to receive(:readme).and_return(true) | ||
gen.invoke_all | ||
end | ||
|
||
describe 'the generated files' do | ||
context 'with active_record orm as default' do | ||
before do | ||
run_generator | ||
end | ||
|
||
describe 'the initializer' do | ||
subject { file('config/initializers/activity_notification.rb') } | ||
it { is_expected.to exist } | ||
it { is_expected.to contain(/ActivityNotification.configure do |config|/) } | ||
end | ||
|
||
describe 'the locale file' do | ||
subject { file('config/locales/activity_notification.en.yml') } | ||
it { is_expected.to exist } | ||
it { is_expected.to contain(/en:\n.+notification:\n.+default:/) } | ||
end | ||
end | ||
|
||
context 'with orm option as not :active_record' do | ||
it 'raise MissingORMError' do | ||
expect { run_generator %w(--orm dummy) } | ||
.to raise_error(TypeError) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'generators/activity_notification/models/notification_generator' | ||
|
||
describe ActivityNotification::Generators::NotificationGenerator, type: :generator do | ||
|
||
# setup_default_destination | ||
destination File.expand_path("../../../../tmp", __FILE__) | ||
before { prepare_destination } | ||
|
||
it 'runs generating model tasks' do | ||
gen = generator | ||
expect(gen).to receive :create_models | ||
gen.invoke_all | ||
end | ||
|
||
describe 'the generated files' do | ||
context 'without name argument' do | ||
before do | ||
run_generator | ||
end | ||
|
||
describe 'app/models/notification.rb' do | ||
subject { file('app/models/notification.rb') } | ||
it { is_expected.to exist } | ||
it { is_expected.to contain(/class Notification < ActivityNotification::Notification/) } | ||
end | ||
end | ||
|
||
context 'with CustomNotification as name argument' do | ||
before do | ||
run_generator %w(CustomNotification) | ||
end | ||
|
||
describe 'app/models/notification.rb' do | ||
subject { file('app/models/custom_notification.rb') } | ||
it { is_expected.to exist } | ||
it { is_expected.to contain(/class CustomNotification < ActivityNotification::Notification/) } | ||
end | ||
end | ||
|
||
end | ||
end |
Oops, something went wrong.