releaf-core 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. metadata +3 -193
  3. data/spec/builders/releaf/builders/association_reflector_spec.rb +0 -138
  4. data/spec/builders/releaf/builders/base_spec.rb +0 -272
  5. data/spec/builders/releaf/builders/collection_spec.rb +0 -18
  6. data/spec/builders/releaf/builders/confirm_destroy_dialog_builder_spec.rb +0 -71
  7. data/spec/builders/releaf/builders/confirm_dialog_builder_spec.rb +0 -107
  8. data/spec/builders/releaf/builders/edit_builder_spec.rb +0 -322
  9. data/spec/builders/releaf/builders/form_builder/associations_spec.rb +0 -129
  10. data/spec/builders/releaf/builders/form_builder/date_fields_spec.rb +0 -86
  11. data/spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb +0 -48
  12. data/spec/builders/releaf/builders/form_builder/label_spec.rb +0 -106
  13. data/spec/builders/releaf/builders/form_builder/number_fields_spec.rb +0 -37
  14. data/spec/builders/releaf/builders/form_builder_spec.rb +0 -228
  15. data/spec/builders/releaf/builders/index_builder_spec.rb +0 -364
  16. data/spec/builders/releaf/builders/page/header_builder_spec.rb +0 -66
  17. data/spec/builders/releaf/builders/page/layout_builder_spec.rb +0 -237
  18. data/spec/builders/releaf/builders/page/menu_builder_spec.rb +0 -345
  19. data/spec/builders/releaf/builders/pagination_builder_spec.rb +0 -330
  20. data/spec/builders/releaf/builders/resource_dialog_spec.rb +0 -21
  21. data/spec/builders/releaf/builders/resource_view_spec.rb +0 -158
  22. data/spec/builders/releaf/builders/show_builder_spec.rb +0 -7
  23. data/spec/builders/releaf/builders/table_builder_spec.rb +0 -637
  24. data/spec/builders/releaf/builders/template_spec.rb +0 -12
  25. data/spec/builders/releaf/builders/toolbox_builder_spec.rb +0 -67
  26. data/spec/builders/releaf/builders/toolbox_spec.rb +0 -48
  27. data/spec/builders/releaf/builders/utilities/date_fields_spec.rb +0 -125
  28. data/spec/builders/releaf/builders/utilities/resolve_attribute_field_method_name_spec.rb +0 -318
  29. data/spec/builders/releaf/builders/view_spec.rb +0 -281
  30. data/spec/builders/releaf/builders_spec.rb +0 -144
  31. data/spec/builders/releaf/settings/form_builder_spec.rb +0 -48
  32. data/spec/builders/releaf/settings/table_builder_spec.rb +0 -23
  33. data/spec/controllers/concerns/releaf/richtext_attachments_spec.rb +0 -51
  34. data/spec/controllers/releaf/action_controller_spec.rb +0 -423
  35. data/spec/controllers/releaf/root_controller_spec.rb +0 -46
  36. data/spec/controllers/releaf/settings_controller_spec.rb +0 -52
  37. data/spec/error_hash_builder_spec.rb +0 -83
  38. data/spec/ext/array_reorder_spec.rb +0 -12
  39. data/spec/features/ajaxbox_spec.rb +0 -111
  40. data/spec/features/authorization_spec.rb +0 -50
  41. data/spec/features/breadcrumbs_spec.rb +0 -16
  42. data/spec/features/dragonfly_integration_spec.rb +0 -24
  43. data/spec/features/edit_actions_spec.rb +0 -186
  44. data/spec/features/errors_spec.rb +0 -47
  45. data/spec/features/index_actions_spec.rb +0 -86
  46. data/spec/features/index_table_spec.rb +0 -35
  47. data/spec/features/menu_spec.rb +0 -71
  48. data/spec/features/richtext_attachments_spec.rb +0 -64
  49. data/spec/features/richtext_custom_config_spec.rb +0 -28
  50. data/spec/features/richtext_embed_spec.rb +0 -29
  51. data/spec/features/richtext_spec.rb +0 -31
  52. data/spec/features/search_spec.rb +0 -825
  53. data/spec/features/settings_spec.rb +0 -70
  54. data/spec/features/title_spec.rb +0 -13
  55. data/spec/fixtures/common_fields.yml +0 -17
  56. data/spec/fixtures/cs.png +0 -0
  57. data/spec/fixtures/time.formats.xlsx +0 -0
  58. data/spec/fixtures/unicorn.jpg +0 -0
  59. data/spec/helpers/application_helper_spec.rb +0 -73
  60. data/spec/helpers/button_helper_spec.rb +0 -146
  61. data/spec/lib/releaf/action_controller/features_spec.rb +0 -171
  62. data/spec/lib/releaf/action_controller/search_spec.rb +0 -84
  63. data/spec/lib/releaf/application_spec.rb +0 -43
  64. data/spec/lib/releaf/assets_resolver_spec.rb +0 -130
  65. data/spec/lib/releaf/build_errors_hash_spec.rb +0 -141
  66. data/spec/lib/releaf/configuration_spec.rb +0 -205
  67. data/spec/lib/releaf/controller_definition_spec.rb +0 -78
  68. data/spec/lib/releaf/controller_group_definition_spec.rb +0 -33
  69. data/spec/lib/releaf/default_searchable_fields_spec.rb +0 -161
  70. data/spec/lib/releaf/instance_cache_spec.rb +0 -98
  71. data/spec/lib/releaf/resource_base_spec.rb +0 -212
  72. data/spec/lib/releaf/resource_fields_spec.rb +0 -12
  73. data/spec/lib/releaf/resource_params_spec.rb +0 -115
  74. data/spec/lib/releaf/resource_table_fields_spec.rb +0 -20
  75. data/spec/lib/releaf/resource_utilities_spec.rb +0 -87
  76. data/spec/lib/releaf/responders/access_denied_responder_spec.rb +0 -12
  77. data/spec/lib/releaf/responders/after_save_responder_spec.rb +0 -88
  78. data/spec/lib/releaf/responders/confirm_destroy_responder_spec.rb +0 -26
  79. data/spec/lib/releaf/responders/destroy_responder_spec.rb +0 -30
  80. data/spec/lib/releaf/responders/error_responder_spec.rb +0 -26
  81. data/spec/lib/releaf/responders/feature_disabled_responder_spec.rb +0 -12
  82. data/spec/lib/releaf/responders/page_not_found_responder_spec.rb +0 -12
  83. data/spec/lib/releaf/responders_spec.rb +0 -61
  84. data/spec/lib/releaf/root/configuration_spec.rb +0 -9
  85. data/spec/lib/releaf/root/default_controller_resolver_spec.rb +0 -44
  86. data/spec/lib/releaf/root_spec.rb +0 -13
  87. data/spec/lib/releaf/service_spec.rb +0 -20
  88. data/spec/lib/releaf/settings/normalize_value_spec.rb +0 -103
  89. data/spec/lib/releaf/settings/register_spec.rb +0 -135
  90. data/spec/lib/releaf/settings_manager_spec.rb +0 -22
  91. data/spec/lib/validation_error_codes_spec.rb +0 -56
  92. data/spec/misc/factories_spec.rb +0 -31
  93. data/spec/models/settings_spec.rb +0 -104
  94. data/spec/routing/route_mapper_spec.rb +0 -185
  95. data/spec/rspec_helpers/test_helpers_spec.rb +0 -20
  96. data/spec/rspec_helpers/test_spec.rb +0 -14
  97. data/spec/services/array/reorder_spec.rb +0 -121
@@ -1,129 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Builders::FormBuilder::Associations, 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(ActionView::LookupContext.new(nil), {}, nil) }
11
- let(:object){ Book.new }
12
- let(:subject){ Releaf::Builders::FormBuilder.new(:book, object, template, {}) }
13
-
14
- describe "#reflect_on_association" do
15
- it "returns reflection for given reflection name" do
16
- expect(subject.reflect_on_association(:author)).to eq(object.class.reflections["author"])
17
- expect(subject.reflect_on_association("author")).to eq(object.class.reflections["author"])
18
- end
19
- end
20
-
21
- describe "#association_reflector" do
22
- before do
23
- resource_fields = subject.resource_fields
24
- allow(resource_fields).to receive(:association_attributes).with(:x).and_return([:c, :d])
25
-
26
- allow(subject).to receive(:resource_fields).and_return(resource_fields)
27
- allow(subject).to receive(:sortable_column_name).and_return("sortable column name")
28
- end
29
-
30
- it "returns association reflector for given reflection" do
31
- expect(subject.association_reflector(:x, [:a, :b])).to be_instance_of Releaf::Builders::AssociationReflector
32
- end
33
-
34
- it "pass reflection, fields and sortable column name to association reflector constructor" do
35
- expect(Releaf::Builders::AssociationReflector).to receive(:new)
36
- .with(:x, [:a, :b], "sortable column name")
37
- subject.association_reflector(:x, [:a, :b])
38
- end
39
-
40
- context "when given fields is nil" do
41
- it "uses resource fields returned association fields instead" do
42
- expect(Releaf::Builders::AssociationReflector).to receive(:new)
43
- .with(:x, [:c, :d], "sortable column name")
44
- subject.association_reflector(:x, nil)
45
- end
46
- end
47
- end
48
-
49
- describe "#releaf_association_fields" do
50
- let(:reflector){ Releaf::Builders::AssociationReflector.new(:a, :b, :c) }
51
- let(:fields){ ["a"] }
52
-
53
- before do
54
- allow(subject).to receive(:association_reflector).with(:author, fields).and_return(reflector)
55
- allow(subject).to receive(:releaf_has_many_association).with(reflector).and_return("_has_many_content_")
56
- allow(subject).to receive(:releaf_belongs_to_association).with(reflector).and_return("_belongs_to_content_")
57
- allow(subject).to receive(:releaf_has_one_association).with(reflector).and_return("_has_one_content_")
58
- end
59
-
60
- context "when reflector macro is :has_many" do
61
- it "renders association with #releaf_has_many_association" do
62
- allow(reflector).to receive(:macro).and_return(:has_many)
63
- expect(subject.releaf_association_fields(:author, fields)).to eq("_has_many_content_")
64
- end
65
- end
66
-
67
- context "when :belongs_to association given" do
68
- it "renders association with #releaf_belongs_to_association" do
69
- allow(reflector).to receive(:macro).and_return(:belongs_to)
70
- expect(subject.releaf_association_fields(:author, fields)).to eq("_belongs_to_content_")
71
- end
72
- end
73
-
74
- context "when :has_one association given" do
75
- it "renders association with #releaf_has_one_association" do
76
- allow(reflector).to receive(:macro).and_return(:has_one)
77
- expect(subject.releaf_association_fields(:author, fields)).to eq("_has_one_content_")
78
- end
79
- end
80
-
81
- context "when non implemented assocation type given" do
82
- it "raises error" do
83
- allow(reflector).to receive(:macro).and_return(:new_macro_type)
84
- expect{ subject.releaf_association_fields(:author, fields) }.to raise_error("not implemented")
85
- end
86
- end
87
- end
88
-
89
- describe "#releaf_item_field_choices" do
90
- before do
91
- collection = [Author.new(name: "a", surname: "b", id: 1), Author.new(name: "c", surname: "d", id: 2)]
92
- allow(subject).to receive(:releaf_item_field_collection)
93
- .with(:author_id, x: "a").and_return(collection)
94
- end
95
-
96
- context "when no select_options passed within options" do
97
- it "returns corresponding collection array" do
98
- expect(subject.releaf_item_field_choices(:author_id, x: "a")).to eq([["a b", 1], ["c d", 2]])
99
- end
100
- end
101
-
102
- context "when options have select_options passed" do
103
- it "returns `select_options` value" do
104
- expect(subject.releaf_item_field_choices(:author_id, select_options: "xx")).to eq("xx")
105
- end
106
- end
107
- end
108
-
109
- describe "#releaf_item_field_collection" do
110
- context "when collection exists within options" do
111
- it "returns collection" do
112
- expect(subject.releaf_item_field_collection(:author_id, collection: "x")).to eq("x")
113
- end
114
- end
115
-
116
- context "when collection does not exist within options" do
117
- it "returns all relation objects" do
118
- allow(Author).to receive(:all).and_return("y")
119
- expect(subject.releaf_item_field_collection(:author_id)).to eq("y")
120
- end
121
- end
122
- end
123
-
124
- describe "#relation_name" do
125
- it "strips _id from given string and returns it as symbol" do
126
- expect(subject.relation_name("admin_id")).to eq(:admin)
127
- end
128
- end
129
- end
@@ -1,86 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Builders::FormBuilder::DateFields, 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(ActionView::LookupContext.new(nil), {}, nil) }
11
- let(:object){ Book.new }
12
- let(:subject){ Releaf::Builders::FormBuilder.new(:book, object, template, {}) }
13
-
14
- describe "#date_or_time_field" do
15
- it "returns releaf text field with resolved date or time input attributes" do
16
- allow(subject).to receive(:date_or_time_field_input_attributes)
17
- .with(:published_at, :datetime, a: 1).and_return(aa: 11)
18
- allow(subject).to receive(:releaf_text_field)
19
- .with(:published_at, input: {aa: 11}, label: {b: 1}, field: {c: 3}, options: {field: {type: "datetime"}, d: 4})
20
- .and_return("_fld")
21
-
22
- expect(subject.date_or_time_field(:published_at, :datetime, input: {a: 1}, label: {b: 1},
23
- field: {c: 3}, options: {d: 4}))
24
- .to eq("_fld")
25
- end
26
- end
27
-
28
- describe "#date_or_time_field_input_attributes" do
29
- before do
30
- allow(object).to receive(:published_at).and_return("_val")
31
- allow(Releaf::Builders::Utilities::DateFields).to receive(:format_date_or_time_value)
32
- .with("_val", :datetime).and_return("_frmt_val")
33
- allow(Releaf::Builders::Utilities::DateFields).to receive(:date_format_for_jquery).and_return("_date_frm")
34
- allow(Releaf::Builders::Utilities::DateFields).to receive(:time_format_for_jquery).and_return("_time_frm")
35
- end
36
-
37
- it "returns date or time field input attributes" do
38
- expect(subject.date_or_time_field_input_attributes(:published_at, :datetime, {})).to eq(
39
- class: "text datetime-picker",
40
- value: "_frmt_val",
41
- data: {"date-format"=>"_date_frm", "time-format"=>"_time_frm"}
42
- )
43
- end
44
-
45
- it "deep merges given attributes over resolved" do
46
- expect(subject.date_or_time_field_input_attributes(:published_at, :datetime, data: {"date-format" => "LK"})).to eq(
47
- class: "text datetime-picker",
48
- value: "_frmt_val",
49
- data: {"date-format"=>"LK", "time-format"=>"_time_frm"}
50
- )
51
- end
52
- end
53
-
54
- describe "#releaf_datetime_field" do
55
- it "returns releaf date or time field with `datetime` option" do
56
- expect(subject).to receive(:date_or_time_field)
57
- .with("year", :datetime, input: {a: "b"}, label: {c: "d"}, field: {e: "f"}, options: {g: "h"})
58
- .and_return("x")
59
-
60
- expect(subject.releaf_datetime_field("year", input: {a: "b"}, label: {c: "d"}, field: {e: "f"}, options: {g: "h"}))
61
- .to eq("x")
62
- end
63
- end
64
-
65
- describe "#releaf_time_field" do
66
- it "returns releaf date or time field with `time` option" do
67
- expect(subject).to receive(:date_or_time_field)
68
- .with("year", :time, input: {a: "b"}, label: {c: "d"}, field: {e: "f"}, options: {g: "h"})
69
- .and_return("x")
70
-
71
- expect(subject.releaf_time_field("year", input: {a: "b"}, label: {c: "d"}, field: {e: "f"}, options: {g: "h"}))
72
- .to eq("x")
73
- end
74
- end
75
-
76
- describe "#releaf_date_field" do
77
- it "returns releaf date or time field with `date` option" do
78
- expect(subject).to receive(:date_or_time_field)
79
- .with("year", :date, input: {a: "b"}, label: {c: "d"}, field: {e: "f"}, options: {g: "h"})
80
- .and_return("x")
81
-
82
- expect(subject.releaf_date_field("year", input: {a: "b"}, label: {c: "d"}, field: {e: "f"}, options: {g: "h"}))
83
- .to eq("x")
84
- end
85
- end
86
- end
@@ -1,48 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Builders::FormBuilder::I18nFields, 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(ActionView::LookupContext.new(nil), {}, nil) }
11
- let(:object){ Book.new }
12
- let(:subject){ Releaf::Builders::FormBuilder.new(:book, object, template, {}) }
13
-
14
- describe "#locales" do
15
- it "returns object globalize locales" do
16
- allow(subject.object.class).to receive(:globalize_locales).and_return([:de, :ru])
17
- expect(subject.locales).to eq([:de, :ru])
18
- end
19
- end
20
-
21
- describe "#default_locale" do
22
- before do
23
- allow(subject).to receive(:layout_settings).with("releaf.i18n.locale").and_return("de")
24
- allow(I18n).to receive(:locale).and_return(:ru)
25
- allow(subject).to receive(:locales).and_return([:de, :ru])
26
- end
27
-
28
- context "when layout settings has stored locale" do
29
- it "returns stored locale normalized to symbol" do
30
- expect(subject.default_locale).to eq(:de)
31
- end
32
- end
33
-
34
- context "when layout settings hasn't stored locale" do
35
- it "returns current I18n locale" do
36
- allow(subject).to receive(:layout_settings).with("releaf.i18n.locale").and_return(nil)
37
- expect(subject.default_locale).to eq(:ru)
38
- end
39
- end
40
-
41
- context "when stored locale or I18n locale is not within form locales" do
42
- it "returns first form locale" do
43
- allow(subject).to receive(:locales).and_return([:lv, :en])
44
- expect(subject.default_locale).to eq(:lv)
45
- end
46
- end
47
- end
48
- end
@@ -1,106 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Builders::FormBuilder::Label, 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(ActionView::LookupContext.new(nil), {}, nil) }
11
- let(:object){ Book.new }
12
- let(:subject){ Releaf::Builders::FormBuilder.new(:book, object, template, {}) }
13
-
14
- describe "#releaf_label" do
15
- it "passes options :label value to #label_text and use returned value for label text content" do
16
- allow(subject).to receive(:label_text).with(:color, a: "b").and_return("xx")
17
- result = '<div class="label-wrap"><label for="book_color">xx</label></div>'
18
-
19
- expect(subject.releaf_label(:color, {}, label: {a: "b"})).to eq(result)
20
- end
21
-
22
- it "uses #label_attributes for label attributes" do
23
- allow(subject).to receive(:label_attributes).with(:color, {class: "red"}, {a: "b"}).and_return(class: "red blue")
24
- result = '<div class="label-wrap"><label class="red blue" for="book_color">Color</label></div>'
25
-
26
- expect(subject.releaf_label(:color, {class: "red"}, {a: "b"})).to eq(result)
27
- end
28
-
29
- context "when options[:label][:description] is not blank" do
30
- context "when label has full version" do
31
- it "includes description" do
32
- result = '<div class="label-wrap"><label for="book_color">Color</label><div class="description">xxx</div></div>'
33
- expect(subject.releaf_label(:color, {}, label: {description: "xxx"})).to eq(result)
34
- end
35
- end
36
-
37
- context "when label has minimal version" do
38
- it "does not include description" do
39
- result = '<label for="book_color">Color</label>'
40
- expect(subject.releaf_label(:color, {}, label: {minimal: true})).to eq(result)
41
- end
42
- end
43
- end
44
-
45
- context "when options[:label][:minimal] is true" do
46
- it "returns label tag without wrap element" do
47
- result = '<label for="book_color">Color</label>'
48
- expect(subject).to_not receive(:wrapper)
49
- expect(subject.releaf_label(:color, {}, label: {minimal: true})).to eq(result)
50
- end
51
- end
52
-
53
- context "when options[:label][:minimal] is not true" do
54
- it "returns label tag with wrap element" do
55
- allow(subject).to receive(:wrapper).with('<label for="book_color">Color</label>', class: "label-wrap").and_return("x")
56
- expect(subject.releaf_label(:color, {}, label: {minimal: false})).to eq("x")
57
- expect(subject.releaf_label(:color, {}, label: {minimal: nil})).to eq("x")
58
- expect(subject.releaf_label(:color, {}, label: {adasd: "xx"})).to eq("x")
59
- end
60
- end
61
- end
62
-
63
- describe "#label_attributes" do
64
- it "returns unmodified attributes (allow further override by other builders)" do
65
- expect(subject.label_attributes(:color, {data: "x"}, {})).to eq(data: "x")
66
- end
67
- end
68
-
69
- describe "#label_text" do
70
- it "returns model attributes scoped translated value" do
71
- allow(subject).to receive(:translate_attribute).with("color").and_return("x")
72
- expect(subject.label_text(:color)).to eq("x")
73
- end
74
-
75
- context "when :label_text option exists" do
76
- context "when :label_text is not blank" do
77
- it "returns :label_text option" do
78
- expect(subject.label_text(:color, label_text: "krāsa")).to eq("krāsa")
79
- end
80
- end
81
-
82
- context "when :label_text is blank" do
83
- it "returns translated value" do
84
- expect(subject.label_text(:color, label_text: nil)).to eq("Color")
85
- expect(subject.label_text(:color, label_text: "")).to eq("Color")
86
- end
87
- end
88
- end
89
-
90
- context "when :translation_key option exists" do
91
- context "when :translation_key is not blank" do
92
- it "passes :translation_key option to translation and return translated value" do
93
- allow(subject).to receive(:translate_attribute).with("true_color").and_return("x")
94
- expect(subject.label_text(:color, translation_key: "true_color")).to eq("x")
95
- end
96
- end
97
-
98
- context "when :translation_key is blank" do
99
- it "returns translated value" do
100
- expect(subject.label_text(:color, translation_key: nil)).to eq("Color")
101
- expect(subject.label_text(:color, translation_key: "")).to eq("Color")
102
- end
103
- end
104
- end
105
- end
106
- end
@@ -1,37 +0,0 @@
1
- require "rails_helper"
2
-
3
- describe Releaf::Builders::FormBuilder::NumberFields, 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(ActionView::LookupContext.new(nil), {}, nil) }
11
- let(:object){ Book.new }
12
- let(:subject){ Releaf::Builders::FormBuilder.new(:book, object, template, {}) }
13
-
14
- describe "#releaf_number_field" do
15
- it "returns input with type 'number'" do
16
- expect(subject).to receive(:number_field).with("title", { value: nil, step: "any", class: "text" }).and_return("x")
17
- expect(subject).to receive(:input_wrapper_with_label).with("title", "x", { label: {}, field: {}, options: { field: { type: "number" }}}).and_return("y")
18
- expect(subject.releaf_number_field("title")).to eq("y")
19
- end
20
-
21
- context "aliases" do
22
- let(:releaf_number_field_method) { subject.method(:releaf_number_field) }
23
-
24
- it "is aliased by #releaf_integer_field" do
25
- expect(subject.method(:releaf_integer_field)).to eq(releaf_number_field_method)
26
- end
27
-
28
- it "is aliased by #releaf_float_field" do
29
- expect(subject.method(:releaf_float_field)).to eq(releaf_number_field_method)
30
- end
31
-
32
- it "is aliased by #releaf_decimal_field" do
33
- expect(subject.method(:releaf_decimal_field)).to eq(releaf_number_field_method)
34
- end
35
- end
36
- end
37
- end
@@ -1,228 +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(ActionView::LookupContext.new(nil), {}, nil) }
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
- describe "#field_names" do
43
- it "returns field names for object class" do
44
- allow(Releaf::ResourceFields).to receive(:new).with(object.class).and_call_original
45
- allow_any_instance_of(Releaf::ResourceFields).to receive(:values).and_return(["a", "b"])
46
- expect(subject.field_names).to eq(["a", "b"])
47
- end
48
- end
49
-
50
- describe "#field_type_method" do
51
- it "returns field type method resolved with ``" do
52
- allow(Releaf::Builders::Utilities::ResolveAttributeFieldMethodName).to receive(:call)
53
- .with(object: object, attribute_name: "color").and_return("some_method")
54
- expect(subject.field_type_method(:color)).to eq("some_method")
55
- end
56
- end
57
-
58
- describe "#field_render_method_name" do
59
- it "returns method name for given field" do
60
- expect(subject.field_render_method_name(:title)).to eq("render_title")
61
- end
62
-
63
- context "when builder has parent builder(-s)" do
64
- it "traverses through all builders and add relation name option to field name" do
65
- root_builder = described_class.new(:author, Author.new, template, {})
66
- middle_builder = described_class.new(:author, Author.new, template, {relation_name: :pages, parent_builder: root_builder})
67
- subject.options[:parent_builder] = middle_builder
68
- subject.options[:relation_name] = :chapters
69
-
70
- expect(subject.field_render_method_name(:title)).to eq("render_pages_chapters_title")
71
- end
72
- end
73
- end
74
-
75
- describe "#normalize_fields" do
76
- it "returns normalized fields for use with #releaf_fields method" do
77
- fields = [
78
- "title",
79
- "author_id",
80
- {chapters: ["title", "text", "sample_html"]},
81
- {book_sequels: ["sequel_id"]}
82
- ]
83
- expect(subject.normalize_fields(fields)).to eq(normalized_fields)
84
- end
85
-
86
- it "handles multi-key hashes" do
87
- fields = [
88
- "title",
89
- "author_id",
90
- {
91
- chapters: ["title", "text", "sample_html"],
92
- book_sequels: ["sequel_id"]
93
- }
94
- ]
95
- expect(subject.normalize_fields(fields)).to eq(normalized_fields)
96
- end
97
- end
98
-
99
- describe "#releaf_fields" do
100
- it "normalizes given fields with #normalize_fields" do
101
- allow(subject).to receive(:render_field_by_options)
102
- expect(subject).to receive(:normalize_fields).with([:a, :b]).and_return([:x, :y])
103
- subject.releaf_fields(:a, :b)
104
- end
105
-
106
- it "passes all normalized field options to #render_field" do
107
- allow(subject).to receive(:normalize_fields).and_return([:x, :y])
108
- expect(subject).to receive(:render_field_by_options).with(:x)
109
- expect(subject).to receive(:render_field_by_options).with(:y)
110
- subject.releaf_fields(:a, :b)
111
- end
112
-
113
- it "concatenates and return all #render_field_by_options outputs with #safe_join" do
114
- allow(subject).to receive(:render_field_by_options).and_return('_a_', '_b_')
115
- allow(subject).to receive(:normalize_fields).and_return([:x, :y])
116
- expect(subject).to receive(:safe_join).with(no_args){|&block|
117
- expect(block.call).to eq(['_a_', '_b_'])
118
- }.and_return("xxx")
119
- expect(subject.releaf_fields(:a, :b)).to eq("xxx")
120
- end
121
- end
122
-
123
- describe "#render_field_by_options" do
124
- let(:options){ {
125
- render_method: "sortable_column_name", # just random method here
126
- field: "title",
127
- subfields: [:a, :b],
128
- } }
129
-
130
- before do
131
- allow(subject).to receive(:reflect_on_association).with("title").and_return(:x)
132
- allow(subject).to receive(:sortable_column_name)
133
- .with(no_args).and_return("_render_method_content_")
134
- allow(subject).to receive(:releaf_association_fields)
135
- .with(:x, [:a, :b]).and_return("_association_method_content_")
136
- allow(subject).to receive(:releaf_field)
137
- .with("title").and_return("_releaf_field_content_")
138
- end
139
-
140
- context "when method defined in options[:render_method] exists" do
141
- it "returns this method output" do
142
- expect(subject.render_field_by_options(options)).to eq("_render_method_content_")
143
- end
144
- end
145
-
146
- context "when custom method does not exist" do
147
- before do
148
- options[:render_method] = "something_unexisting"
149
- end
150
-
151
- context "when reflection exists for given field" do
152
- it "returns #releaf_association_fields by passing options[:field] and options[:subfields]" do
153
- expect(subject.render_field_by_options(options)).to eq("_association_method_content_")
154
- end
155
- end
156
-
157
- context "when reflection does not exist for given field" do
158
- it "returns #releaf_field with options[:field] as argument" do
159
- allow(subject).to receive(:reflect_on_association).with("title").and_return(nil)
160
- expect(subject.render_field_by_options(options)).to eq("_releaf_field_content_")
161
- end
162
- end
163
- end
164
- end
165
-
166
- describe "#input_wrapper_with_label" do
167
- before do
168
- allow(subject).to receive(:wrapper).with("input_content", class: "value").and_return("input_content")
169
- allow(subject).to receive(:releaf_label).with(:color, "label_attributes", "options").and_return("label_content")
170
- allow(subject).to receive(:field).with(:color, "field_attributes", "options"){ |name, field, options, &block|
171
- expect(block.call).to eq("label_contentinput_content")
172
- }.and_return("content")
173
- end
174
-
175
- it "returns wrapped label and input content" do
176
- expect(subject.input_wrapper_with_label(:color, "input_content", label: "label_attributes", field: "field_attributes", options: "options"))
177
- .to eq("content")
178
- end
179
-
180
- context "when block given" do
181
- it "safely concatinate block output to content" do
182
- content = 'input_content<input type="hidden" name="book[id]" id="book_id" />'
183
- allow(subject).to receive(:wrapper).with(content, class: "value").and_return("input_content")
184
- expect(subject.input_wrapper_with_label(:color, "input_content", label: "label_attributes", field: "field_attributes", options: "options"){ subject.hidden_field(:id) })
185
- .to eq("content")
186
- end
187
-
188
- it "correctly handles block nil output" do
189
- expect(subject.input_wrapper_with_label(:color, "input_content", label: "label_attributes", field: "field_attributes", options: "options"){ })
190
- .to eq("content")
191
- end
192
- end
193
- end
194
-
195
- describe "#field_attributes" do
196
- it "adds field data and class attributes and cast name to string within data attributes" do
197
- expect(subject.field_attributes(:color, {}, {field: {type: "text"}})).to eq(data: {name: "color"}, class: ["field", "type-text"])
198
- end
199
-
200
- it "merges attributes over build-in data hash" do
201
- expect(subject.field_attributes(:color, {data: {other: "x"}}, {})[:data]).to eq(name: "color", other: "x")
202
- expect(subject.field_attributes(:color, {data: {other: "x", name: :lll}}, {})[:data]).to eq(name: :lll, other: "x")
203
- end
204
-
205
- it "supports class attributes merging" do
206
- expect(subject.field_attributes(:color, {class: ["a", "b"]}, {})[:class]).to eq(["field", "type-", "a", "b"])
207
- end
208
- end
209
-
210
- describe "#input_attributes" do
211
- it "returns unmodified attributes (allow further override by other builders)" do
212
- expect(subject.input_attributes(:color, {data: "x"}, {})).to eq(data: "x")
213
- end
214
- end
215
-
216
- describe "#sortable_column_name" do
217
- it "returns 'item_position'" do
218
- expect( subject.sortable_column_name ).to eq 'item_position'
219
- end
220
- end
221
-
222
- describe "#translate_attribute" do
223
- it "translates given attribute within object translation scope" do
224
- allow(object.class).to receive(:human_attribute_name).with("x").and_return("z")
225
- expect(subject.translate_attribute("x")).to eq("z")
226
- end
227
- end
228
- end