releaf-content 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +5 -51
- data/spec/builders/content/nodes/action_dialog_spec.rb +0 -39
- data/spec/builders/content/nodes/content_form_builder_spec.rb +0 -24
- data/spec/builders/content/nodes/form_builder_spec.rb +0 -262
- data/spec/builders/content/nodes/toolbox_builder_spec.rb +0 -77
- data/spec/controllers/releaf/content/nodes_controller_spec.rb +0 -52
- data/spec/features/nodes_services_spec.rb +0 -437
- data/spec/features/nodes_spec.rb +0 -573
- data/spec/fixtures/dummy.png +0 -0
- data/spec/lib/releaf/content/acts_as_node_spec.rb +0 -90
- data/spec/lib/releaf/content/configuration_spec.rb +0 -159
- data/spec/lib/releaf/content/engine_spec.rb +0 -149
- data/spec/lib/releaf/content/node_spec.rb +0 -593
- data/spec/lib/releaf/content/route_spec.rb +0 -229
- data/spec/middleware/routes_reloader_spec.rb +0 -96
- data/spec/routing/node_mapper_spec.rb +0 -311
- data/spec/services/releaf/content/build_route_objects_spec.rb +0 -72
- data/spec/services/releaf/content/node/copy_spec.rb +0 -338
- data/spec/services/releaf/content/node/move_spec.rb +0 -20
- data/spec/services/releaf/content/node/save_under_parent_spec.rb +0 -49
- data/spec/services/releaf/content/node/service_spec.rb +0 -19
- data/spec/validators/content/node/parent_validator_spec.rb +0 -56
- data/spec/validators/content/node/root_validator_spec.rb +0 -69
- data/spec/validators/content/node/singleness_validator_spec.rb +0 -145
@@ -1,19 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::Content::Node::Service do
|
4
|
-
class DummyNodeServiceIncluder
|
5
|
-
include Releaf::Content::Node::Service
|
6
|
-
end
|
7
|
-
|
8
|
-
let(:node){ Node.new }
|
9
|
-
subject{ DummyNodeServiceIncluder.new(node: node) }
|
10
|
-
|
11
|
-
describe "#add_error_and_raise" do
|
12
|
-
it "adds errors to base and raise validation error" do
|
13
|
-
expect{ subject.add_error_and_raise("shit happen") }.to raise_error do |exception|
|
14
|
-
expect(exception).to be_instance_of ActiveRecord::RecordInvalid
|
15
|
-
expect(exception.record.errors[:base]).to eq(["shit happen"])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe Releaf::Content::Node::ParentValidator do
|
4
|
-
let!(:root_node) { FactoryBot.create(:node, content_type: 'HomePage') }
|
5
|
-
|
6
|
-
class DummyNodeParentValidatorModel < ActiveRecord::Base
|
7
|
-
acts_as_node
|
8
|
-
self.table_name = 'texts'
|
9
|
-
end
|
10
|
-
|
11
|
-
class DummyNodeParentValidator1Controller < ActionController::Base
|
12
|
-
acts_as_node
|
13
|
-
end
|
14
|
-
|
15
|
-
class DummyNodeParentValidator2Controller < ActionController::Base
|
16
|
-
acts_as_node
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
class DummyNodeParentValidatorNode < ActiveRecord::Base
|
21
|
-
self.table_name = 'nodes'
|
22
|
-
include Releaf::Content::Node
|
23
|
-
validates_with Releaf::Content::Node::ParentValidator, for: DummyNodeParentValidatorModel, under: DummyNodeParentValidator1Controller
|
24
|
-
end
|
25
|
-
|
26
|
-
context "when parent is valid" do
|
27
|
-
it "doesn't add error" do
|
28
|
-
parent = DummyNodeParentValidatorNode.create!( FactoryBot.attributes_for(:node, content_type: 'DummyNodeParentValidator1Controller') )
|
29
|
-
child = DummyNodeParentValidatorNode.new( FactoryBot.attributes_for(:node, content_type: 'DummyNodeParentValidatorModel', parent_id: parent.id) )
|
30
|
-
|
31
|
-
expect( child ).to be_valid
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when parent is invalid" do
|
36
|
-
it "adds error on content_type" do
|
37
|
-
parent = DummyNodeParentValidatorNode.create!( FactoryBot.attributes_for(:node, content_type: 'DummyNodeParentValidator2Controller') )
|
38
|
-
child = DummyNodeParentValidatorNode.new( FactoryBot.attributes_for(:node, content_type: 'DummyNodeParentValidatorModel', parent_id: parent.id) )
|
39
|
-
|
40
|
-
expect( child ).to be_invalid
|
41
|
-
expect( child.errors[:content_type].size ).to eq(1)
|
42
|
-
expect( child.errors[:content_type] ).to include("invalid parent node")
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
context "when content_type is not in child list" do
|
48
|
-
it "doesn't add error" do
|
49
|
-
parent = DummyNodeParentValidatorNode.create!( FactoryBot.attributes_for(:node, content_type: 'DummyNodeParentValidator1Controller') )
|
50
|
-
child = DummyNodeParentValidatorNode.new( FactoryBot.attributes_for(:node, content_type: 'DummyNodeParentValidator2Controller', parent_id: parent.id) )
|
51
|
-
|
52
|
-
expect( child ).to be_valid
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe Releaf::Content::Node::RootValidator do
|
4
|
-
|
5
|
-
|
6
|
-
class DummyRootValidatorController < ActionController::Base
|
7
|
-
acts_as_node
|
8
|
-
end
|
9
|
-
|
10
|
-
class DummyRootValidator2Controller < ActionController::Base
|
11
|
-
acts_as_node
|
12
|
-
end
|
13
|
-
|
14
|
-
class DummyRootValidatorNode < ActiveRecord::Base
|
15
|
-
self.table_name = 'nodes'
|
16
|
-
include Releaf::Content::Node
|
17
|
-
validates_with Releaf::Content::Node::RootValidator, allow: DummyRootValidatorController
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
def create_node *params
|
22
|
-
DummyRootValidatorNode.create!( FactoryBot.attributes_for(:node, *params) )
|
23
|
-
end
|
24
|
-
|
25
|
-
def build_node *params
|
26
|
-
DummyRootValidatorNode.new( FactoryBot.attributes_for(:node, *params) )
|
27
|
-
end
|
28
|
-
|
29
|
-
context "when node is allowed to be root node" do
|
30
|
-
context "when node is a root node" do
|
31
|
-
it "doesn't add an error" do
|
32
|
-
root_node = build_node(content_type: 'DummyRootValidatorController')
|
33
|
-
expect( root_node ).to be_valid
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when node is not a root node" do
|
38
|
-
it "adds an error" do
|
39
|
-
root_node = create_node(content_type: 'DummyRootValidatorController')
|
40
|
-
subnode = build_node(content_type: 'DummyRootValidatorController', parent: root_node)
|
41
|
-
expect( subnode ).to be_invalid
|
42
|
-
expect( subnode.errors[:content_type].size ).to eq(1)
|
43
|
-
expect( subnode.errors[:content_type] ).to include("can't be subnode")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "when node is not allowed to be a root node" do
|
49
|
-
context "when node is a root node" do
|
50
|
-
it "adds an error" do
|
51
|
-
root_node = build_node(content_type: 'DummyRootValidator2Controller')
|
52
|
-
expect( root_node ).to be_invalid
|
53
|
-
expect( root_node.errors[:content_type].size ).to eq(1)
|
54
|
-
expect( root_node.errors[:content_type] ).to include("can't be root node")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "when node is not a root node" do
|
59
|
-
it "doesn't add an error" do
|
60
|
-
root_node = create_node(content_type: 'DummyRootValidatorController')
|
61
|
-
subnode = build_node(content_type: 'DummyRootValidator2Controller', parent: root_node)
|
62
|
-
|
63
|
-
expect( subnode ).to be_valid
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
|
-
end
|
@@ -1,145 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe Releaf::Content::Node::SinglenessValidator do
|
4
|
-
|
5
|
-
|
6
|
-
class DummySinglenessValidatorModel < ActiveRecord::Base
|
7
|
-
acts_as_node
|
8
|
-
self.table_name = 'text_pages'
|
9
|
-
end
|
10
|
-
|
11
|
-
class DummySinglenessValidator2Model < ActiveRecord::Base
|
12
|
-
acts_as_node
|
13
|
-
self.table_name = 'text_pages'
|
14
|
-
end
|
15
|
-
|
16
|
-
class DummySinglenessValidatorController < ActionController::Base
|
17
|
-
acts_as_node
|
18
|
-
end
|
19
|
-
|
20
|
-
class DummySinglenessValidator2Controller < ActionController::Base
|
21
|
-
acts_as_node
|
22
|
-
end
|
23
|
-
|
24
|
-
class DummySinglenessValidatorNode < ActiveRecord::Base
|
25
|
-
self.table_name = 'nodes'
|
26
|
-
include Releaf::Content::Node
|
27
|
-
validates_with Releaf::Content::Node::SinglenessValidator, for: DummySinglenessValidatorModel
|
28
|
-
validates_with Releaf::Content::Node::SinglenessValidator, for: DummySinglenessValidator2Controller, under: TextPage
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
def create_node *params
|
33
|
-
DummySinglenessValidatorNode.create!( FactoryBot.attributes_for(:node, *params) )
|
34
|
-
end
|
35
|
-
|
36
|
-
def build_node *params
|
37
|
-
DummySinglenessValidatorNode.new( FactoryBot.attributes_for(:node, *params) )
|
38
|
-
end
|
39
|
-
|
40
|
-
let!(:root_node) { create_node(content_type: 'HomePage') }
|
41
|
-
|
42
|
-
|
43
|
-
context "when scope is entire page" do
|
44
|
-
|
45
|
-
context "When node not mentioned in list" do
|
46
|
-
it "doesn't add error" do
|
47
|
-
node = build_node(content_type: 'DummySinglenessValidatorController', parent_id: root_node.id)
|
48
|
-
expect( node ).to be_valid
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
context "when node with given content doesn't exist in tree" do
|
54
|
-
it "doesn't add error" do
|
55
|
-
node = build_node(content_type: 'DummySinglenessValidatorModel', parent_id: root_node.id)
|
56
|
-
expect( node ).to be_valid
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "when node with given content exists in tree" do
|
61
|
-
before do
|
62
|
-
create_node(content_type: 'DummySinglenessValidatorModel', parent_id: root_node.id)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "adds error to #content_type" do
|
66
|
-
node = build_node(content_type: 'DummySinglenessValidatorModel', parent_id: root_node.id)
|
67
|
-
expect( node ).to be_invalid
|
68
|
-
expect( node.errors[:content_type].size ).to eq(1)
|
69
|
-
expect( node.errors[:content_type] ).to include("node exists")
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
context "when node is saved, and is only one in the tree" do
|
75
|
-
it "doesn't add error" do
|
76
|
-
node = create_node(content_type: 'DummySinglenessValidatorModel', parent_id: root_node.id)
|
77
|
-
expect( node ).to be_valid
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context "when scope is subtree" do
|
83
|
-
context "when has ancestor in :under list" do
|
84
|
-
let!(:grand_parent_node) { create_node(content_type: 'TextPage', parent_id: root_node.id) }
|
85
|
-
let!(:parent_node) { create_node(content_type: 'DummySinglenessValidator2Model', parent_id: grand_parent_node.id) }
|
86
|
-
|
87
|
-
context "when node with given content doesn't exist in subtree" do
|
88
|
-
it "doesn't add error" do
|
89
|
-
node = build_node(content_type: 'DummySinglenessValidator2Controller', parent_id: parent_node.id)
|
90
|
-
expect( node ).to be_valid
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context "when node with given content exists in subtree" do
|
95
|
-
before do
|
96
|
-
create_node(content_type: 'DummySinglenessValidator2Controller', parent_id: grand_parent_node.id)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "adds error to #content_type" do
|
100
|
-
node = build_node(content_type: 'DummySinglenessValidator2Controller', parent_id: parent_node.id)
|
101
|
-
expect( node ).to be_invalid
|
102
|
-
expect( node.errors[:content_type].size ).to eq(1)
|
103
|
-
expect( node.errors[:content_type] ).to include("node exists")
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
context "when node is saved, and is only one in subtree" do
|
109
|
-
it "doesn't add error" do
|
110
|
-
node = create_node(content_type: 'DummySinglenessValidator2Controller', parent_id: parent_node.id)
|
111
|
-
expect( node ).to be_valid
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
context "when node has no ancestor in :under list" do
|
119
|
-
it "doesn't add error" do
|
120
|
-
node = create_node(content_type: 'DummySinglenessValidator2Controller', parent_id: root_node.id)
|
121
|
-
expect( node ).to be_valid
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context "regression tests" do
|
127
|
-
context "@node.parent.self_and_ancestors bug" do
|
128
|
-
it "works correctly / is worked around" do
|
129
|
-
# for details see Releaf::Content::Node::SinglenessValidator#base_relation_for_subtree
|
130
|
-
@node1 = create_node(content_type: 'TextPage', locale: 'en')
|
131
|
-
@node2 = create_node(content_type: 'TextPage', locale: 'lv')
|
132
|
-
@node3 = create_node(content_type: 'TextPage', locale: 'ru')
|
133
|
-
@node4 = create_node(content_type: 'TextPage', locale: 'sp')
|
134
|
-
|
135
|
-
@node1_1 = create_node(content_type: 'DummySinglenessValidator2Controller', parent: @node1)
|
136
|
-
expect do
|
137
|
-
@node1_2 = create_node(content_type: 'DummySinglenessValidator2Controller', parent: @node2)
|
138
|
-
@node1_3 = create_node(content_type: 'DummySinglenessValidator2Controller', parent: @node3)
|
139
|
-
@node1_4 = create_node(content_type: 'DummySinglenessValidator2Controller', parent: @node4)
|
140
|
-
end.to_not raise_error
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
end
|