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
|
@@ -1,562 +0,0 @@
|
|
|
1
|
-
require "rails_helper"
|
|
2
|
-
|
|
3
|
-
describe Releaf::Builders::FormBuilder, type: :class do
|
|
4
|
-
class FormBuilderTestHelper < ActionView::Base
|
|
5
|
-
include Releaf::ApplicationHelper
|
|
6
|
-
include Releaf::ButtonHelper
|
|
7
|
-
include FontAwesome::Rails::IconHelper
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
let(:template){ FormBuilderTestHelper.new }
|
|
11
|
-
let(:object){ Book.new }
|
|
12
|
-
let(:subject){ described_class.new(:book, object, template, {}) }
|
|
13
|
-
let(:normalized_fields){
|
|
14
|
-
[
|
|
15
|
-
{
|
|
16
|
-
render_method: "render_title",
|
|
17
|
-
field: "title",
|
|
18
|
-
subfields: nil
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
render_method: "render_author_id",
|
|
22
|
-
field: "author_id",
|
|
23
|
-
subfields: nil
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
render_method: "render_chapters",
|
|
27
|
-
field: :chapters,
|
|
28
|
-
subfields: ["title", "text", "sample_html"]
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
render_method: "render_book_sequels",
|
|
32
|
-
field: :book_sequels,
|
|
33
|
-
subfields: ["sequel_id"]
|
|
34
|
-
}
|
|
35
|
-
]
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
it "includes Releaf::Builders::Base" do
|
|
39
|
-
expect(described_class.ancestors).to include(Releaf::Builders::Base)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "includes Releaf::Builders::Orderer" do
|
|
43
|
-
expect(described_class.ancestors).to include(Releaf::Builders::Orderer)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
describe "#field_names" do
|
|
47
|
-
it "returns field names for object class" do
|
|
48
|
-
allow(Releaf::Core::ResourceFields).to receive(:new).with(object.class).and_call_original
|
|
49
|
-
allow_any_instance_of(Releaf::Core::ResourceFields).to receive(:values).and_return(["a", "b"])
|
|
50
|
-
expect(subject.field_names).to eq(["a", "b"])
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
describe "#field_render_method_name" do
|
|
55
|
-
it "returns method name for given field" do
|
|
56
|
-
expect(subject.field_render_method_name(:title)).to eq("render_title")
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
context "when builder has parent builder(-s)" do
|
|
60
|
-
it "traverses through all builders and add relation name option to field name" do
|
|
61
|
-
root_builder = described_class.new(:author, Author.new, template, {})
|
|
62
|
-
middle_builder = described_class.new(:author, Author.new, template, {relation_name: :pages, parent_builder: root_builder})
|
|
63
|
-
subject.options[:parent_builder] = middle_builder
|
|
64
|
-
subject.options[:relation_name] = :chapters
|
|
65
|
-
|
|
66
|
-
expect(subject.field_render_method_name(:title)).to eq("render_pages_chapters_title")
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
describe "#normalize_fields" do
|
|
72
|
-
it "returns normalized fields for use with #releaf_fields method" do
|
|
73
|
-
fields = [
|
|
74
|
-
"title",
|
|
75
|
-
"author_id",
|
|
76
|
-
{chapters: ["title", "text", "sample_html"]},
|
|
77
|
-
{book_sequels: ["sequel_id"]}
|
|
78
|
-
]
|
|
79
|
-
expect(subject.normalize_fields(fields)).to eq(normalized_fields)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
it "handles multi-key hashes" do
|
|
83
|
-
fields = [
|
|
84
|
-
"title",
|
|
85
|
-
"author_id",
|
|
86
|
-
{
|
|
87
|
-
chapters: ["title", "text", "sample_html"],
|
|
88
|
-
book_sequels: ["sequel_id"]
|
|
89
|
-
}
|
|
90
|
-
]
|
|
91
|
-
expect(subject.normalize_fields(fields)).to eq(normalized_fields)
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
describe "#releaf_fields" do
|
|
96
|
-
it "normalizes given fields with #normalize_fields" do
|
|
97
|
-
allow(subject).to receive(:render_field_by_options)
|
|
98
|
-
expect(subject).to receive(:normalize_fields).with([:a, :b]).and_return([:x, :y])
|
|
99
|
-
subject.releaf_fields(:a, :b)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
it "passes all normalized field options to #render_field" do
|
|
103
|
-
allow(subject).to receive(:normalize_fields).and_return([:x, :y])
|
|
104
|
-
expect(subject).to receive(:render_field_by_options).with(:x)
|
|
105
|
-
expect(subject).to receive(:render_field_by_options).with(:y)
|
|
106
|
-
subject.releaf_fields(:a, :b)
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
it "concatenates and return all #render_field_by_options outputs with #safe_join" do
|
|
110
|
-
allow(subject).to receive(:render_field_by_options).and_return('_a_', '_b_')
|
|
111
|
-
allow(subject).to receive(:normalize_fields).and_return([:x, :y])
|
|
112
|
-
expect(subject).to receive(:safe_join).with(no_args){|&block|
|
|
113
|
-
expect(block.call).to eq(['_a_', '_b_'])
|
|
114
|
-
}.and_return("xxx")
|
|
115
|
-
expect(subject.releaf_fields(:a, :b)).to eq("xxx")
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
describe "#render_field_by_options" do
|
|
120
|
-
let(:options){ {
|
|
121
|
-
render_method: "sortable_column_name", # just random method here
|
|
122
|
-
field: "title",
|
|
123
|
-
subfields: [:a, :b],
|
|
124
|
-
} }
|
|
125
|
-
|
|
126
|
-
before do
|
|
127
|
-
allow(subject).to receive(:reflect_on_association).with("title").and_return(:x)
|
|
128
|
-
allow(subject).to receive(:sortable_column_name)
|
|
129
|
-
.with(no_args).and_return("_render_method_content_")
|
|
130
|
-
allow(subject).to receive(:releaf_association_fields)
|
|
131
|
-
.with(:x, [:a, :b]).and_return("_association_method_content_")
|
|
132
|
-
allow(subject).to receive(:releaf_field)
|
|
133
|
-
.with("title").and_return("_releaf_field_content_")
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
context "when method defined in options[:render_method] exists" do
|
|
137
|
-
it "returns this method output" do
|
|
138
|
-
expect(subject.render_field_by_options(options)).to eq("_render_method_content_")
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
context "when custom method does not exist" do
|
|
143
|
-
before do
|
|
144
|
-
options[:render_method] = "something_unexisting"
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
context "when reflection exists for given field" do
|
|
148
|
-
it "returns #releaf_association_fields by passing options[:field] and options[:subfields]" do
|
|
149
|
-
expect(subject.render_field_by_options(options)).to eq("_association_method_content_")
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
context "when reflection does not exist for given field" do
|
|
154
|
-
it "returns #releaf_field with options[:field] as argument" do
|
|
155
|
-
allow(subject).to receive(:reflect_on_association).with("title").and_return(nil)
|
|
156
|
-
expect(subject.render_field_by_options(options)).to eq("_releaf_field_content_")
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
describe "#reflect_on_association" do
|
|
163
|
-
it "returns reflection for given reflection name" do
|
|
164
|
-
expect(subject.reflect_on_association(:author)).to eq(object.class.reflections["author"])
|
|
165
|
-
expect(subject.reflect_on_association("author")).to eq(object.class.reflections["author"])
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
describe "#association_reflector" do
|
|
170
|
-
before do
|
|
171
|
-
resource_fields = subject.resource_fields
|
|
172
|
-
allow(resource_fields).to receive(:association_attributes).with(:x).and_return([:c, :d])
|
|
173
|
-
|
|
174
|
-
allow(subject).to receive(:resource_fields).and_return(resource_fields)
|
|
175
|
-
allow(subject).to receive(:sortable_column_name).and_return("sortable column name")
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
it "returns association reflector for given reflection" do
|
|
179
|
-
expect(subject.association_reflector(:x, [:a, :b])).to be_instance_of Releaf::Builders::AssociationReflector
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
it "pass reflection, fields and sortable column name to association reflector constructor" do
|
|
183
|
-
expect(Releaf::Builders::AssociationReflector).to receive(:new)
|
|
184
|
-
.with(:x, [:a, :b], "sortable column name")
|
|
185
|
-
subject.association_reflector(:x, [:a, :b])
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
context "when given fields is nil" do
|
|
189
|
-
it "uses resource fields returned association fields instead" do
|
|
190
|
-
expect(Releaf::Builders::AssociationReflector).to receive(:new)
|
|
191
|
-
.with(:x, [:c, :d], "sortable column name")
|
|
192
|
-
subject.association_reflector(:x, nil)
|
|
193
|
-
end
|
|
194
|
-
end
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
describe "#releaf_association_fields" do
|
|
198
|
-
let(:reflector){ Releaf::Builders::AssociationReflector.new(:a, :b, :c) }
|
|
199
|
-
let(:fields){ ["a"] }
|
|
200
|
-
|
|
201
|
-
before do
|
|
202
|
-
allow(subject).to receive(:association_reflector).with(:author, fields).and_return(reflector)
|
|
203
|
-
allow(subject).to receive(:releaf_has_many_association).with(reflector).and_return("_has_many_content_")
|
|
204
|
-
allow(subject).to receive(:releaf_belongs_to_association).with(reflector).and_return("_belongs_to_content_")
|
|
205
|
-
allow(subject).to receive(:releaf_has_one_association).with(reflector).and_return("_has_one_content_")
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
context "when reflector macro is :has_many" do
|
|
209
|
-
it "renders association with #releaf_has_many_association" do
|
|
210
|
-
allow(reflector).to receive(:macro).and_return(:has_many)
|
|
211
|
-
expect(subject.releaf_association_fields(:author, fields)).to eq("_has_many_content_")
|
|
212
|
-
end
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
context "when :belongs_to association given" do
|
|
216
|
-
it "renders association with #releaf_belongs_to_association" do
|
|
217
|
-
allow(reflector).to receive(:macro).and_return(:belongs_to)
|
|
218
|
-
expect(subject.releaf_association_fields(:author, fields)).to eq("_belongs_to_content_")
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
context "when :has_one association given" do
|
|
223
|
-
it "renders association with #releaf_has_one_association" do
|
|
224
|
-
allow(reflector).to receive(:macro).and_return(:has_one)
|
|
225
|
-
expect(subject.releaf_association_fields(:author, fields)).to eq("_has_one_content_")
|
|
226
|
-
end
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
context "when non implemented assocation type given" do
|
|
230
|
-
it "raises error" do
|
|
231
|
-
allow(reflector).to receive(:macro).and_return(:new_macro_type)
|
|
232
|
-
expect{ subject.releaf_association_fields(:author, fields) }.to raise_error("not implemented")
|
|
233
|
-
end
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
describe "#input_wrapper_with_label" do
|
|
238
|
-
before do
|
|
239
|
-
allow(subject).to receive(:wrapper).with("input_content", class: "value").and_return("input_content")
|
|
240
|
-
allow(subject).to receive(:releaf_label).with(:color, "label_attributes", "options").and_return("label_content")
|
|
241
|
-
allow(subject).to receive(:field).with(:color, "field_attributes", "options"){ |name, field, options, &block|
|
|
242
|
-
expect(block.call).to eq("label_contentinput_content")
|
|
243
|
-
}.and_return("content")
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
it "returns wrapped label and input content" do
|
|
247
|
-
expect(subject.input_wrapper_with_label(:color, "input_content", label: "label_attributes", field: "field_attributes", options: "options"))
|
|
248
|
-
.to eq("content")
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
context "when block given" do
|
|
252
|
-
it "safely concatinate block output to content" do
|
|
253
|
-
content = 'input_content<input type="hidden" name="book[id]" id="book_id" />'
|
|
254
|
-
allow(subject).to receive(:wrapper).with(content, class: "value").and_return("input_content")
|
|
255
|
-
expect(subject.input_wrapper_with_label(:color, "input_content", label: "label_attributes", field: "field_attributes", options: "options"){ subject.hidden_field(:id) })
|
|
256
|
-
.to eq("content")
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
it "correctly handles block nil output" do
|
|
260
|
-
expect(subject.input_wrapper_with_label(:color, "input_content", label: "label_attributes", field: "field_attributes", options: "options"){ })
|
|
261
|
-
.to eq("content")
|
|
262
|
-
end
|
|
263
|
-
end
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
describe "#releaf_label" do
|
|
267
|
-
it "passes options :label value to #label_text and use returned value for label text content" do
|
|
268
|
-
allow(subject).to receive(:label_text).with(:color, a: "b").and_return("xx")
|
|
269
|
-
result = '<div class="label-wrap"><label for="book_color">xx</label></div>'
|
|
270
|
-
|
|
271
|
-
expect(subject.releaf_label(:color, {}, label: {a: "b"})).to eq(result)
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
it "uses #label_attributes for label attributes" do
|
|
275
|
-
allow(subject).to receive(:label_attributes).with(:color, {class: "red"}, {a: "b"}).and_return(class: "red blue")
|
|
276
|
-
result = '<div class="label-wrap"><label class="red blue" for="book_color">Color</label></div>'
|
|
277
|
-
|
|
278
|
-
expect(subject.releaf_label(:color, {class: "red"}, {a: "b"})).to eq(result)
|
|
279
|
-
end
|
|
280
|
-
|
|
281
|
-
context "when options[:label][:description] is not blank" do
|
|
282
|
-
context "when label has full version" do
|
|
283
|
-
it "includes description" do
|
|
284
|
-
result = '<div class="label-wrap"><label for="book_color">Color</label><div class="description">xxx</div></div>'
|
|
285
|
-
expect(subject.releaf_label(:color, {}, label: {description: "xxx"})).to eq(result)
|
|
286
|
-
end
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
context "when label has minimal version" do
|
|
290
|
-
it "does not include description" do
|
|
291
|
-
result = '<label for="book_color">Color</label>'
|
|
292
|
-
expect(subject.releaf_label(:color, {}, label: {minimal: true})).to eq(result)
|
|
293
|
-
end
|
|
294
|
-
end
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
context "when options[:label][:minimal] is true" do
|
|
298
|
-
it "returns label tag without wrap element" do
|
|
299
|
-
result = '<label for="book_color">Color</label>'
|
|
300
|
-
expect(subject).to_not receive(:wrapper)
|
|
301
|
-
expect(subject.releaf_label(:color, {}, label: {minimal: true})).to eq(result)
|
|
302
|
-
end
|
|
303
|
-
end
|
|
304
|
-
|
|
305
|
-
context "when options[:label][:minimal] is not true" do
|
|
306
|
-
it "returns label tag with wrap element" do
|
|
307
|
-
allow(subject).to receive(:wrapper).with('<label for="book_color">Color</label>', class: "label-wrap").and_return("x")
|
|
308
|
-
expect(subject.releaf_label(:color, {}, label: {minimal: false})).to eq("x")
|
|
309
|
-
expect(subject.releaf_label(:color, {}, label: {minimal: nil})).to eq("x")
|
|
310
|
-
expect(subject.releaf_label(:color, {}, label: {adasd: "xx"})).to eq("x")
|
|
311
|
-
end
|
|
312
|
-
end
|
|
313
|
-
|
|
314
|
-
end
|
|
315
|
-
|
|
316
|
-
describe "#releaf_number_field" do
|
|
317
|
-
it "returns input with type 'number'" do
|
|
318
|
-
expect(subject).to receive(:number_field).with("title", { value: nil, step: "any", class: "text" }).and_return("x")
|
|
319
|
-
expect(subject).to receive(:input_wrapper_with_label).with("title", "x", { label: {}, field: {}, options: { field: { type: "number" }}}).and_return("y")
|
|
320
|
-
expect(subject.releaf_number_field("title")).to eq("y")
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
context "aliases" do
|
|
324
|
-
let(:releaf_number_field_method) { subject.method(:releaf_number_field) }
|
|
325
|
-
|
|
326
|
-
it "is aliased by #releaf_integer_field" do
|
|
327
|
-
expect(subject.method(:releaf_integer_field)).to eq(releaf_number_field_method)
|
|
328
|
-
end
|
|
329
|
-
|
|
330
|
-
it "is aliased by #releaf_float_field" do
|
|
331
|
-
expect(subject.method(:releaf_float_field)).to eq(releaf_number_field_method)
|
|
332
|
-
end
|
|
333
|
-
|
|
334
|
-
it "is aliased by #releaf_decimal_field" do
|
|
335
|
-
expect(subject.method(:releaf_decimal_field)).to eq(releaf_number_field_method)
|
|
336
|
-
end
|
|
337
|
-
end
|
|
338
|
-
end
|
|
339
|
-
|
|
340
|
-
describe "#field_attributes" do
|
|
341
|
-
it "adds field data and class attributes" do
|
|
342
|
-
expect(subject.field_attributes(:color, {}, {field: {type: "text"}})).to eq(data: {name: :color}, class: ["field", "type-text"])
|
|
343
|
-
end
|
|
344
|
-
|
|
345
|
-
it "merges attributes over build-in data hash" do
|
|
346
|
-
expect(subject.field_attributes(:color, {data: {other: "x"}}, {})[:data]).to eq(name: :color, other: "x")
|
|
347
|
-
expect(subject.field_attributes(:color, {data: {other: "x", name: :lll}}, {})[:data]).to eq(name: :lll, other: "x")
|
|
348
|
-
end
|
|
349
|
-
|
|
350
|
-
it "supports class attributes merging" do
|
|
351
|
-
expect(subject.field_attributes(:color, {class: ["a", "b"]}, {})[:class]).to eq(["field", "type-", "a", "b"])
|
|
352
|
-
end
|
|
353
|
-
end
|
|
354
|
-
|
|
355
|
-
describe "#label_attributes" do
|
|
356
|
-
it "returns unmodified attributes (allow further override by other builders)" do
|
|
357
|
-
expect(subject.label_attributes(:color, {data: "x"}, {})).to eq(data: "x")
|
|
358
|
-
end
|
|
359
|
-
end
|
|
360
|
-
|
|
361
|
-
describe "#input_attributes" do
|
|
362
|
-
it "returns unmodified attributes (allow further override by other builders)" do
|
|
363
|
-
expect(subject.input_attributes(:color, {data: "x"}, {})).to eq(data: "x")
|
|
364
|
-
end
|
|
365
|
-
end
|
|
366
|
-
|
|
367
|
-
describe "#label_text" do
|
|
368
|
-
it "returns model attributes scoped translated value" do
|
|
369
|
-
allow(subject).to receive(:translate_attribute).with("color").and_return("x")
|
|
370
|
-
expect(subject.label_text(:color)).to eq("x")
|
|
371
|
-
end
|
|
372
|
-
|
|
373
|
-
context "when :label_text option exists" do
|
|
374
|
-
context "when :label_text is not blank" do
|
|
375
|
-
it "returns :label_text option" do
|
|
376
|
-
expect(subject.label_text(:color, label_text: "krāsa")).to eq("krāsa")
|
|
377
|
-
end
|
|
378
|
-
end
|
|
379
|
-
|
|
380
|
-
context "when :label_text is blank" do
|
|
381
|
-
it "returns translated value" do
|
|
382
|
-
expect(subject.label_text(:color, label_text: nil)).to eq("Color")
|
|
383
|
-
expect(subject.label_text(:color, label_text: "")).to eq("Color")
|
|
384
|
-
end
|
|
385
|
-
end
|
|
386
|
-
end
|
|
387
|
-
|
|
388
|
-
context "when :translation_key option exists" do
|
|
389
|
-
context "when :translation_key is not blank" do
|
|
390
|
-
it "passes :translation_key option to translation and return translated value" do
|
|
391
|
-
allow(subject).to receive(:translate_attribute).with("true_color").and_return("x")
|
|
392
|
-
expect(subject.label_text(:color, translation_key: "true_color")).to eq("x")
|
|
393
|
-
end
|
|
394
|
-
end
|
|
395
|
-
|
|
396
|
-
context "when :translation_key is blank" do
|
|
397
|
-
it "returns translated value" do
|
|
398
|
-
expect(subject.label_text(:color, translation_key: nil)).to eq("Color")
|
|
399
|
-
expect(subject.label_text(:color, translation_key: "")).to eq("Color")
|
|
400
|
-
end
|
|
401
|
-
end
|
|
402
|
-
end
|
|
403
|
-
end
|
|
404
|
-
|
|
405
|
-
describe "#sortable_column_name" do
|
|
406
|
-
it "returns 'item_position'" do
|
|
407
|
-
expect( subject.sortable_column_name ).to eq 'item_position'
|
|
408
|
-
end
|
|
409
|
-
end
|
|
410
|
-
|
|
411
|
-
describe "#releaf_item_field_collection" do
|
|
412
|
-
context "when collection exists within options" do
|
|
413
|
-
it "returns collection" do
|
|
414
|
-
expect(subject.releaf_item_field_collection(:author_id, collection: "x")).to eq("x")
|
|
415
|
-
end
|
|
416
|
-
end
|
|
417
|
-
|
|
418
|
-
context "when collection does not exist within options" do
|
|
419
|
-
it "returns all relation objects" do
|
|
420
|
-
allow(Author).to receive(:all).and_return("y")
|
|
421
|
-
expect(subject.releaf_item_field_collection(:author_id)).to eq("y")
|
|
422
|
-
end
|
|
423
|
-
end
|
|
424
|
-
end
|
|
425
|
-
|
|
426
|
-
describe "#releaf_item_field_choices" do
|
|
427
|
-
before do
|
|
428
|
-
subject.object.author_id = 3
|
|
429
|
-
end
|
|
430
|
-
|
|
431
|
-
context "when no select_options passed within options" do
|
|
432
|
-
it "prefills select_options with corresponding collection array" do
|
|
433
|
-
collection = [Author.new(name: "a", surname: "b", id: 1), Author.new(name: "c", surname: "d", id: 2)]
|
|
434
|
-
allow(subject).to receive(:releaf_item_field_collection)
|
|
435
|
-
.with(:author_id, x: "a").and_return(collection)
|
|
436
|
-
allow(subject).to receive(:options_for_select).with([["a b", 1], ["c d", 2]], 3).and_return("xx")
|
|
437
|
-
expect(subject.releaf_item_field_choices(:author_id, x: "a")).to eq("xx")
|
|
438
|
-
end
|
|
439
|
-
end
|
|
440
|
-
|
|
441
|
-
context "when options have select_options passed" do
|
|
442
|
-
context "when select_options is array" do
|
|
443
|
-
it "process and return select options with `options_for_select` rails helper" do
|
|
444
|
-
collection = [["a b", 1], ["c d", 2]]
|
|
445
|
-
allow(subject).to receive(:options_for_select).with(collection, 3).and_return("xx")
|
|
446
|
-
expect(subject.releaf_item_field_choices(:author_id, select_options: collection)).to eq("xx")
|
|
447
|
-
end
|
|
448
|
-
end
|
|
449
|
-
|
|
450
|
-
context "when select_options is not array" do
|
|
451
|
-
it "returns select_options value" do
|
|
452
|
-
expect(subject.releaf_item_field_choices(:author_id, select_options: "xx")).to eq("xx")
|
|
453
|
-
end
|
|
454
|
-
end
|
|
455
|
-
end
|
|
456
|
-
end
|
|
457
|
-
|
|
458
|
-
describe "#relation_name" do
|
|
459
|
-
it "strips _id from given string and returns it as symbol" do
|
|
460
|
-
expect(subject.relation_name("admin_id")).to eq(:admin)
|
|
461
|
-
end
|
|
462
|
-
end
|
|
463
|
-
|
|
464
|
-
describe "#format_date_or_time_value" do
|
|
465
|
-
context "when given value type is :time" do
|
|
466
|
-
it "format normalized value to default format with `strftime`" do
|
|
467
|
-
value = Date.parse("15 Jan 2015")
|
|
468
|
-
time = Time.parse("15 Jan 2015 12:10:04")
|
|
469
|
-
allow(subject).to receive(:date_or_time_default_format).with(:time).and_return("%H:%M")
|
|
470
|
-
allow(subject).to receive(:normalize_date_or_time_value).with(value, :time).and_return(time)
|
|
471
|
-
|
|
472
|
-
expect(subject.format_date_or_time_value(value, :time)).to eq("12:10")
|
|
473
|
-
end
|
|
474
|
-
end
|
|
475
|
-
|
|
476
|
-
context "when given value type is other than :time" do
|
|
477
|
-
it "format normalized value to default format with `I18n.l`" do
|
|
478
|
-
value = Date.parse("15 Jan 2015")
|
|
479
|
-
time = Time.parse("15 Jan 2015 12:10:04")
|
|
480
|
-
|
|
481
|
-
allow(subject).to receive(:date_or_time_default_format).with(:date).and_return("_format_")
|
|
482
|
-
allow(subject).to receive(:normalize_date_or_time_value).with(value, :date).and_return(time)
|
|
483
|
-
allow(I18n).to receive(:l).with(time, default: "_format_").and_return("x")
|
|
484
|
-
expect(subject.format_date_or_time_value(value, :date)).to eq("x")
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
allow(subject).to receive(:date_or_time_default_format).with(:datetime).and_return("_format_")
|
|
488
|
-
allow(subject).to receive(:normalize_date_or_time_value).with(value, :datetime).and_return(time)
|
|
489
|
-
allow(I18n).to receive(:l).with(time, default: "_format_").and_return("y")
|
|
490
|
-
expect(subject.format_date_or_time_value(value, :datetime)).to eq("y")
|
|
491
|
-
end
|
|
492
|
-
end
|
|
493
|
-
end
|
|
494
|
-
|
|
495
|
-
describe "#locales" do
|
|
496
|
-
it "returns object globalize locales" do
|
|
497
|
-
allow(subject.object.class).to receive(:globalize_locales).and_return([:de, :ru])
|
|
498
|
-
expect(subject.locales).to eq([:de, :ru])
|
|
499
|
-
end
|
|
500
|
-
end
|
|
501
|
-
|
|
502
|
-
describe "#default_locale" do
|
|
503
|
-
before do
|
|
504
|
-
allow(subject).to receive(:cookies).and_return({})
|
|
505
|
-
allow(I18n).to receive(:locale).and_return(:ru)
|
|
506
|
-
allow(subject).to receive(:locales).and_return([:de, :ru])
|
|
507
|
-
end
|
|
508
|
-
|
|
509
|
-
context "when cookies has stored locale" do
|
|
510
|
-
it "returns stored locale normalized to symbol" do
|
|
511
|
-
allow(subject).to receive(:cookies).and_return("releaf.i18n.locale".to_sym => "de")
|
|
512
|
-
expect(subject.default_locale).to eq(:de)
|
|
513
|
-
end
|
|
514
|
-
end
|
|
515
|
-
|
|
516
|
-
context "when cookies hasn't stored locale" do
|
|
517
|
-
it "returns current I18n locale" do
|
|
518
|
-
expect(subject.default_locale).to eq(:ru)
|
|
519
|
-
end
|
|
520
|
-
end
|
|
521
|
-
|
|
522
|
-
context "when stored locale or I18n locale is not within form locales" do
|
|
523
|
-
it "returns first form locale" do
|
|
524
|
-
allow(subject).to receive(:locales).and_return([:lv, :en])
|
|
525
|
-
expect(subject.default_locale).to eq(:lv)
|
|
526
|
-
end
|
|
527
|
-
end
|
|
528
|
-
end
|
|
529
|
-
|
|
530
|
-
describe "#normalize_date_or_time_value" do
|
|
531
|
-
context "when :time type given" do
|
|
532
|
-
it "casts value to time" do
|
|
533
|
-
value = Date.parse("15 Jan 2015")
|
|
534
|
-
expect(subject.normalize_date_or_time_value(value, :time)).to be_instance_of Time
|
|
535
|
-
expect(subject.normalize_date_or_time_value(value, :time)).to eq(value.to_time)
|
|
536
|
-
end
|
|
537
|
-
end
|
|
538
|
-
|
|
539
|
-
context "when :datetime type given" do
|
|
540
|
-
it "casts value to datetime" do
|
|
541
|
-
value = Time.parse("15 Jan 2015 12:10:04")
|
|
542
|
-
expect(subject.normalize_date_or_time_value(value, :datetime)).to be_instance_of DateTime
|
|
543
|
-
expect(subject.normalize_date_or_time_value(value, :datetime)).to eq(value.to_datetime)
|
|
544
|
-
end
|
|
545
|
-
end
|
|
546
|
-
|
|
547
|
-
context "when :time type given" do
|
|
548
|
-
it "casts value to date" do
|
|
549
|
-
value = DateTime.parse("15 Jan 2015 12:10:04")
|
|
550
|
-
expect(subject.normalize_date_or_time_value(value, :date)).to be_instance_of Date
|
|
551
|
-
expect(subject.normalize_date_or_time_value(value, :date)).to eq(value.to_date)
|
|
552
|
-
end
|
|
553
|
-
end
|
|
554
|
-
end
|
|
555
|
-
|
|
556
|
-
describe "#translate_attribute" do
|
|
557
|
-
it "translates given attribute within object translation scope" do
|
|
558
|
-
allow(object.class).to receive(:human_attribute_name).with("x", create_default: false).and_return("z")
|
|
559
|
-
expect(subject.translate_attribute("x")).to eq("z")
|
|
560
|
-
end
|
|
561
|
-
end
|
|
562
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require "rails_helper"
|
|
2
|
-
|
|
3
|
-
describe Releaf::Builders::Orderer, type: :module do
|
|
4
|
-
class OrdererIncluder
|
|
5
|
-
include Releaf::Builders::Orderer
|
|
6
|
-
end
|
|
7
|
-
let(:subject){ OrdererIncluder.new }
|
|
8
|
-
|
|
9
|
-
describe "#orderer" do
|
|
10
|
-
it "initializes new `Releaf::Core::ItemOrderer` instance" do
|
|
11
|
-
expect(subject.orderer([:a, :b])).to be_instance_of Releaf::Core::ItemOrderer
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "initializes new `Releaf::Core::ItemOrderer` with given array values" do
|
|
15
|
-
expect(subject.orderer([:a, :b]).list).to eq([:a, :b])
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "casts given value to array before passing to `Releaf::Core::ItemOrderer` constructor" do
|
|
19
|
-
expect(subject.orderer(Releaf::Core::ItemOrderer.new(:a, :b)).list).to eq([:a, :b])
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|