releaf-content 1.1.21 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/config/releaf_content_manifest.js +2 -0
- data/app/assets/javascripts/controllers/releaf/content/nodes.js +6 -9
- data/app/controllers/releaf/content/nodes_controller.rb +1 -1
- data/lib/releaf/content/engine.rb +2 -2
- data/lib/releaf/content/node.rb +3 -3
- data/lib/releaf/content/route.rb +0 -1
- metadata +12 -57
- 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 -572
- 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 -591
- 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 -310
- 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,229 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::Content::Route do
|
4
|
-
let(:node_route) { FactoryGirl.build(:node_route, node_class: Node, node_id: 12, locale: "en", path: "/en") }
|
5
|
-
|
6
|
-
|
7
|
-
describe ".default_controller" do
|
8
|
-
context "when given node class inherits `ActionController::Base`" do
|
9
|
-
it "returns undercored, stripped down controller class" do
|
10
|
-
expect(described_class.default_controller(HomePagesController)).to eq("home_pages")
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context "when given node class does not inherit `ActionController::Base`" do
|
15
|
-
it "returns pluralized, underscorized class" do
|
16
|
-
expect(described_class.default_controller(TextPage)).to eq("text_pages")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
describe '#params' do
|
23
|
-
let(:options_argument) { { foo: :bar } }
|
24
|
-
|
25
|
-
it "returns params for router method" do
|
26
|
-
expect(node_route.params("home#index")).to eq ['/en', {to: "home#index", node_class: "Node", node_id: "12", locale: "en", as: nil }]
|
27
|
-
end
|
28
|
-
|
29
|
-
it "uses #path_for to calculate path" do
|
30
|
-
allow(node_route).to receive(:path_for).with("home#index", options_argument).and_return( "foo_path" )
|
31
|
-
expect(node_route.params("home#index", options_argument)[0]).to eq "foo_path"
|
32
|
-
end
|
33
|
-
|
34
|
-
it "uses #options_for to calculate options" do
|
35
|
-
allow(node_route).to receive(:options_for).with("home#index", options_argument).and_return( some: :options )
|
36
|
-
expect(node_route.params("home#index", options_argument)[1]).to eq( some: :options )
|
37
|
-
end
|
38
|
-
|
39
|
-
it "converts method_or_path argument to string" do
|
40
|
-
expect(node_route).to receive(:path_for).with("foo", options_argument)
|
41
|
-
expect(node_route).to receive(:options_for).with("foo", options_argument)
|
42
|
-
node_route.params(:foo, options_argument)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "does not require options argument" do
|
46
|
-
expect(node_route).to receive(:path_for).with("home#index", {})
|
47
|
-
expect(node_route).to receive(:options_for).with("home#index", {})
|
48
|
-
node_route.params("home#index")
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#path_for" do
|
54
|
-
|
55
|
-
it "returns route path" do
|
56
|
-
expect( node_route.path_for( "foo", {} ) ).to eq "/en"
|
57
|
-
end
|
58
|
-
|
59
|
-
context "when options contain a :to key" do
|
60
|
-
it "returns route path combined with given method_or_path" do
|
61
|
-
expect( node_route.path_for( "foo", { to: "bar" } ) ).to eq "/en/foo"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "when first argument contains a controller#action or #action string" do
|
66
|
-
it "returns the route path" do
|
67
|
-
expect( node_route.path_for( "home#index", { to: "bar" } ) ).to eq "/en"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "#options_for" do
|
74
|
-
|
75
|
-
it "returns route options hash" do
|
76
|
-
expect( node_route.options_for( "home#index", {} ) ).to be_a Hash
|
77
|
-
end
|
78
|
-
|
79
|
-
it "sets :node_class to route node class name string" do
|
80
|
-
expect( node_route.options_for( "home#index", {} ) ).to include( node_class: "Node" )
|
81
|
-
end
|
82
|
-
|
83
|
-
it "sets :node_id to route node id string" do
|
84
|
-
expect( node_route.options_for( "home#index", {} ) ).to include( node_id: "12" )
|
85
|
-
end
|
86
|
-
|
87
|
-
it "sets :locale to route locale" do
|
88
|
-
expect( node_route.options_for( "home#index", {} ) ).to include( locale: "en" )
|
89
|
-
end
|
90
|
-
|
91
|
-
it "sets :to to the result of #controller_and_action_for" do
|
92
|
-
allow(node_route).to receive(:controller_and_action_for).with( "home#index", foo: :bar).and_return("ok")
|
93
|
-
expect( node_route.options_for( "home#index", foo: :bar ) ).to include( to: "ok" )
|
94
|
-
end
|
95
|
-
|
96
|
-
it "sets :as to the result of #name by passing all other calculated options" do
|
97
|
-
expected_name_options = {
|
98
|
-
foo: :bar,
|
99
|
-
to: "home#index",
|
100
|
-
node_class: "Node",
|
101
|
-
node_id: "12",
|
102
|
-
locale: "en"
|
103
|
-
}
|
104
|
-
|
105
|
-
allow(node_route).to receive(:name).with( expected_name_options ).and_return("ok")
|
106
|
-
expect( node_route.options_for( "home#index", foo: :bar ) ).to include( as: "ok" )
|
107
|
-
end
|
108
|
-
|
109
|
-
it "preserves unrecognized option keys" do
|
110
|
-
expect( node_route.options_for( "home#index", foo: :bar ) ).to include( foo: :bar )
|
111
|
-
end
|
112
|
-
|
113
|
-
it "uses calculated keys in case conflicting option keys given" do
|
114
|
-
in_options = { to: "invalid", node_class: "invalid", node_id: "invalid", locale: "invalid" }
|
115
|
-
|
116
|
-
expect( node_route.options_for( "home#index", in_options ) ).to include({
|
117
|
-
to: "home#index",
|
118
|
-
node_class: "Node",
|
119
|
-
node_id: "12",
|
120
|
-
locale: "en"
|
121
|
-
})
|
122
|
-
end
|
123
|
-
|
124
|
-
context "when node route has site" do
|
125
|
-
|
126
|
-
it "sets :site to route site" do
|
127
|
-
node_route.site = "ok"
|
128
|
-
expect( node_route.options_for( "home#index", {} ) ).to include( site: "ok" )
|
129
|
-
end
|
130
|
-
|
131
|
-
it "overrides site given in options" do
|
132
|
-
node_route.site = "ok"
|
133
|
-
expect( node_route.options_for( "home#index", { site: "foo" } ) ).to include( site: "ok" )
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
context "when node route does not have site" do
|
139
|
-
|
140
|
-
it "does not set :site" do
|
141
|
-
expect( node_route.options_for( "home#index", {} ) ).to_not include( :site )
|
142
|
-
end
|
143
|
-
|
144
|
-
it "allows site from options" do
|
145
|
-
expect( node_route.options_for( "home#index", { site: "ok" } ) ).to include( site: "ok" )
|
146
|
-
end
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
|
151
|
-
end
|
152
|
-
|
153
|
-
describe "#name" do
|
154
|
-
|
155
|
-
context "when route options contain :as option" do
|
156
|
-
|
157
|
-
context "when neither :site nor :locale are set or are blank in route options" do
|
158
|
-
it "returns the value intact" do
|
159
|
-
expect(node_route.name( { as: "foo" } )).to eq "foo"
|
160
|
-
expect(node_route.name( { as: "foo", site: nil, locale: nil } )).to eq "foo"
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
context "when :site is set in route options" do
|
165
|
-
it "returns the value with site prepended" do
|
166
|
-
expect(node_route.name( { as: "foo", site: "sss" } )).to eq "sss_foo"
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
context "when :locale is set in route options" do
|
171
|
-
it "returns the value with locale prepended" do
|
172
|
-
expect(node_route.name( { as: "foo", locale: "lll" } )).to eq "lll_foo"
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
context "when both :site and :locale are set in route options" do
|
177
|
-
it "returns the value with site and locale prepended" do
|
178
|
-
expect(node_route.name( { as: "foo", site: "sss", locale: "lll" } )).to eq "sss_lll_foo"
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
end
|
183
|
-
|
184
|
-
context "when route options do not contain :as option" do
|
185
|
-
it "returns nil" do
|
186
|
-
expect(node_route.name( {} )).to be_nil
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
end
|
191
|
-
|
192
|
-
describe ".for" do
|
193
|
-
before do
|
194
|
-
create(:home_page_node)
|
195
|
-
end
|
196
|
-
|
197
|
-
it "returns an array" do
|
198
|
-
expect(described_class.for(Node, HomePage, 'foo')).to be_a Array
|
199
|
-
end
|
200
|
-
|
201
|
-
context "when database doesn't exists" do
|
202
|
-
it "returns an empty array" do
|
203
|
-
allow(Node).to receive(:where).and_raise(ActiveRecord::NoDatabaseError.new("xxx"))
|
204
|
-
expect(described_class.for(Node, HomePage, 'foo')).to eq([])
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
context "when node table doesn't exist" do
|
209
|
-
it "returns an empty array" do
|
210
|
-
allow(Node).to receive(:where).and_raise(ActiveRecord::StatementInvalid.new("xxx"))
|
211
|
-
expect(described_class.for(Node, HomePage, 'foo')).to eq([])
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
context "when node table exists" do
|
216
|
-
it "returns an array of Node::Route objects processed by Releaf::Content::BuildRouteObjects" do
|
217
|
-
expect(Releaf::Content::BuildRouteObjects).to receive(:call).with(node_class: Node, node_content_class: HomePage, default_controller: 'foo').and_call_original
|
218
|
-
result = described_class.for(Node, HomePage, 'foo')
|
219
|
-
expect(result.count).to eq(1)
|
220
|
-
expect(result.first.class).to eq(described_class)
|
221
|
-
end
|
222
|
-
|
223
|
-
it "accepts node_class as string also" do
|
224
|
-
result = described_class.for('Node', HomePage, 'foo')
|
225
|
-
expect(result.count).to eq(1)
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::Content::RoutesReloader do
|
4
|
-
let(:app) { ->(env) { [200, env, "app"] } }
|
5
|
-
|
6
|
-
let :request do
|
7
|
-
described_class.new(app).call(Rack::MockRequest.env_for('http://example.com'))
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "on application startup" do
|
11
|
-
it "sets routes loading time" do
|
12
|
-
expect(described_class.routes_loaded).to_not be_nil
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "on each request" do
|
17
|
-
it "compares latest updates" do
|
18
|
-
expect(described_class).to receive(:reload_if_needed)
|
19
|
-
request
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe ".reset!" do
|
24
|
-
|
25
|
-
it "changes class @updated_at instance to nil" do
|
26
|
-
described_class.instance_variable_set(:@updated_at, "x")
|
27
|
-
expect{ described_class.reset! }.to change{ described_class.instance_variable_get(:@updated_at) }.to(nil)
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
describe ".reload_if_needed" do
|
33
|
-
|
34
|
-
context "when reload is needed" do
|
35
|
-
it "reloads routes" do
|
36
|
-
allow(described_class).to receive(:needs_reload?).and_return true
|
37
|
-
expect(Rails.application).to receive(:reload_routes!)
|
38
|
-
described_class.reload_if_needed
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "when reload is not needed" do
|
43
|
-
it "does not reload routes" do
|
44
|
-
allow(described_class).to receive(:needs_reload?).and_return false
|
45
|
-
expect(Rails.application).to_not receive(:reload_routes!)
|
46
|
-
described_class.reload_if_needed
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
describe ".needs_reload?" do
|
53
|
-
|
54
|
-
context "when no nodes exist" do
|
55
|
-
it "returns false" do
|
56
|
-
allow(Node).to receive(:updated_at).and_return(nil)
|
57
|
-
expect(described_class.needs_reload?).to be false
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "when node routes has not been loaded" do
|
62
|
-
it "returns true" do
|
63
|
-
described_class.instance_variable_set(:@updated_at, nil)
|
64
|
-
allow(Node).to receive(:updated_at).and_return(Time.parse("1991-01-01"))
|
65
|
-
expect(described_class.needs_reload?).to be true
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "when node routes are up to date" do
|
70
|
-
it "returns false" do
|
71
|
-
described_class.instance_variable_set(:@updated_at, Time.parse("1991-01-01"))
|
72
|
-
allow(Node).to receive(:updated_at).and_return(Time.parse("1991-01-01"))
|
73
|
-
expect(described_class.needs_reload?).to be false
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "when node routes are outdated" do
|
78
|
-
it "returns true" do
|
79
|
-
allow(Node).to receive(:updated_at).and_return(Time.now + 1.minute)
|
80
|
-
expect(described_class.needs_reload?).to be true
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
it "checks all content model classes" do
|
85
|
-
class RouteReloaderDummyNode
|
86
|
-
def self.updated_at
|
87
|
-
Time.now + 1.minute
|
88
|
-
end
|
89
|
-
end
|
90
|
-
allow(Releaf::Content).to receive(:models).and_return [ Node, RouteReloaderDummyNode ]
|
91
|
-
allow(Node).to receive(:updated_at).and_return(nil)
|
92
|
-
expect(described_class.needs_reload?).to be true
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
end
|
@@ -1,310 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::Content::NodeMapper do
|
4
|
-
|
5
|
-
let(:multiple_node_resources) {{
|
6
|
-
'Node' => {
|
7
|
-
controller: 'Releaf::Content::NodesController',
|
8
|
-
routing: { site: "main_site", constraints: { host: /^releaf\.local$/ } }
|
9
|
-
},
|
10
|
-
'OtherSite::OtherNode' => {
|
11
|
-
controller: 'Admin::OtherSite::OtherNodesController',
|
12
|
-
routing: { site: "other_site", constraints: { host: /^other\.releaf\.local$/ } }
|
13
|
-
}
|
14
|
-
}}
|
15
|
-
|
16
|
-
before do
|
17
|
-
@text_page = create(:text_page)
|
18
|
-
@lv_root_node = create(:home_page_node, name: "lv", locale: "lv", slug: 'lv')
|
19
|
-
@node = create(:node, slug: 'test-page', content: @text_page, parent: @lv_root_node)
|
20
|
-
end
|
21
|
-
|
22
|
-
before with_multiple_node_classes: true do
|
23
|
-
allow( Releaf.application.config ).to receive(:content).and_return(
|
24
|
-
Releaf::Content::Configuration.new(resources: multiple_node_resources)
|
25
|
-
)
|
26
|
-
@other_text_page = create(:text_page)
|
27
|
-
@other_lv_root_node = create(:other_home_page_node, name: "lv", locale: "lv", slug: 'lv')
|
28
|
-
@other_node = create(:other_node, slug: 'test-page', content: @other_text_page, parent: @other_lv_root_node)
|
29
|
-
end
|
30
|
-
|
31
|
-
after do
|
32
|
-
Dummy::Application.reload_routes!
|
33
|
-
end
|
34
|
-
|
35
|
-
after(:all) do
|
36
|
-
# without this the test environent remains polluted with test node class config.
|
37
|
-
# the routing configuration gets already reset after each test in the after block above
|
38
|
-
# but that seems to not be enough
|
39
|
-
Dummy::Application.reload_routes!
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "#node_routes_for", create_nodes: true do
|
43
|
-
|
44
|
-
it "draws public website routes for default node class" do
|
45
|
-
|
46
|
-
routes.draw do
|
47
|
-
node_routes_for(TextPage) do |route|
|
48
|
-
get 'show'
|
49
|
-
delete :destroy
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
expect(get: '/lv/test-page').to route_to(
|
54
|
-
"controller" => "text_pages",
|
55
|
-
"action" => "show",
|
56
|
-
"node_class" => "Node",
|
57
|
-
"node_id" => @node.id.to_s,
|
58
|
-
"locale" => 'lv'
|
59
|
-
)
|
60
|
-
|
61
|
-
expect(delete: '/lv/test-page').to route_to(
|
62
|
-
"controller" => "text_pages",
|
63
|
-
"action" => "destroy",
|
64
|
-
"node_class" => "Node",
|
65
|
-
"node_id" => @node.id.to_s,
|
66
|
-
"locale" => 'lv'
|
67
|
-
)
|
68
|
-
end
|
69
|
-
|
70
|
-
context "when a controller is given in arguments" do
|
71
|
-
|
72
|
-
it "draws the public website route to given controller" do
|
73
|
-
routes.draw do
|
74
|
-
node_routes_for(TextPage, controller: 'home_pages') do |route|
|
75
|
-
get 'show'
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
expect(get: '/lv/test-page').to route_to(
|
80
|
-
"controller" => "home_pages",
|
81
|
-
"action" => "show",
|
82
|
-
"node_class" => "Node",
|
83
|
-
"node_id" => @node.id.to_s,
|
84
|
-
"locale" => 'lv'
|
85
|
-
)
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
context "when a controller is passed in route options" do
|
91
|
-
it "draws the public website route using the controller from options" do
|
92
|
-
routes.draw do
|
93
|
-
node_routes_for(TextPage, controller: 'doesnt_matter') do |route|
|
94
|
-
get 'home_pages#hide'
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
expect(get: '/lv/test-page').to route_to(
|
99
|
-
"controller" => "home_pages",
|
100
|
-
"action" => "hide",
|
101
|
-
"node_class" => "Node",
|
102
|
-
"node_id" => @node.id.to_s,
|
103
|
-
"locale" => 'lv'
|
104
|
-
)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context "when custom action is given in :to" do
|
109
|
-
it "draws the public website route using the action from :to" do
|
110
|
-
routes.draw do
|
111
|
-
node_routes_for(TextPage) do |route|
|
112
|
-
get '' , to: '#list'
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
expect(get: '/lv/test-page').to route_to(
|
117
|
-
"controller" => "text_pages",
|
118
|
-
"action" => "list",
|
119
|
-
"node_class" => "Node",
|
120
|
-
"node_id" => @node.id.to_s,
|
121
|
-
"locale" => 'lv'
|
122
|
-
)
|
123
|
-
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
context "when custom controller and action are given in :to" do
|
128
|
-
it "draws the public website route using the given controller and action from :to" do
|
129
|
-
routes.draw do
|
130
|
-
node_routes_for(TextPage) do |route|
|
131
|
-
get '' , to: 'home_pages#list'
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
expect(get: '/lv/test-page').to route_to(
|
136
|
-
"controller" => "home_pages",
|
137
|
-
"action" => "list",
|
138
|
-
"node_class" => "Node",
|
139
|
-
"node_id" => @node.id.to_s,
|
140
|
-
"locale" => 'lv'
|
141
|
-
)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context "when additional params are given in route path" do
|
146
|
-
it "passes the params to the public website route" do
|
147
|
-
routes.draw do
|
148
|
-
node_routes_for(TextPage) do |route|
|
149
|
-
get ':some_id', to: "#view"
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
expect(get: '/lv/test-page/8888').to route_to(
|
154
|
-
"controller" => "text_pages",
|
155
|
-
"action" => "view",
|
156
|
-
"node_class" => "Node",
|
157
|
-
"node_id" => @node.id.to_s,
|
158
|
-
"locale" => 'lv',
|
159
|
-
"some_id" => '8888'
|
160
|
-
)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
context "when custom path is given for route" do
|
165
|
-
it "uses the custom path for public website route" do
|
166
|
-
routes.draw do
|
167
|
-
node_routes_for(TextPage) do |route|
|
168
|
-
get 'home_pages#show', path: "#{route.path}/abc/:my_id"
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
expect(get: '/lv/test-page/abc/333').to route_to(
|
173
|
-
"controller" => "home_pages",
|
174
|
-
"action" => "show",
|
175
|
-
"node_class" => "Node",
|
176
|
-
"node_id" => @node.id.to_s,
|
177
|
-
"locale" => 'lv',
|
178
|
-
"my_id" => '333'
|
179
|
-
)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
context "when custom node class is given as an argument", with_multiple_node_classes: true do
|
184
|
-
|
185
|
-
it "uses that node class for the public website route" do
|
186
|
-
routes.draw do
|
187
|
-
node_routes_for(TextPage, node_class: "OtherSite::OtherNode") do |route|
|
188
|
-
get 'show'
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
expect(get: '/lv/test-page').to route_to(
|
193
|
-
"controller" => "text_pages",
|
194
|
-
"action" => "show",
|
195
|
-
"node_class" => "OtherSite::OtherNode",
|
196
|
-
"node_id" => @other_node.id.to_s,
|
197
|
-
"locale" => 'lv',
|
198
|
-
"site" => 'other_site'
|
199
|
-
)
|
200
|
-
end
|
201
|
-
|
202
|
-
end
|
203
|
-
|
204
|
-
end
|
205
|
-
|
206
|
-
describe "#for_node_class", with_multiple_node_classes: true do
|
207
|
-
|
208
|
-
it "uses given node class as a default when drawing public website routes in the given block" do
|
209
|
-
routes.draw do
|
210
|
-
for_node_class "OtherSite::OtherNode" do
|
211
|
-
node_routes_for(TextPage) do |route|
|
212
|
-
get 'show'
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
expect(get: '/lv/test-page').to route_to(
|
218
|
-
"controller" => "text_pages",
|
219
|
-
"action" => "show",
|
220
|
-
"node_class" => "OtherSite::OtherNode",
|
221
|
-
"node_id" => @other_node.id.to_s,
|
222
|
-
"locale" => 'lv',
|
223
|
-
"site" => 'other_site'
|
224
|
-
)
|
225
|
-
end
|
226
|
-
|
227
|
-
it "restores default node class after block has been executed" do
|
228
|
-
routes.draw do
|
229
|
-
for_node_class "OtherSite::OtherNode" do
|
230
|
-
node_routes_for(TextPage) do |route|
|
231
|
-
get 'show'
|
232
|
-
end
|
233
|
-
end
|
234
|
-
node_routes_for(HomePage) do |route|
|
235
|
-
get 'show'
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
expect(get: '/lv').to route_to(
|
240
|
-
"controller" => "home_pages",
|
241
|
-
"action" => "show",
|
242
|
-
"node_class" => "Node",
|
243
|
-
"node_id" => @lv_root_node.id.to_s,
|
244
|
-
"locale" => 'lv',
|
245
|
-
"site" => 'main_site'
|
246
|
-
)
|
247
|
-
end
|
248
|
-
|
249
|
-
end
|
250
|
-
|
251
|
-
describe "#node_routing", with_multiple_node_classes: true do
|
252
|
-
|
253
|
-
it "draws public website routes for all node classes in the given routing hash using respective route constraints" do
|
254
|
-
|
255
|
-
routes.draw do
|
256
|
-
node_routing( Releaf::Content.routing ) do
|
257
|
-
node_routes_for(TextPage) do |route|
|
258
|
-
get 'show'
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
expect(get: 'http://releaf.local/lv/test-page').to route_to(
|
264
|
-
"controller" => "text_pages",
|
265
|
-
"action" => "show",
|
266
|
-
"node_class" => "Node",
|
267
|
-
"node_id" => @node.id.to_s,
|
268
|
-
"locale" => 'lv',
|
269
|
-
"site" => 'main_site'
|
270
|
-
)
|
271
|
-
|
272
|
-
expect(get: 'http://other.releaf.local/lv/test-page').to route_to(
|
273
|
-
"controller" => "text_pages",
|
274
|
-
"action" => "show",
|
275
|
-
"node_class" => "OtherSite::OtherNode",
|
276
|
-
"node_id" => @other_node.id.to_s,
|
277
|
-
"locale" => 'lv',
|
278
|
-
"site" => 'other_site'
|
279
|
-
)
|
280
|
-
|
281
|
-
end
|
282
|
-
|
283
|
-
context "when passed a routing hash for only a subset of available node classes" do
|
284
|
-
it "draws constrained public website routes only for the given node classes" do
|
285
|
-
routes.draw do
|
286
|
-
routing_hash = Releaf::Content.routing.except('Node')
|
287
|
-
node_routing( routing_hash ) do
|
288
|
-
node_routes_for(TextPage) do |route|
|
289
|
-
get 'show'
|
290
|
-
end
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
expect(get: 'http://other.releaf.local/lv/test-page').to route_to(
|
295
|
-
"controller" => "text_pages",
|
296
|
-
"action" => "show",
|
297
|
-
"node_class" => "OtherSite::OtherNode",
|
298
|
-
"node_id" => @other_node.id.to_s,
|
299
|
-
"locale" => 'lv',
|
300
|
-
"site" => 'other_site'
|
301
|
-
)
|
302
|
-
|
303
|
-
expect(get: 'http://releaf.local/lv/test-page').to_not be_routable
|
304
|
-
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
end
|
309
|
-
|
310
|
-
end
|