faalis 2.0.8 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +15 -9
  5. data/app/assets/javascripts/faalis/dashboard/application.js.erb +4 -3
  6. data/app/assets/javascripts/faalis/dashboard/init.js.coffee +1 -1
  7. data/{spec/dummy/public/favicon.ico → app/assets/javascripts/faalis/dashboard/lib/amd.js.coffee.erb} +0 -0
  8. data/app/assets/stylesheets/faalis/dashboard/share.scss +5 -0
  9. data/app/controllers/faalis/assets_controller.rb +6 -0
  10. data/app/controllers/faalis/dashboard/user_messages_controller.rb +27 -0
  11. data/app/models/application_record.rb +3 -0
  12. data/app/models/faalis/group.rb +4 -3
  13. data/app/models/faalis/permission.rb +2 -2
  14. data/app/models/faalis/user.rb +1 -7
  15. data/app/models/faalis/user_message.rb +6 -0
  16. data/app/policies/faalis/user_message_policy.rb +9 -0
  17. data/app/policies/faalis/user_policy.rb +1 -1
  18. data/app/views/faalis/dashboard/resource/edit.html.slim +1 -1
  19. data/app/views/faalis/dashboard/resource/show.html.slim +1 -2
  20. data/app/views/faalis/dashboard/shared/_header.html.erb +2 -2
  21. data/app/views/faalis/dashboard/user_messages/_form.html.slim +0 -0
  22. data/app/views/faalis/dashboard/user_messages/create.js.erb +0 -0
  23. data/app/views/faalis/dashboard/user_messages/destroy.js.erb +0 -0
  24. data/app/views/faalis/dashboard/user_messages/new.html.slim +72 -0
  25. data/app/views/layouts/faalis/dashboard.html.erb +2 -1
  26. data/config/locales/faalis.en.yml +2 -1
  27. data/config/routes.rb +6 -21
  28. data/db/migrate/20160310105736_create_faalis_user_messages.rb +16 -0
  29. data/lib/faalis.rb +1 -1
  30. data/lib/faalis/configuration.rb +79 -52
  31. data/lib/faalis/dashboard/dsl.rb +1 -0
  32. data/lib/faalis/dashboard/models/sidebar.rb +42 -16
  33. data/lib/faalis/dashboard/sections/resource.rb +152 -130
  34. data/lib/faalis/dashboard/sections/resource_create.rb +1 -3
  35. data/lib/faalis/engine.rb +7 -5
  36. data/lib/faalis/orm.rb +5 -5
  37. data/lib/faalis/version.rb +1 -1
  38. data/{spec → test}/dummy/README.rdoc +0 -0
  39. data/{spec → test}/dummy/Rakefile +0 -0
  40. data/{spec → test}/dummy/app/assets/javascripts/application.js +0 -0
  41. data/{spec → test}/dummy/app/assets/javascripts/dashboard/application.js +0 -0
  42. data/{spec → test}/dummy/app/assets/stylesheets/application.css +0 -0
  43. data/{spec → test}/dummy/app/assets/stylesheets/dashboard/ltr/application.css +0 -0
  44. data/{spec → test}/dummy/app/assets/stylesheets/dashboard/rtl/application.css +0 -0
  45. data/{spec → test}/dummy/app/assets/stylesheets/ltr/application.css +0 -0
  46. data/{spec → test}/dummy/app/assets/stylesheets/rtl/application.css +0 -0
  47. data/{spec → test}/dummy/app/controllers/api_controller.rb +0 -0
  48. data/{spec → test}/dummy/app/controllers/application_controller.rb +0 -0
  49. data/{spec → test}/dummy/app/controllers/dashboard/application_controller.rb +0 -0
  50. data/{spec → test}/dummy/app/helpers/application_helper.rb +0 -0
  51. data/{spec → test}/dummy/app/policies/application_policy.rb +0 -0
  52. data/{spec → test}/dummy/app/views/layouts/application.html.erb +0 -0
  53. data/{spec → test}/dummy/bin/bundle +0 -0
  54. data/{spec → test}/dummy/bin/rails +0 -0
  55. data/{spec → test}/dummy/bin/rake +0 -0
  56. data/{spec → test}/dummy/config.ru +0 -0
  57. data/{spec → test}/dummy/config/application.rb +0 -0
  58. data/{spec → test}/dummy/config/boot.rb +0 -0
  59. data/{spec → test}/dummy/config/database.yml +0 -0
  60. data/{spec → test}/dummy/config/environment.rb +0 -0
  61. data/{spec → test}/dummy/config/environments/development.rb +0 -0
  62. data/{spec → test}/dummy/config/environments/production.rb +0 -0
  63. data/{spec → test}/dummy/config/environments/test.rb +2 -0
  64. data/{spec → test}/dummy/config/initializers/backtrace_silencers.rb +0 -0
  65. data/{spec → test}/dummy/config/initializers/devise.rb +0 -0
  66. data/{spec → test}/dummy/config/initializers/faalis.rb +0 -0
  67. data/{spec → test}/dummy/config/initializers/faalis_assets.rb +0 -0
  68. data/{spec → test}/dummy/config/initializers/filter_parameter_logging.rb +0 -0
  69. data/{spec → test}/dummy/config/initializers/formstatic.rb +0 -0
  70. data/{spec → test}/dummy/config/initializers/formtastic.rb +0 -0
  71. data/{spec → test}/dummy/config/initializers/inflections.rb +0 -0
  72. data/{spec → test}/dummy/config/initializers/kaminari_config.rb +0 -0
  73. data/{spec → test}/dummy/config/initializers/mime_types.rb +0 -0
  74. data/{spec → test}/dummy/config/initializers/secret_token.rb +0 -0
  75. data/{spec → test}/dummy/config/initializers/session_store.rb +0 -0
  76. data/{spec → test}/dummy/config/initializers/wrap_parameters.rb +0 -0
  77. data/{spec → test}/dummy/config/locales/en.yml +0 -0
  78. data/{spec → test}/dummy/config/routes.rb +0 -0
  79. data/test/dummy/db/test.sqlite3 +0 -0
  80. data/{spec → test}/dummy/lib/templates/slim/scaffold/_form.html.slim +0 -0
  81. data/test/dummy/log/test.log +0 -0
  82. data/{spec → test}/dummy/public/404.html +0 -0
  83. data/{spec → test}/dummy/public/422.html +0 -0
  84. data/{spec → test}/dummy/public/500.html +0 -0
  85. data/test/dummy/public/favicon.ico +0 -0
  86. data/test/fabricators/faalis/groups.rb +27 -0
  87. data/test/fabricators/faalis/permissions.rb +14 -0
  88. data/test/fabricators/faalis/users.rb +17 -0
  89. data/test/generators/install_generator_test.rb +84 -0
  90. data/test/integration/faalis/authentication_test.rb +36 -0
  91. data/test/integration/faalis/dashboard_test.rb +64 -0
  92. data/test/test_helper.rb +72 -0
  93. metadata +291 -150
  94. metadata.gz.sig +1 -0
  95. data/app/controllers/faalis/api/v1/conversations_controller.rb +0 -120
  96. data/app/controllers/faalis/api/v1/groups_controller.rb +0 -71
  97. data/app/controllers/faalis/api/v1/logs_controller.rb +0 -12
  98. data/app/controllers/faalis/api/v1/permissions_controller.rb +0 -61
  99. data/app/controllers/faalis/api/v1/profiles_controller.rb +0 -42
  100. data/app/controllers/faalis/api/v1/users_controller.rb +0 -75
  101. data/lib/faalis_application.rb +0 -446
  102. data/lib/faalis_plugin.rb +0 -477
  103. data/spec/factories/faalis/groups.rb +0 -31
  104. data/spec/factories/faalis/permissions.rb +0 -16
  105. data/spec/factories/faalis/users.rb +0 -23
  106. data/spec/features/dashboard_spec.rb +0 -36
  107. data/spec/features/record_not_found_spec.rb +0 -24
  108. data/spec/features/sign_in_spec.rb +0 -37
  109. data/spec/generators/install_spec.rb +0 -58
  110. data/spec/models/faalis/group_spec.rb +0 -32
  111. data/spec/models/faalis/permission_spec.rb +0 -15
  112. data/spec/models/faalis/user_spec.rb +0 -100
  113. data/spec/policies/faalis/admin_only_policy_spec.rb +0 -39
  114. data/spec/policies/faalis/application_policy_spec.rb +0 -49
  115. data/spec/spec_helper.rb +0 -89
  116. data/spec/support/factory_girl.rb +0 -3
@@ -200,9 +200,7 @@ module Faalis::Dashboard::Sections
200
200
  # end
201
201
  # end
202
202
  def in_form(&block)
203
- name = controller_name
204
- path = controller_path.gsub(name, '').gsub(/dashboard\//, '')
205
- model = "#{path}#{name}".classify.constantize
203
+ model = model_class
206
204
  form_props = Faalis::Dashboard::DSL::Create.new(model)
207
205
 
208
206
  unless block_given?
@@ -18,13 +18,13 @@
18
18
  # -----------------------------------------------------------------------------
19
19
 
20
20
  require_relative './middlewares/locale'
21
+ require_relative './configuration'
21
22
 
22
23
  module Faalis
23
24
 
24
25
  # `Engine` class of **Faalis**.
25
26
  class Engine < ::Rails::Engine
26
-
27
- extend Faalis::Configuration
27
+ extend ::Faalis::Configuration
28
28
 
29
29
  # TODO: Add a facility to allow developers to select
30
30
  # features of faalis
@@ -38,15 +38,17 @@ module Faalis
38
38
  end
39
39
 
40
40
  config.generators do |g|
41
- g.test_framework :rspec, fixture: false
42
- g.fixture_replacement :factory_girl, dir: 'spec/factories'
43
- g.integration_tool :rspec
41
+ g.test_framework :minitest, fixture_replacement: :fabrication
42
+ g.fixture_replacement :fabrication, dir: "test/fabricators"
43
+ g.integration_tool :minitest
44
44
  g.assets false
45
45
  g.helper false
46
46
  end
47
47
 
48
48
  def self.setup
49
49
  yield self
50
+
51
+ load_dependencies_based_on_configuration
50
52
  end
51
53
 
52
54
  # Override devise layout
@@ -13,17 +13,17 @@ module Faalis
13
13
 
14
14
  # current orm
15
15
  def self.current
16
- Faalis::Engine.orm.to_s
16
+ ::Faalis::Engine.orm.to_s
17
17
  end
18
18
 
19
19
  # This class method returns the base class of current ORM
20
20
  # It will be used in models to specify which class to inherit
21
21
  # from, based on current ORM
22
22
  def self.proper_base_class
23
- return ActiveRecord::Base if active_record?
24
- return Object if mongoid?
25
- Faalis::Engine.orm = 'active_record'
26
- ActiveRecord::Base
23
+ return ::ActiveRecord::Base if active_record?
24
+ return ::Object if mongoid?
25
+ ::Faalis::Engine.orm = 'active_record'
26
+ ::ActiveRecord::Base
27
27
  end
28
28
  end
29
29
  end
@@ -18,5 +18,5 @@
18
18
  # -----------------------------------------------------------------------------
19
19
 
20
20
  module Faalis
21
- VERSION = '2.0.8'
21
+ VERSION = '2.1.0'
22
22
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -33,4 +33,6 @@ Dummy::Application.configure do
33
33
 
34
34
  # Print deprecation notices to the stderr.
35
35
  config.active_support.deprecation = :stderr
36
+ config.active_support.test_order = :sorted
37
+
36
38
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,27 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ def group(role)
4
+ # get existing group or create new one
5
+ Faalis::Group.where(role: role).first || Fabricate("#{role}_group")
6
+ end
7
+
8
+ Fabricator :guest_group, class_name: 'Faalis::Group' do
9
+ name 'Guest'
10
+ role 'guest'
11
+ end
12
+
13
+ Fabricator :admin_group, class_name: 'Faalis::Group' do
14
+ name 'Admin'
15
+ role 'admin'
16
+ end
17
+
18
+ Fabricator :manager_group, class_name: 'Faalis::Group' do
19
+ name 'Manager'
20
+ role 'manager'
21
+
22
+ permissions do
23
+ [:index, :show, :update, :create, :destroy].map do |x|
24
+ define_permission(x, :group)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ def define_permission(action, model)
4
+ perm = Faalis::Permission.find_by(permission_type: action,
5
+ model: "Faalis::#{model.to_s.titleize}")
6
+ perm || Fabricate("#{action}_#{model}")
7
+ end
8
+
9
+ [:index, :show, :update, :create, :destroy].each do |action|
10
+ Fabricator "#{action}_group".to_sym, class_name: 'Faalis::Permission' do
11
+ model 'Faalis::Group'
12
+ permission_type action
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ Fabricator :user, class_name: 'Faalis::User' do
2
+ first_name Faker::Name.first_name
3
+ last_name Faker::Name.first_name
4
+ email { sequence(:email) { |n| "person#{n}@example.com" } }
5
+ end
6
+
7
+ Fabricator :admin, from: :user do
8
+ groups(count: 1){ Fabricate(:admin_group) }
9
+ end
10
+
11
+ Fabricator :guest, from: :user do
12
+ groups(count: 1){ Fabricate(:guest_group) }
13
+ end
14
+
15
+ Fabricator :manager, from: :user do
16
+ groups(count: 1){ Fabricate(:manager_group) }
17
+ end
@@ -0,0 +1,84 @@
1
+ # require 'test_helper'
2
+ # require 'generators/faalis/install_generator'
3
+
4
+ # class InstallGeneratorTest < Rails::Generators::TestCase
5
+ # tests ::Faalis::Generators::InstallGenerator
6
+ # destination File.expand_path('../../dummy/tmp/install', __FILE__)
7
+ # setup :prepare_destination
8
+
9
+ # def run_generator(args=self.default_arguments, config={})
10
+ # args += ['--skip-bundle'] unless args.include? '--dev'
11
+ # self.generator_class.start(args, config.reverse_merge(destination_root: destination_root))
12
+ # end
13
+
14
+ # before do
15
+ # path = File.expand_path('../../dummy/tmp/install', __FILE__)
16
+ # dummy = File.expand_path('../../dummy/', __FILE__)
17
+
18
+ # mkdir_p path
19
+ # mkdir_p("#{path}/config/initializers")
20
+ # mkdir_p("#{path}/app/controllers")
21
+ # mkdir_p("#{path}/db")
22
+ # mkdir_p("#{path}/bin")
23
+ # touch("#{path}/config/routes.rb")
24
+ # touch("#{path}/Gemfile")
25
+ # touch("#{path}/config/initializers/assets.rb")
26
+ # touch("#{path}/config/initializers/formtastic.rb")
27
+ # touch("#{path}/db/seeds.rb")
28
+ # cp("#{dummy}/bin/rails", "#{path}/bin/rails")
29
+ # cp("#{dummy}/config/boot.rb", "#{path}/config/boot.rb")
30
+ # cp("#{dummy}/config/application.rb", "#{path}/config/application.rb")
31
+ # touch("#{path}/app/controllers/application_controller.rb")
32
+
33
+ # # run_generator
34
+ # end
35
+
36
+ # after do
37
+ # capture(:stdout) do
38
+ # path = File.expand_path('../../dummy/tmp/install', __FILE__)
39
+ # rm_rf path
40
+ # end
41
+ # end
42
+
43
+ # def test_copies_the_files
44
+ # run_generator
45
+
46
+ # assert_file 'config/initializers/faalis.rb'
47
+ # assert_file 'config/initializers/devise.rb'
48
+ # assert_file 'db/seeds.rb'
49
+ # assert_file 'app/controllers/api_controller.rb'
50
+ # assert_file 'app/controllers/dashboard/application_controller.rb'
51
+ # assert_file 'app/policies/application_policy.rb'
52
+ # assert_file 'app/assets/javascripts/dashboard/application.js'
53
+ # assert_file 'app/assets/stylesheets/dashboard/ltr/application.css'
54
+ # assert_file 'app/assets/stylesheets/dashboard/rtl/application.css'
55
+ # end
56
+ # end
57
+
58
+
59
+
60
+
61
+ # # def content_of(path)
62
+ # # full_path = "#{destination_root}/#{path}"
63
+ # # File.read(full_path)
64
+ # # end
65
+
66
+ # # before :all do
67
+ # # prepare_destination
68
+
69
+ # # path = File.expand_path('../../dummy/tmp/', __FILE__)
70
+
71
+ # # FileUtils.mkdir_p("#{path}/config/initializers")
72
+ # # FileUtils.mkdir_p("#{path}/app/controllers")
73
+ # # FileUtils.mkdir_p("#{path}/db")
74
+
75
+ # # FileUtils.touch("#{path}/config/routes.rb")
76
+ # # FileUtils.touch("#{path}/Gemfile")
77
+ # # FileUtils.touch("#{path}/config/initializers/assets.rb")
78
+ # # FileUtils.touch("#{path}/config/initializers/formtastic.rb")
79
+ # # FileUtils.touch("#{path}/db/seeds.rb")
80
+
81
+
82
+ # # FileUtils.touch("#{path}/app/controllers/application_controller.rb")
83
+ # # run_generator
84
+ # # end
@@ -0,0 +1,36 @@
1
+ require "test_helper"
2
+
3
+ class AuthenticationTest < ActionDispatch::IntegrationTest
4
+ def setup
5
+ @admin = Fabricate(:admin, password: '123123123',
6
+ password_confirmation: '123123123',
7
+ email: 'admin@example.com')
8
+
9
+ @admin.save
10
+ @guest = Fabricate(:guest, password: '123123123',
11
+ password_confirmation: '123123123')
12
+
13
+ end
14
+
15
+ test 'authentication is up and running' do
16
+ visit user_session_path
17
+
18
+ assert_text 'Sign In'
19
+ assert_css '.login-box-msg'
20
+ assert_selector '#user_email'
21
+ assert_selector '#user_password'
22
+ end
23
+
24
+ test 'authentication allows user to successfully log in using valid credentials' do
25
+ visit dashboard_index_path
26
+
27
+ fill_in 'user_email', with: @admin.email
28
+ fill_in 'user_password', with: '123123123'
29
+
30
+ click_button 'sign_in'
31
+
32
+ assert_text 'Dashboard'
33
+ assert_no_text 'Sign In'
34
+ assert_equal current_path, dashboard_index_path
35
+ end
36
+ end
@@ -0,0 +1,64 @@
1
+ require "test_helper"
2
+
3
+ class DashboardTest < ActionDispatch::IntegrationTest
4
+
5
+ def setup
6
+ @admin = Fabricate(:admin, password: '123123123',
7
+ password_confirmation: '123123123')
8
+
9
+ @guest = Fabricate(:guest, password: '123123123',
10
+ password_confirmation: '123123123')
11
+ @faalis = Faalis::Engine.routes.url_helpers
12
+ end
13
+
14
+ test "loads normally after login" do
15
+ login_as(@admin, scope: :user)
16
+ path = "/#{Faalis::Engine.dashboard_namespace}"
17
+
18
+ visit faalis.dashboard_index_path
19
+
20
+ assert_equal page.status_code, 200
21
+ assert_text 'Faalis'
22
+ assert_text 'Dashboard'
23
+ assert_no_text '404'
24
+ assert_no_text 'Oops!'
25
+ assert_equal current_path, path
26
+ end
27
+
28
+ test 'does not load with anonymous users' do
29
+ visit @faalis.dashboard_index_path
30
+
31
+ assert_equal page.status_code, 200
32
+ assert_equal current_path, @faalis.user_session_path
33
+ end
34
+
35
+ test 'does not provide authentication section for guests' do
36
+ visit @faalis.dashboard_index_path
37
+
38
+ assert_equal page.status_code, 200
39
+ assert_no_text('User Management')
40
+ assert_no_text('Users')
41
+ assert_no_text('Groups')
42
+ end
43
+
44
+ test 'User try to find a resource which does not exists via js format.' do
45
+ login_as(@admin, scope: :user)
46
+
47
+ visit @faalis.dashboard_auth_user_path({ id: 3242, format: :js})
48
+
49
+ assert_equal page.status_code, 200
50
+ assert_text('error_message(')
51
+ end
52
+
53
+ test 'User try to find a valid resource' do
54
+ login_as(@admin, scope: :user)
55
+
56
+ visit @faalis.dashboard_auth_user_path({ id: 1 })
57
+
58
+ assert_equal page.status_code, 200
59
+ assert_no_text('404')
60
+ assert_text('User')
61
+ assert_no_text('Oops!')
62
+ end
63
+
64
+ end
@@ -0,0 +1,72 @@
1
+ ENV["RAILS_ENV"] ||= 'test'
2
+
3
+ require File.expand_path("../../test/dummy/config/environment", __FILE__)
4
+ require "rails/test_help"
5
+ #require "mocha/mini_test"
6
+
7
+ # FABRICATION -----------------------------------
8
+ require 'fabrication'
9
+
10
+ Fabrication.configure do |config|
11
+ config.fabricator_path = 'test/fabricators/faalis/'
12
+ config.path_prefix = Faalis::Engine.root
13
+ end
14
+
15
+ # MINITEST REPORTER -----------------------------
16
+ require "minitest/reporters"
17
+
18
+ Minitest::Reporters.use!(Minitest::Reporters::ProgressReporter.new,
19
+ ENV,
20
+ Minitest.backtrace_filter)
21
+
22
+
23
+ class ActiveSupport::TestCase
24
+ fixtures :all
25
+ end
26
+
27
+ # CAPYBARA ---------------------------------------
28
+ # Capybara and poltergeist integration
29
+ require 'minitest/rails/capybara'
30
+ require 'capybara/rails'
31
+ require 'capybara/poltergeist'
32
+
33
+ class ActionDispatch::IntegrationTest
34
+ include Capybara::DSL
35
+ include Capybara::Assertions
36
+ include Faalis::Engine.routes.url_helpers
37
+ include Warden::Test::Helpers
38
+
39
+ Warden.test_mode!
40
+
41
+ after do
42
+ Warden.test_reset!
43
+ end
44
+ end
45
+
46
+ Capybara.javascript_driver = :poltergeist
47
+
48
+
49
+ # DATABASE CLEANER -------------------------------
50
+
51
+ require 'database_cleaner'
52
+ require 'minitest/around/spec'
53
+
54
+ class Minitest::Spec
55
+ around do |tests|
56
+ DatabaseCleaner.cleaning(&tests)
57
+ end
58
+ end
59
+
60
+ # CONNECTION POOL --------------------------------
61
+ require 'connection_pool'
62
+
63
+ class ActiveRecord::Base
64
+ mattr_accessor :shared_connection
65
+ @@shared_connection = nil
66
+
67
+ def self.connection
68
+ @@shared_connection || ::ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
69
+ end
70
+ end
71
+
72
+ ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection