ditty 0.7.1 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.test +2 -0
- data/.gitignore +3 -0
- data/.pryrc +2 -0
- data/.rubocop.yml +24 -8
- data/.travis.yml +4 -8
- data/CNAME +1 -0
- data/Dockerfile +18 -0
- data/Gemfile.ci +0 -15
- data/Rakefile +5 -4
- data/Readme.md +24 -2
- data/_config.yml +1 -0
- data/config.ru +4 -4
- data/ditty.gemspec +31 -20
- data/docs/CNAME +1 -0
- data/docs/_config.yml +1 -0
- data/docs/index.md +34 -0
- data/exe/ditty +2 -0
- data/lib/ditty.rb +30 -4
- data/lib/ditty/cli.rb +38 -5
- data/lib/ditty/components/ditty.rb +82 -0
- data/lib/ditty/controllers/application_controller.rb +267 -0
- data/lib/ditty/controllers/{audit_logs.rb → audit_logs_controller.rb} +5 -7
- data/lib/ditty/controllers/{auth.rb → auth_controller.rb} +56 -32
- data/lib/ditty/controllers/{component.rb → component_controller.rb} +35 -24
- data/lib/ditty/controllers/{main.rb → main_controller.rb} +7 -7
- data/lib/ditty/controllers/roles_controller.rb +23 -0
- data/lib/ditty/controllers/user_login_traits_controller.rb +46 -0
- data/lib/ditty/controllers/{users.rb → users_controller.rb} +17 -20
- data/lib/ditty/db.rb +9 -5
- data/lib/ditty/emails/base.rb +48 -34
- data/lib/ditty/generators/crud_generator.rb +114 -0
- data/lib/ditty/generators/migration_generator.rb +26 -0
- data/lib/ditty/generators/project_generator.rb +52 -0
- data/lib/ditty/helpers/authentication.rb +6 -5
- data/lib/ditty/helpers/component.rb +11 -2
- data/lib/ditty/helpers/pundit.rb +24 -8
- data/lib/ditty/helpers/response.rb +38 -15
- data/lib/ditty/helpers/views.rb +48 -6
- data/lib/ditty/listener.rb +44 -14
- data/lib/ditty/memcached.rb +8 -0
- data/lib/ditty/middleware/accept_extension.rb +4 -2
- data/lib/ditty/middleware/error_catchall.rb +4 -2
- data/lib/ditty/models/audit_log.rb +1 -0
- data/lib/ditty/models/base.rb +13 -0
- data/lib/ditty/models/identity.rb +10 -7
- data/lib/ditty/models/role.rb +2 -0
- data/lib/ditty/models/user.rb +40 -3
- data/lib/ditty/models/user_login_trait.rb +17 -0
- data/lib/ditty/policies/audit_log_policy.rb +6 -6
- data/lib/ditty/policies/role_policy.rb +3 -3
- data/lib/ditty/policies/user_login_trait_policy.rb +45 -0
- data/lib/ditty/policies/user_policy.rb +3 -3
- data/lib/ditty/rubocop.rb +3 -0
- data/lib/ditty/seed.rb +2 -0
- data/lib/ditty/services/authentication.rb +31 -15
- data/lib/ditty/services/email.rb +22 -12
- data/lib/ditty/services/logger.rb +30 -13
- data/lib/ditty/services/pagination_wrapper.rb +9 -5
- data/lib/ditty/services/settings.rb +19 -7
- data/lib/ditty/tasks/ditty.rake +127 -0
- data/lib/ditty/tasks/omniauth-ldap.rake +43 -0
- data/lib/ditty/templates/.gitignore +5 -0
- data/lib/ditty/templates/.rspec +2 -0
- data/lib/ditty/templates/.rubocop.yml +7 -0
- data/lib/ditty/templates/Rakefile +12 -0
- data/lib/ditty/templates/application.rb +12 -0
- data/lib/ditty/templates/config.ru +37 -0
- data/lib/ditty/templates/controller.rb.erb +64 -0
- data/lib/ditty/templates/env.example +4 -0
- data/lib/ditty/templates/lib/project.rb.erb +5 -0
- data/lib/ditty/templates/migration.rb.erb +7 -0
- data/lib/ditty/templates/model.rb.erb +26 -0
- data/lib/ditty/templates/pids/.empty_directory +0 -0
- data/lib/ditty/templates/policy.rb.erb +48 -0
- data/{public → lib/ditty/templates/public}/browserconfig.xml +0 -0
- data/lib/ditty/templates/public/css/sb-admin-2.min.css +10 -0
- data/lib/ditty/templates/public/css/styles.css +13 -0
- data/lib/ditty/templates/public/favicon.ico +0 -0
- data/{public → lib/ditty/templates/public}/images/apple-icon.png +0 -0
- data/{public → lib/ditty/templates/public}/images/favicon-16x16.png +0 -0
- data/{public → lib/ditty/templates/public}/images/favicon-32x32.png +0 -0
- data/{public → lib/ditty/templates/public}/images/launcher-icon-1x.png +0 -0
- data/{public → lib/ditty/templates/public}/images/launcher-icon-2x.png +0 -0
- data/{public → lib/ditty/templates/public}/images/launcher-icon-4x.png +0 -0
- data/{public → lib/ditty/templates/public}/images/mstile-150x150.png +0 -0
- data/{public → lib/ditty/templates/public}/images/safari-pinned-tab.svg +0 -0
- data/lib/ditty/templates/public/js/sb-admin-2.min.js +7 -0
- data/lib/ditty/templates/public/js/scripts.js +1 -0
- data/{public/manifest.json → lib/ditty/templates/public/manifest.json.erb} +2 -2
- data/lib/ditty/templates/settings.yml.erb +19 -0
- data/lib/ditty/templates/sidekiq.rb +18 -0
- data/lib/ditty/templates/sidekiq.yml +9 -0
- data/lib/ditty/templates/spec_helper.rb +43 -0
- data/lib/ditty/templates/type.rb.erb +21 -0
- data/lib/ditty/templates/views/display.haml.tt +20 -0
- data/lib/ditty/templates/views/edit.haml.tt +10 -0
- data/lib/ditty/templates/views/form.haml.tt +11 -0
- data/lib/ditty/templates/views/index.haml.tt +29 -0
- data/lib/ditty/templates/views/new.haml.tt +10 -0
- data/lib/ditty/version.rb +1 -1
- data/lib/rubocop/cop/ditty/call_services_directly.rb +42 -0
- data/migrate/20181209_add_user_login_traits.rb +16 -0
- data/migrate/20181209_extend_audit_log.rb +12 -0
- data/migrate/20190220_add_parent_id_to_roles.rb +9 -0
- data/spec/ditty/api_spec.rb +51 -0
- data/spec/ditty/controllers/roles_spec.rb +67 -0
- data/spec/ditty/controllers/user_login_traits_spec.rb +72 -0
- data/spec/ditty/controllers/users_spec.rb +72 -0
- data/spec/ditty/emails/base_spec.rb +76 -0
- data/spec/ditty/emails/forgot_password_spec.rb +20 -0
- data/spec/ditty/helpers/component_spec.rb +85 -0
- data/spec/ditty/models/user_spec.rb +36 -0
- data/spec/ditty/services/email_spec.rb +36 -0
- data/spec/ditty/services/logger_spec.rb +68 -0
- data/spec/ditty/services/settings_spec.rb +63 -0
- data/spec/ditty_spec.rb +9 -0
- data/spec/factories.rb +46 -0
- data/spec/fixtures/logger.yml +17 -0
- data/spec/fixtures/section.yml +3 -0
- data/spec/fixtures/settings.yml +8 -0
- data/spec/spec_helper.rb +51 -0
- data/spec/support/api_shared_examples.rb +250 -0
- data/spec/support/crud_shared_examples.rb +145 -0
- data/views/403.haml +2 -0
- data/views/404.haml +2 -4
- data/views/500.haml +11 -0
- data/views/audit_logs/index.haml +32 -28
- data/views/auth/forgot_password.haml +32 -16
- data/views/auth/identity.haml +14 -13
- data/views/auth/ldap.haml +17 -0
- data/views/auth/login.haml +23 -17
- data/views/auth/register.haml +20 -18
- data/views/auth/register_identity.haml +27 -12
- data/views/auth/reset_password.haml +36 -19
- data/views/blank.haml +43 -0
- data/views/emails/forgot_password.haml +1 -1
- data/views/emails/layouts/action.haml +10 -6
- data/views/emails/layouts/alert.haml +2 -1
- data/views/emails/layouts/billing.haml +2 -1
- data/views/embedded.haml +17 -11
- data/views/error.haml +8 -3
- data/views/index.haml +1 -1
- data/views/layout.haml +45 -30
- data/views/partials/actions.haml +15 -14
- data/views/partials/content_tag.haml +0 -0
- data/views/partials/delete_form.haml +1 -1
- data/views/partials/filter_control.haml +2 -2
- data/views/partials/footer.haml +13 -5
- data/views/partials/form_control.haml +30 -19
- data/views/partials/form_tag.haml +1 -1
- data/views/partials/navitems.haml +42 -0
- data/views/partials/notifications.haml +12 -8
- data/views/partials/pager.haml +44 -25
- data/views/partials/search.haml +15 -11
- data/views/partials/sidebar.haml +15 -37
- data/views/partials/sort_ui.haml +2 -0
- data/views/partials/timespan_selector.haml +64 -0
- data/views/partials/topbar.haml +53 -0
- data/views/partials/user_associations.haml +32 -0
- data/views/quick_start.haml +23 -0
- data/views/roles/display.haml +27 -6
- data/views/roles/edit.haml +3 -3
- data/views/roles/form.haml +1 -0
- data/views/roles/index.haml +23 -14
- data/views/roles/new.haml +2 -2
- data/views/user_login_traits/display.haml +32 -0
- data/views/user_login_traits/edit.haml +10 -0
- data/views/user_login_traits/form.haml +5 -0
- data/views/user_login_traits/index.haml +28 -0
- data/views/user_login_traits/new.haml +10 -0
- data/views/users/display.haml +15 -16
- data/views/users/edit.haml +3 -3
- data/views/users/form.haml +0 -0
- data/views/users/index.haml +31 -24
- data/views/users/login_traits.haml +25 -0
- data/views/users/new.haml +2 -2
- data/views/users/profile.haml +17 -15
- data/views/users/user.haml +1 -1
- metadata +314 -76
- data/lib/ditty/components/app.rb +0 -77
- data/lib/ditty/controllers/application.rb +0 -175
- data/lib/ditty/controllers/roles.rb +0 -16
- data/lib/ditty/rake_tasks.rb +0 -102
- data/views/partials/navbar.haml +0 -23
data/lib/ditty/version.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubocop'
|
4
|
+
require 'rubocop/ast/node'
|
5
|
+
require 'rubocop/cop/cop'
|
6
|
+
|
7
|
+
module RuboCop
|
8
|
+
module Cop
|
9
|
+
module Ditty
|
10
|
+
# This cop enforces the use of `Service.method` instead of
|
11
|
+
# `Service.instance.method`. Calling the singleton instance has been
|
12
|
+
# deprecated for services.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# # bad
|
16
|
+
# ::Ditty::Services::Logger.instance.info 'This is a log message'
|
17
|
+
#
|
18
|
+
# # good
|
19
|
+
# ::Ditty::Services::Logger.info 'This is a log message'
|
20
|
+
class CallServicesDirectly < RuboCop::Cop::Cop
|
21
|
+
MSG = 'Do not use `.instance` on services. Call the method directly instead'
|
22
|
+
|
23
|
+
def_node_matcher :service_instance_call?, <<-PATTERN
|
24
|
+
(send (const (const (const ... :Ditty) :Services) _) :instance)
|
25
|
+
PATTERN
|
26
|
+
|
27
|
+
def on_send(node)
|
28
|
+
return unless service_instance_call?(node)
|
29
|
+
|
30
|
+
add_offense(node)
|
31
|
+
end
|
32
|
+
|
33
|
+
def autocorrect(node)
|
34
|
+
lambda do |corrector|
|
35
|
+
internal = node.children.first.source
|
36
|
+
corrector.replace(node.loc.expression, internal)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Sequel.migration do
|
4
|
+
change do
|
5
|
+
create_table :user_login_traits do
|
6
|
+
primary_key :id
|
7
|
+
foreign_key :user_id, :users
|
8
|
+
String :ip_address, null: true
|
9
|
+
String :platform, null: true
|
10
|
+
String :device, null: true
|
11
|
+
String :browser, null: true
|
12
|
+
DateTime :created_at
|
13
|
+
DateTime :updated_at
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
Dir.glob('./lib/ditty/controllers/*.rb').sort.each { |f| require f }
|
5
|
+
require 'support/api_shared_examples'
|
6
|
+
|
7
|
+
describe ::Ditty::RolesController, type: :controller do
|
8
|
+
def app
|
9
|
+
described_class
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:user) { create(:super_admin_user) }
|
13
|
+
|
14
|
+
before do
|
15
|
+
env 'rack.session', 'user_id' => user.id
|
16
|
+
end
|
17
|
+
|
18
|
+
it_behaves_like 'an API interface', :role, {}
|
19
|
+
end
|
20
|
+
|
21
|
+
describe ::Ditty::UsersController, type: :controller do
|
22
|
+
def app
|
23
|
+
described_class
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:user) { create(:super_admin_user) }
|
27
|
+
|
28
|
+
before { env 'rack.session', 'user_id' => user.id }
|
29
|
+
|
30
|
+
params = {
|
31
|
+
identity: {
|
32
|
+
username: 'test-user@abc.abc',
|
33
|
+
password: 'som3Password!',
|
34
|
+
password_confirmation: 'som3Password!'
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
it_behaves_like 'an API interface', :user, params
|
39
|
+
end
|
40
|
+
|
41
|
+
describe ::Ditty::UserLoginTraitsController, type: :controller do
|
42
|
+
def app
|
43
|
+
described_class
|
44
|
+
end
|
45
|
+
|
46
|
+
let(:user) { create(:super_admin_user) }
|
47
|
+
|
48
|
+
before { env 'rack.session', 'user_id' => user.id }
|
49
|
+
|
50
|
+
it_behaves_like 'an API interface', :user_login_trait, {}
|
51
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'ditty/controllers/roles_controller'
|
5
|
+
require 'support/crud_shared_examples'
|
6
|
+
|
7
|
+
describe ::Ditty::RolesController do
|
8
|
+
def app
|
9
|
+
described_class
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'as super_admin_user' do
|
13
|
+
let(:user) { create(:super_admin_user) }
|
14
|
+
let(:model) { create(app.model_class.name.to_sym) }
|
15
|
+
let(:create_data) do
|
16
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
17
|
+
{ group => build(described_class.model_class.name.to_sym).to_hash }
|
18
|
+
end
|
19
|
+
let(:update_data) do
|
20
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
21
|
+
{ group => build(described_class.model_class.name.to_sym).to_hash }
|
22
|
+
end
|
23
|
+
let(:invalid_create_data) do
|
24
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
25
|
+
{ group => { name: '' } }
|
26
|
+
end
|
27
|
+
let(:invalid_update_data) do
|
28
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
29
|
+
{ group => { name: '' } }
|
30
|
+
end
|
31
|
+
|
32
|
+
before do
|
33
|
+
# Log in
|
34
|
+
env 'rack.session', 'user_id' => user.id
|
35
|
+
end
|
36
|
+
|
37
|
+
it_behaves_like 'a CRUD Controller', '/roles'
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'as user' do
|
41
|
+
let(:user) { create(:user) }
|
42
|
+
let(:model) { create(app.model_class.name.to_sym) }
|
43
|
+
let(:create_data) do
|
44
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
45
|
+
{ group => build(described_class.model_class.name.to_sym).to_hash }
|
46
|
+
end
|
47
|
+
let(:update_data) do
|
48
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
49
|
+
{ group => build(described_class.model_class.name.to_sym).to_hash }
|
50
|
+
end
|
51
|
+
let(:invalid_create_data) do
|
52
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
53
|
+
{ group => { name: '' } }
|
54
|
+
end
|
55
|
+
let(:invalid_update_data) do
|
56
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
57
|
+
{ group => { name: '' } }
|
58
|
+
end
|
59
|
+
|
60
|
+
before do
|
61
|
+
# Log in
|
62
|
+
env 'rack.session', 'user_id' => user.id
|
63
|
+
end
|
64
|
+
|
65
|
+
it_behaves_like 'a CRUD Controller', '/roles'
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'ditty/controllers/user_login_traits_controller'
|
5
|
+
require 'support/crud_shared_examples'
|
6
|
+
|
7
|
+
describe ::Ditty::UserLoginTraitsController do
|
8
|
+
def app
|
9
|
+
described_class
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'as super_admin_user' do
|
13
|
+
let(:user) { create(:super_admin_user) }
|
14
|
+
let(:model) { create(app.model_class.name.to_sym) }
|
15
|
+
let(:create_data) do
|
16
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
17
|
+
identity = build(:identity).to_hash
|
18
|
+
identity['password_confirmation'] = identity['password'] = 'som3Password!'
|
19
|
+
{
|
20
|
+
group => build(described_class.model_class.name.to_sym).to_hash,
|
21
|
+
'identity' => identity
|
22
|
+
}
|
23
|
+
end
|
24
|
+
let(:update_data) do
|
25
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
26
|
+
{ group => build(described_class.model_class.name.to_sym).to_hash }
|
27
|
+
end
|
28
|
+
let(:invalid_create_data) do
|
29
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
30
|
+
{ group => { user_id: nil } }
|
31
|
+
end
|
32
|
+
let(:invalid_update_data) do
|
33
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
34
|
+
{ group => { user_id: nil } }
|
35
|
+
end
|
36
|
+
|
37
|
+
before do
|
38
|
+
# Log in
|
39
|
+
env 'rack.session', 'user_id' => user.id
|
40
|
+
end
|
41
|
+
|
42
|
+
it_behaves_like 'a CRUD Controller', '/user-login-traits'
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'as user' do
|
46
|
+
let(:user) { create(:user) }
|
47
|
+
let(:model) { create(app.model_class.name.to_sym, user: user) }
|
48
|
+
let(:create_data) do
|
49
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
50
|
+
{ group => build(described_class.model_class.name.to_sym).to_hash }
|
51
|
+
end
|
52
|
+
let(:update_data) do
|
53
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
54
|
+
{ group => build(described_class.model_class.name.to_sym).to_hash }
|
55
|
+
end
|
56
|
+
let(:invalid_create_data) do
|
57
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
58
|
+
{ group => { user_id: nil } }
|
59
|
+
end
|
60
|
+
let(:invalid_update_data) do
|
61
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
62
|
+
{ group => { user_id: nil } }
|
63
|
+
end
|
64
|
+
|
65
|
+
before do
|
66
|
+
# Log in
|
67
|
+
env 'rack.session', 'user_id' => user.id
|
68
|
+
end
|
69
|
+
|
70
|
+
it_behaves_like 'a CRUD Controller', '/user-login-traits'
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'ditty/controllers/users_controller'
|
5
|
+
require 'support/crud_shared_examples'
|
6
|
+
|
7
|
+
describe ::Ditty::UsersController do
|
8
|
+
def app
|
9
|
+
described_class
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'as super_admin_user' do
|
13
|
+
let(:user) { create(:super_admin_user) }
|
14
|
+
let(:model) { create(app.model_class.name.to_sym) }
|
15
|
+
let(:create_data) do
|
16
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
17
|
+
identity = build(:identity).to_hash
|
18
|
+
identity['password_confirmation'] = identity['password'] = 'som3Password!'
|
19
|
+
{
|
20
|
+
group => build(described_class.model_class.name.to_sym).to_hash,
|
21
|
+
'identity' => identity
|
22
|
+
}
|
23
|
+
end
|
24
|
+
let(:update_data) do
|
25
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
26
|
+
{ group => build(described_class.model_class.name.to_sym).to_hash }
|
27
|
+
end
|
28
|
+
let(:invalid_create_data) do
|
29
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
30
|
+
{ group => { email: 'invalidemail' } }
|
31
|
+
end
|
32
|
+
let(:invalid_update_data) do
|
33
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
34
|
+
{ group => { email: 'invalidemail' } }
|
35
|
+
end
|
36
|
+
|
37
|
+
before do
|
38
|
+
# Log in
|
39
|
+
env 'rack.session', 'user_id' => user.id
|
40
|
+
end
|
41
|
+
|
42
|
+
it_behaves_like 'a CRUD Controller', '/users'
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'as user' do
|
46
|
+
let(:user) { create(:user) }
|
47
|
+
let(:model) { create(app.model_class.name.to_sym) }
|
48
|
+
let(:create_data) do
|
49
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
50
|
+
{ group => build(described_class.model_class.name.to_sym).to_hash }
|
51
|
+
end
|
52
|
+
let(:update_data) do
|
53
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
54
|
+
{ group => build(described_class.model_class.name.to_sym).to_hash }
|
55
|
+
end
|
56
|
+
let(:invalid_create_data) do
|
57
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
58
|
+
{ group => { email: 'invalidemail' } }
|
59
|
+
end
|
60
|
+
let(:invalid_update_data) do
|
61
|
+
group = described_class.model_class.to_s.demodulize.underscore
|
62
|
+
{ group => { email: 'invalidemail' } }
|
63
|
+
end
|
64
|
+
|
65
|
+
before do
|
66
|
+
# Log in
|
67
|
+
env 'rack.session', 'user_id' => user.id
|
68
|
+
end
|
69
|
+
|
70
|
+
it_behaves_like 'a CRUD Controller', '/users'
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'ditty/emails/base'
|
5
|
+
require 'mail'
|
6
|
+
|
7
|
+
describe ::Ditty::Emails::Base do
|
8
|
+
let(:mail) do
|
9
|
+
mail = Mail.new
|
10
|
+
allow(mail).to receive(:deliver!)
|
11
|
+
mail
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.new' do
|
15
|
+
it 'defaults to base options' do
|
16
|
+
expect(subject.options).to include subject: '(No Subject)', from: 'no-reply@ditty.io', view: :base
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'allows the use of layouts' do
|
20
|
+
skip 'Test is not accurate. The class no longer uses body.'
|
21
|
+
base = described_class.new(layout: 'action', mail: mail)
|
22
|
+
expect(mail).to receive(:body).with(/^<!DOCTYPE html>/m)
|
23
|
+
base.deliver!('test@email.com')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '.deliver!' do
|
28
|
+
it 'delivers the email to the specified email address' do
|
29
|
+
expect(mail).to receive(:to).with('test@email.com')
|
30
|
+
expect(mail).to receive(:deliver!)
|
31
|
+
described_class.deliver!('test@email.com', mail: mail)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'passes down local variables' do
|
35
|
+
skip 'Test is not accurate. The class no longer uses body.'
|
36
|
+
expect(mail).to receive(:body).with("test content\n")
|
37
|
+
described_class.deliver!('test@email.com', locals: { content: 'test content' }, mail: mail)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'sets the email\'s subject and from address' do
|
41
|
+
expect(mail).to receive(:subject).with('test subject')
|
42
|
+
expect(mail).to receive(:from).with('from@test.com')
|
43
|
+
described_class.deliver!('test@email.com', subject: 'test subject', from: 'from@test.com', mail: mail)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#deliver!' do
|
48
|
+
it 'delivers the email to the specified email address' do
|
49
|
+
expect(mail).to receive(:to).with('test2@email.com')
|
50
|
+
base = described_class.new(mail: mail)
|
51
|
+
base.deliver!('test2@email.com')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'passes the local variables to the template' do
|
55
|
+
skip 'Test is not accurate. The class no longer uses body.'
|
56
|
+
expect(mail).to receive(:body).with("test content\n")
|
57
|
+
base = described_class.new(mail: mail)
|
58
|
+
base.deliver!('test@email.com', content: 'test content')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'sets the email\'s subject and from address' do
|
62
|
+
expect(mail).to receive(:subject).with('test subject')
|
63
|
+
expect(mail).to receive(:from).with('from@test.com')
|
64
|
+
base = described_class.new(subject: 'test subject', from: 'from@test.com', mail: mail)
|
65
|
+
base.deliver!('test@email.com')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'method_missing' do
|
70
|
+
it 'passes unknown message to the underlying mail object' do
|
71
|
+
expect(mail).to receive(:cc).with('cc@test.com')
|
72
|
+
base = described_class.new(mail: mail)
|
73
|
+
base.cc 'cc@test.com'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'ditty/emails/forgot_password'
|
5
|
+
require 'mail'
|
6
|
+
|
7
|
+
describe ::Ditty::Emails::ForgotPassword do
|
8
|
+
let(:mail) do
|
9
|
+
mail = Mail.new
|
10
|
+
allow(mail).to receive(:deliver!)
|
11
|
+
mail
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.new' do
|
15
|
+
it 'defaults to base options' do
|
16
|
+
expect(subject.options).to include subject: 'Request to reset password', from: 'no-reply@ditty.io',
|
17
|
+
view: :forgot_password
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|