releaf-permissions 1.1.19 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/releaf_permissions_manifest.js +1 -0
  3. data/app/builders/releaf/permissions/page/menu_builder.rb +5 -1
  4. data/app/controllers/releaf/permissions/sessions_controller.rb +1 -1
  5. data/lib/releaf/permissions/engine.rb +2 -2
  6. metadata +10 -58
  7. data/spec/builders/releaf/permissions/page/header_builder_spec.rb +0 -87
  8. data/spec/builders/releaf/permissions/page/layout_builder_spec.rb +0 -60
  9. data/spec/builders/releaf/permissions/page/menu_builder_spec.rb +0 -100
  10. data/spec/builders/releaf/permissions/profile/form_builder_spec.rb +0 -18
  11. data/spec/builders/releaf/permissions/roles/form_builder_spec.rb +0 -56
  12. data/spec/builders/releaf/permissions/roles/table_builder_spec.rb +0 -41
  13. data/spec/builders/releaf/permissions/users/form_builder_spec.rb +0 -23
  14. data/spec/builders/releaf/permissions/users/table_builder_spec.rb +0 -21
  15. data/spec/controllers/permissions/profile_controller_spec.rb +0 -39
  16. data/spec/controllers/permissions/users_controller_spec.rb +0 -28
  17. data/spec/features/profile_updating_spec.rb +0 -35
  18. data/spec/features/roles_spec.rb +0 -64
  19. data/spec/features/users_spec.rb +0 -107
  20. data/spec/lib/access_control_spec.rb +0 -66
  21. data/spec/lib/releaf/permissions/configuration_spec.rb +0 -38
  22. data/spec/lib/releaf/permissions/controller_support_spec.rb +0 -76
  23. data/spec/lib/releaf/permissions/default_controller_resolver_spec.rb +0 -49
  24. data/spec/lib/releaf/permissions/layout_spec.rb +0 -10
  25. data/spec/lib/releaf/permissions/profile_spec.rb +0 -11
  26. data/spec/lib/releaf/permissions/roles_spec.rb +0 -10
  27. data/spec/lib/releaf/permissions/settings_manager_spec.rb +0 -38
  28. data/spec/lib/releaf/permissions/users_spec.rb +0 -17
  29. data/spec/models/permissions/role_spec.rb +0 -13
  30. data/spec/models/permissions/user_spec.rb +0 -53
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7c4264ba9fe80c9bf3f40d63567fa899dd06e2e143c254eebf67b8410a0a1e6
4
- data.tar.gz: 1be0544255bf48992cfac81040a8f9ab33f4a75b9573e15023434a15b0f8d8fd
3
+ metadata.gz: 0623a5fb8f65df7425de74395566b750377c68cce26064fd8c8fbade05091bb0
4
+ data.tar.gz: af7ac5e232ed0b859a051ad9700ff14bfcd61b84dc1b130516bd878b9325bc16
5
5
  SHA512:
6
- metadata.gz: 17c66630b99273e5b21c9a26e4ae0a5bb0bc3664ca6a1898d8705f5e47154552484908d44eaf55164587c1f80a6aaa67e68e464a10c1b8073d4a0624b01f9cb9
7
- data.tar.gz: 0e77e47b996977719e0b096368a8ed87bb01aac80a78fb0073b5bb186534f17b2f45fb87a88864be441719725fffe2b9082ec916810bad9372adb913d6d3ccdf
6
+ metadata.gz: e11770c7153bafa05e50aff973b092871574bcd24bdd060f52b161f44237806096a0162afbfcc0b399db85e40d5e1e37550e0a320b2f04c82bdf7d86e0529122
7
+ data.tar.gz: 903fc5b48075e3d1bc14b1cafdb843269ba8c6133143e70782a9da5d8b4c56bdddb7f48798d3863796065f7dc48f67a3826c62387cc1b49b6aceb5466b832542
@@ -0,0 +1 @@
1
+ //= link controllers/releaf/permissions/sessions.css
@@ -13,6 +13,10 @@ class Releaf::Permissions::Page::MenuBuilder < Releaf::Builders::Page::MenuBuild
13
13
  end
14
14
 
15
15
  def controller_permitted?(controller_name)
16
- Releaf.application.config.permissions.access_control.new(user: controller.user).controller_permitted?(controller_name)
16
+ access_control.controller_permitted?(controller_name)
17
+ end
18
+
19
+ def access_control
20
+ @access_control ||= Releaf.application.config.permissions.access_control.new(user: controller.user)
17
21
  end
18
22
  end
@@ -4,7 +4,7 @@ class Releaf::Permissions::SessionsController < Devise::SessionsController
4
4
  helper_method :page_title
5
5
 
6
6
  def page_title
7
- Rails.application.class.parent_name
7
+ Rails.application.class.module_parent_name
8
8
  end
9
9
 
10
10
  protected
@@ -1,7 +1,7 @@
1
1
  module Releaf::Permissions
2
2
  class Engine < ::Rails::Engine
3
- initializer 'precompile', group: :all do |app|
4
- app.config.assets.precompile += %w(controllers/releaf/permissions/*)
3
+ initializer 'releaf_permissions.assets_precompile', group: :all do |app|
4
+ app.config.assets.precompile << "releaf_permissions_manifest.js"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: releaf-permissions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.19
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - CubeSystems
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-17 00:00:00.000000000 Z
11
+ date: 2020-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: releaf-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.1.19
19
+ version: 2.0.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 1.1.19
26
+ version: 2.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: devise
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -45,6 +45,7 @@ extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
47
  - LICENSE
48
+ - app/assets/config/releaf_permissions_manifest.js
48
49
  - app/assets/stylesheets/controllers/releaf/permissions/sessions.scss
49
50
  - app/builders/releaf/permissions/page/header_builder.rb
50
51
  - app/builders/releaf/permissions/page/layout_builder.rb
@@ -73,35 +74,11 @@ files:
73
74
  - lib/releaf/permissions/roles.rb
74
75
  - lib/releaf/permissions/settings_manager.rb
75
76
  - lib/releaf/permissions/users.rb
76
- - spec/builders/releaf/permissions/page/header_builder_spec.rb
77
- - spec/builders/releaf/permissions/page/layout_builder_spec.rb
78
- - spec/builders/releaf/permissions/page/menu_builder_spec.rb
79
- - spec/builders/releaf/permissions/profile/form_builder_spec.rb
80
- - spec/builders/releaf/permissions/roles/form_builder_spec.rb
81
- - spec/builders/releaf/permissions/roles/table_builder_spec.rb
82
- - spec/builders/releaf/permissions/users/form_builder_spec.rb
83
- - spec/builders/releaf/permissions/users/table_builder_spec.rb
84
- - spec/controllers/permissions/profile_controller_spec.rb
85
- - spec/controllers/permissions/users_controller_spec.rb
86
- - spec/features/profile_updating_spec.rb
87
- - spec/features/roles_spec.rb
88
- - spec/features/users_spec.rb
89
- - spec/lib/access_control_spec.rb
90
- - spec/lib/releaf/permissions/configuration_spec.rb
91
- - spec/lib/releaf/permissions/controller_support_spec.rb
92
- - spec/lib/releaf/permissions/default_controller_resolver_spec.rb
93
- - spec/lib/releaf/permissions/layout_spec.rb
94
- - spec/lib/releaf/permissions/profile_spec.rb
95
- - spec/lib/releaf/permissions/roles_spec.rb
96
- - spec/lib/releaf/permissions/settings_manager_spec.rb
97
- - spec/lib/releaf/permissions/users_spec.rb
98
- - spec/models/permissions/role_spec.rb
99
- - spec/models/permissions/user_spec.rb
100
77
  homepage: https://github.com/cubesystems/releaf
101
78
  licenses:
102
79
  - MIT
103
80
  metadata: {}
104
- post_install_message:
81
+ post_install_message:
105
82
  rdoc_options: []
106
83
  require_paths:
107
84
  - lib
@@ -116,33 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
93
  - !ruby/object:Gem::Version
117
94
  version: '0'
118
95
  requirements: []
119
- rubyforge_project:
120
- rubygems_version: 2.7.7
121
- signing_key:
96
+ rubygems_version: 3.0.8
97
+ signing_key:
122
98
  specification_version: 4
123
99
  summary: Built-in admin and role support for releaf
124
- test_files:
125
- - spec/builders/releaf/permissions/page/menu_builder_spec.rb
126
- - spec/builders/releaf/permissions/page/layout_builder_spec.rb
127
- - spec/builders/releaf/permissions/page/header_builder_spec.rb
128
- - spec/builders/releaf/permissions/roles/table_builder_spec.rb
129
- - spec/builders/releaf/permissions/roles/form_builder_spec.rb
130
- - spec/builders/releaf/permissions/profile/form_builder_spec.rb
131
- - spec/builders/releaf/permissions/users/table_builder_spec.rb
132
- - spec/builders/releaf/permissions/users/form_builder_spec.rb
133
- - spec/features/roles_spec.rb
134
- - spec/features/profile_updating_spec.rb
135
- - spec/features/users_spec.rb
136
- - spec/models/permissions/user_spec.rb
137
- - spec/models/permissions/role_spec.rb
138
- - spec/lib/releaf/permissions/settings_manager_spec.rb
139
- - spec/lib/releaf/permissions/configuration_spec.rb
140
- - spec/lib/releaf/permissions/roles_spec.rb
141
- - spec/lib/releaf/permissions/layout_spec.rb
142
- - spec/lib/releaf/permissions/controller_support_spec.rb
143
- - spec/lib/releaf/permissions/profile_spec.rb
144
- - spec/lib/releaf/permissions/users_spec.rb
145
- - spec/lib/releaf/permissions/default_controller_resolver_spec.rb
146
- - spec/lib/access_control_spec.rb
147
- - spec/controllers/permissions/users_controller_spec.rb
148
- - spec/controllers/permissions/profile_controller_spec.rb
100
+ test_files: []
@@ -1,87 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::Page::HeaderBuilder, type: :class do
4
- class PageHeaderBuilderTestHelper < ActionView::Base
5
- include Rails.application.routes.url_helpers
6
- include FontAwesome::Rails::IconHelper
7
-
8
- def protect_against_forgery?
9
- true
10
- end
11
-
12
- def form_authenticity_token
13
- "xxx"
14
- end
15
-
16
- def request_forgery_protection_token
17
- "yyy"
18
- end
19
- end
20
-
21
- subject { described_class.new(template) }
22
- let(:template){ PageHeaderBuilderTestHelper.new }
23
-
24
- describe "#items" do
25
- it "returns array of home link, profile block and logout form content" do
26
- allow(subject).to receive(:home_link).and_return("a")
27
- allow(subject).to receive(:profile_block).and_return("b")
28
- allow(subject).to receive(:sign_out_form).and_return("c")
29
- expect(subject.items).to eq(["a", "b", "c"])
30
- end
31
- end
32
-
33
- describe "#profile_path" do
34
- it "returns profile edit url for defined profile controller" do
35
- expect(subject.profile_path).to eq("/admin/profile")
36
- end
37
- end
38
-
39
- describe "#profile_block" do
40
- it "returns profile block with content" do
41
- allow(subject).to receive(:profile_user_name).and_return("neim")
42
- allow(subject).to receive(:profile_path).and_return("url_b")
43
- content = '<a class="button profile" href="url_b"><span class="name">neim</span></a>'
44
- expect(subject.profile_block).to eq(content)
45
- end
46
- end
47
-
48
- describe "#user" do
49
- it "returns permissions manager user" do
50
- controller = Releaf::RootController.new
51
- allow(subject).to receive(:controller).and_return(controller)
52
- allow(controller).to receive(:user).and_return("x")
53
- expect(subject.user).to eq("x")
54
- end
55
- end
56
-
57
- describe "#profile_user_name" do
58
- it "returns title for user instance" do
59
- user = Releaf::Permissions::User.new(name: "a", surname: "b")
60
- allow(subject).to receive(:user).and_return(user)
61
- allow(subject).to receive(:resource_title).with(user).and_return("x t")
62
- expect(subject.profile_user_name).to eq("x t")
63
- end
64
- end
65
-
66
- describe "#sign_out_path" do
67
- it "returns sign out url" do
68
- expect(subject.sign_out_path).to eq("/admin/sign_out")
69
- end
70
- end
71
-
72
- describe "#sign_out_form" do
73
- it "returns sign out form" do
74
- allow(subject).to receive(:sign_out_path).and_return("url_a")
75
- content = %Q[
76
- <form class="sign-out" action="url_a" accept-charset="UTF-8" method="post">
77
- <input name="utf8" type="hidden" value="&#x2713;" />
78
- <input type="hidden" name="_method" value="delete" />
79
- <input type="hidden" name="yyy" value="xxx" />
80
- <button class="button only-icon" type="submit" title="Sign out">
81
- <i class="fa fa-power-off fa-icon-header"></i>
82
- </button>
83
- </form>]
84
- expect(subject.sign_out_form).to match_html( content )
85
- end
86
- end
87
- end
@@ -1,60 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::Page::LayoutBuilder, type: :class do
4
- class PermissionsLayoutBuilderView < ActionView::Base; end
5
-
6
- let(:controller){ Releaf::RootController.new }
7
- let(:template){ PermissionsLayoutBuilderView.new }
8
- subject { described_class.new(template) }
9
-
10
- before do
11
- allow(subject).to receive(:controller).and_return(controller)
12
- end
13
-
14
- it "inherits Releaf::Builders::Page::LayoutBuilder" do
15
- expect(described_class.superclass).to eq(Releaf::Builders::Page::LayoutBuilder)
16
- end
17
-
18
- describe "#header_builder" do
19
- it "returns `Releaf::Permissions::Page::HeaderBuilder` class" do
20
- expect(subject.header_builder).to eq(Releaf::Permissions::Page::HeaderBuilder)
21
- end
22
- end
23
-
24
- describe "#menu_builder" do
25
- it "returns `Releaf::Permissions::Page::MenuBuilder` class" do
26
- expect(subject.menu_builder).to eq(Releaf::Permissions::Page::MenuBuilder)
27
- end
28
- end
29
-
30
- describe "#body_content_blocks" do
31
- before do
32
- allow(subject).to receive(:header).and_return("_header")
33
- allow(subject).to receive(:menu).and_return("_menu")
34
- allow(subject).to receive(:notifications).and_return("_notifications")
35
- allow(subject).to receive(:assets).and_return("_assets_")
36
- end
37
-
38
- context "when controller responds to `authorized?` and `authorized?` call return true" do
39
- it "returns `super` content" do
40
- allow(controller).to receive(:authorized?).and_return(true)
41
- expect(subject.body_content_blocks{ "x" }).to eq(["_header", "_menu", "<main id=\"main\">x</main>",
42
- "_notifications", "_assets_"])
43
- end
44
- end
45
-
46
- context "when controller responds to `authorized?` and `authorized?` call return false" do
47
- it "returns given block content" do
48
- allow(controller).to receive(:authorized?).and_return(false)
49
- expect(subject.body_content_blocks{ "x" }).to eq(["x"])
50
- end
51
- end
52
-
53
- context "when controller does not responds to `authorized?`" do
54
- it "returns given block content" do
55
- allow(controller).to receive(:respond_to?).with(:authorized?).and_return(false)
56
- expect(subject.body_content_blocks{ "x" }).to eq(["x"])
57
- end
58
- end
59
- end
60
- end
@@ -1,100 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::Page::MenuBuilder, type: :class do
4
- class MenuBuilderTestHelper < ActionView::Base
5
- include FontAwesome::Rails::IconHelper
6
- end
7
-
8
- let(:controller){ Releaf::ActionController.new }
9
- let(:template){ MenuBuilderTestHelper.new }
10
- let(:group_item){ Releaf::ControllerGroupDefinition.new(name: "x", items: []) }
11
- let(:controller_item){ Releaf::ControllerDefinition.new(name: "y", controller: "_controller_") }
12
- subject { described_class.new(template) }
13
-
14
- before do
15
- allow(template).to receive(:controller).and_return(controller)
16
- end
17
-
18
- it "inherits `Releaf::Builders::Page::MenuBuilder`" do
19
- expect(described_class.ancestors).to include(Releaf::Builders::Page::MenuBuilder)
20
- end
21
-
22
- describe "#menu_item" do
23
- before do
24
- allow(subject).to receive(:item_attributes).and_return({})
25
- allow(subject).to receive(:menu_item_group).and_return("_content_")
26
- end
27
-
28
- context "when item is permitted" do
29
- it "returns parent method content" do
30
- allow(subject).to receive(:menu_item_permitted?).with(group_item).and_return(true)
31
- expect(subject.menu_item(group_item)).to eq("<li>_content_</li>")
32
- end
33
- end
34
-
35
- context "when item is not permitted" do
36
- it "returns nil" do
37
- allow(subject).to receive(:menu_item_permitted?).with(group_item).and_return(false)
38
- expect(subject.menu_item(group_item)).to be nil
39
- end
40
- end
41
- end
42
-
43
- describe "#menu_item_permitted?" do
44
- context "when item is instance of `Releaf::ControllerGroupDefinition`" do
45
- before do
46
- allow(group_item).to receive(:controllers).and_return([
47
- Releaf::ControllerDefinition.new(name: "a1", controller: "c1"),
48
- Releaf::ControllerDefinition.new(name: "a2", controller: "c2"),
49
- Releaf::ControllerDefinition.new(name: "a3", controller: "c3"),
50
- ])
51
- end
52
-
53
- context "when any of group item controller is allowed" do
54
- it "returns true" do
55
- allow(subject).to receive(:controller_permitted?).with("c1").and_return(false)
56
- allow(subject).to receive(:controller_permitted?).with("c2").and_return(true)
57
- expect(subject).to_not receive(:controller_permitted?).with("c3")
58
- expect(subject.menu_item_permitted?(group_item)).to be true
59
- end
60
- end
61
-
62
- context "when none of group item controller is allowed" do
63
- it "returns false" do
64
- allow(subject).to receive(:controller_permitted?).with("c1").and_return(false)
65
- allow(subject).to receive(:controller_permitted?).with("c2").and_return(false)
66
- allow(subject).to receive(:controller_permitted?).with("c3").and_return(false)
67
- expect(subject.menu_item_permitted?(group_item)).to be false
68
- end
69
- end
70
- end
71
-
72
- context "when item is instance of `Releaf::ControllerDefinition`" do
73
- context "when item controller is allowed" do
74
- it "returns true" do
75
- allow(subject).to receive(:controller_permitted?).with("_controller_").and_return(true)
76
- expect(subject.menu_item_permitted?(controller_item)).to be true
77
- end
78
- end
79
-
80
- context "when item controller is not allowed" do
81
- it "returns false" do
82
- allow(subject).to receive(:controller_permitted?).with("_controller_").and_return(false)
83
- expect(subject.menu_item_permitted?(controller_item)).to be false
84
- end
85
- end
86
- end
87
- end
88
-
89
- describe "#controller_permitted?" do
90
- it "returns access controller controller permission query result for given controller name" do
91
- user = Releaf::Permissions::User.new
92
- allow(controller).to receive(:user).and_return("x")
93
- access_control = Releaf::Permissions::AccessControl.new(user: user)
94
- allow(Releaf.application.config.permissions.access_control).to receive(:new).with(user: "x").and_return(access_control)
95
- allow(access_control).to receive(:controller_permitted?).with("kjasdasd").and_return("_true")
96
-
97
- expect(subject.controller_permitted?("kjasdasd")).to eq("_true")
98
- end
99
- end
100
- end
@@ -1,18 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::Profile::FormBuilder, type: :class do
4
- class FormBuilderTestHelper < ActionView::Base; end
5
- let(:template){ FormBuilderTestHelper.new }
6
- let(:object){ Releaf::Permissions::User.new }
7
- let(:subject){ described_class.new(:resource, object, template, {}) }
8
-
9
- it "inherits Releaf::Permissions::Users::FormBuilder" do
10
- expect(described_class.superclass).to eq(Releaf::Permissions::Users::FormBuilder)
11
- end
12
-
13
- describe "#field_names" do
14
- it "returns name, surname, locale, email, password and password_confirmation as field names array" do
15
- expect(subject.field_names).to eq(%w(name surname locale email password password_confirmation))
16
- end
17
- end
18
- end
@@ -1,56 +0,0 @@
1
- require 'rails_helper'
2
-
3
- describe Releaf::Permissions::Roles::FormBuilder, type: :class do
4
- class FormBuilderTestHelper < ActionView::Base; end
5
- let(:template){ FormBuilderTestHelper.new }
6
- let(:object){ Releaf::Permissions::Role.new }
7
- let(:subject){ described_class.new(:resource, object, template, {}) }
8
-
9
- before do
10
- allow(Releaf.application.config).to receive(:available_controllers)
11
- .and_return(["releaf/content/nodes", "admin/chapters"])
12
-
13
- definition_1 = Releaf::ControllerDefinition.new("xx")
14
- allow(definition_1).to receive(:localized_name).and_return("controller 1")
15
- allow(definition_1).to receive(:controller_name).and_return("admin/controller_1")
16
-
17
- definition_2 = Releaf::ControllerDefinition.new("xx")
18
- allow(definition_2).to receive(:localized_name).and_return("controller 2")
19
- allow(definition_2).to receive(:controller_name).and_return("admin/controller_2")
20
-
21
- allow(Releaf::ControllerDefinition).to receive(:for).with("releaf/content/nodes").and_return(definition_1)
22
- allow(Releaf::ControllerDefinition).to receive(:for).with("admin/chapters").and_return(definition_2)
23
- end
24
-
25
- describe "#render_default_controller" do
26
- it "pass localized controller options to releaf item field" do
27
- translated_controllers = {
28
- "controller 1" => "admin/controller_1",
29
- "controller 2" => "admin/controller_2"
30
- }
31
-
32
- allow(subject).to receive(:releaf_item_field)
33
- .with(:default_controller, options: {select_options: translated_controllers})
34
- .and_return("x")
35
- expect(subject.render_default_controller).to eq("x")
36
- end
37
- end
38
-
39
- describe "#render_permissions" do
40
- it "returns associated set field" do
41
- options = {association: {items: "x", field: :permission}}
42
- allow(subject).to receive(:permission_items).and_return("x")
43
- allow(subject).to receive(:releaf_associated_set_field).with(:permissions, options: options).and_return("y")
44
- expect(subject.render_permissions).to eq("y")
45
- end
46
- end
47
-
48
- describe "#permission_items" do
49
- it "returns scoped and translated controller values" do
50
- expect(subject.permission_items).to eq(
51
- "controller.admin/controller_1" => "controller 1",
52
- "controller.admin/controller_2" => "controller 2"
53
- )
54
- end
55
- end
56
- end
@@ -1,41 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::Roles::TableBuilder, type: :class do
4
- class TableBuilderTestHelper < ActionView::Base; end
5
- let(:template){ TableBuilderTestHelper.new }
6
- let(:resource_class){ Releaf::Permissions::Role }
7
- let(:subject){ described_class.new([], resource_class, template, {}) }
8
-
9
- describe "#column_names" do
10
- it "returns name and default_controller as column names array" do
11
- expect(subject.column_names).to eq([:name, :default_controller])
12
- end
13
- end
14
-
15
- describe "#default_controller_content" do
16
- context "when given resource default controller definition exists" do
17
- it "returns localized controller name from definitioned followed by application name" do
18
- definition = Releaf::ControllerDefinition.new("xx")
19
- allow(definition).to receive(:localized_name).and_return("x")
20
- allow(Releaf::ControllerDefinition).to receive(:for).with("contr").and_return(definition)
21
- expect(subject.default_controller_content(resource_class.new(default_controller: "contr"))).to eq("x")
22
- end
23
- end
24
-
25
- context "when given resource default controller definition does not exist" do
26
- it "returns dash" do
27
- definition = Releaf::ControllerDefinition.new("xx")
28
- allow(definition).to receive(:localized_name).and_return("x")
29
- allow(Releaf::ControllerDefinition).to receive(:for).with("contr").and_return(nil)
30
- expect(subject.default_controller_content(resource_class.new(default_controller: "contr"))).to eq("-")
31
- end
32
- end
33
-
34
- context "when default controller is not defined for given resource" do
35
- it "returns dash" do
36
- expect(Releaf::ControllerDefinition).to_not receive(:for)
37
- expect(subject.default_controller_content(resource_class.new)).to eq("-")
38
- end
39
- end
40
- end
41
- end
@@ -1,23 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::Users::FormBuilder, type: :class do
4
- class FormBuilderTestHelper < ActionView::Base; end
5
- let(:template){ FormBuilderTestHelper.new }
6
- let(:object){ Releaf::Permissions::Role.new }
7
- let(:subject){ described_class.new(:resource, object, template, {}) }
8
-
9
- describe "#field_names" do
10
- it "returns name, surname, locale, role_id, email, password and password_confirmation as field names array" do
11
- expect(subject.field_names).to eq(%w(name surname locale role_id email password password_confirmation))
12
- end
13
- end
14
-
15
- describe "#render_locale" do
16
- it "pass localized controller options to releaf item field" do
17
- allow(Releaf.application.config).to receive(:available_admin_locales).and_return(["de", "ze"])
18
- allow(subject).to receive(:locale_options).with(["de", "ze"]).and_return(["xx", "yy"])
19
- allow(subject).to receive(:releaf_item_field).with(:locale, options: {select_options: ["xx", "yy"]}).and_return("x")
20
- expect(subject.render_locale).to eq("x")
21
- end
22
- end
23
- end
@@ -1,21 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::Users::TableBuilder, type: :class do
4
- class TableBuilderTestHelper < ActionView::Base; end
5
- let(:template){ TableBuilderTestHelper.new }
6
- let(:resource_class){ Releaf::Permissions::User }
7
- let(:subject){ described_class.new([], resource_class, template, {}) }
8
-
9
- describe "#column_names" do
10
- it "returns name, surname, role, email and locale as column names array" do
11
- expect(subject.column_names).to eq([:name, :surname, :role, :email, :locale])
12
- end
13
- end
14
-
15
- describe "#locale_content" do
16
- it "returns translated locale" do
17
- allow(subject).to receive(:translate_locale).with("de").and_return("deutch")
18
- expect(subject.locale_content(resource_class.new(locale: "de"))).to eq("deutch")
19
- end
20
- end
21
- end
@@ -1,39 +0,0 @@
1
- require 'rails_helper'
2
-
3
- describe Releaf::Permissions::ProfileController do
4
- let(:another_role){ FactoryGirl.create(:content_role) }
5
- let(:user){ subject.current_releaf_permissions_user }
6
- login_as_user :user
7
-
8
- describe "#resource_class" do
9
- it "returns current releaf user user class" do
10
- expect(described_class.new.resource_class).to eq(Releaf::Permissions::User)
11
- end
12
- end
13
-
14
- describe "PATCH update" do
15
- context 'when attributes contain role_id' do
16
- it "does not update it" do
17
- expect{ patch :update, {resource: {role_id: another_role.id}} }.to_not change{ user.role_id }
18
- end
19
- end
20
-
21
- context 'with allowed attributes' do
22
- it "saves new attributes" do
23
- attributes = {
24
- "name" => "new name",
25
- "surname" => "new surname",
26
- "email" => "new.email@example.com",
27
- "locale" => "lv"
28
- }
29
-
30
- # This is needed in order to get same instance as we expect.
31
- # Otherwise we'll get same record, but different instance and test will fail
32
- allow( user ).to receive(:becomes).with(Releaf::Permissions::User).and_return(user)
33
-
34
- expect(user).to receive(:update_attributes).with(attributes)
35
- patch :update, {resource: attributes}
36
- end
37
- end
38
- end
39
- end
@@ -1,28 +0,0 @@
1
- require 'rails_helper'
2
-
3
- # use Admin::BooksController as it inherit Releaf::ActionController and
4
- # have no extra methods or overrides
5
- describe Releaf::Permissions::UsersController do
6
- before do
7
- sign_in FactoryGirl.create(:user)
8
- end
9
-
10
- describe "GET #new" do
11
- it "assigns default role" do
12
- get :new
13
- expect(assigns(:resource).role).to eq(Releaf::Permissions::Role.first)
14
- end
15
- end
16
-
17
- describe "GET #index" do
18
- before do
19
- FactoryGirl.create(:content_user, name: "John")
20
- FactoryGirl.create(:content_user, name: "Bill", surname: "Green", email: "another@example.com")
21
- end
22
-
23
- it "searches by name, surname and email" do
24
- get :index, search: "bill green another@example"
25
- expect(assigns(:collection).count).to eq(1)
26
- end
27
- end
28
- end
@@ -1,35 +0,0 @@
1
- require 'rails_helper'
2
- feature "User profile" do
3
- background do
4
- auth_as_user(false, FactoryGirl.create(:user, email: "email@example.com"))
5
- visit releaf_permissions_user_profile_path
6
- end
7
-
8
- scenario "name, surname and locale" do
9
- fill_in 'Name', with: "Edward"
10
- fill_in 'Surname', with: "Bat"
11
- select "Lv", from: "Locale"
12
- click_button 'Save'
13
-
14
- expect(page).to have_css('header .profile .name', text: "Edward Bat")
15
- end
16
-
17
- scenario "password and email" do
18
- # update
19
- fill_in 'Email', with: "new.email@example.com"
20
- fill_in 'Password', with: "newpassword123", match: :prefer_exact
21
- fill_in 'Password confirmation', with: "newpassword123", match: :prefer_exact
22
- click_button 'Save'
23
-
24
- # logout
25
- find('body > header form.sign-out button').click
26
-
27
- # login
28
- visit releaf_root_path
29
- fill_in 'Email', with: "new.email@example.com"
30
- fill_in 'Password', with: "newpassword123"
31
- click_button 'Sign in'
32
-
33
- expect(page).to have_css('.sign-out')
34
- end
35
- end
@@ -1,64 +0,0 @@
1
- require 'rails_helper'
2
- feature "Roles management", js: true do
3
- background do
4
- auth_as_user
5
- @role = Releaf::Permissions::Role.first
6
- end
7
-
8
- scenario "Role search", focus: true do
9
- create(:admin_role, name: 'super role')
10
- visit releaf_permissions_roles_path
11
- expect(page).to have_content @role.name
12
- expect(page).to have_content 'super role'
13
- search "super"
14
- expect(page).to have_no_content @role.name
15
- expect(page).to have_content 'super role'
16
- end
17
-
18
- scenario "User creates a new role" do
19
- visit releaf_permissions_roles_path
20
- create_resource do
21
- fill_in("Name", with: "second role")
22
- select('Admin/nodes', from: 'Default controller')
23
- end
24
- visit releaf_permissions_roles_path
25
- expect(page).to have_content "second role"
26
- end
27
-
28
- scenario "User updates an existing role" do
29
- visit releaf_permissions_roles_path
30
- click_link @role.name
31
- update_resource do
32
- fill_in("Name", with: "new name")
33
- end
34
-
35
- visit releaf_permissions_roles_path
36
- expect(page).to have_content "new name"
37
- end
38
-
39
- scenario "User changes the default controller of a role" do
40
- visit releaf_permissions_roles_path
41
- click_link @role.name
42
- update_resource do
43
- select('Admin/books', from: 'Default controller')
44
- end
45
-
46
- expect(page).to have_select('Default controller', selected: 'Admin/books')
47
- end
48
-
49
- scenario "User changes permissions of a role controller" do
50
- visit releaf_permissions_roles_path
51
- click_link @role.name
52
- update_resource do
53
- uncheck('Admin/books')
54
- end
55
-
56
- Releaf.application.config.available_controllers.each do |controller|
57
- if controller == "admin/books"
58
- expect(page).to have_unchecked_field(I18n.t(controller))
59
- else
60
- expect(page).to have_checked_field(I18n.t(controller))
61
- end
62
- end
63
- end
64
- end
@@ -1,107 +0,0 @@
1
- require 'rails_helper'
2
- feature "Users", js: true do
3
- let!(:user){ create(:user, email: "admin@example.com") }
4
- let!(:simple_user){ create(:content_user, email: "simple@example.com") }
5
-
6
- describe "users CRUD" do
7
- background do
8
- visit "/admin"
9
- within("form.login") do
10
- fill_in 'Email', with: user.email
11
- fill_in 'Password', with: user.password
12
- end
13
- click_button 'Sign in'
14
- expect(page).to have_css('body > header form.sign-out button')
15
- end
16
-
17
- scenario "new user creation", js: true do
18
- visit releaf_permissions_users_path
19
- create_resource do
20
- fill_in 'Name', with: "John"
21
- fill_in 'Surname', with: "Appleseed"
22
- fill_in 'Email', with: "john@example.com"
23
- fill_in 'Password', with: "password", match: :prefer_exact
24
- fill_in 'Password confirmation', with: "password", match: :prefer_exact
25
-
26
- expect(page).to have_select('Locale', options: ["", "En", "Lv"])
27
- select 'En', from: 'Locale'
28
- end
29
-
30
- expect(page).to have_content 'John Appleseed'
31
- visit '/admin/users'
32
- expect(page).to have_content 'john@example.com'
33
-
34
- visit (releaf_permissions_users_path)
35
- open_toolbox_dialog("Delete", Releaf::Permissions::User.last)
36
- click_button 'Yes'
37
- expect(page).not_to have_content 'john@example.com'
38
- end
39
-
40
- scenario "user search" do
41
- visit '/admin/users'
42
- expect(page).to have_content 'simple@example.com'
43
- search "admin@example.com"
44
- expect(page).not_to have_content 'simple@example.com'
45
- end
46
- end
47
-
48
- describe "login as user procedure" do
49
- background do
50
- visit "/admin"
51
- within("form.login") do
52
- fill_in 'Email', with: user.email
53
- fill_in 'Password', with: user.password
54
- end
55
- click_button 'Sign in'
56
- end
57
-
58
- scenario "user page content" do
59
- expect(page).to have_css('body > header form.sign-out button')
60
- expect(page).to have_content 'Admin/nodes'
61
- expect(page).to have_content 'Permissions'
62
- expect(page).to have_content 'Releaf/i18n database/translations'
63
- # admin/users index view
64
- expect(page).to have_content 'admin@example.com'
65
- expect(page).to have_content 'simple@example.com'
66
- end
67
-
68
- scenario "logout sequence" do
69
- find('body > header form.sign-out button').click
70
-
71
- expect(page).to have_content 'Welcome to Releaf'
72
-
73
- visit "/admin"
74
- expect(page).to have_content 'Sign in'
75
- end
76
- end
77
-
78
- describe "login as simple user procedure" do
79
- background do
80
- visit "/admin"
81
- within("form.login") do
82
- fill_in 'Email', with: simple_user.email
83
- fill_in 'Password', with: simple_user.password
84
- end
85
- click_button 'Sign in'
86
- end
87
-
88
- scenario "user page content" do
89
- expect(page).to have_css('body > header form.sign-out button')
90
- expect(page).to have_content 'Admin/nodes'
91
- end
92
-
93
- scenario "translations module access denied" do
94
- visit "/admin/translations"
95
- expect(page).to have_content 'You are not authorized to access translations'
96
- end
97
-
98
- scenario "logout sequence" do
99
- find('body > header form.sign-out button').click
100
-
101
- expect(page).to have_content 'Welcome to Releaf'
102
-
103
- visit "/admin"
104
- expect(page).to have_content 'Sign in'
105
- end
106
- end
107
- end
@@ -1,66 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::AccessControl do
4
- let(:role){ Releaf::Permissions::Role.new }
5
- let(:user){ Releaf::Permissions::User.new(role: role) }
6
- subject{ described_class.new(user: user) }
7
-
8
-
9
- describe "#controller_permitted?" do
10
- context "when allowed controllers contains given controller" do
11
- it "returns true" do
12
- allow(subject).to receive(:allowed_controllers).and_return(["a", "b"])
13
- expect(subject.controller_permitted?("a")).to be true
14
- end
15
- end
16
-
17
- context "when allowed controllers does not contain given controller" do
18
- it "returns false" do
19
- allow(subject).to receive(:allowed_controllers).and_return(["c", "b"])
20
- expect(subject.controller_permitted?("a")).to be false
21
- end
22
- end
23
- end
24
-
25
- describe "#allowed_controllers" do
26
- it "returns array with permanent allowed controllers and role allowed controllers" do
27
- allow(subject).to receive(:permanent_allowed_controllers).and_return(["a", "b"])
28
- allow(subject).to receive(:role_allowed_controllers).and_return(["c", "d"])
29
- expect(subject.allowed_controllers).to eq(%w(a b c d))
30
- end
31
- end
32
-
33
- describe "#permanent_allowed_controllers" do
34
- it "returns array with permanent allowed controllers" do
35
- allow(Releaf.application.config.permissions).to receive(:permanent_allowed_controllers).and_return("x")
36
- expect(subject.permanent_allowed_controllers).to eq("x")
37
- end
38
- end
39
-
40
- describe "#role_allowed_controllers" do
41
- it "returns array of roles allowed controllers" do
42
- role.permissions.build(permission: "controller.a")
43
- role.permissions.build(permission: "controller.x")
44
- role.permissions.build(permission: "export.some_data")
45
- allow(subject).to receive(:controller_name_from_permission).with("controller.a").and_return(nil)
46
- allow(subject).to receive(:controller_name_from_permission).with("controller.x").and_return("asd")
47
- allow(subject).to receive(:controller_name_from_permission).with("export.some_data").and_return("fd")
48
-
49
- expect(subject.role_allowed_controllers).to match_array(["asd", "fd"])
50
- end
51
- end
52
-
53
- describe "#controller_name_from_permission" do
54
- context "when given permission contains `controller`" do
55
- it "returns name" do
56
- expect(subject.controller_name_from_permission("controller.a")).to eq("a")
57
- end
58
- end
59
-
60
- context "when given permission does not contain `controller`" do
61
- it "returns nil" do
62
- expect(subject.controller_name_from_permission("aasd.a")).to be nil
63
- end
64
- end
65
- end
66
- end
@@ -1,38 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::Configuration do
4
- subject{ described_class.new(devise_for: "asd", access_control: "X", permanent_allowed_controllers: [1, 2]) }
5
-
6
- it do
7
- is_expected.to have_attributes(devise_for: "asd")
8
- is_expected.to have_attributes(access_control: "X")
9
- is_expected.to have_attributes(permanent_allowed_controllers: [1, 2])
10
- end
11
-
12
- describe "#devise_model_name" do
13
- it "returns devise model name with slashes replaced by underscores" do
14
- subject.devise_for = "releaf/permissions/user"
15
- expect(subject.devise_model_name).to eq("releaf_permissions_user")
16
- end
17
- end
18
-
19
- describe "#devise_model_class" do
20
- it "returns devise model class" do
21
- subject.devise_for = "releaf/permissions/role"
22
- expect(subject.devise_model_class).to eq(Releaf::Permissions::Role)
23
- end
24
- end
25
-
26
- describe ".configure_component" do
27
- it "adds `Releaf::Permissions::Configuration` configuration with devise, access_control and permanent allowed controllers configured" do
28
- allow(Releaf::Permissions::Configuration).to receive(:new)
29
- .with(
30
- devise_for: "releaf/permissions/user",
31
- access_control: Releaf::Permissions::AccessControl,
32
- permanent_allowed_controllers: ["releaf/root"]
33
- ).and_return("_new")
34
- expect(Releaf.application.config).to receive(:add_configuration).with("_new")
35
- described_class.configure_component
36
- end
37
- end
38
- end
@@ -1,76 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::ControllerSupport do
4
- let(:user){ Releaf::Permissions::User.new(locale: "de") }
5
-
6
- class AcessControllDummyController < Releaf::ActionController
7
- include Releaf::Permissions::ControllerSupport
8
- end
9
-
10
- subject{ AcessControllDummyController.new }
11
-
12
- before do
13
- allow(subject).to receive(:current_releaf_permissions_user).and_return(user)
14
- end
15
-
16
- describe "before filters" do
17
- it "prepends `:authenticate!, :verify_controller_access!, :set_locale` before filters" do
18
- all_before_actions = subject._process_action_callbacks.select{|f| f.kind == :before}.map{|f| f.filter }
19
- expect(all_before_actions).to start_with(:authenticate!, :verify_controller_access!, :set_locale)
20
- end
21
- end
22
-
23
- describe "#set_locale" do
24
- it "assigns user locale to I18n locale" do
25
- expect(I18n).to receive(:locale=).with("de")
26
- subject.set_locale
27
- end
28
- end
29
-
30
- describe "#verify_controller_access!" do
31
- let(:access_control){ Releaf::Permissions::AccessControl.new(user: user) }
32
-
33
- before do
34
- allow(subject).to receive(:short_name).and_return("some_controller")
35
- allow(Releaf.application.config.permissions.access_control).to receive(:new)
36
- .with(user: user).and_return(access_control)
37
- end
38
-
39
- context "when controller is not permitted" do
40
- it "raises `Releaf::AccessDenied exception`" do
41
- allow(access_control).to receive(:controller_permitted?).with("some_controller").and_return(false)
42
- expect{ subject.verify_controller_access! }.to raise_error(Releaf::AccessDenied)
43
- end
44
- end
45
-
46
- context "when controller is permitted" do
47
- it "does not raise `Releaf::AccessDenied exception`" do
48
- allow(access_control).to receive(:controller_permitted?).with("some_controller").and_return(true)
49
- expect{ subject.verify_controller_access! }.to_not raise_error
50
- end
51
- end
52
- end
53
-
54
- describe "#user" do
55
- it "returns current controller devise user instance" do
56
- expect(subject.user).to eq(user)
57
- end
58
- end
59
-
60
- describe "#authorized?" do
61
- it "returns whether devise has signed in current user" do
62
- allow(subject).to receive(:releaf_permissions_user_signed_in?).and_return(true)
63
- expect(subject.authorized?).to be true
64
-
65
- allow(subject).to receive(:releaf_permissions_user_signed_in?).and_return(false)
66
- expect(subject.authorized?).to be false
67
- end
68
- end
69
-
70
- describe "#authenticate!" do
71
- it "returns whether devise has signed in current user" do
72
- expect(subject).to receive(:authenticate_releaf_permissions_user!)
73
- subject.authenticate!
74
- end
75
- end
76
- end
@@ -1,49 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::DefaultControllerResolver do
4
- subject{ described_class.new(current_controller: Releaf::RootController.new) }
5
-
6
- it "inherit `Releaf::Root::DefaultControllerResolver`" do
7
- expect(described_class.ancestors.include?(Releaf::Root::DefaultControllerResolver)).to be true
8
- end
9
-
10
- describe ".configure_component" do
11
- it "adds itself as default controller resolver" do
12
- expect(Releaf.application.config.root).to receive(:default_controller_resolver=).with(described_class)
13
- described_class.configure_component
14
- end
15
- end
16
-
17
- describe "#controllers" do
18
- it "returns user available controllers with role default controller as first" do
19
- role = Releaf::Permissions::Role.new(default_controller: "a")
20
- user = Releaf::Permissions::User.new(role: role)
21
- allow(Releaf.application.config).to receive(:available_controllers).and_return(["a", "b", "c"])
22
- allow(subject).to receive(:user).and_return(user)
23
-
24
- allow(subject).to receive(:allowed_controllers).and_return(["a", "c", "d"])
25
- expect(subject.controllers).to eq(["a", "c"])
26
-
27
- allow(subject).to receive(:allowed_controllers).and_return(["c", "d"])
28
- expect(subject.controllers).to eq(["c"])
29
- end
30
- end
31
-
32
- describe "#allowed_controllers" do
33
- it "returns allowed controllers from access contro for given user" do
34
- allow(subject).to receive(:user).and_return("_user")
35
- access_control = Releaf::Permissions::AccessControl.new(user: Releaf::Permissions::User.new)
36
- allow(access_control).to receive(:allowed_controllers).and_return(["a", "d"])
37
- allow(Releaf.application.config.permissions.access_control).to receive(:new).with(user: "_user").and_return(access_control)
38
-
39
- expect(subject.allowed_controllers).to eq(["a", "d"])
40
- end
41
- end
42
-
43
- describe "#user" do
44
- it "returns controller user" do
45
- allow(subject.current_controller).to receive(:user).and_return("_user")
46
- expect(subject.user).to eq("_user")
47
- end
48
- end
49
- end
@@ -1,10 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::Layout do
4
- describe ".configure_component" do
5
- it "changes layout_builder_class_name to `Releaf::Permissions::Page::LayoutBuilder`" do
6
- expect(Releaf.application.config).to receive(:layout_builder_class_name=).with("Releaf::Permissions::Page::LayoutBuilder")
7
- described_class.configure_component
8
- end
9
- end
10
- end
@@ -1,11 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::Profile do
4
- describe ".configure_component" do
5
- it "adds `releaf/permissions/profile` to additional controllers" do
6
- expect(Releaf.application.config).to receive(:additional_controllers).and_return(["a", "b"])
7
- expect(Releaf.application.config).to receive(:additional_controllers=).with(["a", "b", "releaf/permissions/profile"])
8
- described_class.configure_component
9
- end
10
- end
11
- end
@@ -1,10 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::Roles do
4
- describe ".draw_component_routes" do
5
- it "register roles resource route" do
6
- expect(described_class).to receive(:resource_route).with("_router", :permissions, :roles)
7
- described_class.draw_component_routes("_router")
8
- end
9
- end
10
- end
@@ -1,38 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::SettingsManager do
4
- let(:controller){ Releaf::RootController.new }
5
- let(:user){ Releaf::Permissions::User.new }
6
-
7
- before do
8
- allow(user.settings).to receive(:[]).with("asd.a").and_return("lalal")
9
- allow(controller).to receive(:user).and_return(user)
10
- end
11
-
12
- describe ".configure_component" do
13
- it "registers itself as settings manager" do
14
- expect(Releaf.application.config).to receive(:settings_manager=).and_return(described_class)
15
- described_class.configure_component
16
- end
17
- end
18
-
19
- describe ".read" do
20
- it "returns user settings for given key" do
21
- expect(described_class.read(controller: controller, key: "asd.a")).to eq("lalal")
22
- end
23
-
24
- context "when controller has no user method" do
25
- it "returns nil" do
26
- allow(controller).to receive(:respond_to?).with(:user).and_return(false)
27
- expect(described_class.read(controller: controller, key: "asd.a")).to be nil
28
- end
29
- end
30
- end
31
-
32
- describe ".write" do
33
- it "writes user settings for given key and value" do
34
- expect(user.settings).to receive(:[]=).with("asd.a", "op")
35
- described_class.write(controller: controller, key: "asd.a", value: "op")
36
- end
37
- end
38
- end
@@ -1,17 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::Users do
4
- describe ".configure_component" do
5
- it "sets `releaf/permissions/user` as devise model" do
6
- expect(Releaf.application.config.permissions).to receive(:devise_for=).with("releaf/permissions/user")
7
- described_class.configure_component
8
- end
9
- end
10
-
11
- describe ".draw_component_routes" do
12
- it "register users resource route" do
13
- expect(described_class).to receive(:resource_route).with("_router", :permissions, :users)
14
- described_class.draw_component_routes("_router")
15
- end
16
- end
17
- end
@@ -1,13 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::Role do
4
- describe 'validations' do
5
- it { is_expected.to validate_presence_of(:name) }
6
- it { is_expected.to validate_presence_of(:default_controller) }
7
- it { is_expected.to validate_uniqueness_of(:name).case_insensitive }
8
- end
9
-
10
- describe 'associations' do
11
- it { is_expected.to have_many(:users).dependent(:restrict_with_exception) }
12
- end
13
- end
@@ -1,53 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Permissions::User do
4
- describe 'validations' do
5
- it { is_expected.to validate_presence_of(:name) }
6
- it { is_expected.to validate_presence_of(:surname) }
7
- it { is_expected.to validate_presence_of(:role) }
8
- it { is_expected.to validate_presence_of(:locale) }
9
- it { is_expected.to validate_presence_of(:email) }
10
- it { create(:user); is_expected.to validate_uniqueness_of(:email).case_insensitive }
11
- end
12
-
13
- describe 'associations' do
14
- it { is_expected.to belong_to(:role) }
15
- end
16
-
17
- describe "#releaf_title" do
18
- it "returns concated name and surname" do
19
- subject.name = "John"
20
- subject.surname = "Baum"
21
- expect(subject.releaf_title).to eq("John Baum")
22
- end
23
- end
24
-
25
- describe "#password_required?" do
26
- context "when existing record" do
27
- before do
28
- allow(subject).to receive(:new_record?).and_return(false)
29
- end
30
-
31
- context "when new password is blank" do
32
- it "returns true" do
33
- allow(subject).to receive(:encrypted_password).and_return("")
34
- expect(subject.password_required?).to be true
35
- end
36
- end
37
-
38
- context "when new password is not blank" do
39
- it "returns false" do
40
- allow(subject).to receive(:encrypted_password).and_return("asdasd")
41
- expect(subject.password_required?).to be false
42
- end
43
- end
44
- end
45
-
46
- context "when new record" do
47
- it "returns true" do
48
- allow(subject).to receive(:new_record?).and_return(true)
49
- expect(subject.password_required?).to be true
50
- end
51
- end
52
- end
53
- end