releaf-core 0.2.1 → 1.0.3
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.
- checksums.yaml +4 -4
- data/LICENSE +19 -21
- data/app/assets/javascripts/releaf/application.js +1 -2
- data/app/assets/javascripts/releaf/include/field.type_date_or_datetime_or_time.js +19 -21
- data/app/assets/javascripts/releaf/include/field.type_richtext.js +31 -9
- data/app/assets/javascripts/releaf/include/localization.js +3 -8
- data/app/assets/javascripts/releaf/include/nested_fields.js +1 -1
- data/app/assets/javascripts/releaf/include/remote_validator.js +7 -4
- data/app/assets/javascripts/releaf/include/sortable.js +1 -1
- data/app/assets/javascripts/releaf/include/{profile_settings.js → store_settings.js} +4 -10
- data/app/assets/javascripts/releaf/include/toolbox.js +7 -11
- data/app/assets/stylesheets/releaf/layout/fields.scss +1 -0
- data/app/assets/stylesheets/releaf/layout/header.scss +1 -0
- data/app/assets/stylesheets/releaf/layout/search.scss +15 -0
- data/app/builders/releaf/builders/base.rb +11 -9
- data/app/builders/releaf/builders/confirm_destroy_dialog_builder.rb +2 -2
- data/app/builders/releaf/builders/confirm_dialog_builder.rb +3 -3
- data/app/builders/releaf/builders/edit_builder.rb +51 -6
- data/app/builders/releaf/builders/form_builder/associated_set_field.rb +37 -0
- data/app/builders/releaf/builders/form_builder/associations.rb +153 -0
- data/app/builders/releaf/builders/form_builder/boolean_fields.rb +12 -0
- data/app/builders/releaf/builders/form_builder/date_fields.rb +30 -0
- data/app/builders/releaf/builders/form_builder/fields.rb +10 -0
- data/app/builders/releaf/builders/form_builder/file_fields.rb +47 -0
- data/app/builders/releaf/builders/form_builder/i18n_fields.rb +75 -0
- data/app/builders/releaf/builders/form_builder/label.rb +34 -0
- data/app/builders/releaf/builders/form_builder/number_fields.rb +13 -0
- data/app/builders/releaf/builders/form_builder/richtext_fields.rb +28 -0
- data/app/builders/releaf/builders/form_builder/text_fields.rb +43 -0
- data/app/builders/releaf/builders/form_builder.rb +8 -489
- data/app/builders/releaf/builders/index_builder.rb +10 -3
- data/app/builders/releaf/builders/page/header_builder.rb +23 -59
- data/app/builders/releaf/builders/page/layout_builder.rb +125 -115
- data/app/builders/releaf/builders/page/menu_builder.rb +96 -106
- data/app/builders/releaf/builders/refused_destroy_dialog_builder.rb +7 -12
- data/app/builders/releaf/builders/resource_view.rb +4 -4
- data/app/builders/releaf/builders/table_builder.rb +20 -30
- data/app/builders/releaf/builders/toolbox_builder.rb +1 -1
- data/app/builders/releaf/builders/utilities/date_fields.rb +100 -0
- data/app/builders/releaf/builders/utilities/resolve_attribute_field_method_name.rb +80 -0
- data/app/builders/releaf/builders/view.rb +5 -2
- data/app/builders/releaf/settings/form_builder.rb +18 -0
- data/app/builders/releaf/settings/table_builder.rb +9 -0
- data/app/controllers/releaf/action_controller.rb +174 -0
- data/app/controllers/releaf/{core/errors_controller.rb → errors_controller.rb} +1 -1
- data/app/controllers/releaf/root_controller.rb +23 -0
- data/app/controllers/releaf/settings_controller.rb +22 -0
- data/app/helpers/releaf/application_helper.rb +1 -1
- data/app/lib/releaf/action_controller/ajax.rb +24 -0
- data/app/lib/releaf/action_controller/breadcrumbs.rb +26 -0
- data/app/lib/releaf/action_controller/builders.rb +34 -0
- data/app/lib/releaf/action_controller/features.rb +47 -0
- data/app/lib/releaf/action_controller/notifications.rb +28 -0
- data/app/lib/releaf/action_controller/resources.rb +59 -0
- data/app/{controllers/concerns/releaf → lib/releaf/action_controller}/richtext_attachments.rb +1 -1
- data/app/lib/releaf/action_controller/search.rb +22 -0
- data/app/lib/releaf/action_controller/urls.rb +49 -0
- data/app/lib/releaf/action_controller/views.rb +29 -0
- data/app/lib/releaf/assets_resolver.rb +51 -0
- data/app/lib/releaf/build_errors_hash.rb +81 -0
- data/app/lib/releaf/controller_definition.rb +22 -0
- data/app/lib/releaf/controller_group_definition.rb +12 -0
- data/app/lib/releaf/{core/default_searchable_fields.rb → default_searchable_fields.rb} +1 -1
- data/app/lib/releaf/{core/resource_base.rb → resource_base.rb} +14 -6
- data/app/lib/releaf/{core/resource_fields.rb → resource_fields.rb} +1 -1
- data/app/lib/releaf/{core/resource_params.rb → resource_params.rb} +3 -3
- data/app/lib/releaf/resource_table_fields.rb +10 -0
- data/app/lib/releaf/{core/resource_utilities.rb → resource_utilities.rb} +2 -2
- data/app/lib/releaf/{core/responders → responders}/access_denied_responder.rb +2 -2
- data/app/lib/releaf/{core/responders → responders}/after_save_responder.rb +3 -3
- data/app/lib/releaf/{core/responders → responders}/confirm_destroy_responder.rb +1 -1
- data/app/lib/releaf/{core/responders → responders}/destroy_responder.rb +1 -1
- data/app/lib/releaf/{core/responders → responders}/error_responder.rb +1 -1
- data/app/lib/releaf/{core/responders → responders}/feature_disabled_responder.rb +2 -2
- data/app/lib/releaf/{core/responders → responders}/page_not_found_responder.rb +2 -2
- data/app/lib/releaf/responders.rb +31 -0
- data/app/lib/releaf/{core/search.rb → search.rb} +1 -1
- data/app/lib/releaf/settings/normalize_value.rb +45 -0
- data/app/lib/releaf/settings/register.rb +45 -0
- data/app/models/releaf/settings.rb +25 -13
- data/app/services/array/reorder.rb +82 -0
- data/app/views/releaf/{base → action}/confirm_destroy.ruby +0 -0
- data/app/views/releaf/{base → action}/create_releaf_richtext_attachment.haml +0 -0
- data/app/views/releaf/{base → action}/edit.ruby +0 -0
- data/app/views/releaf/{base → action}/index.ruby +0 -0
- data/app/views/releaf/{base → action}/new.ruby +0 -0
- data/app/views/releaf/{base → action}/refused_destroy.ruby +0 -0
- data/app/views/releaf/{base → action}/show.ruby +0 -0
- data/app/views/releaf/{base → action}/toolbox.ruby +0 -0
- data/lib/generators/dummy/install_generator.rb +5 -0
- data/lib/generators/dummy/templates/assets/javascripts/controllers/admin/books.js +23 -0
- data/lib/generators/dummy/templates/assets/javascripts/controllers/admin/nodes.js +1 -0
- data/lib/generators/dummy/templates/assets/javascripts/controllers/admin/other_site/other_nodes.js +1 -0
- data/lib/generators/dummy/templates/assets/stylesheets/controllers/admin/nodes.scss +1 -0
- data/lib/generators/dummy/templates/assets/stylesheets/controllers/admin/other_site/other_nodes.scss +1 -0
- data/lib/generators/dummy/templates/builders/admin/books/form_builder.rb +11 -1
- data/lib/generators/dummy/templates/config/routes.rb +31 -7
- data/lib/generators/dummy/templates/controllers/admin/authors_controller.rb +3 -6
- data/lib/generators/dummy/templates/controllers/admin/books_controller.rb +1 -1
- data/lib/generators/dummy/templates/controllers/admin/chapters_controller.rb +1 -1
- data/lib/generators/dummy/templates/controllers/admin/nodes_controller.rb +3 -0
- data/lib/generators/dummy/templates/controllers/admin/other_site/other_nodes_controller.rb +3 -0
- data/lib/generators/dummy/templates/controllers/admin/publishers_controller.rb +1 -1
- data/lib/generators/dummy/templates/controllers/application_controller.rb +27 -5
- data/lib/generators/dummy/templates/controllers/concerns/node_controller.rb +13 -3
- data/lib/generators/dummy/templates/controllers/contacts_controller.rb +3 -1
- data/lib/generators/dummy/templates/initializers/releaf.rb +31 -25
- data/lib/generators/dummy/templates/migrations/create_home_pages.rb +1 -0
- data/lib/generators/dummy/templates/migrations/create_other_nodes.rb +29 -0
- data/lib/generators/dummy/templates/models/author.rb +2 -2
- data/lib/generators/dummy/templates/models/book.rb +0 -2
- data/lib/generators/dummy/templates/models/chapter.rb +0 -2
- data/lib/generators/dummy/templates/models/home_page.rb +1 -0
- data/lib/generators/dummy/templates/models/other_site/other_node.rb +7 -0
- data/lib/generators/dummy/templates/models/publisher.rb +0 -5
- data/lib/generators/dummy/templates/models/text_page.rb +0 -1
- data/lib/generators/dummy/templates/views/contacts/show.html.haml +1 -1
- data/lib/generators/dummy/templates/views/layouts/application.html.haml +9 -1
- data/lib/generators/dummy/templates/views/text_pages/show.haml +1 -1
- data/lib/generators/releaf/templates/initializers/releaf.rb +6 -17
- data/lib/generators/releaf/templates/migrations/create_releaf_translations.rb +13 -14
- data/lib/generators/releaf/templates/seeds/seeds.rb +28 -32
- data/lib/releaf/{core/application.rb → application.rb} +5 -4
- data/lib/releaf/{core/component.rb → component.rb} +6 -2
- data/lib/releaf/configuration.rb +95 -0
- data/lib/releaf/core_ext/array/reorder.rb +5 -0
- data/lib/releaf/engine.rb +12 -0
- data/lib/releaf/exceptions.rb +5 -0
- data/lib/releaf/instance_cache.rb +72 -0
- data/lib/releaf/{core → rails_ext}/validation_error_codes.rb +1 -1
- data/lib/releaf/root/configuration.rb +6 -0
- data/lib/releaf/root/default_controller_resolver.rb +37 -0
- data/lib/releaf/root/settings_manager.rb +12 -0
- data/lib/releaf/root.rb +17 -0
- data/lib/releaf/{core/route_mapper.rb → route_mapper.rb} +6 -6
- data/lib/releaf/service.rb +11 -0
- data/lib/releaf/settings_ui.rb +7 -0
- data/lib/releaf/version.rb +1 -1
- data/lib/releaf-core.rb +38 -9
- data/spec/builders/{builders → releaf/builders}/association_reflector_spec.rb +0 -0
- data/spec/builders/{builders → releaf/builders}/base_spec.rb +17 -21
- data/spec/builders/{builders → releaf/builders}/collection_spec.rb +0 -0
- data/spec/builders/{builders → releaf/builders}/confirm_destroy_dialog_builder_spec.rb +5 -5
- data/spec/builders/{builders → releaf/builders}/confirm_dialog_builder_spec.rb +9 -7
- data/spec/builders/{builders → releaf/builders}/edit_builder_spec.rb +127 -20
- data/spec/builders/releaf/builders/form_builder/associations_spec.rb +129 -0
- data/spec/builders/releaf/builders/form_builder/date_fields_spec.rb +86 -0
- data/spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb +48 -0
- data/spec/builders/releaf/builders/form_builder/label_spec.rb +106 -0
- data/spec/builders/releaf/builders/form_builder/number_fields_spec.rb +37 -0
- data/spec/builders/releaf/builders/form_builder_spec.rb +228 -0
- data/spec/builders/{builders → releaf/builders}/index_builder_spec.rb +29 -10
- data/spec/builders/releaf/builders/page/header_builder_spec.rb +65 -0
- data/spec/builders/releaf/builders/page/layout_builder_spec.rb +170 -0
- data/spec/builders/releaf/builders/page/menu_builder_spec.rb +345 -0
- data/spec/builders/{builders → releaf/builders}/pagination_builder_spec.rb +0 -0
- data/spec/builders/{builders → releaf/builders}/resource_dialog_spec.rb +0 -0
- data/spec/builders/{builders → releaf/builders}/resource_view_spec.rb +8 -8
- data/spec/builders/{builders → releaf/builders}/show_builder_spec.rb +0 -0
- data/spec/builders/{builders → releaf/builders}/table_builder_spec.rb +31 -75
- data/spec/builders/{builders → releaf/builders}/template_spec.rb +0 -0
- data/spec/builders/{builders → releaf/builders}/toolbox_builder_spec.rb +4 -4
- data/spec/builders/{builders → releaf/builders}/toolbox_spec.rb +0 -0
- data/spec/builders/releaf/builders/utilities/date_fields_spec.rb +125 -0
- data/spec/builders/releaf/builders/utilities/resolve_attribute_field_method_name_spec.rb +318 -0
- data/spec/builders/{builders → releaf/builders}/view_spec.rb +1 -1
- data/spec/builders/{builders_spec.rb → releaf/builders_spec.rb} +0 -0
- data/spec/builders/releaf/settings/form_builder_spec.rb +48 -0
- data/spec/builders/{core → releaf}/settings/table_builder_spec.rb +6 -4
- data/spec/controllers/concerns/releaf/richtext_attachments_spec.rb +1 -1
- data/spec/controllers/releaf/{base_controller_spec.rb → action_controller_spec.rb} +132 -161
- data/spec/controllers/releaf/root_controller_spec.rb +40 -0
- data/spec/controllers/releaf/settings_controller_spec.rb +52 -0
- data/spec/error_hash_builder_spec.rb +83 -0
- data/spec/ext/array_reorder_spec.rb +12 -0
- data/spec/features/ajaxbox_spec.rb +6 -6
- data/spec/features/errors_spec.rb +2 -1
- data/spec/features/index_table_spec.rb +6 -3
- data/spec/features/richtext_attachments_spec.rb +2 -2
- data/spec/features/richtext_custom_config_spec.rb +28 -0
- data/spec/features/richtext_embed_spec.rb +1 -1
- data/spec/features/richtext_spec.rb +10 -1
- data/spec/features/search_spec.rb +1 -1
- data/spec/features/settings_spec.rb +10 -5
- data/spec/helpers/application_helper_spec.rb +4 -6
- data/spec/lib/releaf/action_controller/features_spec.rb +171 -0
- data/spec/lib/releaf/action_controller/search_spec.rb +84 -0
- data/spec/lib/releaf/{core/application_spec.rb → application_spec.rb} +7 -6
- data/spec/lib/releaf/assets_resolver_spec.rb +130 -0
- data/spec/lib/releaf/build_errors_hash_spec.rb +141 -0
- data/spec/lib/releaf/configuration_spec.rb +205 -0
- data/spec/lib/releaf/controller_definition_spec.rb +49 -0
- data/spec/lib/releaf/controller_group_definition_spec.rb +27 -0
- data/spec/lib/releaf/{core/default_searchable_fields_spec.rb → default_searchable_fields_spec.rb} +1 -1
- data/spec/lib/releaf/instance_cache_spec.rb +98 -0
- data/spec/lib/releaf/{core/resource_base_spec.rb → resource_base_spec.rb} +59 -21
- data/spec/lib/releaf/{core/resource_fields_spec.rb → resource_fields_spec.rb} +1 -1
- data/spec/lib/releaf/{core/resource_params_spec.rb → resource_params_spec.rb} +3 -5
- data/spec/lib/releaf/resource_table_fields_spec.rb +20 -0
- data/spec/lib/releaf/{core/resource_utilities_spec.rb → resource_utilities_spec.rb} +1 -1
- data/spec/lib/releaf/{core/responders → responders}/access_denied_responder_spec.rb +1 -1
- data/spec/lib/releaf/{core/responders → responders}/after_save_responder_spec.rb +9 -8
- data/spec/lib/releaf/{core/responders → responders}/confirm_destroy_responder_spec.rb +2 -2
- data/spec/lib/releaf/{core/responders → responders}/destroy_responder_spec.rb +2 -2
- data/spec/lib/releaf/{core/responders → responders}/error_responder_spec.rb +4 -4
- data/spec/lib/releaf/{core/responders → responders}/feature_disabled_responder_spec.rb +1 -1
- data/spec/lib/releaf/{core/responders → responders}/page_not_found_responder_spec.rb +1 -1
- data/spec/lib/releaf/{core/responders_spec.rb → responders_spec.rb} +14 -14
- data/spec/lib/releaf/root/configuration_spec.rb +9 -0
- data/spec/lib/releaf/root/default_controller_resolver_spec.rb +108 -0
- data/spec/lib/releaf/root_spec.rb +13 -0
- data/spec/lib/releaf/service_spec.rb +20 -0
- data/spec/lib/releaf/settings/normalize_value_spec.rb +103 -0
- data/spec/lib/releaf/settings/register_spec.rb +135 -0
- data/spec/lib/releaf/settings_manager_spec.rb +22 -0
- data/spec/lib/validation_error_codes_spec.rb +1 -1
- data/spec/misc/factories_spec.rb +0 -12
- data/spec/models/settings_spec.rb +74 -32
- data/spec/routing/route_mapper_spec.rb +5 -5
- data/spec/rspec_helpers/test_helpers_spec.rb +1 -1
- data/spec/rspec_helpers/test_spec.rb +14 -0
- data/spec/{lib/releaf/core/item_orderer_spec.rb → services/array/reorder_spec.rb} +32 -53
- metadata +299 -224
- data/app/builders/releaf/builders/orderer.rb +0 -5
- data/app/builders/releaf/builders/tags/releaf_associated_set_field.rb +0 -40
- data/app/builders/releaf/core/settings/form_builder.rb +0 -21
- data/app/builders/releaf/core/settings/table_builder.rb +0 -11
- data/app/controllers/concerns/releaf/breadcrumbs.rb +0 -42
- data/app/controllers/releaf/base_controller.rb +0 -458
- data/app/controllers/releaf/core/settings_controller.rb +0 -50
- data/app/helpers/releaf/javascript_helper.rb +0 -75
- data/app/lib/releaf/core/assets_resolver.rb +0 -58
- data/app/lib/releaf/core/error_formatter.rb +0 -103
- data/app/lib/releaf/core/item_orderer.rb +0 -102
- data/app/lib/releaf/core/resource_table_fields.rb +0 -10
- data/app/lib/releaf/core/responders.rb +0 -31
- data/app/lib/releaf/core/template_field_type_mapper.rb +0 -127
- data/lib/generators/dummy/templates/controllers/concerns/.keep +0 -0
- data/lib/releaf/core/builders_autoload.rb +0 -27
- data/lib/releaf/core/configuration.rb +0 -101
- data/lib/releaf/core/engine.rb +0 -35
- data/lib/releaf/core/exceptions.rb +0 -38
- data/lib/releaf/core/settings_ui_component.rb +0 -7
- data/releaf-core.gemspec +0 -35
- data/spec/builders/builders/form_builder_spec.rb +0 -562
- data/spec/builders/builders/orderer_spec.rb +0 -22
- data/spec/builders/builders/page/header_builder_spec.rb +0 -143
- data/spec/builders/builders/page/layout_builder_spec.rb +0 -73
- data/spec/builders/builders/page/menu_builder_spec.rb +0 -160
- data/spec/builders/core/settings/form_builder_spec.rb +0 -69
- data/spec/controllers/releaf/core/settings_controller_spec.rb +0 -31
- data/spec/lib/releaf/core/assets_resolver_spec.rb +0 -113
- data/spec/lib/releaf/core/configuration_spec.rb +0 -230
- data/spec/lib/releaf/core/error_formatter_spec.rb +0 -242
- data/spec/lib/releaf/core/resource_table_fields_spec.rb +0 -18
- data/spec/lib/releaf/core/template_field_type_mapper_spec.rb +0 -311
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
require "rails_helper"
|
|
2
|
+
|
|
3
|
+
describe Releaf::Builders::Page::MenuBuilder, type: :class do
|
|
4
|
+
class MenuBuilderTestHelper < ActionView::Base
|
|
5
|
+
include FontAwesome::Rails::IconHelper
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
let(:controller){ Releaf::ActionController.new }
|
|
9
|
+
let(:template){ MenuBuilderTestHelper.new }
|
|
10
|
+
let(:group_item){ Releaf::ControllerGroupDefinition.new(name: "_group_name", items: []) }
|
|
11
|
+
let(:controller_item){ Releaf::ControllerDefinition.new(name: "y", controller: "_controller_") }
|
|
12
|
+
subject { described_class.new(template) }
|
|
13
|
+
|
|
14
|
+
before do
|
|
15
|
+
allow(template).to receive(:controller).and_return(controller)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "includes Releaf::Builders::Base" do
|
|
19
|
+
expect(described_class.ancestors).to include(Releaf::Builders::Base)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "includes Releaf::Builders::Template" do
|
|
23
|
+
expect(described_class.ancestors).to include(Releaf::Builders::Template)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "#output" do
|
|
27
|
+
it "returns compacter and first level menu" do
|
|
28
|
+
allow(Releaf.application.config).to receive(:menu).and_return("_menu_config")
|
|
29
|
+
allow(subject).to receive(:compacter).and_return("cmpt")
|
|
30
|
+
allow(subject).to receive(:menu_level).with("_menu_config").and_return("_items")
|
|
31
|
+
|
|
32
|
+
expect(subject.output).to eq("cmpt<nav>_items</nav>")
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "#active?" do
|
|
37
|
+
context "when item is instance of `Releaf::ControllerGroupDefinition`" do
|
|
38
|
+
before do
|
|
39
|
+
allow(subject).to receive(:active?).and_call_original
|
|
40
|
+
allow(group_item).to receive(:controllers).and_return([:a, :b, :c])
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context "when any of group item controller is active" do
|
|
44
|
+
it "returns true" do
|
|
45
|
+
allow(subject).to receive(:active?).with(:a).and_return(false)
|
|
46
|
+
allow(subject).to receive(:active?).with(:b).and_return(true)
|
|
47
|
+
expect(subject).to_not receive(:active?).with(:c)
|
|
48
|
+
expect(subject.active?(group_item)).to be true
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context "when none of group item controller is active" do
|
|
53
|
+
it "returns false" do
|
|
54
|
+
allow(subject).to receive(:active?).with(:a).and_return(false)
|
|
55
|
+
allow(subject).to receive(:active?).with(:b).and_return(false)
|
|
56
|
+
allow(subject).to receive(:active?).with(:c).and_return(false)
|
|
57
|
+
expect(subject.active?(group_item)).to be false
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
context "when item is instance of `Releaf::ControllerDefinition`" do
|
|
63
|
+
context "when item controller name is same as current controller short name" do
|
|
64
|
+
it "returns true" do
|
|
65
|
+
allow(controller).to receive(:short_name).and_return("_controller_")
|
|
66
|
+
expect(subject.active?(controller_item)).to be true
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
context "when item controller name is not same as current controller short name" do
|
|
71
|
+
it "returns false" do
|
|
72
|
+
allow(controller).to receive(:short_name).and_return("_another_controller_")
|
|
73
|
+
expect(subject.active?(controller_item)).to be false
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe "#menu_level" do
|
|
80
|
+
it "returns unordered list of menu level from given items" do
|
|
81
|
+
allow(subject).to receive(:menu_item).with("a").and_return("_a_")
|
|
82
|
+
allow(subject).to receive(:menu_item).with("b").and_return("_b_")
|
|
83
|
+
expect(subject.menu_level(%w(a b))).to eq("<ul>_a__b_</ul>")
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
context "when all menu items content is empty" do
|
|
87
|
+
it "returns nil" do
|
|
88
|
+
allow(subject).to receive(:menu_item).with("a").and_return(nil)
|
|
89
|
+
allow(subject).to receive(:menu_item).with("b").and_return(nil)
|
|
90
|
+
expect(subject.menu_level(%w(a b))).to be nil
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe "#menu_item" do
|
|
96
|
+
before do
|
|
97
|
+
allow(subject).to receive(:item_attributes).with(controller_item).and_return(class: "red")
|
|
98
|
+
allow(subject).to receive(:menu_item_single).with(controller_item).and_return("_item")
|
|
99
|
+
allow(subject).to receive(:item_attributes).with(group_item).and_return(class: "blue")
|
|
100
|
+
allow(subject).to receive(:menu_item_group).with(group_item).and_return("_items_group")
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
context "when item is instance of `Releaf::ControllerDefinition`" do
|
|
104
|
+
it "returns single menu item" do
|
|
105
|
+
expect(subject.menu_item(controller_item)).to eq("<li class=\"red\">_item</li>")
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
context "when item is instance of `Releaf::ControllerGroupDefinition`" do
|
|
110
|
+
it "returns group menu item" do
|
|
111
|
+
expect(subject.menu_item(group_item)).to eq("<li class=\"blue\">_items_group</li>")
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
describe "#menu_item_single" do
|
|
117
|
+
it "returns single menu item" do
|
|
118
|
+
allow(controller_item).to receive(:path).and_return("_url")
|
|
119
|
+
allow(subject).to receive(:item_name_content).with(controller_item).and_return("_name")
|
|
120
|
+
expect(subject.menu_item_single(controller_item)).to eq("<a class=\"trigger\" href=\"_url\">_name</a>")
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
describe "#menu_item_group" do
|
|
125
|
+
it "returns group menu item" do
|
|
126
|
+
allow(group_item).to receive(:controllers).and_return(["a"])
|
|
127
|
+
allow(subject).to receive(:item_collapser).with(group_item).and_return("_collapser")
|
|
128
|
+
allow(subject).to receive(:item_name_content).with(group_item).and_return("_name")
|
|
129
|
+
allow(subject).to receive(:menu_level).with(["a"]).and_return("_level")
|
|
130
|
+
expect(subject.menu_item_group(group_item)).to eq("<span class=\"trigger\">_name_collapser</span>_level")
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
describe "#collapsed_item?" do
|
|
135
|
+
before do
|
|
136
|
+
allow(subject).to receive(:layout_settings).with("releaf.menu.collapsed._group_name").and_return(true)
|
|
137
|
+
allow(subject).to receive(:active?).with(group_item).and_return(false)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
context "when non-active and permanently collapsed group item given" do
|
|
141
|
+
it "returns true" do
|
|
142
|
+
expect(subject.collapsed_item?(group_item)).to be true
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
context "when non-active and non-permanently collapsed group item given" do
|
|
147
|
+
it "returns false" do
|
|
148
|
+
allow(subject).to receive(:layout_settings).with("releaf.menu.collapsed._group_name").and_return(false)
|
|
149
|
+
expect(subject.collapsed_item?(group_item)).to be false
|
|
150
|
+
|
|
151
|
+
allow(subject).to receive(:layout_settings).with("releaf.menu.collapsed._group_name").and_return(nil)
|
|
152
|
+
expect(subject.collapsed_item?(group_item)).to be false
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
context "when active and permanently collapsed group item given" do
|
|
157
|
+
it "returns false" do
|
|
158
|
+
allow(subject).to receive(:active?).with(group_item).and_return(true)
|
|
159
|
+
expect(subject.collapsed_item?(group_item)).to be false
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
context "when non-active and permanently collapsed single item given" do
|
|
164
|
+
it "returns false" do
|
|
165
|
+
expect(subject).to_not receive(:active?)
|
|
166
|
+
expect(subject.collapsed_item?(controller_item)).to be false
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
describe "#item_attributes" do
|
|
172
|
+
it "returns data name and classes within hash" do
|
|
173
|
+
allow(subject).to receive(:item_classes).with(controller_item).and_return(["ol", "al"])
|
|
174
|
+
expect(subject.item_attributes(controller_item)).to eq(class: ["ol", "al"], data: {name: "y"})
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
context "when classes attribute is empty" do
|
|
178
|
+
it "does not return class attribute within returned hash" do
|
|
179
|
+
allow(subject).to receive(:item_classes).with(controller_item).and_return([])
|
|
180
|
+
expect(subject.item_attributes(controller_item)).to_not include(:class)
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
describe "#item_classes" do
|
|
186
|
+
context "when given item is active" do
|
|
187
|
+
it "adds `active` class to returned array" do
|
|
188
|
+
allow(subject).to receive(:active?).with(controller_item).and_return(true)
|
|
189
|
+
expect(subject.item_classes(controller_item)).to include("active")
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
context "when given item is collapsed" do
|
|
194
|
+
it "adds `collapsed` class to returned array" do
|
|
195
|
+
allow(subject).to receive(:collapsed_item?).with(controller_item).and_return(true)
|
|
196
|
+
expect(subject.item_classes(controller_item)).to include("collapsed")
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
context "when no extra classes added" do
|
|
201
|
+
it "returns empty array" do
|
|
202
|
+
allow(subject).to receive(:active?).with(controller_item).and_return(false)
|
|
203
|
+
expect(subject.item_classes(controller_item)).to eq([])
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
describe "#item_name_content" do
|
|
209
|
+
it "returns abbreviation and full name elements" do
|
|
210
|
+
allow(controller_item).to receive(:localized_name).and_return('Item full name')
|
|
211
|
+
allow(subject).to receive(:item_name_abbreviation).with('Item full name').and_return('Item abbreviation')
|
|
212
|
+
expect( subject.item_name_content(controller_item) ).to eq('<abbr title="Item full name">Item abbreviation</abbr><span class="name">Item full name</span>')
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
describe "#item_name_abbreviation" do
|
|
217
|
+
|
|
218
|
+
it "returns first two letters of given text string" do
|
|
219
|
+
expect( subject.item_name_abbreviation( "Foo bar" )).to eq("Fo")
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
context "when the first two letters are lowercase" do
|
|
223
|
+
it "capitalizes the first letter" do
|
|
224
|
+
expect( subject.item_name_abbreviation( "foo bar" )).to eq("Fo")
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
context "when the first two letters are uppercase" do
|
|
229
|
+
it "makes the second letter lowercase" do
|
|
230
|
+
expect( subject.item_name_abbreviation( "FOO BAR" )).to eq("Fo")
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
context "when the string contains slashes" do
|
|
235
|
+
|
|
236
|
+
it "uses the first word after the last slash" do
|
|
237
|
+
expect( subject.item_name_abbreviation( "Releaf/core/settings" )).to eq("Se")
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
it "ignores slashes surrounded by spaces" do
|
|
241
|
+
expect( subject.item_name_abbreviation( "Inputs / Outputs" )).to eq("In")
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
it "ignores trailing slashes" do
|
|
245
|
+
expect( subject.item_name_abbreviation( "Releaf/core/settings/" )).to eq("Se")
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
context "when string consists of a single slash" do
|
|
249
|
+
it "returns an empty string" do
|
|
250
|
+
expect( subject.item_name_abbreviation( "/" )).to eq("")
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
it "works with non-latin characters" do
|
|
256
|
+
expect( subject.item_name_abbreviation( "žņ" )).to eq("Žņ")
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
context "when given an empty string value" do
|
|
260
|
+
it "returns an empty string" do
|
|
261
|
+
expect( subject.item_name_abbreviation( "" )).to eq("")
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
context "when given nil" do
|
|
266
|
+
it "returns an empty string" do
|
|
267
|
+
expect( subject.item_name_abbreviation( nil )).to eq("")
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
describe "#item_collapser" do
|
|
273
|
+
|
|
274
|
+
it "returns a collapser span with a button and collapser icon" do
|
|
275
|
+
allow(subject).to receive(:item_collapser_icon).with(:foo).and_return(subject.icon('dummy'))
|
|
276
|
+
expect(subject.item_collapser(:foo)).to eq '<span class="collapser"><button type="button"><i class="fa fa-dummy"></i></button></span>'
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
describe "#item_collapser_icon" do
|
|
282
|
+
let(:item) { {} }
|
|
283
|
+
|
|
284
|
+
before do
|
|
285
|
+
allow(subject).to receive(:layout_settings).with('releaf.side.compact').and_return(false)
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
context "when side is compacted in layout settings" do
|
|
289
|
+
it "returns a beak pointing right" do
|
|
290
|
+
allow(subject).to receive(:layout_settings).with('releaf.side.compact').and_return(true)
|
|
291
|
+
allow(subject).to receive(:icon).with('chevron-right').and_return("icon ok")
|
|
292
|
+
expect(subject.item_collapser_icon(item)).to eq "icon ok"
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
context "when side is not compacted in layout settings" do
|
|
297
|
+
context "when the given item is collapsed" do
|
|
298
|
+
it "returns a beak pointing down" do
|
|
299
|
+
allow(subject).to receive(:collapsed_item?).with(item).and_return(true)
|
|
300
|
+
allow(subject).to receive(:icon).with('chevron-down').and_return("icon ok")
|
|
301
|
+
expect(subject.item_collapser_icon(item)).to eq "icon ok"
|
|
302
|
+
end
|
|
303
|
+
end
|
|
304
|
+
context "when the given item is expanded" do
|
|
305
|
+
it "returns a beak pointing up" do
|
|
306
|
+
allow(subject).to receive(:collapsed_item?).with(item).and_return(false)
|
|
307
|
+
allow(subject).to receive(:icon).with('chevron-up').and_return("icon ok")
|
|
308
|
+
expect(subject.item_collapser_icon(item)).to eq "icon ok"
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
describe "#compact_side?" do
|
|
315
|
+
it "returns layout settings for `releaf.side.compact`" do
|
|
316
|
+
allow(subject).to receive(:layout_settings).with("releaf.side.compact").and_return("_ls")
|
|
317
|
+
expect(subject.compact_side?).to eq("_ls")
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
describe "#compacter" do
|
|
322
|
+
before do
|
|
323
|
+
allow(subject).to receive(:button)
|
|
324
|
+
.with(nil, "angle-double-right", title: "Expand", data: {"title-expand"=>"Expand", "title-collapse"=>"Collapse"})
|
|
325
|
+
.and_return("_expand_btn")
|
|
326
|
+
allow(subject).to receive(:button)
|
|
327
|
+
.with(nil, "angle-double-left", title: "Collapse", data: {"title-expand"=>"Expand", "title-collapse"=>"Collapse"})
|
|
328
|
+
.and_return("_collapse_btn")
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
context "when compact mode" do
|
|
332
|
+
it "returns expanding button" do
|
|
333
|
+
allow(subject).to receive(:compact_side?).and_return(true)
|
|
334
|
+
expect(subject.compacter).to eq("<div class=\"compacter\">_expand_btn</div>")
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
context "when non-compact mode" do
|
|
339
|
+
it "returns collapsing button" do
|
|
340
|
+
allow(subject).to receive(:compact_side?).and_return(false)
|
|
341
|
+
expect(subject.compacter).to eq("<div class=\"compacter\">_collapse_btn</div>")
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
end
|
|
345
|
+
end
|
|
File without changes
|
|
File without changes
|
|
@@ -12,13 +12,13 @@ describe Releaf::Builders::ResourceView, type: :class do
|
|
|
12
12
|
let(:described_class){ ResourceViewIncluder }
|
|
13
13
|
let(:template){ ResourceViewTestHelper.new }
|
|
14
14
|
let(:subject){ described_class.new(template) }
|
|
15
|
-
let(:controller){ Releaf::
|
|
15
|
+
let(:controller){ Releaf::ActionController.new }
|
|
16
16
|
let(:resource){ Book.new }
|
|
17
17
|
|
|
18
18
|
before do
|
|
19
19
|
allow(template).to receive(:controller).and_return(controller)
|
|
20
20
|
allow(subject).to receive(:resource).and_return(resource)
|
|
21
|
-
allow(subject).to receive(:
|
|
21
|
+
allow(subject).to receive(:index_path).and_return("_index_path_")
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it "includes Releaf::Builders::View" do
|
|
@@ -47,7 +47,7 @@ describe Releaf::Builders::ResourceView, type: :class do
|
|
|
47
47
|
describe "#section_header_text" do
|
|
48
48
|
before do
|
|
49
49
|
allow(subject).to receive(:t).with("Create new resource").and_return("newww")
|
|
50
|
-
allow(subject).to receive(:
|
|
50
|
+
allow(subject).to receive(:resource_title).with(resource).and_return("existng")
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
context "when resource is new object" do
|
|
@@ -66,7 +66,7 @@ describe Releaf::Builders::ResourceView, type: :class do
|
|
|
66
66
|
|
|
67
67
|
describe "#section_header_extras" do
|
|
68
68
|
before do
|
|
69
|
-
allow(subject).to receive(:toolbox).with(resource,
|
|
69
|
+
allow(subject).to receive(:toolbox).with(resource, index_path: "_index_path_").and_return("_tlbx_")
|
|
70
70
|
allow(subject).to receive(:feature_available?).with(:toolbox).and_return(true)
|
|
71
71
|
end
|
|
72
72
|
|
|
@@ -122,17 +122,17 @@ describe Releaf::Builders::ResourceView, type: :class do
|
|
|
122
122
|
|
|
123
123
|
describe "#back_to_list?" do
|
|
124
124
|
before do
|
|
125
|
-
allow(subject).to receive(:params).and_return(
|
|
125
|
+
allow(subject).to receive(:params).and_return(index_path: "xxx")
|
|
126
126
|
allow(subject).to receive(:feature_available?).with(:index).and_return(true)
|
|
127
127
|
end
|
|
128
128
|
|
|
129
|
-
context "when index feature is available and
|
|
129
|
+
context "when index feature is available and index_path is present within params" do
|
|
130
130
|
it "returns true" do
|
|
131
131
|
expect(subject.back_to_list?).to be true
|
|
132
132
|
end
|
|
133
133
|
end
|
|
134
134
|
|
|
135
|
-
context "when
|
|
135
|
+
context "when index_path is not present within params" do
|
|
136
136
|
it "returns false" do
|
|
137
137
|
allow(subject).to receive(:params).and_return(search: "xxx")
|
|
138
138
|
expect(subject.back_to_list?).to be false
|
|
@@ -150,7 +150,7 @@ describe Releaf::Builders::ResourceView, type: :class do
|
|
|
150
150
|
describe "#back_to_list_button" do
|
|
151
151
|
it "returns `back to list` button" do
|
|
152
152
|
allow(subject).to receive(:button)
|
|
153
|
-
.with("to_list", "caret-left", {class: "secondary", href: "
|
|
153
|
+
.with("to_list", "caret-left", {class: "secondary", href: "_index_path_"}).and_return("_btn_")
|
|
154
154
|
allow(subject).to receive(:t).with("Back to list").and_return("to_list")
|
|
155
155
|
expect(subject.back_to_list_button).to eq("_btn_")
|
|
156
156
|
end
|
|
File without changes
|
|
@@ -29,10 +29,6 @@ describe Releaf::Builders::TableBuilder, type: :class do
|
|
|
29
29
|
expect(described_class.ancestors).to include(Releaf::Builders::Toolbox)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
it "includes Releaf::Builders::Orderer" do
|
|
33
|
-
expect(described_class.ancestors).to include(Releaf::Builders::Orderer)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
32
|
describe "#initialize" do
|
|
37
33
|
it "assigns collection" do
|
|
38
34
|
expect(subject.collection.to_sql).to eq(collection.to_sql)
|
|
@@ -66,8 +62,8 @@ describe Releaf::Builders::TableBuilder, type: :class do
|
|
|
66
62
|
|
|
67
63
|
describe "#column_names" do
|
|
68
64
|
it "returns column names for resource_class" do
|
|
69
|
-
allow(Releaf::
|
|
70
|
-
allow_any_instance_of(Releaf::
|
|
65
|
+
allow(Releaf::ResourceTableFields).to receive(:new).with(subject.resource_class).and_call_original
|
|
66
|
+
allow_any_instance_of(Releaf::ResourceTableFields).to receive(:values)
|
|
71
67
|
.with(include_associations: false).and_return(["a", "b"])
|
|
72
68
|
expect(subject.column_names).to eq(["a", "b"])
|
|
73
69
|
end
|
|
@@ -200,12 +196,12 @@ describe Releaf::Builders::TableBuilder, type: :class do
|
|
|
200
196
|
|
|
201
197
|
describe "#head_cell_content" do
|
|
202
198
|
it "returns translated column scoped to resource class attributes" do
|
|
203
|
-
allow(resource_class).to receive(:human_attribute_name).with("some_long_name"
|
|
199
|
+
allow(resource_class).to receive(:human_attribute_name).with("some_long_name").and_return("Taittls")
|
|
204
200
|
expect(subject.head_cell_content("some_long_name")).to eq('Taittls')
|
|
205
201
|
end
|
|
206
202
|
|
|
207
203
|
it "casts given column to string" do
|
|
208
|
-
allow(resource_class).to receive(:human_attribute_name).with("title",
|
|
204
|
+
allow(resource_class).to receive(:human_attribute_name).with("title",).and_return("Taittls")
|
|
209
205
|
expect(subject.head_cell_content(:title)).to eq('Taittls')
|
|
210
206
|
end
|
|
211
207
|
|
|
@@ -236,16 +232,16 @@ describe Releaf::Builders::TableBuilder, type: :class do
|
|
|
236
232
|
end
|
|
237
233
|
|
|
238
234
|
describe "#row_url" do
|
|
239
|
-
let(:controller){ Releaf::
|
|
235
|
+
let(:controller){ Releaf::ActionController.new }
|
|
240
236
|
|
|
241
237
|
before do
|
|
242
238
|
allow(subject).to receive(:controller).and_return(controller)
|
|
243
|
-
allow(controller).to receive(:
|
|
239
|
+
allow(controller).to receive(:index_path).and_return("_index_path_")
|
|
244
240
|
end
|
|
245
241
|
|
|
246
242
|
it "returns edit url for given resource" do
|
|
247
243
|
allow(subject).to receive(:row_url_action).with(resource).and_return(:show)
|
|
248
|
-
allow(template).to receive(:url_for).with(action: :show, id: 77,
|
|
244
|
+
allow(template).to receive(:url_for).with(action: :show, id: 77, index_path: "_index_path_").and_return('_url_')
|
|
249
245
|
expect(subject.row_url(resource)).to eq('_url_')
|
|
250
246
|
end
|
|
251
247
|
|
|
@@ -258,7 +254,7 @@ describe Releaf::Builders::TableBuilder, type: :class do
|
|
|
258
254
|
end
|
|
259
255
|
|
|
260
256
|
describe "#row_url_action" do
|
|
261
|
-
let(:controller){ Releaf::
|
|
257
|
+
let(:controller){ Releaf::ActionController.new }
|
|
262
258
|
|
|
263
259
|
before do
|
|
264
260
|
allow(subject).to receive(:controller).and_return(controller)
|
|
@@ -369,26 +365,15 @@ describe Releaf::Builders::TableBuilder, type: :class do
|
|
|
369
365
|
end
|
|
370
366
|
|
|
371
367
|
describe "#format_string_content" do
|
|
372
|
-
context "when resource column value respond to #
|
|
373
|
-
it "returns
|
|
374
|
-
|
|
375
|
-
allow(
|
|
376
|
-
|
|
377
|
-
allow(subject).to receive(:column_value).with(resource, :id)
|
|
378
|
-
.and_return(fake_obj)
|
|
368
|
+
context "when resource column value respond to #resource_title method" do
|
|
369
|
+
it "returns resource to title result" do
|
|
370
|
+
another_obj = Book.new
|
|
371
|
+
allow(subject).to receive(:column_value).with(resource, :id).and_return(another_obj)
|
|
372
|
+
allow(subject).to receive(:resource_title).with(another_obj).and_return("nineninine")
|
|
379
373
|
|
|
380
374
|
expect(subject.format_string_content(resource, :id)).to eq("nineninine")
|
|
381
375
|
end
|
|
382
376
|
end
|
|
383
|
-
|
|
384
|
-
context "when resource column value do not respond to #to_text method" do
|
|
385
|
-
it "returns value casted to string" do
|
|
386
|
-
allow(subject).to receive(:column_value).with(resource, :id)
|
|
387
|
-
.and_return(99)
|
|
388
|
-
|
|
389
|
-
expect(subject.format_string_content(resource, :id)).to eq("99")
|
|
390
|
-
end
|
|
391
|
-
end
|
|
392
377
|
end
|
|
393
378
|
|
|
394
379
|
describe "#format_boolean_content" do
|
|
@@ -435,8 +420,8 @@ describe Releaf::Builders::TableBuilder, type: :class do
|
|
|
435
420
|
allow(subject).to receive(:column_value).with(resource, :created_at)
|
|
436
421
|
.and_return(value)
|
|
437
422
|
|
|
438
|
-
|
|
439
|
-
.
|
|
423
|
+
allow(I18n).to receive(:l).with(value, format: :default, default: "%Y-%m-%d %H:%M:%S")
|
|
424
|
+
.and_return("2012-12-29 17:12:07")
|
|
440
425
|
|
|
441
426
|
expect(subject.format_datetime_content(resource, :created_at)).to eq("2012-12-29 17:12:07")
|
|
442
427
|
end
|
|
@@ -490,48 +475,26 @@ describe Releaf::Builders::TableBuilder, type: :class do
|
|
|
490
475
|
let(:controller){ double(ActionController::Base) }
|
|
491
476
|
before do
|
|
492
477
|
allow(subject).to receive(:controller).and_return(controller)
|
|
493
|
-
allow(controller).to receive(:
|
|
478
|
+
allow(controller).to receive(:index_path).and_return("_index_path_")
|
|
494
479
|
end
|
|
495
480
|
|
|
496
481
|
it "returns cell with toolbox" do
|
|
497
482
|
allow(subject).to receive(:toolbox)
|
|
498
|
-
.with(resource,
|
|
483
|
+
.with(resource, index_path: "_index_path_").and_return("_toolbox_")
|
|
499
484
|
|
|
500
485
|
content = '<td class="only-icon toolbox-cell">_toolbox_</td>'
|
|
501
486
|
expect(subject.toolbox_cell(resource, {})).to eq(content)
|
|
502
487
|
end
|
|
503
488
|
|
|
504
489
|
it "merges given toolbox options and passes it to toolbox heplper" do
|
|
505
|
-
allow(subject.controller).to receive(:
|
|
490
|
+
allow(subject.controller).to receive(:index_path).and_return("_index_path_")
|
|
506
491
|
expect(subject).to receive(:toolbox)
|
|
507
|
-
.with(resource,
|
|
492
|
+
.with(resource, index_path: "_index_path_", some_url: "xx").and_return("_toolbox_")
|
|
508
493
|
subject.toolbox_cell(resource, {toolbox: {some_url: "xx"}})
|
|
509
494
|
|
|
510
495
|
expect(subject).to receive(:toolbox)
|
|
511
|
-
.with(resource,
|
|
512
|
-
subject.toolbox_cell(resource, {toolbox: {
|
|
513
|
-
end
|
|
514
|
-
end
|
|
515
|
-
|
|
516
|
-
describe "#format_image_content" do
|
|
517
|
-
context "when resource value is not blank" do
|
|
518
|
-
let(:resource){ create(:book, cover_image: File.expand_path('../fixtures/cs.png', __dir__)) }
|
|
519
|
-
|
|
520
|
-
it "returns thumnail image" do
|
|
521
|
-
pattern = /\<img alt=\"\" src=\"\/media\/.*\" \/\>/
|
|
522
|
-
expect(subject.format_image_content(resource, :cover_image_uid)).to match(pattern)
|
|
523
|
-
end
|
|
524
|
-
|
|
525
|
-
it "uses 16px height for thumbnail" do
|
|
526
|
-
expect(resource.cover_image).to receive(:thumb).with('x16').and_call_original
|
|
527
|
-
subject.format_image_content(resource, :cover_image_uid)
|
|
528
|
-
end
|
|
529
|
-
end
|
|
530
|
-
|
|
531
|
-
context "when resource value is blank" do
|
|
532
|
-
it "returns nil" do
|
|
533
|
-
expect(subject.format_image_content(resource, :cover_image_uid)).to be nil
|
|
534
|
-
end
|
|
496
|
+
.with(resource, index_path: "xx").and_return("_toolbox_")
|
|
497
|
+
subject.toolbox_cell(resource, {toolbox: {index_path: "xx"}})
|
|
535
498
|
end
|
|
536
499
|
end
|
|
537
500
|
|
|
@@ -551,21 +514,22 @@ describe Releaf::Builders::TableBuilder, type: :class do
|
|
|
551
514
|
describe "#column_type_format_method" do
|
|
552
515
|
it "uses column klass and column name for type calculation" do
|
|
553
516
|
allow(subject).to receive(:column_klass).with(resource_class, "some.column").and_return(Chapter)
|
|
554
|
-
|
|
555
|
-
subject.
|
|
517
|
+
allow(subject).to receive(:column_type).with(Chapter, "some.column").and_return(:extra_type)
|
|
518
|
+
allow(subject).to receive(:type_format_method).with(:extra_type).and_return("extra_type_method")
|
|
519
|
+
expect(subject.column_type_format_method("some.column")).to eq("extra_type_method")
|
|
556
520
|
end
|
|
521
|
+
end
|
|
557
522
|
|
|
523
|
+
describe "#type_format_method" do
|
|
558
524
|
context "when format method for returned column type exists" do
|
|
559
525
|
it "returns column type format method" do
|
|
560
|
-
|
|
561
|
-
expect(subject.column_type_format_method(:title)).to eq(:format_date_content)
|
|
526
|
+
expect(subject.type_format_method(:date)).to eq(:format_date_content)
|
|
562
527
|
end
|
|
563
528
|
end
|
|
564
529
|
|
|
565
530
|
context "when format method for returned column type does not exist" do
|
|
566
531
|
it "returns :format_string_content" do
|
|
567
|
-
|
|
568
|
-
expect(subject.column_type_format_method(:title)).to eq(:format_string_content)
|
|
532
|
+
expect(subject.type_format_method(:big_boolean)).to eq(:format_string_content)
|
|
569
533
|
end
|
|
570
534
|
end
|
|
571
535
|
end
|
|
@@ -573,7 +537,6 @@ describe Releaf::Builders::TableBuilder, type: :class do
|
|
|
573
537
|
describe "#cell_format_method" do
|
|
574
538
|
before do
|
|
575
539
|
allow(subject).to receive(:association_column?).with(:title).and_return(false)
|
|
576
|
-
allow(subject).to receive(:image_column?).with(:title).and_return(false)
|
|
577
540
|
allow(subject).to receive(:column_type_format_method).with(:title).and_return(:format_crazy_shit)
|
|
578
541
|
end
|
|
579
542
|
|
|
@@ -587,13 +550,6 @@ describe Releaf::Builders::TableBuilder, type: :class do
|
|
|
587
550
|
expect(subject.cell_format_method(:title)).to eq(:format_association_content)
|
|
588
551
|
end
|
|
589
552
|
end
|
|
590
|
-
|
|
591
|
-
context "when #association_column? returns true for given column" do
|
|
592
|
-
it "returns :format_association_content" do
|
|
593
|
-
allow(subject).to receive(:image_column?).with(:title).and_return(true)
|
|
594
|
-
expect(subject.cell_format_method(:title)).to eq(:format_image_content)
|
|
595
|
-
end
|
|
596
|
-
end
|
|
597
553
|
end
|
|
598
554
|
|
|
599
555
|
describe "#association_column?" do
|
|
@@ -612,11 +568,11 @@ describe Releaf::Builders::TableBuilder, type: :class do
|
|
|
612
568
|
|
|
613
569
|
describe "#cell" do
|
|
614
570
|
context "when cell options :url value is blank" do
|
|
615
|
-
it "returns cell with #
|
|
571
|
+
it "returns cell with #cell_contentoutput wrapped in a span" do
|
|
616
572
|
options = {a: "x"}
|
|
617
573
|
allow(subject).to receive(:cell_content)
|
|
618
574
|
.with(resource, :title, options).and_return("_cell_content_")
|
|
619
|
-
content = '<td>_cell_content_</td>'
|
|
575
|
+
content = '<td><span>_cell_content_</span></td>'
|
|
620
576
|
|
|
621
577
|
expect(subject.cell(resource, :title, options)).to eq(content)
|
|
622
578
|
|
|
@@ -626,7 +582,7 @@ describe Releaf::Builders::TableBuilder, type: :class do
|
|
|
626
582
|
end
|
|
627
583
|
|
|
628
584
|
context "when cell options :url value is not blank" do
|
|
629
|
-
it "returns cell with #cell_content output wrapped in
|
|
585
|
+
it "returns cell with #cell_content output wrapped in a link" do
|
|
630
586
|
allow(subject).to receive(:cell_content)
|
|
631
587
|
.with(resource, :title, {a: "x", url: "y"}).and_return("_cell_content_")
|
|
632
588
|
|
|
File without changes
|
|
@@ -56,11 +56,11 @@ describe Releaf::Builders::ToolboxBuilder, type: :class do
|
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
describe "#destroy_confirmation_url" do
|
|
59
|
-
it "returns resource destroy confirmation url with
|
|
59
|
+
it "returns resource destroy confirmation url with index_path param" do
|
|
60
60
|
subject.resource = Book.new(id: 99)
|
|
61
|
-
allow(subject.template).to receive(:url_for).with(action: :confirm_destroy, id: 99,
|
|
62
|
-
allow(subject.template).to receive(:controller).and_return(Releaf::
|
|
63
|
-
allow(subject.controller).to receive(:
|
|
61
|
+
allow(subject.template).to receive(:url_for).with(action: :confirm_destroy, id: 99, index_path: "y").and_return("x")
|
|
62
|
+
allow(subject.template).to receive(:controller).and_return(Releaf::ActionController.new)
|
|
63
|
+
allow(subject.controller).to receive(:index_path).and_return("y")
|
|
64
64
|
expect(subject.destroy_confirmation_url).to eq("x")
|
|
65
65
|
end
|
|
66
66
|
end
|
|
File without changes
|