releaf-permissions 2.0.0 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. metadata +6 -54
  3. data/spec/builders/releaf/permissions/page/header_builder_spec.rb +0 -86
  4. data/spec/builders/releaf/permissions/page/layout_builder_spec.rb +0 -60
  5. data/spec/builders/releaf/permissions/page/menu_builder_spec.rb +0 -112
  6. data/spec/builders/releaf/permissions/profile/form_builder_spec.rb +0 -18
  7. data/spec/builders/releaf/permissions/roles/form_builder_spec.rb +0 -56
  8. data/spec/builders/releaf/permissions/roles/table_builder_spec.rb +0 -41
  9. data/spec/builders/releaf/permissions/users/form_builder_spec.rb +0 -23
  10. data/spec/builders/releaf/permissions/users/table_builder_spec.rb +0 -21
  11. data/spec/controllers/permissions/profile_controller_spec.rb +0 -40
  12. data/spec/controllers/permissions/users_controller_spec.rb +0 -28
  13. data/spec/features/profile_updating_spec.rb +0 -35
  14. data/spec/features/roles_spec.rb +0 -64
  15. data/spec/features/users_spec.rb +0 -107
  16. data/spec/lib/access_control_spec.rb +0 -66
  17. data/spec/lib/releaf/permissions/configuration_spec.rb +0 -38
  18. data/spec/lib/releaf/permissions/controller_support_spec.rb +0 -76
  19. data/spec/lib/releaf/permissions/default_controller_resolver_spec.rb +0 -49
  20. data/spec/lib/releaf/permissions/layout_spec.rb +0 -10
  21. data/spec/lib/releaf/permissions/profile_spec.rb +0 -11
  22. data/spec/lib/releaf/permissions/roles_spec.rb +0 -10
  23. data/spec/lib/releaf/permissions/settings_manager_spec.rb +0 -38
  24. data/spec/lib/releaf/permissions/users_spec.rb +0 -17
  25. data/spec/models/permissions/role_spec.rb +0 -13
  26. data/spec/models/permissions/user_spec.rb +0 -53
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa31bd6692140be7d800598e94aff5d1ce8276fc96bff80a4c1b3756d18ac05d
4
- data.tar.gz: 3508caf658624203c8a6ea595421fe306740874f9a3e764a4750def9d5dd9169
3
+ metadata.gz: 377558e18e84941c82966437a3b4579e8f394a500ea4bb1305d46b646f74e25e
4
+ data.tar.gz: a96e27ff24c657b4d15fcc6895b450b70bcc65684c7169a33af982fefaf8c446
5
5
  SHA512:
6
- metadata.gz: 24a3c172b366c01960f213fc29508b125cd7ec5c0d3dff1acbc3957056b3559a5bafceafd046eed8b2fbd21de550cf90065667562d9636ff44e7ad26da6eb3f9
7
- data.tar.gz: 74b8a2740261d062c12ab5d7a30d5d1b80dfaa2a2d4ed92e70ac690f1ec797fd2057197f2b4c13a3b1e66962e91f13dff387f3a44e46b75ca46d455b1853bc41
6
+ metadata.gz: f0232e12958d869feaf99e3814867f8374a356b4f49019df73b1346dbe254c0c6809c41bb0c17195f2c903aafb2c7c3a0383771005805fbc383c8e2fae8105a7
7
+ data.tar.gz: 271549d0755d34b369c3696cf30b706972d57d0dcf199d73f6e098a3a1a6e8d92bcf75bcde0cf47857bdb1178ec539f21929f2f28c6f11004444cbf85b8891d1
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: 2.0.0
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - CubeSystems
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-29 00:00:00.000000000 Z
11
+ date: 2021-08-19 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: 2.0.0
19
+ version: 2.1.2
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: 2.0.0
26
+ version: 2.1.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: devise
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -74,30 +74,6 @@ files:
74
74
  - lib/releaf/permissions/roles.rb
75
75
  - lib/releaf/permissions/settings_manager.rb
76
76
  - lib/releaf/permissions/users.rb
77
- - spec/builders/releaf/permissions/page/header_builder_spec.rb
78
- - spec/builders/releaf/permissions/page/layout_builder_spec.rb
79
- - spec/builders/releaf/permissions/page/menu_builder_spec.rb
80
- - spec/builders/releaf/permissions/profile/form_builder_spec.rb
81
- - spec/builders/releaf/permissions/roles/form_builder_spec.rb
82
- - spec/builders/releaf/permissions/roles/table_builder_spec.rb
83
- - spec/builders/releaf/permissions/users/form_builder_spec.rb
84
- - spec/builders/releaf/permissions/users/table_builder_spec.rb
85
- - spec/controllers/permissions/profile_controller_spec.rb
86
- - spec/controllers/permissions/users_controller_spec.rb
87
- - spec/features/profile_updating_spec.rb
88
- - spec/features/roles_spec.rb
89
- - spec/features/users_spec.rb
90
- - spec/lib/access_control_spec.rb
91
- - spec/lib/releaf/permissions/configuration_spec.rb
92
- - spec/lib/releaf/permissions/controller_support_spec.rb
93
- - spec/lib/releaf/permissions/default_controller_resolver_spec.rb
94
- - spec/lib/releaf/permissions/layout_spec.rb
95
- - spec/lib/releaf/permissions/profile_spec.rb
96
- - spec/lib/releaf/permissions/roles_spec.rb
97
- - spec/lib/releaf/permissions/settings_manager_spec.rb
98
- - spec/lib/releaf/permissions/users_spec.rb
99
- - spec/models/permissions/role_spec.rb
100
- - spec/models/permissions/user_spec.rb
101
77
  homepage: https://github.com/cubesystems/releaf
102
78
  licenses:
103
79
  - MIT
@@ -117,32 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
93
  - !ruby/object:Gem::Version
118
94
  version: '0'
119
95
  requirements: []
120
- rubygems_version: 3.0.8
96
+ rubygems_version: 3.2.6
121
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,86 +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(ActionView::LookupContext.new(nil), {}, nil) }
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 type="hidden" name="_method" value="delete" />
78
- <input type="hidden" name="yyy" value="xxx" />
79
- <button class="button only-icon" type="submit" title="Sign out">
80
- <i class="fa fa-power-off fa-icon-header"></i>
81
- </button>
82
- </form>]
83
- expect(subject.sign_out_form).to match_html( content )
84
- end
85
- end
86
- 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(ActionView::LookupContext.new(nil), {}, nil) }
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,112 +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(:user){ Releaf::Permissions::User.new }
9
- let(:controller){ Releaf::ActionController.new }
10
- let(:template){ MenuBuilderTestHelper.new(ActionView::LookupContext.new(nil), {}, nil) }
11
- let(:group_item){ Releaf::ControllerGroupDefinition.new(name: "x", items: []) }
12
- let(:controller_item){ Releaf::ControllerDefinition.new(name: "y", controller: "_controller_") }
13
- subject { described_class.new(template) }
14
-
15
- before do
16
- allow(template).to receive(:controller).and_return(controller)
17
- end
18
-
19
- it "inherits `Releaf::Builders::Page::MenuBuilder`" do
20
- expect(described_class.ancestors).to include(Releaf::Builders::Page::MenuBuilder)
21
- end
22
-
23
- describe "#menu_item" do
24
- before do
25
- allow(subject).to receive(:item_attributes).and_return({})
26
- allow(subject).to receive(:menu_item_group).and_return("_content_")
27
- end
28
-
29
- context "when item is permitted" do
30
- it "returns parent method content" do
31
- allow(subject).to receive(:menu_item_permitted?).with(group_item).and_return(true)
32
- expect(subject.menu_item(group_item)).to eq("<li>_content_</li>")
33
- end
34
- end
35
-
36
- context "when item is not permitted" do
37
- it "returns nil" do
38
- allow(subject).to receive(:menu_item_permitted?).with(group_item).and_return(false)
39
- expect(subject.menu_item(group_item)).to be nil
40
- end
41
- end
42
- end
43
-
44
- describe "#menu_item_permitted?" do
45
- context "when item is instance of `Releaf::ControllerGroupDefinition`" do
46
- before do
47
- allow(group_item).to receive(:controllers).and_return([
48
- Releaf::ControllerDefinition.new(name: "a1", controller: "c1"),
49
- Releaf::ControllerDefinition.new(name: "a2", controller: "c2"),
50
- Releaf::ControllerDefinition.new(name: "a3", controller: "c3"),
51
- ])
52
- end
53
-
54
- context "when any of group item controller is allowed" do
55
- it "returns true" do
56
- allow(subject).to receive(:controller_permitted?).with("c1").and_return(false)
57
- allow(subject).to receive(:controller_permitted?).with("c2").and_return(true)
58
- expect(subject).to_not receive(:controller_permitted?).with("c3")
59
- expect(subject.menu_item_permitted?(group_item)).to be true
60
- end
61
- end
62
-
63
- context "when none of group item controller is allowed" do
64
- it "returns false" do
65
- allow(subject).to receive(:controller_permitted?).with("c1").and_return(false)
66
- allow(subject).to receive(:controller_permitted?).with("c2").and_return(false)
67
- allow(subject).to receive(:controller_permitted?).with("c3").and_return(false)
68
- expect(subject.menu_item_permitted?(group_item)).to be false
69
- end
70
- end
71
- end
72
-
73
- context "when item is instance of `Releaf::ControllerDefinition`" do
74
- context "when item controller is allowed" do
75
- it "returns true" do
76
- allow(subject).to receive(:controller_permitted?).with("_controller_").and_return(true)
77
- expect(subject.menu_item_permitted?(controller_item)).to be true
78
- end
79
- end
80
-
81
- context "when item controller is not allowed" do
82
- it "returns false" do
83
- allow(subject).to receive(:controller_permitted?).with("_controller_").and_return(false)
84
- expect(subject.menu_item_permitted?(controller_item)).to be false
85
- end
86
- end
87
- end
88
- end
89
-
90
- describe "#controller_permitted?" do
91
- it "returns access controller controller permission query result for given controller name" do
92
- access_control = Releaf::Permissions::AccessControl.new(user: user)
93
- allow(subject).to receive(:access_control).and_return(access_control)
94
- allow(access_control).to receive(:controller_permitted?).with("kjasdasd").and_return("_true")
95
-
96
- expect(subject.controller_permitted?("kjasdasd")).to eq("_true")
97
- end
98
- end
99
-
100
- describe "#access_control" do
101
- it "returns cached access control instance" do
102
- allow(controller).to receive(:user).and_return("x")
103
- access_control = Releaf::Permissions::AccessControl.new(user: user)
104
-
105
- allow(Releaf.application.config.permissions.access_control).to receive(:new).with(user: "x").and_return(access_control)
106
- expect(subject.access_control).to eq access_control
107
-
108
- expect(Releaf.application.config.permissions.access_control).to_not receive(:new)
109
- expect(subject.access_control).to eq access_control
110
- end
111
- end
112
- 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(ActionView::LookupContext.new(nil), {}, nil) }
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(ActionView::LookupContext.new(nil), {}, nil) }
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(ActionView::LookupContext.new(nil), {}, nil) }
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(ActionView::LookupContext.new(nil), {}, nil) }
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(ActionView::LookupContext.new(nil), {}, nil) }
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,40 +0,0 @@
1
- require 'rails_helper'
2
-
3
- describe Releaf::Permissions::ProfileController do
4
- let(:another_role){ FactoryBot.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, params: {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 = ActionController::Parameters.new({
24
- "name" => "new name",
25
- "surname" => "new surname",
26
- "email" => "new.email@example.com",
27
- "locale" => "lv"
28
- })
29
- attributes.permit!
30
-
31
- # This is needed in order to get same instance as we expect.
32
- # Otherwise we'll get same record, but different instance and test will fail
33
- allow( user ).to receive(:becomes).with(Releaf::Permissions::User).and_return(user)
34
-
35
- expect(user).to receive(:update).with(attributes)
36
- patch :update, params: {resource: attributes}
37
- end
38
- end
39
- end
40
- 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 FactoryBot.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
- FactoryBot.create(:content_user, name: "John")
20
- FactoryBot.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, params: {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, FactoryBot.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 { subject.name = "x"; 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