releaf-core 2.0.0 → 2.0.1

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 (97) hide show
  1. checksums.yaml +4 -4
  2. metadata +3 -193
  3. data/spec/builders/releaf/builders/association_reflector_spec.rb +0 -138
  4. data/spec/builders/releaf/builders/base_spec.rb +0 -272
  5. data/spec/builders/releaf/builders/collection_spec.rb +0 -18
  6. data/spec/builders/releaf/builders/confirm_destroy_dialog_builder_spec.rb +0 -71
  7. data/spec/builders/releaf/builders/confirm_dialog_builder_spec.rb +0 -107
  8. data/spec/builders/releaf/builders/edit_builder_spec.rb +0 -322
  9. data/spec/builders/releaf/builders/form_builder/associations_spec.rb +0 -129
  10. data/spec/builders/releaf/builders/form_builder/date_fields_spec.rb +0 -86
  11. data/spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb +0 -48
  12. data/spec/builders/releaf/builders/form_builder/label_spec.rb +0 -106
  13. data/spec/builders/releaf/builders/form_builder/number_fields_spec.rb +0 -37
  14. data/spec/builders/releaf/builders/form_builder_spec.rb +0 -228
  15. data/spec/builders/releaf/builders/index_builder_spec.rb +0 -364
  16. data/spec/builders/releaf/builders/page/header_builder_spec.rb +0 -66
  17. data/spec/builders/releaf/builders/page/layout_builder_spec.rb +0 -237
  18. data/spec/builders/releaf/builders/page/menu_builder_spec.rb +0 -345
  19. data/spec/builders/releaf/builders/pagination_builder_spec.rb +0 -330
  20. data/spec/builders/releaf/builders/resource_dialog_spec.rb +0 -21
  21. data/spec/builders/releaf/builders/resource_view_spec.rb +0 -158
  22. data/spec/builders/releaf/builders/show_builder_spec.rb +0 -7
  23. data/spec/builders/releaf/builders/table_builder_spec.rb +0 -637
  24. data/spec/builders/releaf/builders/template_spec.rb +0 -12
  25. data/spec/builders/releaf/builders/toolbox_builder_spec.rb +0 -67
  26. data/spec/builders/releaf/builders/toolbox_spec.rb +0 -48
  27. data/spec/builders/releaf/builders/utilities/date_fields_spec.rb +0 -125
  28. data/spec/builders/releaf/builders/utilities/resolve_attribute_field_method_name_spec.rb +0 -318
  29. data/spec/builders/releaf/builders/view_spec.rb +0 -281
  30. data/spec/builders/releaf/builders_spec.rb +0 -144
  31. data/spec/builders/releaf/settings/form_builder_spec.rb +0 -48
  32. data/spec/builders/releaf/settings/table_builder_spec.rb +0 -23
  33. data/spec/controllers/concerns/releaf/richtext_attachments_spec.rb +0 -51
  34. data/spec/controllers/releaf/action_controller_spec.rb +0 -423
  35. data/spec/controllers/releaf/root_controller_spec.rb +0 -46
  36. data/spec/controllers/releaf/settings_controller_spec.rb +0 -52
  37. data/spec/error_hash_builder_spec.rb +0 -83
  38. data/spec/ext/array_reorder_spec.rb +0 -12
  39. data/spec/features/ajaxbox_spec.rb +0 -111
  40. data/spec/features/authorization_spec.rb +0 -50
  41. data/spec/features/breadcrumbs_spec.rb +0 -16
  42. data/spec/features/dragonfly_integration_spec.rb +0 -24
  43. data/spec/features/edit_actions_spec.rb +0 -186
  44. data/spec/features/errors_spec.rb +0 -47
  45. data/spec/features/index_actions_spec.rb +0 -86
  46. data/spec/features/index_table_spec.rb +0 -35
  47. data/spec/features/menu_spec.rb +0 -71
  48. data/spec/features/richtext_attachments_spec.rb +0 -64
  49. data/spec/features/richtext_custom_config_spec.rb +0 -28
  50. data/spec/features/richtext_embed_spec.rb +0 -29
  51. data/spec/features/richtext_spec.rb +0 -31
  52. data/spec/features/search_spec.rb +0 -825
  53. data/spec/features/settings_spec.rb +0 -70
  54. data/spec/features/title_spec.rb +0 -13
  55. data/spec/fixtures/common_fields.yml +0 -17
  56. data/spec/fixtures/cs.png +0 -0
  57. data/spec/fixtures/time.formats.xlsx +0 -0
  58. data/spec/fixtures/unicorn.jpg +0 -0
  59. data/spec/helpers/application_helper_spec.rb +0 -73
  60. data/spec/helpers/button_helper_spec.rb +0 -146
  61. data/spec/lib/releaf/action_controller/features_spec.rb +0 -171
  62. data/spec/lib/releaf/action_controller/search_spec.rb +0 -84
  63. data/spec/lib/releaf/application_spec.rb +0 -43
  64. data/spec/lib/releaf/assets_resolver_spec.rb +0 -130
  65. data/spec/lib/releaf/build_errors_hash_spec.rb +0 -141
  66. data/spec/lib/releaf/configuration_spec.rb +0 -205
  67. data/spec/lib/releaf/controller_definition_spec.rb +0 -78
  68. data/spec/lib/releaf/controller_group_definition_spec.rb +0 -33
  69. data/spec/lib/releaf/default_searchable_fields_spec.rb +0 -161
  70. data/spec/lib/releaf/instance_cache_spec.rb +0 -98
  71. data/spec/lib/releaf/resource_base_spec.rb +0 -212
  72. data/spec/lib/releaf/resource_fields_spec.rb +0 -12
  73. data/spec/lib/releaf/resource_params_spec.rb +0 -115
  74. data/spec/lib/releaf/resource_table_fields_spec.rb +0 -20
  75. data/spec/lib/releaf/resource_utilities_spec.rb +0 -87
  76. data/spec/lib/releaf/responders/access_denied_responder_spec.rb +0 -12
  77. data/spec/lib/releaf/responders/after_save_responder_spec.rb +0 -88
  78. data/spec/lib/releaf/responders/confirm_destroy_responder_spec.rb +0 -26
  79. data/spec/lib/releaf/responders/destroy_responder_spec.rb +0 -30
  80. data/spec/lib/releaf/responders/error_responder_spec.rb +0 -26
  81. data/spec/lib/releaf/responders/feature_disabled_responder_spec.rb +0 -12
  82. data/spec/lib/releaf/responders/page_not_found_responder_spec.rb +0 -12
  83. data/spec/lib/releaf/responders_spec.rb +0 -61
  84. data/spec/lib/releaf/root/configuration_spec.rb +0 -9
  85. data/spec/lib/releaf/root/default_controller_resolver_spec.rb +0 -44
  86. data/spec/lib/releaf/root_spec.rb +0 -13
  87. data/spec/lib/releaf/service_spec.rb +0 -20
  88. data/spec/lib/releaf/settings/normalize_value_spec.rb +0 -103
  89. data/spec/lib/releaf/settings/register_spec.rb +0 -135
  90. data/spec/lib/releaf/settings_manager_spec.rb +0 -22
  91. data/spec/lib/validation_error_codes_spec.rb +0 -56
  92. data/spec/misc/factories_spec.rb +0 -31
  93. data/spec/models/settings_spec.rb +0 -104
  94. data/spec/routing/route_mapper_spec.rb +0 -185
  95. data/spec/rspec_helpers/test_helpers_spec.rb +0 -20
  96. data/spec/rspec_helpers/test_spec.rb +0 -14
  97. data/spec/services/array/reorder_spec.rb +0 -121
@@ -1,364 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Builders::IndexBuilder, type: :class do
4
- class TranslationsIndexBuilderTestHelper < ActionView::Base
5
- include Releaf::ApplicationHelper
6
- delegate :resource_class, :table_options, to: :controller
7
-
8
- def controller
9
- @controller ||= Admin::BooksController.new
10
- end
11
- end
12
-
13
- let(:template){ TranslationsIndexBuilderTestHelper.new(ActionView::LookupContext.new(nil), {}, nil) }
14
- let(:subject){ described_class.new(template) }
15
- let(:collection){ Book.page(1).per_page(2) }
16
-
17
- before do
18
- allow(subject).to receive(:controller_name).and_return("_controller_name_")
19
- allow(subject).to receive(:collection).and_return(collection)
20
- end
21
-
22
- it "includes Releaf::Builders::View" do
23
- expect(described_class.ancestors).to include(Releaf::Builders::View)
24
- end
25
-
26
- it "includes Releaf::Builders::Collection" do
27
- expect(described_class.ancestors).to include(Releaf::Builders::Collection)
28
- end
29
-
30
- describe "#dialog?" do
31
- it "returns false" do
32
- expect(subject.dialog?).to be false
33
- end
34
- end
35
-
36
- describe "#search_block" do
37
- before do
38
- allow(subject).to receive(:text_search_block).and_return("aa")
39
- allow(subject).to receive(:extra_search_block).and_return("bb")
40
- allow(subject).to receive(:search_form_attributes).and_return(a: "xx")
41
- end
42
-
43
- it "returns search from with attributes and text/extra search blocks" do
44
- expect(subject.search_block).to eq('<form a="xx">aabb</form>')
45
- end
46
-
47
- context "when no text blocks available" do
48
- it "returns nil" do
49
- allow(subject).to receive(:text_search_block).and_return(nil)
50
- allow(subject).to receive(:extra_search_block).and_return(nil)
51
- expect(subject.search_block).to be nil
52
- end
53
- end
54
- end
55
-
56
- describe "#search_form_attributes" do
57
- before do
58
- allow(subject).to receive(:text_search_available?).and_return(true)
59
- allow(subject).to receive(:extra_search_available?).and_return(true)
60
- allow(subject.template).to receive(:url_for).with(controller: "_controller_name_", action: "index").and_return("x")
61
- end
62
-
63
- it "returns url and css classes for search form" do
64
- classes = ["search", "has-text-search", "has-extra-search"]
65
- expect(subject.search_form_attributes).to eq(class: classes, action: "x")
66
- end
67
-
68
- context "when text search is not available" do
69
- it "does not add text search class" do
70
- allow(subject).to receive(:text_search_available?).and_return(false)
71
- expect(subject.search_form_attributes[:class]).to_not include("has-text-search")
72
- end
73
- end
74
-
75
- context "when extra search is not available" do
76
- it "does not add extra search class" do
77
- allow(subject).to receive(:extra_search_available?).and_return(false)
78
- expect(subject.search_form_attributes[:class]).to_not include("has-extra-search")
79
- end
80
- end
81
- end
82
-
83
- describe "#header_extras" do
84
- before do
85
- allow(subject).to receive(:search_block).and_return("x")
86
- end
87
-
88
- context "when search feature is enabled" do
89
- it "returns search block" do
90
- allow(subject).to receive(:feature_available?).with(:search).and_return(true)
91
- expect(subject.header_extras).to eq("x")
92
- end
93
- end
94
-
95
- context "when search feature is disabled" do
96
- it "returns nil" do
97
- allow(subject).to receive(:feature_available?).with(:search).and_return(false)
98
- expect(subject.header_extras).to be nil
99
- end
100
- end
101
- end
102
-
103
- describe "#extra_search_available?" do
104
- context "when extra search block is present" do
105
- it "returns true" do
106
- allow(subject).to receive(:extra_search_block).and_return("x")
107
- expect(subject.extra_search_available?).to be true
108
- end
109
- end
110
-
111
- context "when extra search block is nil" do
112
- it "returns false" do
113
- allow(subject).to receive(:extra_search_block).and_return(nil)
114
- expect(subject.extra_search_available?).to be false
115
- end
116
- end
117
- end
118
-
119
- describe "#text_search_available?", focus: true do
120
- context "when template variable `searchable_fields` is present" do
121
- it "returns true" do
122
- allow( template.controller ).to receive(:searchable_fields).and_return([:a])
123
- expect(subject.text_search_available?).to be true
124
- end
125
- end
126
-
127
- context "when template variable `searchable_fields` is blank" do
128
- it "returns false" do
129
- allow( template.controller ).to receive(:searchable_fields).and_return([])
130
- expect(subject.text_search_available?).to be false
131
- end
132
- end
133
- end
134
-
135
- describe "#text_search_block" do
136
- before do
137
- allow(subject).to receive(:text_search_content).and_return("x")
138
- end
139
-
140
- context "when text search is available" do
141
- it "returns true" do
142
- allow(subject).to receive(:text_search_available?).and_return(true)
143
- expect(subject.text_search_block).to eq('<div class="text-search">x</div>')
144
- end
145
- end
146
-
147
- context "when text search is not available" do
148
- it "returns false" do
149
- allow(subject).to receive(:text_search_available?).and_return(false)
150
- expect(subject.text_search_block).to be nil
151
- end
152
- end
153
- end
154
-
155
- describe "#text_search_content" do
156
-
157
- it "returns text search field and button" do
158
- allow(subject).to receive(:t).with('Search').and_return("sss")
159
- allow(subject).to receive(:params).and_return(search: "xxx")
160
- allow(subject).to receive(:button)
161
- .with(nil, "search", type: "submit", title: 'sss')
162
- .and_return("<search_button />".html_safe)
163
- expect(subject).to receive(:search_field).with("search").and_call_original
164
- expect(subject.text_search_content).to match_html(%Q[
165
- <div class="search-field" data-name="search">
166
- <input name="search" type="search" class="text" value="xxx" autofocus="autofocus"></input>
167
- <search_button />
168
- </div>
169
- ])
170
- end
171
-
172
- end
173
-
174
- describe "#search_field" do
175
- it "returns the given block in a search field wrapper" do
176
- expect(subject.search_field("foo") { '<block_html>'.html_safe }).to match_html(%Q[
177
- <div class="search-field" data-name="foo">
178
- <block_html>
179
- </div>
180
- ])
181
- end
182
- end
183
-
184
- describe "#extra_search_content" do
185
- it "returns nil(available for override)" do
186
- expect(subject.extra_search_content).to be nil
187
- end
188
- end
189
-
190
- describe "#extra_search_button" do
191
- it "returns extra search button" do
192
- allow(subject).to receive(:t).with('Search').and_return("sss")
193
- allow(subject).to receive(:t).with('Filter').and_return("fff")
194
- allow(subject).to receive(:button)
195
- .with("fff", "search", type: "submit", title: 'sss')
196
- .and_return("xx")
197
- expect(subject.extra_search_button).to eq("xx")
198
- end
199
- end
200
-
201
- describe "#extra_search_block" do
202
- before do
203
- allow(subject).to receive(:extra_search_button).and_return("btn")
204
- allow(subject).to receive(:extra_search_content).and_return("xx")
205
- end
206
-
207
- it "returns extra search block" do
208
- expect(subject.extra_search_block).to eq('<div class="extras">xxbtn</div>')
209
- end
210
-
211
- it "caches extra search content" do
212
- allow(subject).to receive(:extra_search_content).and_return("xx").once
213
- subject.extra_search_block
214
- subject.extra_search_block
215
- end
216
-
217
- context "when extra search content is not present" do
218
- it "returns nil" do
219
- allow(subject).to receive(:extra_search_content).and_return(nil)
220
- expect(subject.extra_search_block).to be nil
221
- end
222
- end
223
- end
224
-
225
- describe "#section_header_text" do
226
- it "returns section header text" do
227
- allow(subject).to receive(:t).with('All resources').and_return("all")
228
- expect(subject.section_header_text).to eq("all")
229
- end
230
- end
231
-
232
- describe "#section_header_extras" do
233
- it "returns true" do
234
- allow(subject).to receive(:t)
235
- .with("Resources found", count: 0, default: "%{count} resources found", create_plurals: true)
236
- .and_return("sss")
237
- expect(subject.section_header_extras).to eq('<span class="extras totals only-text">sss</span>')
238
- end
239
-
240
- context "when collection does not respond to total_entries" do
241
- it "returns nil" do
242
- allow(subject).to receive(:collection).and_return(Book.all)
243
- expect(subject.section_header_extras).to be nil
244
- end
245
- end
246
- end
247
-
248
- describe "#footer_blocks" do
249
- before do
250
- allow(subject).to receive(:footer_primary_block).and_return("a")
251
- allow(subject).to receive(:pagination_block).and_return("b")
252
- allow(subject).to receive(:footer_secondary_block).and_return("c")
253
- allow(subject).to receive(:pagination?).and_return(true)
254
- end
255
-
256
- it "returns array with footer primary, pagination and secondary blocks" do
257
- expect(subject.footer_blocks).to eq(["a", "b", "c"])
258
- end
259
-
260
- context "when pagination is not available" do
261
- it "does not include pagination block within returned array" do
262
- allow(subject).to receive(:pagination?).and_return(false)
263
- expect(subject.footer_blocks).to eq(["a", "c"])
264
- end
265
- end
266
- end
267
-
268
- describe "#footer_primary_tools" do
269
- before do
270
- allow(subject).to receive(:resource_creation_button).and_return("a")
271
- allow(subject).to receive(:feature_available?).with(:create).and_return(true)
272
- end
273
-
274
- it "returns array with resource creation button" do
275
- expect(subject.footer_primary_tools).to eq(["a"])
276
- end
277
-
278
- context "when creation feature is not available" do
279
- it "returns empty array" do
280
- allow(subject).to receive(:feature_available?).with(:create).and_return(false)
281
- expect(subject.footer_primary_tools).to eq([])
282
- end
283
- end
284
- end
285
-
286
- describe "#pagination?" do
287
- context "when collection responds to `page` method" do
288
- it "returns true" do
289
- expect(subject.pagination?).to be true
290
- end
291
- end
292
-
293
- context "when collection does not respond to `page` method" do
294
- it "returns false" do
295
- allow(subject).to receive(:collection).and_return(Book.all)
296
- expect(subject.pagination?).to be true
297
- end
298
- end
299
- end
300
-
301
- describe "#pagination_builder_class" do
302
- it "returns a builder class" do
303
- expect(subject.pagination_builder_class).to be_a Class
304
- end
305
- end
306
-
307
- describe "#pagination_block" do
308
-
309
- before do
310
- allow(subject).to receive(:params).and_return(page: "2")
311
- end
312
-
313
- it "constructs a new pagination builder and returns its output" do
314
- builder_args = [ template, { collection: collection, params: { page: "2" } } ]
315
- builder = Releaf::Builders::PaginationBuilder.new( *builder_args )
316
-
317
- expect(builder.class).to receive(:new).with( *builder_args ).and_return( builder )
318
- expect(builder).to receive(:output).and_return("xx")
319
-
320
- expect(subject.pagination_block).to eq("xx")
321
- end
322
-
323
- it "uses pagination builder class" do
324
- dummy = double
325
- allow(dummy).to receive(:new).and_return(dummy)
326
- allow(dummy).to receive(:output).and_return(:ok)
327
- expect(subject).to receive(:pagination_builder_class).and_return(dummy)
328
- expect( subject.pagination_block).to eq :ok
329
- end
330
- end
331
-
332
- describe "#resource_creation_button" do
333
- it "returns resource creation button" do
334
- allow(subject.template).to receive(:url_for).with(controller: "_controller_name_", action: "new").and_return("x")
335
- allow(subject).to receive(:t).with('Create new resource').and_return("sss")
336
- allow(subject).to receive(:button)
337
- .with("sss", "plus", class: "primary", href: "x")
338
- .and_return("btn")
339
- expect(subject.resource_creation_button).to eq("btn")
340
- end
341
- end
342
-
343
- describe "#section_body" do
344
- it "returns collection table" do
345
- allow(template).to receive(:releaf_table)
346
- .with(collection, Book, builder: Admin::Books::TableBuilder, toolbox: true)
347
- .and_return("xx")
348
- expect(subject.section_body).to eq('<div class="body">xx</div>')
349
- end
350
- end
351
-
352
- describe "#table_options" do
353
- it "returns table options" do
354
- allow(subject).to receive(:builder_class).with(:table).and_return("CustomTableBuilderClassHere")
355
- allow(subject).to receive(:feature_available?).with(:toolbox).and_return("boolean_value_here")
356
-
357
- options = {
358
- builder: "CustomTableBuilderClassHere",
359
- toolbox: "boolean_value_here"
360
- }
361
- expect(subject.table_options).to eq(options)
362
- end
363
- end
364
- end
@@ -1,66 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Builders::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 "#output" do
25
- it "returns safely joined items" do
26
- allow(subject).to receive(:items).and_return([ '<', ActiveSupport::SafeBuffer.new(">")])
27
- expect(subject.output).to eq("&lt;>")
28
- end
29
- end
30
-
31
- describe "#items" do
32
- it "returns array of home link, profile block and logout form content" do
33
- allow(subject).to receive(:home_link).and_return("a")
34
- expect(subject.items).to eq(["a"])
35
- end
36
- end
37
-
38
- describe "#home_link" do
39
- it "returns home link with a logo" do
40
- allow(subject).to receive(:home_url).and_return("www.xxx")
41
- allow(subject).to receive(:home_text).and_return("Rrr")
42
- allow(subject).to receive(:home_image_path).and_return("releaf/foo.png")
43
- allow(subject).to receive(:image_tag).with("releaf/foo.png", alt: "Rrr").and_return('IMG')
44
- content = '<a class="home" href="www.xxx">IMG</a>'
45
- expect(subject.home_link).to eq(content)
46
- end
47
- end
48
-
49
- describe "#home_url" do
50
- it "returns home url" do
51
- expect(subject.home_url).to eq("/admin")
52
- end
53
- end
54
-
55
- describe "#home_image_path" do
56
- it "returns image to the logo image asset" do
57
- expect(subject.home_image_path).to eq("releaf/logo.png")
58
- end
59
- end
60
-
61
- describe "#home_text" do
62
- it "returns releaf home link text" do
63
- expect(subject.home_text).to eq("Releaf")
64
- end
65
- end
66
- end
@@ -1,237 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Builders::Page::LayoutBuilder, type: :class do
4
- class DummyBuilder
5
- include Releaf::Builders::Base
6
- include Releaf::Builders::Template
7
- def output; end
8
- end
9
-
10
- class DummyAssetsResolver
11
- def self.controller_assets(_a, _b); end
12
- end
13
-
14
- class PageHeaderBuilderTestHelper < ActionView::Base
15
- include Rails.application.routes.url_helpers
16
- include FontAwesome::Rails::IconHelper
17
-
18
- def protect_against_forgery?
19
- true
20
- end
21
-
22
- def form_authenticity_token
23
- "xxx"
24
- end
25
-
26
- def request_forgery_protection_token
27
- "yyy"
28
- end
29
- end
30
-
31
- class NewRolesController < Releaf::Permissions::RolesController
32
- end
33
-
34
- subject { described_class.new(template) }
35
- let(:template){ PageHeaderBuilderTestHelper.new(ActionView::LookupContext.new(nil), {}, nil) }
36
-
37
- describe "#controller_classes" do
38
- it "returns array of ignorable ancester classes" do
39
- allow(subject).to receive(:controller).and_return(NewRolesController.new)
40
- expect(subject.controller_classes).to eq([Releaf::Permissions::RolesController, NewRolesController])
41
-
42
- allow(subject).to receive(:controller).and_return(Releaf::Permissions::RolesController.new)
43
- expect(subject.controller_classes).to eq([Releaf::Permissions::RolesController])
44
-
45
- allow(subject).to receive(:controller).and_return(Releaf::Permissions::SessionsController.new)
46
- expect(subject.controller_classes).to eq([Releaf::Permissions::SessionsController])
47
- end
48
- end
49
-
50
- describe "#features" do
51
- it "returns controller layout features" do
52
- allow(subject).to receive(:controller).and_return(NewRolesController.new)
53
- allow(subject.controller).to receive(:layout_features).and_return([:a, :c])
54
- expect(subject.features).to eq([:a, :c])
55
- end
56
- end
57
-
58
- describe "#header_builder" do
59
- it "returns `Releaf::Builders::Page::HeaderBuilder` class" do
60
- expect(subject.header_builder).to eq(Releaf::Builders::Page::HeaderBuilder)
61
- end
62
- end
63
-
64
- describe "#assets_resolver" do
65
- it "returns `Releaf::AssetsResolver` class" do
66
- expect(subject.assets_resolver).to eq(Releaf::AssetsResolver)
67
- end
68
- end
69
-
70
- describe "#feature_available?" do
71
- before do
72
- allow(subject).to receive(:features).and_return([:a, :b])
73
- end
74
-
75
- it "returns true when feature is available" do
76
- expect(subject.feature_available?(:a)).to be true
77
- end
78
-
79
- it "returns false when feature is not available" do
80
- expect(subject.feature_available?(:c)).to be false
81
- end
82
- end
83
-
84
- describe "#stylesheets" do
85
- it "returns stylesheets from assets resolver for given controller" do
86
- allow(subject).to receive(:assets_resolver).and_return(DummyAssetsResolver)
87
- allow(subject).to receive(:controller_name).and_return("_controller")
88
- allow(DummyAssetsResolver).to receive(:controller_assets).with("_controller", :stylesheets)
89
- .and_return("x")
90
- expect(subject.stylesheets).to eq("x")
91
- end
92
- end
93
-
94
- describe "#javascripts" do
95
- it "returns javascripts from assets resolver for given controller" do
96
- allow(subject).to receive(:assets_resolver).and_return(DummyAssetsResolver)
97
- allow(subject).to receive(:controller_name).and_return("_controller")
98
- allow(DummyAssetsResolver).to receive(:controller_assets).with("_controller", :javascripts)
99
- .and_return("y")
100
- expect(subject.javascripts).to eq("y")
101
- end
102
- end
103
-
104
- describe "#header" do
105
- it "returns menu builder output wrapped within `aside` tag" do
106
- menu_builder = DummyBuilder.new(template)
107
- allow(menu_builder).to receive(:output).and_return("_header")
108
- allow(DummyBuilder).to receive(:new).with(template).and_return(menu_builder)
109
- allow(subject).to receive(:header_builder).and_return(DummyBuilder)
110
- allow(subject).to receive(:tag).with(:header, "_header").and_return("<_header>")
111
-
112
- expect(subject.header).to eq("<_header>")
113
- end
114
- end
115
-
116
- describe "#menu" do
117
- it "returns menu builder output wrapped within `aside` tag" do
118
- menu_builder = DummyBuilder.new(template)
119
- allow(menu_builder).to receive(:output).and_return("_menu")
120
- allow(DummyBuilder).to receive(:new).with(template).and_return(menu_builder)
121
- allow(subject).to receive(:menu_builder).and_return(DummyBuilder)
122
- allow(subject).to receive(:tag).with(:aside, "_menu").and_return("<_menu>")
123
-
124
- expect(subject.menu).to eq("<_menu>")
125
- end
126
- end
127
-
128
- describe "#menu_builder" do
129
- it "returns `Releaf::Builders::Page::MenuBuilder` class" do
130
- expect(subject.menu_builder).to eq(Releaf::Builders::Page::MenuBuilder)
131
- end
132
- end
133
-
134
- describe "#body" do
135
- it "returns body with body attributes and" do
136
- allow(subject).to receive(:body_atttributes).and_return(class: ["xx", "y"], id: "121212")
137
- allow(subject).to receive(:body_content_blocks){|*args, &block| expect(block.call).to eq("x") }
138
- .and_return(["a<b>".html_safe, "b<i>", "c<d>".html_safe])
139
- expect(subject.body{ "x" }).to eq("<body class=\"xx y\" id=\"121212\">a<b>b&lt;i&gt;c<d></body>")
140
- end
141
- end
142
-
143
- #parts = []
144
- #parts << header if feature_available?(:header)
145
- #parts << menu if feature_available?(:sidebar)
146
- #parts << tag(:main, id: "main"){ yield } if feature_available?(:main)
147
- #parts << notifications
148
- #parts << assets(:javascripts, :javascript_include_tag)
149
- #parts
150
-
151
-
152
- describe "#body_content_blocks" do
153
- before do
154
- allow(subject).to receive(:feature_available?).with(:header).and_return(true)
155
- allow(subject).to receive(:feature_available?).with(:sidebar).and_return(true)
156
- allow(subject).to receive(:feature_available?).with(:main).and_return(true)
157
-
158
- allow(subject).to receive(:assets).with(:javascripts, :javascript_include_tag).and_return("_assets_")
159
- allow(subject).to receive(:header).and_return("_header_")
160
- allow(subject).to receive(:menu).and_return("_menu_")
161
- allow(subject).to receive(:notifications).and_return("_notifications_")
162
- allow(subject).to receive(:tag).with(:main, id: :main){|*args, &block| expect(block.call).to eq("x") }.and_return("body content")
163
- end
164
-
165
- it "returns body with body attributes and" do
166
- expect(subject.body_content_blocks{ "x" }).to eq(["_header_", "_menu_", "body content", "_notifications_", "_assets_"])
167
- end
168
-
169
- it "skips header when header feature not available" do
170
- allow(subject).to receive(:feature_available?).with(:header).and_return(false)
171
- expect(subject.body_content_blocks{ "x" }).to eq(["_menu_", "body content", "_notifications_", "_assets_"])
172
- end
173
-
174
- it "skips menu when sidebar feature not available" do
175
- allow(subject).to receive(:feature_available?).with(:sidebar).and_return(false)
176
- expect(subject.body_content_blocks{ "x" }).to eq(["_header_", "body content", "_notifications_", "_assets_"])
177
- end
178
-
179
- it "skips main conrtent when main feature not available" do
180
- allow(subject).to receive(:feature_available?).with(:main).and_return(false)
181
- expect(subject.body_content_blocks{ "x" }).to eq(["_header_", "_menu_", "_notifications_", "_assets_"])
182
- end
183
- end
184
-
185
- describe "#controller_body_classes" do
186
- it "returns normalized html classes from controller classes" do
187
- allow(subject).to receive(:controller_classes).and_return([Releaf::ActionController, Releaf::Permissions::RolesController])
188
- expect(subject.controller_body_classes).to eq(["controller-releaf-action", "controller-releaf-permissions-roles"])
189
- end
190
- end
191
-
192
- describe "#settings_path" do
193
- it "returns root controller settings path" do
194
- allow(subject).to receive(:url_for).with(action: "store_settings", controller: "/releaf/root", only_path: true)
195
- .and_return("asdasdasd")
196
- expect(subject.settings_path).to eq("asdasdasd")
197
- end
198
- end
199
-
200
- describe "#body_atttributes" do
201
- it "returns hash with classes, data-settings-path and data-layout-features" do
202
- allow(subject).to receive(:features).and_return([:top, :bottom])
203
- allow(subject).to receive(:controller_body_classes).and_return(["a", "b"])
204
- allow(subject).to receive(:settings_path).and_return("/xxx/sett")
205
- expect(subject.body_atttributes).to eq(class: ["application-dummy", "a", "b"],
206
- "data-settings-path" => "/xxx/sett",
207
- "data-layout-features" => "top bottom")
208
- end
209
- end
210
-
211
- describe "#head_blocks" do
212
- it "returns array" do
213
- {
214
- title: :title_sym,
215
- meta: :meta_sym,
216
- favicons: :favicon_sym,
217
- ms_tile: :ms_tile_sym,
218
- assets: :assets_sym,
219
- csrf: :csrf_sym,
220
- }.each_pair do |method, stub_answer|
221
- allow(subject).to receive(method).and_return stub_answer
222
- end
223
-
224
- expect(subject.head_blocks).to match_array(
225
- [
226
- :title_sym,
227
- :meta_sym,
228
- :favicon_sym,
229
- :ms_tile_sym,
230
- :assets_sym,
231
- :csrf_sym,
232
- ]
233
- )
234
- end
235
- end
236
- end
237
-