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,84 +0,0 @@
1
- require 'rails_helper'
2
-
3
- describe Releaf::ActionController::Search do
4
- let(:subject){ DummyActionControllerSearchIncluder.new }
5
-
6
- class DummySearcher < Releaf::Search
7
- end
8
-
9
- class DummyActionControllerSearchIncluder < Releaf::ActionController
10
- include Releaf::ActionController::Features
11
- include Releaf::ActionController::Search
12
-
13
- def resource_class
14
- Book
15
- end
16
- end
17
-
18
- describe "#search" do
19
- before do
20
- allow(subject).to receive(:searchable_fields).and_return([:name, :email])
21
- allow(subject).to receive(:feature_available?).with(:search).and_return(true)
22
-
23
- subject.instance_variable_set(:@collection, "_collection")
24
- allow(subject).to receive(:searcher_class).and_return(DummySearcher)
25
- allow(DummySearcher).to receive(:prepare).with(relation: "_collection", fields: [:name, :email], text: "_some")
26
- .and_return("_collection_with_search")
27
- end
28
-
29
- context "when feature is enabled, text and searchable fields is not blank" do
30
- it "replaces collection with searchable collection" do
31
- expect{ subject.search("_some") }.to change{ subject.instance_variable_get(:@collection) }
32
- .from("_collection").to("_collection_with_search")
33
- end
34
- end
35
-
36
- context "when `show` feature is not available" do
37
- it "does not replace collection with searchable collection" do
38
- allow(subject).to receive(:feature_available?).with(:search).and_return(false)
39
- expect{ subject.search("_some") }.to_not change{ subject.instance_variable_get(:@collection) }
40
- end
41
- end
42
-
43
- context "when blank search given" do
44
- it "does not replace collection with searchable collection" do
45
- expect{ subject.search("") }.to_not change{ subject.instance_variable_get(:@collection) }
46
- end
47
- end
48
-
49
- context "when no search fields exists" do
50
- it "does not replace collection with searchable collection" do
51
- allow(subject).to receive(:searchable_fields).and_return([])
52
- expect{ subject.search("_some") }.to_not change{ subject.instance_variable_get(:@collection) }
53
- end
54
- end
55
- end
56
-
57
- describe "#searcher_class" do
58
- it "returns `Releaf::Search` class" do
59
- expect(subject.searcher_class).to eq(Releaf::Search)
60
- end
61
- end
62
-
63
- describe "#searchable_fields" do
64
- let(:searchable_fields){ Releaf::DefaultSearchableFields.new(Author) }
65
-
66
- it "adds itself as helper" do
67
- expect(subject._helper_methods).to include(:searchable_fields)
68
- end
69
-
70
- it "returns default searchable fields from `Releaf::DefaultSearchableFields` instance" do
71
- allow(Releaf::DefaultSearchableFields).to receive(:new).with(Book).and_return(searchable_fields)
72
- allow(searchable_fields).to receive(:find).and_return("x").once
73
-
74
- expect(subject.searchable_fields).to eq("x")
75
- end
76
-
77
- it "caches returned searchable fields" do
78
- allow(Releaf::DefaultSearchableFields).to receive(:new).and_return(searchable_fields)
79
- expect(searchable_fields).to receive(:find).and_return("x").once
80
- subject.searchable_fields
81
- subject.searchable_fields
82
- end
83
- end
84
- end
@@ -1,43 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Application do
4
- describe "#configure" do
5
- it "assigns new configuration instance, evaluate block, initialize locales and components" do
6
- configuration = Releaf::Configuration.new
7
- allow(Releaf::Configuration).to receive(:new).and_return(configuration)
8
-
9
- expect(subject).to receive(:config=).with(configuration).and_call_original.ordered
10
- expect(configuration).to receive(:menu=).with("x").ordered
11
- expect(configuration).to receive(:initialize_locales).ordered
12
- expect(configuration).to receive(:initialize_components).ordered
13
- subject.configure{ config.menu = "x" }
14
- end
15
- end
16
-
17
- describe "#render_layout" do
18
- before do
19
- class DummyBuilder
20
- def initialize(x)
21
- end
22
-
23
- def output(&block)
24
- yield
25
- end
26
- end
27
-
28
- subject.config = Releaf::Configuration.new
29
- allow(subject.config).to receive(:layout_builder_class_name).and_return("DummyBuilder")
30
- builder = DummyBuilder.new("xx")
31
- allow(DummyBuilder).to receive(:new).with("tmpl").and_return(builder)
32
- end
33
-
34
- it "returns layout builder rendered layout" do
35
- expect(subject.render_layout("tmpl"){ "pp" }).to eq("pp")
36
- end
37
-
38
- it "returns html safe content" do
39
- expect(subject.render_layout("tmpl"){ "pp" }.html_safe?).to be true
40
- end
41
- end
42
- end
43
-
@@ -1,130 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::AssetsResolver do
4
- describe ".base_assets" do
5
- it "returns array with `releaf/application`" do
6
- expect(described_class.base_assets).to eq(["releaf/application"])
7
- end
8
- end
9
-
10
- describe ".controller_assets" do
11
- before do
12
- allow(described_class).to receive(:base_assets).and_return(["a", "b"])
13
- end
14
-
15
- context "when controller assets of given type (javascripts/stylesheets) exists" do
16
- it "returns array with controller specific asset alognside base assets" do
17
- allow(described_class).to receive(:assets).and_return(
18
- "controllers/releaf/i18n_database/translations.js" => "controllers/releaf/i18n_database/translations.js",
19
- "controllers/releaf/i18n_database/translations.css" => "controllers/releaf/i18n_database/translations.css",
20
- )
21
- expect(described_class.controller_assets("releaf/i18n_database/translations", :javascripts))
22
- .to eq(["a", "b", "controllers/releaf/i18n_database/translations.js"])
23
-
24
- expect(described_class.controller_assets("releaf/i18n_database/translations", :stylesheets))
25
- .to eq(["a", "b", "controllers/releaf/i18n_database/translations.css"])
26
- end
27
- end
28
-
29
- context "when no controller assets of given type (javascripts/stylesheets) exists" do
30
- it "returns only base assets" do
31
- allow(described_class).to receive(:assets).and_return(
32
- "controllers/releaf/i18n_database/translations.fonts" => "controllers/releaf/i18n_database/translations.fonts",
33
- "i18n_database/translations.css" => "i18n_database/translations.css",
34
- )
35
- expect(described_class.controller_assets("releaf/i18n_database/translations", :javascripts))
36
- .to eq(["a", "b"])
37
-
38
- expect(described_class.controller_assets("releaf/i18n_database/translations", :stylesheets))
39
- .to eq(["a", "b"])
40
- end
41
- end
42
- end
43
-
44
- describe ".compiled_assets" do
45
- it "returns array with uniq controller scoped stylesheets and javascripts" do
46
- allow(Rails.application.assets_manifest).to receive(:files).and_return(
47
- "controllers/releaf/content/nodes-72ac849dd467fe827933f15c45ea77a2b7beac55379147f3be4a21779787f484.js"=>{"logical_path"=>"controllers/releaf/content/nodes.js", "mtime"=>"2015-12-01T13:55:41+02:00", "size"=>1530, "digest"=>"72ac849dd467fe827933f15c45ea77a2b7beac55379147f3be4a21779787f484", "integrity"=>"sha256-cqyEndRn/oJ5M/FcRep3ore+rFU3kUfzvkohd5eH9IQ="},
48
- "controllers/releaf/content/nodes-2ac6b38702a01d9e0918adasasdasda45e746.css"=>{"logical_path"=>"controllers/releaf/content/nodes.css", "mtime"=>"2016-02-18T13:36:15+02:00", "size"=>4301, "digest"=>"2ac6b38702a01d9e0918adasasdasda45e746", "integrity"=>"sha256-asdasdasdsa+adasdasda="},
49
- # simulate old assets cache here
50
- "controllers/releaf/content/nodes-adsaassdkdasd.css"=>{"logical_path"=>"controllers/releaf/content/nodes.css", "mtime"=>"2016-02-18T13:36:15+02:00", "size"=>4301, "digest"=>"adsaassdkdasd", "integrity"=>"sha256-asdasdasdsa+adasdasda="},
51
- "releaontxzcent/nodes-asdassdasdsaasdasd.css"=>{"logical_path"=>"releaontxzcent/nodes-asdassdasdsaasdasd.css", "mtime"=>"2016-01-18T13:36:15+02:00", "size"=>5919, "digest"=>"asdassdasdsaasdasd", "integrity"=>"sha256-KsazhwKgHZ4JGPBY+SOznIMgzfph9Bx0lHUrZIpF50Y="},
52
- "controllers/releaf/permissions/sessions-9eb2f3275ea7578a6a95ca413d318a9984ef93c0d6645f11cf77fe82a2639cf0.css"=>{"logical_path"=>"controllers/releaf/permissions/sessions.css", "mtime"=>"2016-01-18T13:36:15+02:00", "size"=>2205, "digest"=>"9eb2f3275ea7578a6a95ca413d318a9984ef93c0d6645f11cf77fe82a2639cf0", "integrity"=>"sha256-nrLzJ16nV4pqlcpBPTGKmYTvk8DWZF8Rz3f+gqJjnPA="}
53
- )
54
-
55
- list = [
56
- "controllers/releaf/content/nodes.js",
57
- "controllers/releaf/content/nodes.css",
58
- "controllers/releaf/permissions/sessions.css"
59
- ]
60
- expect(described_class.compiled_assets).to eq(list)
61
- end
62
- end
63
-
64
- describe ".noncompiled_assets" do
65
- it "returns array with controller scoped stylesheets and javascripts" do
66
- list = [
67
- "controllers/admin/books.js",
68
- "controllers/admin/nodes.js",
69
- "controllers/admin/other_site/other_nodes.js",
70
- "controllers/admin/nodes.css",
71
- "controllers/admin/other_site/other_nodes.css",
72
- "controllers/releaf/content/nodes.js",
73
- "controllers/releaf/content/nodes.css",
74
- "controllers/releaf/permissions/sessions.css",
75
- "controllers/releaf/i18n_database/translations.js",
76
- "controllers/releaf/i18n_database/translations.css"
77
- ]
78
- expect(described_class.noncompiled_assets).to eq(list)
79
- end
80
- end
81
-
82
- describe ".compiled_assets?" do
83
- context "when `Rails.application.assets` is not nil" do
84
- it "returns true" do
85
- allow(Rails.application).to receive(:assets).and_return(nil)
86
- expect(described_class.compiled_assets?).to be true
87
- end
88
- end
89
-
90
- context "when `Rails.application.assets` is nil" do
91
- it "returns false" do
92
- allow(Rails.application).to receive(:assets).and_return("x")
93
- expect(described_class.compiled_assets?).to be false
94
- end
95
- end
96
- end
97
-
98
- describe ".assets" do
99
- before do
100
- described_class.class_variable_set(:@@compiled_assets, nil)
101
- allow(described_class).to receive(:compiled_assets).and_return("a")
102
- allow(described_class).to receive(:noncompiled_assets).and_return("b")
103
- allow(described_class).to receive(:assets_hash).with("a").and_return("aa")
104
- allow(described_class).to receive(:assets_hash).with("b").and_return("bb")
105
- end
106
-
107
- context "when compiled assets is not available" do
108
- it "returns grouped non compiled assets" do
109
- allow(described_class).to receive(:compiled_assets?).and_return(false)
110
- expect(described_class.assets).to eq("bb")
111
- end
112
- end
113
-
114
- context "when compiled assets available" do
115
- before do
116
- allow(described_class).to receive(:compiled_assets?).and_return(true)
117
- end
118
-
119
- it "caches grouped compiled assets list" do
120
- expect(described_class).to receive(:assets_hash).once.and_return("aa")
121
- described_class.assets
122
- described_class.assets
123
- end
124
-
125
- it "returns grouped compiled assets" do
126
- expect(described_class.assets).to eq("aa")
127
- end
128
- end
129
- end
130
- end
@@ -1,141 +0,0 @@
1
- require 'rails_helper'
2
-
3
- describe Releaf::BuildErrorsHash do
4
- let(:resource) { Book.new }
5
- let(:error){ ActiveModel::ErrorMessage.new("blank value", :blank) }
6
-
7
- subject do
8
- described_class.new(resource: resource, field_name_prefix: :resource)
9
- end
10
-
11
- describe "#call" do
12
- it "returns hash with merged errors" do
13
- allow(subject).to receive(:errors).and_return([
14
- {
15
- field_name: "name",
16
- message: "error blank",
17
- error_code: :blank,
18
- },
19
- {
20
- field_name: "name",
21
- message: "invalid format",
22
- error_code: :invalid_format,
23
- },
24
- {
25
- field_name: "surname",
26
- message: "error blank",
27
- error_code: :blank,
28
- },
29
- ])
30
- expect(subject.call).to eq(
31
- "name" => [{message: "error blank", error_code: :blank}, {message: "invalid format", error_code: :invalid_format}],
32
- "surname" => [{message: "error blank", error_code: :blank}]
33
- )
34
- end
35
- end
36
-
37
- describe "#errors" do
38
- it "returns flattened errors array" do
39
- allow(resource).to receive(:errors).and_return(name: "er1", surname: "er2", role: "er3")
40
- allow(subject).to receive(:format_error).with(:name, "er1").and_return("error1")
41
- allow(subject).to receive(:format_error).with(:surname, "er2").and_return("error2")
42
- allow(subject).to receive(:format_error).with(:role, "er3").and_return(["error3", "error4"])
43
- expect(subject.errors).to eq(["error1", "error2", "error3", "error4"])
44
- end
45
- end
46
-
47
- describe "#format_error" do
48
- before do
49
- allow(subject).to receive(:attribute_error).with(:name, "er1").and_return("error1")
50
- allow(subject).to receive(:nested_attribute_errors).with(:name).and_return(["error1", "error2"])
51
- end
52
-
53
- context "when resource attribute given" do
54
- it "returns attribute error" do
55
- allow(subject).to receive(:resource_attribute?).and_return(true)
56
- expect(subject.format_error(:name, "er1")).to eq("error1")
57
- end
58
- end
59
-
60
- context "when nested attribute given" do
61
- it "returns nested attribute errors" do
62
- allow(subject).to receive(:resource_attribute?).and_return(false)
63
- expect(subject.format_error(:name, "er1")).to eq(["error1", "error2"])
64
- end
65
- end
66
- end
67
-
68
- describe "#attribute_error" do
69
- it "returns attribute error hash" do
70
- allow(subject).to receive(:field_name).with(:name).and_return("xxx_name")
71
- expect(subject.format_error(:name, error)).to eq(field_name: "xxx_name", error_code: :blank, message: "blank value")
72
- end
73
- end
74
-
75
- describe "#single_association?" do
76
- context "for :belongs_to association" do
77
- it "returns true" do
78
- expect( subject.single_association?('author') ).to be true
79
- end
80
- end
81
-
82
- context "for :has_many association" do
83
- it "returns false" do
84
- expect( subject.single_association?('chapters') ).to be false
85
- end
86
- end
87
-
88
- context "for :has_one association" do
89
- it "returns true" do
90
- allow(subject).to receive(:association_type).with('author').and_return(:has_one)
91
- expect( subject.single_association?('author') ).to be true
92
- end
93
- end
94
- end
95
-
96
- describe "#association" do
97
- it "returns active record reflection of association" do
98
- expect( subject.send(:association, 'author') ).to eq Book.reflect_on_association(:author)
99
- end
100
- end
101
-
102
- describe "#association_type" do
103
- it "returns active record reflection macro" do
104
- expect( subject.association_type('author') ).to eq :belongs_to
105
- end
106
- end
107
-
108
- describe "#resource_attribute?" do
109
- context "when attribute name contains dot" do
110
- it "returns false" do
111
- expect( subject.resource_attribute?('test.attribute') ).to be false
112
- end
113
- end
114
-
115
- context "when attribute name doesn't contain dot" do
116
- it "returns true" do
117
- expect( subject.resource_attribute?('test') ).to be true
118
- end
119
- end
120
- end
121
-
122
- describe "#field_name" do
123
- context "when error is on base" do
124
- it "returns resource field_id" do
125
- expect( subject.field_name('base')).to eq 'resource'
126
- end
127
- end
128
-
129
- context "when attribute is association" do
130
- it "returns field_id for associations foreign key" do
131
- expect( subject.field_name('author')).to eq 'resource[author_id]'
132
- end
133
- end
134
-
135
- context "when attribute is not association" do
136
- it "returns field_id for field" do
137
- expect( subject.field_name('title')).to eq 'resource[title]'
138
- end
139
- end
140
- end
141
- end
@@ -1,205 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Configuration do
4
- class DummyComponentA
5
- def self.configure_component; end
6
- end
7
- class DummyComponentB
8
- def self.initialize_component; end
9
- end
10
- class DummyComponentC
11
- def self.initialize_component; end
12
- def self.configure_component; end
13
- end
14
-
15
- describe "#components=" do
16
- before do
17
- allow(subject).to receive(:flatten_components).with(["x", "s"])
18
- .and_return([DummyComponentA, DummyComponentB, DummyComponentC])
19
- end
20
-
21
- it "assigns normalized components" do
22
- expect{ subject.components = ["x", "s"] }.to change{ subject.components }.to([DummyComponentA, DummyComponentB, DummyComponentC])
23
- end
24
-
25
- it "calls component configuration if available" do
26
- expect(DummyComponentA).to receive(:configure_component).ordered
27
- expect(DummyComponentC).to receive(:configure_component).ordered
28
- subject.components = ["x", "s"]
29
- end
30
- end
31
-
32
- describe "#initialize_components" do
33
- it "adds component configuration and calls component initializing method if available" do
34
- allow(subject).to receive(:components).and_return([DummyComponentA, DummyComponentB, DummyComponentC])
35
- expect(DummyComponentB).to receive(:initialize_component).ordered
36
- expect(DummyComponentC).to receive(:initialize_component).ordered
37
- subject.initialize_components
38
- end
39
- end
40
-
41
- describe "#add_configuration" do
42
- it "creates configuration class accessor for given configuration instance, and assigns given instance to it" do
43
- class Releaf::Configuration::DummySampleConfiguration; end
44
- configuration = Releaf::Configuration::DummySampleConfiguration.new
45
-
46
- expect(subject.respond_to?(:dummy_sample)).to be false
47
- subject.add_configuration(configuration)
48
-
49
- expect(subject.respond_to?(:dummy_sample)).to be true
50
- expect(subject.dummy_sample).to eq(configuration)
51
- end
52
- end
53
-
54
- describe "#initialize_locales" do
55
- before do
56
- subject.available_locales = [:a, :b]
57
- subject.available_admin_locales = [:b, :c]
58
- allow(::I18n).to receive(:available_locales=)
59
- end
60
-
61
- it "assigns available locales to `I18n.available_locales`" do
62
- expect(::I18n).to receive(:available_locales=).with([:a, :b])
63
- subject.initialize_locales
64
- end
65
-
66
- context "when no `available_admin_locales` defined" do
67
- it "overwrites it with available locales" do
68
- expect{ subject.initialize_locales }.to_not change{ subject.available_admin_locales }
69
-
70
- subject.available_admin_locales = nil
71
- expect{ subject.initialize_locales }.to change{ subject.available_admin_locales }.to eq([:a, :b])
72
- end
73
- end
74
- end
75
-
76
- describe "#all_locales" do
77
- before do
78
- subject.available_locales = [:a, :b]
79
- subject.available_admin_locales = [:b, :c]
80
- end
81
-
82
- it "merges unique locales form admin and available locales, casts it to strings and assign to `all_locales`" do
83
- expect( subject.all_locales ).to eq(["a", "b", "c"])
84
- end
85
-
86
- it "caches resolved locales" do
87
- expect(subject).to receive(:available_locales).and_call_original.once
88
- expect(subject).to receive(:available_admin_locales).and_call_original.once
89
- subject.all_locales
90
- subject.all_locales
91
- end
92
- end
93
-
94
- describe "#flatten_components" do
95
- it "returns recursively flattened component list" do
96
- class DummyComponentA; end
97
- class DummyComponentB
98
- def self.components
99
- ["o", "p"]
100
- end
101
- end
102
-
103
- allow(subject).to receive(:flatten_components).and_call_original
104
- allow(subject).to receive(:flatten_components).with(["o", "p"]).and_return(["x", "y"])
105
- expect(subject.flatten_components([DummyComponentA, DummyComponentB])).to eq([DummyComponentA, "x", "y", DummyComponentB])
106
- end
107
- end
108
-
109
- describe "#menu=" do
110
- it "normalizes menu before assigning" do
111
- allow(described_class).to receive(:normalize_controllers).with(["a"]).and_return(["aa"])
112
- expect{ subject.menu = ["a"] }.to change{ subject.menu }.to(["aa"])
113
- end
114
- end
115
-
116
- describe "#additional_controllers=" do
117
- it "normalizes additional controllers before assigning" do
118
- allow(described_class).to receive(:normalize_controllers).with(["b"]).and_return(["bb"])
119
- expect{ subject.additional_controllers = ["b"] }.to change{ subject.additional_controllers }.to(["bb"])
120
- end
121
- end
122
-
123
- describe "#controllers" do
124
- it "returns extracted controllers from menu and additional controllers attributes" do
125
- allow(subject).to receive(:menu).and_return(["a", "b"])
126
- allow(subject).to receive(:additional_controllers).and_return(["c", "d"])
127
- allow(subject).to receive(:extract_controllers).with(["a", "b", "c", "d"]).and_return("xxx")
128
- expect( subject.controllers ).to eq("xxx")
129
- end
130
-
131
- it "caches resolved controllers" do
132
- expect(subject).to receive(:extract_controllers).and_call_original.once
133
- subject.controllers
134
- subject.controllers
135
- end
136
- end
137
-
138
- describe "#available_controllers" do
139
- before do
140
- allow(subject).to receive(:controllers).and_return("c" => "d", "l" => "k")
141
- end
142
-
143
- it "returns controller names" do
144
- expect( subject.available_controllers ).to eq(["c", "l"])
145
- end
146
-
147
- it "caches resolved controller names" do
148
- expect(subject).to receive(:controllers).and_call_original.once
149
- subject.available_controllers
150
- subject.available_controllers
151
- end
152
- end
153
-
154
- describe "#extract_controllers" do
155
- it "returns recursively built hash with controllers from given array" do
156
- item_1 = Releaf::ControllerDefinition.new(name: "aa", controller: :a)
157
- item_2 = Releaf::ControllerDefinition.new(name: "bb", controller: :b)
158
- item_3 = Releaf::ControllerDefinition.new(name: "cc", controller: :c)
159
- item_4 = Releaf::ControllerDefinition.new(name: "dd", controller: :d)
160
- item_5 = Releaf::ControllerDefinition.new(name: "ff", controller: :f)
161
-
162
- group_item_1 = Releaf::ControllerGroupDefinition.new(name: "x", items: [])
163
- group_item_2 = Releaf::ControllerGroupDefinition.new(name: "y", items: [])
164
- allow(group_item_1).to receive(:controllers).and_return([item_3, item_4])
165
- allow(group_item_2).to receive(:controllers).and_return([item_5])
166
-
167
- list = [item_1, group_item_1, group_item_2, item_2]
168
- result = {a: item_1, b: item_2, c: item_3, d: item_4, f: item_5}
169
- expect(subject.extract_controllers(list)).to eq(result)
170
- end
171
- end
172
-
173
- describe ".normalize_controllers" do
174
- it "returns list of normalized controllers" do
175
- item_1 = Releaf::ControllerDefinition.new(name: "aa", controller: :a)
176
- item_2 = Releaf::ControllerDefinition.new(name: "bb", controller: :b)
177
- item_3 = Releaf::ControllerDefinition.new(name: "cc", controller: :c)
178
-
179
- group_item_1 = Releaf::ControllerGroupDefinition.new(name: "x", items: [])
180
- group_item_2 = Releaf::ControllerGroupDefinition.new(name: "y", items: [])
181
-
182
- allow(Releaf::ControllerGroupDefinition).to receive(:new).with(items: "x").and_return(group_item_2)
183
- allow(Releaf::ControllerDefinition).to receive(:new).with(name: "y").and_return(item_2)
184
- allow(Releaf::ControllerDefinition).to receive(:new).with("z").and_return(item_3)
185
-
186
- list = [
187
- item_1,
188
- group_item_1,
189
- {items: "x"},
190
- {name: "y"},
191
- "z"
192
- ]
193
-
194
- result = [
195
- item_1,
196
- group_item_1,
197
- group_item_2,
198
- item_2,
199
- item_3
200
- ]
201
-
202
- expect(described_class.normalize_controllers(list)).to eq(result)
203
- end
204
- end
205
- end