anoubis 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +38 -0
  5. data/app/controllers/anoubis/application_controller.rb +78 -0
  6. data/app/controllers/anoubis/core/application_controller.rb +343 -0
  7. data/app/controllers/anoubis/core/data/actions.rb +962 -0
  8. data/app/controllers/anoubis/core/data/callbacks.rb +68 -0
  9. data/app/controllers/anoubis/core/data/convert.rb +407 -0
  10. data/app/controllers/anoubis/core/data/defaults.rb +217 -0
  11. data/app/controllers/anoubis/core/data/get.rb +531 -0
  12. data/app/controllers/anoubis/core/data/load.rb +89 -0
  13. data/app/controllers/anoubis/core/data/set.rb +49 -0
  14. data/app/controllers/anoubis/core/data/setup.rb +104 -0
  15. data/app/controllers/anoubis/core/data_controller.rb +28 -0
  16. data/app/controllers/anoubis/core/index/actions.rb +53 -0
  17. data/app/controllers/anoubis/core/index/callbacks.rb +23 -0
  18. data/app/controllers/anoubis/core/index_controller.rb +36 -0
  19. data/app/controllers/anoubis/etc/base.rb +52 -0
  20. data/app/controllers/anoubis/etc/data.rb +89 -0
  21. data/app/controllers/anoubis/etc/field.rb +468 -0
  22. data/app/controllers/anoubis/etc/field_options.rb +83 -0
  23. data/app/controllers/anoubis/etc/field_order.rb +51 -0
  24. data/app/controllers/anoubis/etc/filter.rb +251 -0
  25. data/app/controllers/anoubis/etc/menu.rb +101 -0
  26. data/app/controllers/anoubis/etc/model.rb +67 -0
  27. data/app/controllers/anoubis/etc/tab_item.rb +91 -0
  28. data/app/controllers/anoubis/etc.rb +8 -0
  29. data/app/controllers/anoubis/export.rb +47 -0
  30. data/app/controllers/anoubis/output/autocomplete.rb +30 -0
  31. data/app/controllers/anoubis/output/basic.rb +86 -0
  32. data/app/controllers/anoubis/output/data.rb +101 -0
  33. data/app/controllers/anoubis/output/delete.rb +41 -0
  34. data/app/controllers/anoubis/output/edit.rb +55 -0
  35. data/app/controllers/anoubis/output/frame.rb +227 -0
  36. data/app/controllers/anoubis/output/login.rb +71 -0
  37. data/app/controllers/anoubis/output/menu.rb +220 -0
  38. data/app/controllers/anoubis/output/update.rb +43 -0
  39. data/app/controllers/anoubis/sso/client/application_controller.rb +139 -0
  40. data/app/controllers/anoubis/sso/client/data/actions.rb +5 -0
  41. data/app/controllers/anoubis/sso/client/data/callbacks.rb +5 -0
  42. data/app/controllers/anoubis/sso/client/data/convert.rb +5 -0
  43. data/app/controllers/anoubis/sso/client/data/defaults.rb +5 -0
  44. data/app/controllers/anoubis/sso/client/data/get.rb +5 -0
  45. data/app/controllers/anoubis/sso/client/data/load.rb +26 -0
  46. data/app/controllers/anoubis/sso/client/data/set.rb +5 -0
  47. data/app/controllers/anoubis/sso/client/data/setup.rb +5 -0
  48. data/app/controllers/anoubis/sso/client/data_controller.rb +21 -0
  49. data/app/controllers/anoubis/sso/client/index/actions.rb +79 -0
  50. data/app/controllers/anoubis/sso/client/index/callbacks.rb +13 -0
  51. data/app/controllers/anoubis/sso/client/index_controller.rb +18 -0
  52. data/app/controllers/anoubis/sso/server/application_controller.rb +49 -0
  53. data/app/controllers/anoubis/sso/server/login_controller.rb +342 -0
  54. data/app/controllers/anoubis/sso/server/user_controller.rb +142 -0
  55. data/app/controllers/anoubis/tenant/application_controller.rb +54 -0
  56. data/app/controllers/anoubis/tenant/data/actions.rb +11 -0
  57. data/app/controllers/anoubis/tenant/data/callbacks.rb +11 -0
  58. data/app/controllers/anoubis/tenant/data/convert.rb +11 -0
  59. data/app/controllers/anoubis/tenant/data/defaults.rb +11 -0
  60. data/app/controllers/anoubis/tenant/data/get.rb +11 -0
  61. data/app/controllers/anoubis/tenant/data/load.rb +52 -0
  62. data/app/controllers/anoubis/tenant/data/set.rb +11 -0
  63. data/app/controllers/anoubis/tenant/data/setup.rb +11 -0
  64. data/app/controllers/anoubis/tenant/data_controller.rb +28 -0
  65. data/app/controllers/anoubis/tenant/index/actions.rb +191 -0
  66. data/app/controllers/anoubis/tenant/index/callbacks.rb +11 -0
  67. data/app/controllers/anoubis/tenant/index_controller.rb +38 -0
  68. data/app/controllers/anoubis/tenants_controller.rb +7 -0
  69. data/app/controllers/anoubis/users_controller.rb +7 -0
  70. data/app/jobs/anoubis/application_job.rb +6 -0
  71. data/app/mailers/anoubis/application_mailer.rb +8 -0
  72. data/app/models/anoubis/application_record.rb +45 -0
  73. data/app/models/anoubis/core/application_record.rb +250 -0
  74. data/app/models/anoubis/core/locales.rb +27 -0
  75. data/app/models/anoubis/sso/client/application_record.rb +3 -0
  76. data/app/models/anoubis/sso/client/group.rb +19 -0
  77. data/app/models/anoubis/sso/client/group_menu.rb +109 -0
  78. data/app/models/anoubis/sso/client/menu.rb +145 -0
  79. data/app/models/anoubis/sso/client/user.rb +81 -0
  80. data/app/models/anoubis/sso/client/user_group.rb +32 -0
  81. data/app/models/anoubis/sso/server/system.rb +36 -0
  82. data/app/models/anoubis/sso/server/user.rb +79 -0
  83. data/app/models/anoubis/tenant/application_record.rb +41 -0
  84. data/app/models/anoubis/tenant/group.rb +95 -0
  85. data/app/models/anoubis/tenant/group_locale.rb +19 -0
  86. data/app/models/anoubis/tenant/group_menu.rb +84 -0
  87. data/app/models/anoubis/tenant/menu.rb +156 -0
  88. data/app/models/anoubis/tenant/menu_locale.rb +27 -0
  89. data/app/models/anoubis/tenant/system.rb +127 -0
  90. data/app/models/anoubis/tenant/system_locale.rb +19 -0
  91. data/app/models/anoubis/tenant/system_menu.rb +51 -0
  92. data/app/models/anoubis/tenant/tenant.rb +107 -0
  93. data/app/models/anoubis/tenant/tenant_system.rb +19 -0
  94. data/app/models/anoubis/tenant/user.rb +225 -0
  95. data/app/models/anoubis/tenant/user_group.rb +32 -0
  96. data/app/services/anoubis/core_service.rb +16 -0
  97. data/app/services/anoubis/session_service.rb +17 -0
  98. data/app/validators/presence_in_tenant_validator.rb +20 -0
  99. data/config/initializers/mime_type.rb +1 -0
  100. data/config/locales/en.yml +120 -0
  101. data/config/locales/ru.yml +245 -0
  102. data/config/routes.rb +74 -0
  103. data/db/migrate/20181018085843_create_tenants.rb +13 -0
  104. data/db/migrate/20181018111217_create_systems.rb +10 -0
  105. data/db/migrate/20181018111713_create_tenant_systems.rb +11 -0
  106. data/db/migrate/20181018111925_create_groups.rb +13 -0
  107. data/db/migrate/20181018112151_create_users.rb +25 -0
  108. data/db/migrate/20181018115737_add_title_to_users.rb +10 -0
  109. data/db/migrate/20181022060211_create_menus.rb +18 -0
  110. data/db/migrate/20181115055245_create_group_menus.rb +12 -0
  111. data/db/migrate/20181115060830_create_system_menus.rb +11 -0
  112. data/db/migrate/20181122062131_create_user_groups.rb +11 -0
  113. data/db/migrate/20181221060727_create_menu_locales.rb +14 -0
  114. data/db/migrate/20181225062303_create_system_locales.rb +11 -0
  115. data/db/migrate/20181225062339_create_group_locales.rb +11 -0
  116. data/db/seeds.rb +268 -0
  117. data/lib/anoubis/engine.rb +13 -0
  118. data/lib/anoubis/version.rb +5 -0
  119. data/lib/anoubis.rb +213 -0
  120. data/lib/tasks/anubis_tasks.rake +10 -0
  121. data/lib/tasks/sessions/clear_sessions.rake +10 -0
  122. data/spec/anubis_spec.rb +5 -0
  123. data/spec/controllers/anoubis/index_controller_spec.rb +77 -0
  124. data/spec/dummy/Rakefile +3 -0
  125. data/spec/dummy/app/assets/config/manifest.js +2 -0
  126. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  127. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  128. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  129. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  130. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  131. data/spec/dummy/app/jobs/application_job.rb +2 -0
  132. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  133. data/spec/dummy/app/models/application_record.rb +3 -0
  134. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  135. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  136. data/spec/dummy/bin/bundle +3 -0
  137. data/spec/dummy/bin/rails +4 -0
  138. data/spec/dummy/bin/rake +4 -0
  139. data/spec/dummy/bin/setup +33 -0
  140. data/spec/dummy/bin/update +28 -0
  141. data/spec/dummy/config/application.rb +14 -0
  142. data/spec/dummy/config/boot.rb +5 -0
  143. data/spec/dummy/config/cable.yml +10 -0
  144. data/spec/dummy/config/database.yml +54 -0
  145. data/spec/dummy/config/environment.rb +5 -0
  146. data/spec/dummy/config/environments/development.rb +54 -0
  147. data/spec/dummy/config/environments/production.rb +85 -0
  148. data/spec/dummy/config/environments/test.rb +46 -0
  149. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  150. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  151. data/spec/dummy/config/initializers/cors.rb +16 -0
  152. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  153. data/spec/dummy/config/initializers/inflections.rb +16 -0
  154. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  155. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  156. data/spec/dummy/config/locales/en.yml +33 -0
  157. data/spec/dummy/config/puma.rb +34 -0
  158. data/spec/dummy/config/routes.rb +3 -0
  159. data/spec/dummy/config/spring.rb +6 -0
  160. data/spec/dummy/config/storage.yml +34 -0
  161. data/spec/dummy/config.ru +5 -0
  162. data/spec/dummy/db/schema.rb +167 -0
  163. data/spec/dummy/db/seeds.rb +1 -0
  164. data/spec/factories/anubis_group_locales.rb +7 -0
  165. data/spec/factories/anubis_group_menus.rb +7 -0
  166. data/spec/factories/anubis_groups.rb +6 -0
  167. data/spec/factories/anubis_menu_locales.rb +9 -0
  168. data/spec/factories/anubis_menus.rb +6 -0
  169. data/spec/factories/anubis_system_locales.rb +7 -0
  170. data/spec/factories/anubis_system_menus.rb +6 -0
  171. data/spec/factories/anubis_systems.rb +5 -0
  172. data/spec/factories/anubis_tenants.rb +7 -0
  173. data/spec/factories/anubis_users.rb +10 -0
  174. data/spec/integration/navigation_test.rb +7 -0
  175. data/spec/models/anoubis/group_locale_spec.rb +25 -0
  176. data/spec/models/anoubis/group_menu_spec.rb +50 -0
  177. data/spec/models/anoubis/group_spec.rb +52 -0
  178. data/spec/models/anoubis/menu_locale_spec.rb +31 -0
  179. data/spec/models/anoubis/menu_spec.rb +48 -0
  180. data/spec/models/anoubis/system_locale_spec.rb +20 -0
  181. data/spec/models/anoubis/system_menu_spec.rb +49 -0
  182. data/spec/models/anoubis/system_spec.rb +53 -0
  183. data/spec/models/anoubis/tenant_spec.rb +67 -0
  184. data/spec/models/anoubis/user_spec.rb +57 -0
  185. data/spec/rails_helper.rb +32 -0
  186. data/spec/requests/anoubis/users_request_spec.rb +5 -0
  187. data/spec/spec_helper.rb +13 -0
  188. metadata +408 -0
@@ -0,0 +1,50 @@
1
+ require 'rails_helper'
2
+
3
+ module Anubis
4
+ RSpec.describe GroupMenu, type: :model do
5
+ before(:all) do
6
+ @system = create :system, ident: 'test'
7
+ @group = create :group, ident: 'test', system: @system
8
+ @menu1 = create :menu, mode: 'menu1', action: 'data'
9
+ @menu2 = create :menu, mode: 'menu2', action: 'data', menu: @menu1
10
+ @menu3 = create :menu, mode: 'menu3', action: 'data', menu: @menu2
11
+ create :system_menu, system: @system, menu: @menu3
12
+ end
13
+
14
+ it "can create" do
15
+ expect(build_stubbed(:group_menu, group: @group, menu: @menu1)).to be_valid
16
+ end
17
+
18
+ it "can create tree" do
19
+ expect(build_stubbed(:group_menu, group: @group, menu: @menu3)).to be_valid
20
+ end
21
+
22
+ it "check created tree" do
23
+ create :group_menu, group: @group, menu: @menu3
24
+ expect(Anubis::GroupMenu.where(group: @group).count(:id)).to eq 3
25
+ end
26
+
27
+ it "can destroy" do
28
+ data = create :group_menu, group: @group, menu: @menu1
29
+ data.destroy
30
+ expect(data.destroyed?).to eq true
31
+ end
32
+
33
+ it "can destroy tree" do
34
+ create :group_menu, group: @group, menu: @menu3
35
+ Anubis::GroupMenu.where(group: @group, menu: @menu1).first.destroy
36
+ expect(Anubis::GroupMenu.where(group: @group).count(:id)).to eq 0
37
+ end
38
+
39
+ after(:all) do
40
+ Anubis::SystemMenu.where(system: @system, menu: @menu1).first.destroy
41
+ @menu3.destroy
42
+ @menu2.destroy
43
+ @menu1.destroy
44
+ Anubis::Group.where(system_id: @system.id).each do |item|
45
+ item.destroy
46
+ end
47
+ @system.destroy
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,52 @@
1
+ require 'rails_helper'
2
+
3
+ module Anubis
4
+ RSpec.describe Group, type: :model do
5
+ it "is valid" do
6
+ expect(build_stubbed(:group)).to be_valid
7
+ end
8
+
9
+ it "has short ident" do
10
+ expect(build_stubbed(:group, ident: 'T'*2)).to be_invalid
11
+ end
12
+
13
+ it "has long ident" do
14
+ expect(build_stubbed(:group, ident: 'T'*51)).to be_invalid
15
+ end
16
+
17
+ it "has invalid ident" do
18
+ expect(build_stubbed(:group, ident: '1'*5)).to be_invalid
19
+ end
20
+
21
+ it "has duplicated ident" do
22
+ system = create :system
23
+ create :group, system: system
24
+ expect(build(:group, system: system)).to be_invalid
25
+ end
26
+
27
+ it "can change group" do
28
+ group = create :group
29
+ group.ident = 'wrkt'
30
+ expect(group.save).to eq true
31
+ end
32
+
33
+ it "can't change admin group ident" do
34
+ system = create :system
35
+ group = Anubis::Group.where(system: system, ident: 'admin').first
36
+ group.ident = 'tst'
37
+ expect(group.save).to eq false
38
+ end
39
+
40
+ it "can destroy" do
41
+ group = create :group, ident: 'dst'
42
+ group.destroy
43
+ expect(group.destroyed?).to eq true
44
+ end
45
+
46
+ it "can't destroy admin group of main system" do
47
+ group = Anubis::Group.where(system_id: 1, ident: 'admin').first
48
+ group.destroy
49
+ expect(group.destroyed?).to eq false
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,31 @@
1
+ require 'rails_helper'
2
+
3
+ module Anubis
4
+ RSpec.describe MenuLocale, type: :model do
5
+ it "has short title" do
6
+ expect(build_stubbed(:menu_locale, title: 'T'*2)).to be_invalid
7
+ end
8
+
9
+ it "has long title" do
10
+ expect(build_stubbed(:menu_locale, title: 'T'*101)).to be_invalid
11
+ end
12
+
13
+ it "has short page title" do
14
+ expect(build_stubbed(:menu_locale, page_title: 'T'*2)).to be_invalid
15
+ end
16
+
17
+ it "has long page title" do
18
+ expect(build_stubbed(:menu_locale, page_title: 'T'*201)).to be_invalid
19
+ end
20
+
21
+ it "has long short title" do
22
+ expect(build_stubbed(:menu_locale, short_title: 'T'*201)).to be_invalid
23
+ end
24
+
25
+ it "can change data" do
26
+ menu = create :menu_locale
27
+ menu.title = 'Test title 2'
28
+ expect(menu.save).to eq true
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,48 @@
1
+ require 'rails_helper'
2
+
3
+ module Anubis
4
+ RSpec.describe Menu, type: :model do
5
+ it "is valid" do
6
+ expect(build_stubbed(:menu)).to be_valid
7
+ end
8
+
9
+ it "has no action" do
10
+ expect(build_stubbed(:menu, action: nil)).to be_invalid
11
+ end
12
+
13
+ it "has no mode" do
14
+ expect(build_stubbed(:menu, mode: nil)).to be_invalid
15
+ end
16
+
17
+ it "has dublicate mode" do
18
+ create :menu
19
+ expect(build_stubbed(:menu)).to be_invalid
20
+ end
21
+
22
+ it "has invalid position" do
23
+ menu = create :menu
24
+ menu.position = 'dd'
25
+ expect(menu.save).to eq false
26
+ end
27
+
28
+ it "can change data" do
29
+ menu = create :menu
30
+ menu.mode = 'tst_data'
31
+ expect(menu.save).to eq true
32
+ end
33
+
34
+ it "can change position" do
35
+ menu1 = create :menu
36
+ menu2 = create :menu, mode: 'test2'
37
+ menu3 = create :menu, mode: 'test3'
38
+ menu3.position = menu1.position
39
+ expect(menu3.save).to eq true
40
+ end
41
+
42
+ it "can destroy" do
43
+ menu = create :menu
44
+ menu.destroy
45
+ expect(menu.destroyed?).to eq true
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ require 'rails_helper'
2
+
3
+ module Anubis
4
+ RSpec.describe SystemLocale, type: :model do
5
+ it "has short title" do
6
+ expect(build_stubbed(:system_locale, title: 'T'*2)).to be_invalid
7
+ end
8
+
9
+ it "has long title" do
10
+ expect(build_stubbed(:system_locale, title: 'T'*101)).to be_invalid
11
+ end
12
+
13
+ it "has duplicated title" do
14
+ system = create :system
15
+ create :system_locale, system: system
16
+ expect(build_stubbed(:system_locale, system: system)).to be_invalid
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,49 @@
1
+ require 'rails_helper'
2
+
3
+ module Anubis
4
+ RSpec.describe SystemMenu, type: :model do
5
+ before(:all) do
6
+ @system = create :system, ident: 'test'
7
+ #@group = create :group, ident: 'test', title: 'Test', system: @system
8
+ @menu1 = create :menu, mode: 'menu1', action: 'data'
9
+ @menu2 = create :menu, mode: 'menu2', action: 'data', menu: @menu1
10
+ @menu3 = create :menu, mode: 'menu3', action: 'data', menu: @menu2
11
+ end
12
+
13
+ it "can create" do
14
+ expect(build_stubbed(:system_menu, system: @system, menu: @menu1)).to be_valid
15
+ end
16
+
17
+ it "can create tree" do
18
+ expect(build_stubbed(:system_menu, system: @system, menu: @menu3)).to be_valid
19
+ end
20
+
21
+ it "check created tree" do
22
+ create :system_menu, system: @system, menu: @menu3
23
+ expect(Anubis::SystemMenu.where(system: @system).count(:id)).to eq 3
24
+ end
25
+
26
+ it "can destroy" do
27
+ data = create :system_menu, system: @system, menu: @menu1
28
+ data.destroy
29
+ expect(data.destroyed?).to eq true
30
+ end
31
+
32
+ it "can destroy tree" do
33
+ create :system_menu, system: @system, menu: @menu3
34
+ Anubis::SystemMenu.where(system: @system, menu: @menu1).first.destroy
35
+ expect(Anubis::SystemMenu.where(system: @system).count(:id)).to eq 0
36
+ end
37
+
38
+ after(:all) do
39
+ @menu3.destroy
40
+ @menu2.destroy
41
+ @menu1.destroy
42
+ #@group.destroy
43
+ Anubis::Group.where(system_id: @system.id).each do |item|
44
+ item.destroy
45
+ end
46
+ @system.destroy
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,53 @@
1
+ require 'rails_helper'
2
+
3
+ module Anubis
4
+ RSpec.describe System, type: :model do
5
+ it "is valid" do
6
+ expect(build_stubbed(:system)).to be_valid
7
+ end
8
+
9
+ it "has short ident" do
10
+ expect(build_stubbed(:system, ident: 'T'*2)).to be_invalid
11
+ end
12
+
13
+ it "has long ident" do
14
+ expect(build_stubbed(:system, ident: 'T'*16)).to be_invalid
15
+ end
16
+
17
+ it "has invalid ident" do
18
+ expect(build_stubbed(:system, ident: '1'*5)).to be_invalid
19
+ end
20
+
21
+ it "has duplicated ident" do
22
+ create :system
23
+ expect(build_stubbed(:system)).to be_invalid
24
+ end
25
+
26
+ it "can change system" do
27
+ system = create :system
28
+ system.ident = 'wrkt'
29
+ expect(system.save).to eq true
30
+ end
31
+
32
+ it "can't change main system ident" do
33
+ system = Anubis::System.find(1)
34
+ system.ident = 'tst'
35
+ expect(system.save).to eq false
36
+ end
37
+
38
+ it "can destroy" do
39
+ system = create :system, ident: 'dst'
40
+ Anubis::Group.where(system_id: system.id).each do |item|
41
+ item.destroy
42
+ end
43
+ system.destroy
44
+ expect(system.destroyed?).to eq true
45
+ end
46
+
47
+ it "can't destroy main system" do
48
+ system = Anubis::System.find(1)
49
+ system.destroy
50
+ expect(system.destroyed?).to eq false
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,67 @@
1
+ require 'rails_helper'
2
+
3
+ module Anubis
4
+ RSpec.describe Tenant, type: :model do
5
+ it "is valid" do
6
+ expect(build_stubbed(:tenant)).to be_valid
7
+ end
8
+
9
+ it "has short title" do
10
+ expect(build_stubbed(:tenant, title: 'T'*2)).to be_invalid
11
+ end
12
+
13
+ it "has long title" do
14
+ expect(build_stubbed(:tenant, title: 'T'*101)).to be_invalid
15
+ end
16
+
17
+ it "has short ident" do
18
+ expect(build_stubbed(:tenant, ident: 'T'*2)).to be_invalid
19
+ end
20
+
21
+ it "has long ident" do
22
+ expect(build_stubbed(:tenant, ident: 'T'*11)).to be_invalid
23
+ end
24
+
25
+ it "has invalid ident" do
26
+ expect(build_stubbed(:tenant, ident: '1'*5)).to be_invalid
27
+ end
28
+
29
+ it "has duplicated title" do
30
+ create :tenant
31
+ expect(build_stubbed(:tenant, ident: 'T'*5)).to be_invalid
32
+ end
33
+
34
+ it "has duplicated ident" do
35
+ create :tenant
36
+ expect(build_stubbed(:tenant, title: 'T'*10)).to be_invalid
37
+ end
38
+
39
+ it "can change tenant" do
40
+ tenant = create :tenant
41
+ tenant.title = 'Work Tenant Test'
42
+ tenant.ident = 'wrkt'
43
+ expect(tenant.save).to eq true
44
+ end
45
+
46
+ it "can't change system tenant ident" do
47
+ tenant = Anubis::Tenant.find(1)
48
+ tenant.ident = 'tst'
49
+ expect(tenant.save).to eq false
50
+ end
51
+
52
+ it "can destroy" do
53
+ tenant = create :tenant, title: 'Destroy', ident: 'dst'
54
+ Anubis::TenantSystem.where(tenant_id: tenant.id).each do |item|
55
+ item.destroy
56
+ end
57
+ tenant.destroy
58
+ expect(tenant.destroyed?).to eq true
59
+ end
60
+
61
+ it "can't destroy system tenant" do
62
+ tenant = Anubis::Tenant.find(1)
63
+ tenant.destroy
64
+ expect(tenant.destroyed?).to eq false
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,57 @@
1
+ require 'rails_helper'
2
+
3
+ module Anubis
4
+ RSpec.describe User, type: :model do
5
+ it "is valid" do
6
+ expect(build_stubbed(:user)).to be_valid
7
+ end
8
+
9
+ it "hasn't name" do
10
+ expect(build_stubbed(:user, name: nil)).to be_invalid
11
+ end
12
+
13
+ it "hasn't surname" do
14
+ expect(build_stubbed(:user, surname: nil)).to be_invalid
15
+ end
16
+
17
+ it "hasn't email" do
18
+ expect(build_stubbed(:user, email: nil)).to be_invalid
19
+ end
20
+
21
+ it "has incorrect email" do
22
+ expect(build_stubbed(:user, email: 'T'*10)).to be_invalid
23
+ end
24
+
25
+ it "has short pasword" do
26
+ expect(build_stubbed(:user, password: 'T'*4, password_confirmation: 'T'*4)).to be_invalid
27
+ end
28
+
29
+ it "has different paswords" do
30
+ expect(build_stubbed(:user, password: 'T'*5, password_confirmation: 'I'*5)).to be_invalid
31
+ end
32
+
33
+ it "has duplicated email" do
34
+ tenant = create :tenant
35
+ create :user, tenant: tenant
36
+ expect(build(:user, tenant: tenant)).to be_invalid
37
+ end
38
+
39
+ it "can change email" do
40
+ user = create :user
41
+ user.email = 'wrk@wrk.com'
42
+ expect(user.save).to eq true
43
+ end
44
+
45
+ it "can destroy user" do
46
+ user = create :user
47
+ user.destroy
48
+ expect(user.destroyed?).to eq true
49
+ end
50
+
51
+ it "can't destroy Main Administrator" do
52
+ user = Anubis::User.find(1)
53
+ user.destroy
54
+ expect(user.destroyed?).to eq false
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ ENV['RAILS_ENV'] ||= 'test'
4
+ require File.expand_path('../dummy/config/environment', __FILE__)
5
+
6
+ # Prevent database truncation if the environment is production
7
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
8
+
9
+ require 'rspec/rails'
10
+
11
+ require 'factory_bot_rails'
12
+
13
+ begin
14
+ ActiveRecord::Migration.maintain_test_schema!
15
+ rescue ActiveRecord::PendingMigrationError => e
16
+ puts e.to_s.strip
17
+ exit 1
18
+ end
19
+ RSpec.configure do |config|
20
+ config.use_transactional_fixtures = true
21
+
22
+ config.infer_base_class_for_anonymous_controllers = false
23
+
24
+ config.order = "random"
25
+
26
+ config.infer_spec_type_from_file_location!
27
+
28
+ # Filter lines from Rails gems in backtraces.
29
+ config.filter_rails_from_backtrace!
30
+
31
+ config.include FactoryBot::Syntax::Methods
32
+ end
@@ -0,0 +1,5 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "Users", type: :request do
4
+
5
+ end
@@ -0,0 +1,13 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |expectations|
3
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4
+ end
5
+
6
+ config.mock_with :rspec do |mocks|
7
+ mocks.verify_partial_doubles = true
8
+ end
9
+
10
+ config.shared_context_metadata_behavior = :apply_to_host_groups
11
+
12
+ config.order = :random
13
+ end