releaf-core 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +3 -193
- data/spec/builders/releaf/builders/association_reflector_spec.rb +0 -138
- data/spec/builders/releaf/builders/base_spec.rb +0 -272
- data/spec/builders/releaf/builders/collection_spec.rb +0 -18
- data/spec/builders/releaf/builders/confirm_destroy_dialog_builder_spec.rb +0 -71
- data/spec/builders/releaf/builders/confirm_dialog_builder_spec.rb +0 -107
- data/spec/builders/releaf/builders/edit_builder_spec.rb +0 -322
- data/spec/builders/releaf/builders/form_builder/associations_spec.rb +0 -129
- data/spec/builders/releaf/builders/form_builder/date_fields_spec.rb +0 -86
- data/spec/builders/releaf/builders/form_builder/i18n_fields_spec.rb +0 -48
- data/spec/builders/releaf/builders/form_builder/label_spec.rb +0 -106
- data/spec/builders/releaf/builders/form_builder/number_fields_spec.rb +0 -37
- data/spec/builders/releaf/builders/form_builder_spec.rb +0 -228
- data/spec/builders/releaf/builders/index_builder_spec.rb +0 -364
- data/spec/builders/releaf/builders/page/header_builder_spec.rb +0 -66
- data/spec/builders/releaf/builders/page/layout_builder_spec.rb +0 -237
- data/spec/builders/releaf/builders/page/menu_builder_spec.rb +0 -345
- data/spec/builders/releaf/builders/pagination_builder_spec.rb +0 -330
- data/spec/builders/releaf/builders/resource_dialog_spec.rb +0 -21
- data/spec/builders/releaf/builders/resource_view_spec.rb +0 -158
- data/spec/builders/releaf/builders/show_builder_spec.rb +0 -7
- data/spec/builders/releaf/builders/table_builder_spec.rb +0 -637
- data/spec/builders/releaf/builders/template_spec.rb +0 -12
- data/spec/builders/releaf/builders/toolbox_builder_spec.rb +0 -67
- data/spec/builders/releaf/builders/toolbox_spec.rb +0 -48
- data/spec/builders/releaf/builders/utilities/date_fields_spec.rb +0 -125
- data/spec/builders/releaf/builders/utilities/resolve_attribute_field_method_name_spec.rb +0 -318
- data/spec/builders/releaf/builders/view_spec.rb +0 -281
- data/spec/builders/releaf/builders_spec.rb +0 -144
- data/spec/builders/releaf/settings/form_builder_spec.rb +0 -48
- data/spec/builders/releaf/settings/table_builder_spec.rb +0 -23
- data/spec/controllers/concerns/releaf/richtext_attachments_spec.rb +0 -51
- data/spec/controllers/releaf/action_controller_spec.rb +0 -423
- data/spec/controllers/releaf/root_controller_spec.rb +0 -46
- data/spec/controllers/releaf/settings_controller_spec.rb +0 -52
- data/spec/error_hash_builder_spec.rb +0 -83
- data/spec/ext/array_reorder_spec.rb +0 -12
- data/spec/features/ajaxbox_spec.rb +0 -111
- data/spec/features/authorization_spec.rb +0 -50
- data/spec/features/breadcrumbs_spec.rb +0 -16
- data/spec/features/dragonfly_integration_spec.rb +0 -24
- data/spec/features/edit_actions_spec.rb +0 -186
- data/spec/features/errors_spec.rb +0 -47
- data/spec/features/index_actions_spec.rb +0 -86
- data/spec/features/index_table_spec.rb +0 -35
- data/spec/features/menu_spec.rb +0 -71
- data/spec/features/richtext_attachments_spec.rb +0 -64
- data/spec/features/richtext_custom_config_spec.rb +0 -28
- data/spec/features/richtext_embed_spec.rb +0 -29
- data/spec/features/richtext_spec.rb +0 -31
- data/spec/features/search_spec.rb +0 -825
- data/spec/features/settings_spec.rb +0 -70
- data/spec/features/title_spec.rb +0 -13
- data/spec/fixtures/common_fields.yml +0 -17
- data/spec/fixtures/cs.png +0 -0
- data/spec/fixtures/time.formats.xlsx +0 -0
- data/spec/fixtures/unicorn.jpg +0 -0
- data/spec/helpers/application_helper_spec.rb +0 -73
- data/spec/helpers/button_helper_spec.rb +0 -146
- data/spec/lib/releaf/action_controller/features_spec.rb +0 -171
- data/spec/lib/releaf/action_controller/search_spec.rb +0 -84
- data/spec/lib/releaf/application_spec.rb +0 -43
- data/spec/lib/releaf/assets_resolver_spec.rb +0 -130
- data/spec/lib/releaf/build_errors_hash_spec.rb +0 -141
- data/spec/lib/releaf/configuration_spec.rb +0 -205
- data/spec/lib/releaf/controller_definition_spec.rb +0 -78
- data/spec/lib/releaf/controller_group_definition_spec.rb +0 -33
- data/spec/lib/releaf/default_searchable_fields_spec.rb +0 -161
- data/spec/lib/releaf/instance_cache_spec.rb +0 -98
- data/spec/lib/releaf/resource_base_spec.rb +0 -212
- data/spec/lib/releaf/resource_fields_spec.rb +0 -12
- data/spec/lib/releaf/resource_params_spec.rb +0 -115
- data/spec/lib/releaf/resource_table_fields_spec.rb +0 -20
- data/spec/lib/releaf/resource_utilities_spec.rb +0 -87
- data/spec/lib/releaf/responders/access_denied_responder_spec.rb +0 -12
- data/spec/lib/releaf/responders/after_save_responder_spec.rb +0 -88
- data/spec/lib/releaf/responders/confirm_destroy_responder_spec.rb +0 -26
- data/spec/lib/releaf/responders/destroy_responder_spec.rb +0 -30
- data/spec/lib/releaf/responders/error_responder_spec.rb +0 -26
- data/spec/lib/releaf/responders/feature_disabled_responder_spec.rb +0 -12
- data/spec/lib/releaf/responders/page_not_found_responder_spec.rb +0 -12
- data/spec/lib/releaf/responders_spec.rb +0 -61
- data/spec/lib/releaf/root/configuration_spec.rb +0 -9
- data/spec/lib/releaf/root/default_controller_resolver_spec.rb +0 -44
- data/spec/lib/releaf/root_spec.rb +0 -13
- data/spec/lib/releaf/service_spec.rb +0 -20
- data/spec/lib/releaf/settings/normalize_value_spec.rb +0 -103
- data/spec/lib/releaf/settings/register_spec.rb +0 -135
- data/spec/lib/releaf/settings_manager_spec.rb +0 -22
- data/spec/lib/validation_error_codes_spec.rb +0 -56
- data/spec/misc/factories_spec.rb +0 -31
- data/spec/models/settings_spec.rb +0 -104
- data/spec/routing/route_mapper_spec.rb +0 -185
- data/spec/rspec_helpers/test_helpers_spec.rb +0 -20
- data/spec/rspec_helpers/test_spec.rb +0 -14
- data/spec/services/array/reorder_spec.rb +0 -121
@@ -1,21 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::Builders::ResourceDialog, type: :class do
|
4
|
-
class DialogTestHelper < ActionView::Base
|
5
|
-
end
|
6
|
-
|
7
|
-
class UnitTestDialogBuilder
|
8
|
-
include Releaf::Builders::Base
|
9
|
-
include Releaf::Builders::Template
|
10
|
-
include Releaf::Builders::ResourceDialog
|
11
|
-
end
|
12
|
-
|
13
|
-
subject { UnitTestDialogBuilder.new(template) }
|
14
|
-
let(:template){ DialogTestHelper.new(ActionView::LookupContext.new(nil), {}, nil) }
|
15
|
-
|
16
|
-
describe "#dialog?" do
|
17
|
-
it "always returns true" do
|
18
|
-
expect(subject.dialog?).to be true
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,158 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::Builders::ResourceView, type: :class do
|
4
|
-
class ResourceViewIncluder
|
5
|
-
include Releaf::Builders::ResourceView
|
6
|
-
end
|
7
|
-
|
8
|
-
class ResourceViewTestHelper < ActionView::Base
|
9
|
-
include Releaf::ApplicationHelper
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:described_class){ ResourceViewIncluder }
|
13
|
-
let(:template){ ResourceViewTestHelper.new(ActionView::LookupContext.new(nil), {}, nil) }
|
14
|
-
let(:subject){ described_class.new(template) }
|
15
|
-
let(:controller){ Releaf::ActionController.new }
|
16
|
-
let(:resource){ Book.new }
|
17
|
-
|
18
|
-
before do
|
19
|
-
allow(template).to receive(:controller).and_return(controller)
|
20
|
-
allow(subject).to receive(:resource).and_return(resource)
|
21
|
-
allow(subject).to receive(:index_path).and_return("_index_path_")
|
22
|
-
end
|
23
|
-
|
24
|
-
it "includes Releaf::Builders::View" do
|
25
|
-
expect(described_class.ancestors).to include(Releaf::Builders::View)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "includes Releaf::Builders::Resource" do
|
29
|
-
expect(described_class.ancestors).to include(Releaf::Builders::Resource)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "includes Releaf::Builders::Toolbox" do
|
33
|
-
expect(described_class.ancestors).to include(Releaf::Builders::Toolbox)
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "#section" do
|
37
|
-
before do
|
38
|
-
allow(subject).to receive(:section_attributes).and_return(a: "b")
|
39
|
-
allow(subject).to receive(:section_blocks).and_return(["_section_","_blocks_"])
|
40
|
-
end
|
41
|
-
|
42
|
-
it "returns section with index url preserver and section blocks" do
|
43
|
-
expect(subject.section).to eq('<section a="b">_section__blocks_</section>')
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#section_header_text" do
|
48
|
-
before do
|
49
|
-
allow(subject).to receive(:t).with("Create new resource").and_return("newww")
|
50
|
-
allow(subject).to receive(:resource_title).with(resource).and_return("existng")
|
51
|
-
end
|
52
|
-
|
53
|
-
context "when resource is new object" do
|
54
|
-
it "returns resource to text cast result" do
|
55
|
-
expect(subject.section_header_text).to eq("newww")
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "when resource is persisted object" do
|
60
|
-
it "returns resource to text cast result" do
|
61
|
-
allow(resource).to receive(:new_record?).and_return(false)
|
62
|
-
expect(subject.section_header_text).to eq("existng")
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "#section_header_extras" do
|
68
|
-
before do
|
69
|
-
allow(subject).to receive(:toolbox).with(resource, index_path: "_index_path_").and_return("_tlbx_")
|
70
|
-
allow(subject).to receive(:feature_available?).with(:toolbox).and_return(true)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "returns header extras with toolbox button" do
|
74
|
-
expect(subject.section_header_extras).to eq('<div class="extras toolbox-wrap">_tlbx_</div>')
|
75
|
-
end
|
76
|
-
|
77
|
-
context "when toolbox feature is not available" do
|
78
|
-
it "returns nil" do
|
79
|
-
allow(subject).to receive(:feature_available?).with(:toolbox).and_return(false)
|
80
|
-
expect(subject.section_header_extras).to be nil
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "#section_body" do
|
86
|
-
it "returns section body block with applied section body attributes" do
|
87
|
-
allow(subject).to receive(:section_body_blocks).and_return(["a", "b"])
|
88
|
-
allow(subject).to receive(:section_body_attributes).and_return(class: "x")
|
89
|
-
expect(subject.section_body).to eq('<div class="x">ab</div>')
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe "#section_body_attributes" do
|
94
|
-
it "returns section hash with body class" do
|
95
|
-
expect(subject.section_body_attributes).to eq(class: ["body"])
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "#section_body_blocks" do
|
100
|
-
it "returns empty array" do
|
101
|
-
expect(subject.section_body_blocks).to eq([])
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "#footer_secondary_tools" do
|
106
|
-
before do
|
107
|
-
allow(subject).to receive(:back_to_list_button).and_return("_btn_")
|
108
|
-
allow(subject).to receive(:back_to_list?).and_return(true)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "returns array with back to list button" do
|
112
|
-
expect(subject.footer_secondary_tools).to eq(["_btn_"])
|
113
|
-
end
|
114
|
-
|
115
|
-
context "when toolbox feature is not available" do
|
116
|
-
it "returns empty array" do
|
117
|
-
allow(subject).to receive(:back_to_list?).and_return(false)
|
118
|
-
expect(subject.footer_secondary_tools).to eq([])
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe "#back_to_list?" do
|
124
|
-
before do
|
125
|
-
allow(subject).to receive(:params).and_return(index_path: "xxx")
|
126
|
-
allow(subject).to receive(:feature_available?).with(:index).and_return(true)
|
127
|
-
end
|
128
|
-
|
129
|
-
context "when index feature is available and index_path is present within params" do
|
130
|
-
it "returns true" do
|
131
|
-
expect(subject.back_to_list?).to be true
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
context "when index_path is not present within params" do
|
136
|
-
it "returns false" do
|
137
|
-
allow(subject).to receive(:params).and_return(search: "xxx")
|
138
|
-
expect(subject.back_to_list?).to be false
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
context "when index feature is not available" do
|
143
|
-
it "returns false" do
|
144
|
-
allow(subject).to receive(:feature_available?).with(:index).and_return(false)
|
145
|
-
expect(subject.back_to_list?).to be false
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
describe "#back_to_list_button" do
|
151
|
-
it "returns `back to list` button" do
|
152
|
-
allow(subject).to receive(:button)
|
153
|
-
.with("to_list", "caret-left", {class: "secondary", href: "_index_path_"}).and_return("_btn_")
|
154
|
-
allow(subject).to receive(:t).with("Back to list").and_return("to_list")
|
155
|
-
expect(subject.back_to_list_button).to eq("_btn_")
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
@@ -1,637 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::Builders::TableBuilder, type: :class do
|
4
|
-
class TableBuilderTestHelper < ActionView::Base
|
5
|
-
include Releaf::ApplicationHelper
|
6
|
-
end
|
7
|
-
|
8
|
-
class DummyTableBuilderInheriter < Releaf::Builders::TableBuilder
|
9
|
-
def some_cell_method(resource, column); end
|
10
|
-
def custom_format(resource, column); end
|
11
|
-
def format_big_boolean_content(resource, column); end
|
12
|
-
def title_cell; end
|
13
|
-
def custom_title(resource); end
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:template){ TableBuilderTestHelper.new(ActionView::LookupContext.new(nil), {}, nil) }
|
17
|
-
let(:resource_class){ Book }
|
18
|
-
let(:resource){ resource_class.new(id: 77, title: "Life of Brian") }
|
19
|
-
let(:collection){ Book.all }
|
20
|
-
let(:options){ {toolbox: false} }
|
21
|
-
let(:subject){ described_class.new(collection, resource_class, template, options) }
|
22
|
-
let(:inheriter_subject){ DummyTableBuilderInheriter.new(collection, resource_class, template, options) }
|
23
|
-
|
24
|
-
it "includes Releaf::Builders::Base" do
|
25
|
-
expect(described_class.ancestors).to include(Releaf::Builders::Base)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "includes Releaf::Builders::Toolbox" do
|
29
|
-
expect(described_class.ancestors).to include(Releaf::Builders::Toolbox)
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#initialize" do
|
33
|
-
it "assigns collection" do
|
34
|
-
expect(subject.collection.to_sql).to eq(collection.to_sql)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "assigns resource_class" do
|
38
|
-
expect(subject.resource_class).to eq(resource_class)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "assigns template" do
|
42
|
-
expect(subject.template).to eq(template)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "assigns options" do
|
46
|
-
expect(subject.options).to eq(options)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "#columns" do
|
51
|
-
it "returns columns schema" do
|
52
|
-
allow(subject).to receive(:columns_schema).and_return("schema")
|
53
|
-
expect(subject.columns).to eq("schema")
|
54
|
-
end
|
55
|
-
|
56
|
-
it "caches columns schema data" do
|
57
|
-
expect(subject).to receive(:columns_schema).and_return("schema").once
|
58
|
-
subject.columns
|
59
|
-
subject.columns
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "#column_names" do
|
64
|
-
it "returns column names for resource_class" do
|
65
|
-
allow(Releaf::ResourceTableFields).to receive(:new).with(subject.resource_class).and_call_original
|
66
|
-
allow_any_instance_of(Releaf::ResourceTableFields).to receive(:values)
|
67
|
-
.with(include_associations: false).and_return(["a", "b"])
|
68
|
-
expect(subject.column_names).to eq(["a", "b"])
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "#columns_schema" do
|
73
|
-
before do
|
74
|
-
allow(subject).to receive(:column_names).and_return([:price, :title, :author_id])
|
75
|
-
allow(subject).to receive(:cell_content_method).with(:price).and_return(:title_content)
|
76
|
-
allow(subject).to receive(:cell_content_method).with(:title).and_return(:title_content)
|
77
|
-
allow(subject).to receive(:cell_content_method).with(:author_id).and_return(nil)
|
78
|
-
allow(subject).to receive(:cell_format_method).with(:author_id).and_return(:some_text_format)
|
79
|
-
end
|
80
|
-
|
81
|
-
it "returns hash with columns and corresponding method" do
|
82
|
-
allow(subject).to receive(:cell_method).with(:price).and_return("price_cell")
|
83
|
-
allow(subject).to receive(:cell_method).with(:title).and_return(nil)
|
84
|
-
allow(subject).to receive(:cell_method).with(:author_id).and_return(nil)
|
85
|
-
columns = {
|
86
|
-
price: {cell_method: "price_cell"},
|
87
|
-
title: {content_method: :title_content},
|
88
|
-
author_id: {format_method: :some_text_format}
|
89
|
-
}
|
90
|
-
expect(subject.columns_schema).to eq(columns)
|
91
|
-
end
|
92
|
-
|
93
|
-
it "preserves order as in #column_names" do
|
94
|
-
expect(subject.columns_schema.keys).to eq([:price, :title, :author_id])
|
95
|
-
end
|
96
|
-
|
97
|
-
context "when options[:toolbox] value is 'true'" do
|
98
|
-
let(:options){ {toolbox: true} }
|
99
|
-
it "adds toolbox as last column" do
|
100
|
-
expect(subject.columns_schema.keys.last).to eq(:toolbox)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "uses #toolbox_cell for toolbox cell rendering" do
|
104
|
-
expect(subject.columns_schema[:toolbox]).to eq(cell_method: "toolbox_cell")
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe "#column_klass" do
|
110
|
-
context "when association column given" do
|
111
|
-
it "returns corresponding association class" do
|
112
|
-
resource.author = Author.new(name: "Brian")
|
113
|
-
expect(subject.column_klass(resource_class, "author.name")).to eq(Author)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context "when base resource column given" do
|
118
|
-
it "returns give resource class" do
|
119
|
-
expect(subject.column_klass(resource_class, "year")).to eq(resource_class)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe "#column_value" do
|
125
|
-
it "returns value for column of given resource" do
|
126
|
-
expect(subject.column_value(resource, "title")).to eq("Life of Brian")
|
127
|
-
end
|
128
|
-
|
129
|
-
it "supports association columns" do
|
130
|
-
resource.author = Author.new(name: "Brian")
|
131
|
-
expect(subject.column_value(resource, "author.name")).to eq("Brian")
|
132
|
-
end
|
133
|
-
|
134
|
-
it "supports empty association columns" do
|
135
|
-
resource.author = nil
|
136
|
-
expect(subject.column_value(resource, "author.name")).to be nil
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe "#output" do
|
141
|
-
before do
|
142
|
-
allow(subject).to receive(:empty_body).and_return("empty")
|
143
|
-
end
|
144
|
-
|
145
|
-
it "returns table with #empty_body content" do
|
146
|
-
allow(subject).to receive(:table_attributes).and_return(class: "a", data: {some: "b"})
|
147
|
-
content = '<table class="a" data-some="b">empty</table>'
|
148
|
-
expect(subject.output).to eq(content)
|
149
|
-
end
|
150
|
-
|
151
|
-
context "when collection is not empty" do
|
152
|
-
it "returns table with #header and #body" do
|
153
|
-
create(:book)
|
154
|
-
content = '<table class="table books">header_contentbody_content</table>'
|
155
|
-
allow(subject).to receive(:head).and_return("header_content")
|
156
|
-
allow(subject).to receive(:body).and_return("body_content")
|
157
|
-
|
158
|
-
expect(subject.output).to eq(content)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
context "when collection is empty" do
|
163
|
-
it "returns table with #empty_body content" do
|
164
|
-
content = '<table class="table books">empty</table>'
|
165
|
-
expect(subject.output).to eq(content)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe "#table_attributes" do
|
171
|
-
it "returns hash with table and pluralized, dasherized resource classes" do
|
172
|
-
expect(subject.table_attributes).to eq(class: ["table", "books"])
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe "#head" do
|
177
|
-
it "returns header row with #head_cell generated cells for each columns" do
|
178
|
-
allow(subject).to receive(:column_names).and_return([:price, :title, :author_id])
|
179
|
-
allow(subject).to receive(:head_cell).with(:price).and_return("_price_cell_")
|
180
|
-
allow(subject).to receive(:head_cell).with(:title).and_return("_title_cell_")
|
181
|
-
allow(subject).to receive(:head_cell).with(:author_id).and_return("_author_id_cell_")
|
182
|
-
|
183
|
-
content = '<thead><tr>_price_cell__title_cell__author_id_cell_</tr></thead>'
|
184
|
-
expect(subject.head).to eq(content)
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
describe "#head_cell" do
|
189
|
-
it "returns 'th' element with content from #head_cell_column" do
|
190
|
-
allow(subject).to receive(:head_cell_content).with(:title).and_return("_title_content_")
|
191
|
-
content = '<th>_title_content_</th>'
|
192
|
-
expect(subject.head_cell(:title)).to eq(content)
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
|
197
|
-
describe "#head_cell_content" do
|
198
|
-
it "returns translated column scoped to resource class attributes" do
|
199
|
-
allow(resource_class).to receive(:human_attribute_name).with("some_long_name").and_return("Taittls")
|
200
|
-
expect(subject.head_cell_content("some_long_name")).to eq('Taittls')
|
201
|
-
end
|
202
|
-
|
203
|
-
it "casts given column to string" do
|
204
|
-
allow(resource_class).to receive(:human_attribute_name).with("title",).and_return("Taittls")
|
205
|
-
expect(subject.head_cell_content(:title)).to eq('Taittls')
|
206
|
-
end
|
207
|
-
|
208
|
-
context "when column value is 'toolbox'" do
|
209
|
-
it "returns nil" do
|
210
|
-
expect(subject.head_cell_content(:toolbox)).to eq(nil)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
describe "#empty_body" do
|
216
|
-
it "returns empty table body content" do
|
217
|
-
allow(subject).to receive(:t).with("Nothing found").and_return("ntnn")
|
218
|
-
content = '<tr><th><div class="nothing-found">ntnn</div></th></tr>'
|
219
|
-
expect(subject.empty_body).to eq(content)
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
describe "#body" do
|
224
|
-
it "returns table body with rows for each collection items generated with #row method" do
|
225
|
-
subject.collection = ["a", "b"]
|
226
|
-
allow(subject).to receive(:row).with("a").and_return("_a_row_")
|
227
|
-
allow(subject).to receive(:row).with("b").and_return("_b_row_")
|
228
|
-
|
229
|
-
content = '<tbody class="tbody">_a_row__b_row_</tbody>'
|
230
|
-
expect(subject.body).to eq(content)
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
describe "#row_url" do
|
235
|
-
let(:controller){ Releaf::ActionController.new }
|
236
|
-
|
237
|
-
before do
|
238
|
-
allow(subject).to receive(:controller).and_return(controller)
|
239
|
-
allow(controller).to receive(:index_path).and_return("_index_path_")
|
240
|
-
end
|
241
|
-
|
242
|
-
it "returns edit url for given resource" do
|
243
|
-
allow(subject).to receive(:row_url_action).with(resource).and_return(:show)
|
244
|
-
allow(template).to receive(:url_for).with(action: :show, id: 77, index_path: "_index_path_").and_return('_url_')
|
245
|
-
expect(subject.row_url(resource)).to eq('_url_')
|
246
|
-
end
|
247
|
-
|
248
|
-
context "when resource do not have row url action" do
|
249
|
-
it "returns nil" do
|
250
|
-
allow(subject).to receive(:row_url_action).with(resource).and_return(nil)
|
251
|
-
expect(subject.row_url(resource)).to be nil
|
252
|
-
end
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
describe "#row_url_action" do
|
257
|
-
let(:controller){ Releaf::ActionController.new }
|
258
|
-
|
259
|
-
before do
|
260
|
-
allow(subject).to receive(:controller).and_return(controller)
|
261
|
-
allow(controller).to receive(:feature_available?).with(:show).and_return(true)
|
262
|
-
allow(controller).to receive(:feature_available?).with(:edit).and_return(true)
|
263
|
-
end
|
264
|
-
|
265
|
-
context "when show and edit features is available" do
|
266
|
-
it "returns :show" do
|
267
|
-
expect(subject.row_url_action(resource)).to eq(:show)
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
context "when show feature is not available and edit feature is available" do
|
272
|
-
it "returns :edit" do
|
273
|
-
allow(controller).to receive(:feature_available?).with(:show).and_return(false)
|
274
|
-
expect(subject.row_url_action(resource)).to eq(:edit)
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
context "when show and edit features is not available" do
|
279
|
-
it "returns nil" do
|
280
|
-
allow(controller).to receive(:feature_available?).with(:show).and_return(false)
|
281
|
-
allow(controller).to receive(:feature_available?).with(:edit).and_return(false)
|
282
|
-
expect(subject.row_url_action(resource)).to be nil
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
describe "#row_attributes" do
|
288
|
-
it "returns row attributes with html class and resource id as data value" do
|
289
|
-
resource = resource_class.new(id: 77)
|
290
|
-
expect(subject.row_attributes(resource)).to eq(class: "row", data: {id: 77})
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
describe "#row" do
|
295
|
-
it "adds attributes returned from #row_attributes to row" do
|
296
|
-
resource = resource_class.new
|
297
|
-
allow(subject).to receive(:column_names).and_return([])
|
298
|
-
allow(subject).to receive(:row_attributes).with(resource).and_return(class: "color", data: {color: "red"})
|
299
|
-
allow(subject).to receive(:row_url)
|
300
|
-
|
301
|
-
content = '<tr class="color" data-color="red"></tr>'
|
302
|
-
expect(subject.row(resource)).to eq(content)
|
303
|
-
end
|
304
|
-
|
305
|
-
it "calls #row_url only once" do
|
306
|
-
resource = resource_class.new
|
307
|
-
allow(subject).to receive(:column_names).and_return([:title, :author_id])
|
308
|
-
expect(subject).to receive(:row_url).with(resource).once
|
309
|
-
subject.row(resource)
|
310
|
-
end
|
311
|
-
|
312
|
-
it "output each cell contents by using either custom or default cell method" do
|
313
|
-
columns = {
|
314
|
-
title: {cell_method: "some_cell_method"},
|
315
|
-
color: {},
|
316
|
-
}
|
317
|
-
resource = resource_class.new(id: 89)
|
318
|
-
|
319
|
-
allow(inheriter_subject).to receive(:columns).and_return(columns)
|
320
|
-
allow(inheriter_subject).to receive(:row_url).with(resource).and_return("url_value")
|
321
|
-
|
322
|
-
allow(inheriter_subject).to receive(:some_cell_method)
|
323
|
-
.with(resource, cell_method: "some_cell_method", url: "url_value").and_return("_title_cell_value")
|
324
|
-
allow(inheriter_subject).to receive(:cell)
|
325
|
-
.with(resource, :color, url: "url_value").and_return("_color_cell_value")
|
326
|
-
|
327
|
-
content = '<tr class="row" data-id="89">_title_cell_value_color_cell_value</tr>'
|
328
|
-
expect(inheriter_subject.row(resource)).to eq(content)
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
describe "#cell_content" do
|
333
|
-
it "returns format method output with resource and column as arguments" do
|
334
|
-
options = {format_method: "custom_format"}
|
335
|
-
allow(inheriter_subject).to receive(:custom_format).with("a", :title).and_return('_custom " format_')
|
336
|
-
|
337
|
-
content = '_custom " format_'
|
338
|
-
expect(inheriter_subject.cell_content("a", :title, options)).to eq(content)
|
339
|
-
end
|
340
|
-
|
341
|
-
context "when given options has :content_method" do
|
342
|
-
it "returns content method output with resource as argument" do
|
343
|
-
options = {content_method: "custom_title", format_method: "custom_format"}
|
344
|
-
allow(inheriter_subject).to receive(:custom_title).with("a").and_return('_custom " _value_')
|
345
|
-
|
346
|
-
content = '_custom " _value_'
|
347
|
-
expect(inheriter_subject.cell_content("a", :title, options)).to eq(content)
|
348
|
-
end
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
describe "#format_text_content" do
|
353
|
-
it "returns truncated and escape column value" do
|
354
|
-
allow(subject).to receive(:column_value).with(resource, :title)
|
355
|
-
.and_return('"Pra<tag>nt commodo cursus magn')
|
356
|
-
expect(subject.format_text_content(resource, :title))
|
357
|
-
.to eq('"Pra<tag>nt commodo cursus magn')
|
358
|
-
end
|
359
|
-
|
360
|
-
it "casts value to string before truncation" do
|
361
|
-
allow(subject).to receive(:column_value).with(resource, :title)
|
362
|
-
.and_return(nil)
|
363
|
-
expect(subject.format_text_content(resource, :title)).to eq("")
|
364
|
-
end
|
365
|
-
end
|
366
|
-
|
367
|
-
describe "#format_richtext_content" do
|
368
|
-
it "returns truncated and sanitized column value" do
|
369
|
-
allow(subject).to receive(:column_value).with(resource, :title)
|
370
|
-
.and_return('"Pra<tag>nt commodo\ncursus magn')
|
371
|
-
expect(subject.format_richtext_content(resource, :title))
|
372
|
-
.to eq('"Prant commodo\ncursus magn')
|
373
|
-
end
|
374
|
-
|
375
|
-
it "casts value to string before truncation" do
|
376
|
-
allow(subject).to receive(:column_value).with(resource, :title)
|
377
|
-
.and_return(nil)
|
378
|
-
expect(subject.format_richtext_content(resource, :title)).to eq("")
|
379
|
-
end
|
380
|
-
end
|
381
|
-
|
382
|
-
describe "#format_textarea_content" do
|
383
|
-
it "returns truncated and escape column value" do
|
384
|
-
allow(subject).to receive(:column_value).with(resource, :title)
|
385
|
-
.and_return('"Pra<tag>nt commodo\ncursus magn')
|
386
|
-
expect(subject.format_textarea_content(resource, :title))
|
387
|
-
.to eq('"Pra<tag>nt commodo\ncursus magn')
|
388
|
-
end
|
389
|
-
|
390
|
-
it "casts value to string before truncation" do
|
391
|
-
allow(subject).to receive(:column_value).with(resource, :title)
|
392
|
-
.and_return(nil)
|
393
|
-
expect(subject.format_textarea_content(resource, :title)).to eq("")
|
394
|
-
end
|
395
|
-
end
|
396
|
-
|
397
|
-
describe "#format_string_content" do
|
398
|
-
context "when resource column value respond to #resource_title method" do
|
399
|
-
it "returns resource to title result" do
|
400
|
-
another_obj = Book.new
|
401
|
-
allow(subject).to receive(:column_value).with(resource, :id).and_return(another_obj)
|
402
|
-
allow(subject).to receive(:resource_title).with(another_obj).and_return("nineninine")
|
403
|
-
|
404
|
-
expect(subject.format_string_content(resource, :id)).to eq("nineninine")
|
405
|
-
end
|
406
|
-
end
|
407
|
-
end
|
408
|
-
|
409
|
-
describe "#format_boolean_content" do
|
410
|
-
context "when resource column value is 'true'" do
|
411
|
-
it "returns localized 'yes' value" do
|
412
|
-
allow(subject).to receive(:t).with("Yes").and_return("Jā")
|
413
|
-
allow(subject).to receive(:column_value).with(resource, :active)
|
414
|
-
.and_return(true)
|
415
|
-
|
416
|
-
expect(subject.format_boolean_content(resource, :active)).to eq("Jā")
|
417
|
-
end
|
418
|
-
end
|
419
|
-
|
420
|
-
context "when resource column value is other than 'true'" do
|
421
|
-
it "returns localized 'no' value" do
|
422
|
-
allow(subject).to receive(:t).with("No").and_return("Nē")
|
423
|
-
allow(subject).to receive(:column_value).with(resource, :active)
|
424
|
-
.and_return(false)
|
425
|
-
expect(subject.format_boolean_content(resource, :active)).to eq("Nē")
|
426
|
-
|
427
|
-
allow(subject).to receive(:column_value).with(resource, :active)
|
428
|
-
.and_return(nil)
|
429
|
-
expect(subject.format_boolean_content(resource, :active)).to eq("Nē")
|
430
|
-
end
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
|
-
describe "#format_date_content" do
|
435
|
-
it "returns localized date value" do
|
436
|
-
value = Date.parse("2012.12.29")
|
437
|
-
allow(subject).to receive(:column_value).with(resource, :birth_date)
|
438
|
-
.and_return(value)
|
439
|
-
|
440
|
-
expect(I18n).to receive(:l).with(value, format: :default)
|
441
|
-
.and_call_original
|
442
|
-
|
443
|
-
expect(subject.format_date_content(resource, :birth_date)).to eq("2012-12-29")
|
444
|
-
end
|
445
|
-
end
|
446
|
-
|
447
|
-
describe "#format_datetime_content" do
|
448
|
-
it "returns localized datetime value" do
|
449
|
-
value = DateTime.parse("2012.12.29 17:12:07")
|
450
|
-
allow(subject).to receive(:column_value).with(resource, :created_at)
|
451
|
-
.and_return(value)
|
452
|
-
|
453
|
-
allow(I18n).to receive(:l).with(value, format: "%Y-%m-%d %H:%M")
|
454
|
-
.and_return("2012-12-29 17:12:07")
|
455
|
-
|
456
|
-
expect(subject.format_datetime_content(resource, :created_at)).to eq("2012-12-29 17:12:07")
|
457
|
-
end
|
458
|
-
end
|
459
|
-
|
460
|
-
describe "#format_time_content" do
|
461
|
-
it "returns localized time value" do
|
462
|
-
value = Time.parse("2012.12.29 17:12:07")
|
463
|
-
allow(subject).to receive(:column_value).with(resource, :created_at)
|
464
|
-
.and_return(value)
|
465
|
-
|
466
|
-
allow(I18n).to receive(:l).with(value, format: "%H:%M")
|
467
|
-
.and_return("17:12")
|
468
|
-
|
469
|
-
expect(subject.format_time_content(resource, :created_at)).to eq("17:12")
|
470
|
-
end
|
471
|
-
end
|
472
|
-
|
473
|
-
describe "#association_name" do
|
474
|
-
it "normalizes given column name by removing '_id' postfix and returning new value as symbol" do
|
475
|
-
expect(subject.association_name(:author_id)).to eq(:author)
|
476
|
-
end
|
477
|
-
end
|
478
|
-
|
479
|
-
describe "#format_association_content" do
|
480
|
-
it "pass resource and association name to #format_string_content" do
|
481
|
-
resource = resource_class.new
|
482
|
-
allow(subject).to receive(:association_name).with(:author_id).and_return(:another_author)
|
483
|
-
allow(subject).to receive(:format_string_content).with(resource, :another_author).and_return("x")
|
484
|
-
|
485
|
-
expect(subject.format_association_content(resource, :author_id)).to eq("x")
|
486
|
-
end
|
487
|
-
end
|
488
|
-
|
489
|
-
describe "#cell_content_method" do
|
490
|
-
context "when custom cell content method exists" do
|
491
|
-
it "returns custom cell content method name" do
|
492
|
-
expect(subject.cell_content_method(:format_string)).to eq("format_string_content")
|
493
|
-
end
|
494
|
-
end
|
495
|
-
|
496
|
-
context "when custom cell content does not method exist" do
|
497
|
-
it "returns nil" do
|
498
|
-
expect(subject.cell_content_method(:title)).to be nil
|
499
|
-
end
|
500
|
-
end
|
501
|
-
end
|
502
|
-
|
503
|
-
describe "#cell_method" do
|
504
|
-
context "when custom cell method exists" do
|
505
|
-
it "returns custom cell method name" do
|
506
|
-
expect(inheriter_subject.cell_method(:title)).to eq("title_cell")
|
507
|
-
end
|
508
|
-
end
|
509
|
-
|
510
|
-
context "when custom cell does not method exist" do
|
511
|
-
it "returns nil" do
|
512
|
-
expect(subject.cell_method(:title)).to be nil
|
513
|
-
end
|
514
|
-
end
|
515
|
-
end
|
516
|
-
|
517
|
-
describe "#toolbox_cell" do
|
518
|
-
let(:controller){ double(ActionController::Base) }
|
519
|
-
before do
|
520
|
-
allow(subject).to receive(:controller).and_return(controller)
|
521
|
-
allow(controller).to receive(:index_path).and_return("_index_path_")
|
522
|
-
end
|
523
|
-
|
524
|
-
it "returns cell with toolbox" do
|
525
|
-
allow(subject).to receive(:toolbox)
|
526
|
-
.with(resource, index_path: "_index_path_").and_return("_toolbox_")
|
527
|
-
|
528
|
-
content = '<td class="only-icon toolbox-cell">_toolbox_</td>'
|
529
|
-
expect(subject.toolbox_cell(resource, {})).to eq(content)
|
530
|
-
end
|
531
|
-
|
532
|
-
it "merges given toolbox options and passes it to toolbox heplper" do
|
533
|
-
allow(subject.controller).to receive(:index_path).and_return("_index_path_")
|
534
|
-
expect(subject).to receive(:toolbox)
|
535
|
-
.with(resource, index_path: "_index_path_", some_url: "xx").and_return("_toolbox_")
|
536
|
-
subject.toolbox_cell(resource, {toolbox: {some_url: "xx"}})
|
537
|
-
|
538
|
-
expect(subject).to receive(:toolbox)
|
539
|
-
.with(resource, index_path: "xx").and_return("_toolbox_")
|
540
|
-
subject.toolbox_cell(resource, {toolbox: {index_path: "xx"}})
|
541
|
-
end
|
542
|
-
end
|
543
|
-
|
544
|
-
describe "#column_type" do
|
545
|
-
it "returns database column type for given column" do
|
546
|
-
expect(subject.column_type(resource_class, :active)).to eq(:boolean)
|
547
|
-
expect(subject.column_type(resource_class, :created_at)).to eq(:datetime)
|
548
|
-
end
|
549
|
-
|
550
|
-
context "when given column does not exists within database column definitions" do
|
551
|
-
it "returns :string as default value" do
|
552
|
-
expect(subject.column_type(resource_class, :random_title)).to eq(:string)
|
553
|
-
end
|
554
|
-
end
|
555
|
-
end
|
556
|
-
|
557
|
-
describe "#column_type_format_method" do
|
558
|
-
it "uses column klass and column name for type calculation" do
|
559
|
-
allow(subject).to receive(:column_klass).with(resource_class, "some.column").and_return(Chapter)
|
560
|
-
allow(subject).to receive(:column_type).with(Chapter, "some.column").and_return(:extra_type)
|
561
|
-
allow(subject).to receive(:type_format_method).with(:extra_type).and_return("extra_type_method")
|
562
|
-
expect(subject.column_type_format_method("some.column")).to eq("extra_type_method")
|
563
|
-
end
|
564
|
-
end
|
565
|
-
|
566
|
-
describe "#type_format_method" do
|
567
|
-
context "when format method for returned column type exists" do
|
568
|
-
it "returns column type format method" do
|
569
|
-
expect(subject.type_format_method(:date)).to eq(:format_date_content)
|
570
|
-
end
|
571
|
-
end
|
572
|
-
|
573
|
-
context "when format method for returned column type does not exist" do
|
574
|
-
it "returns :format_string_content" do
|
575
|
-
expect(subject.type_format_method(:big_boolean)).to eq(:format_string_content)
|
576
|
-
end
|
577
|
-
end
|
578
|
-
end
|
579
|
-
|
580
|
-
describe "#cell_format_method" do
|
581
|
-
before do
|
582
|
-
allow(subject).to receive(:association_column?).with(:title).and_return(false)
|
583
|
-
allow(subject).to receive(:column_type_format_method).with(:title).and_return(:format_crazy_shit)
|
584
|
-
end
|
585
|
-
|
586
|
-
it "returns #column_type_format_method for given column" do
|
587
|
-
expect(subject.cell_format_method(:title)).to eq(:format_crazy_shit)
|
588
|
-
end
|
589
|
-
|
590
|
-
context "when #association_column? returns true for given column" do
|
591
|
-
it "returns :format_association_content" do
|
592
|
-
allow(subject).to receive(:association_column?).with(:title).and_return(true)
|
593
|
-
expect(subject.cell_format_method(:title)).to eq(:format_association_content)
|
594
|
-
end
|
595
|
-
end
|
596
|
-
end
|
597
|
-
|
598
|
-
describe "#association_column?" do
|
599
|
-
context "when given column is association" do
|
600
|
-
it "returns true" do
|
601
|
-
expect(subject.association_column?(:author_id)).to be true
|
602
|
-
end
|
603
|
-
end
|
604
|
-
|
605
|
-
context "when given column is not association" do
|
606
|
-
it "returns false" do
|
607
|
-
expect(subject.association_column?(:title)).to be false
|
608
|
-
end
|
609
|
-
end
|
610
|
-
end
|
611
|
-
|
612
|
-
describe "#cell" do
|
613
|
-
context "when cell options :url value is blank" do
|
614
|
-
it "returns cell with #cell_contentoutput wrapped in a span" do
|
615
|
-
options = {a: "x"}
|
616
|
-
allow(subject).to receive(:cell_content)
|
617
|
-
.with(resource, :title, options).and_return("_cell_content_")
|
618
|
-
content = '<td><span>_cell_content_</span></td>'
|
619
|
-
|
620
|
-
expect(subject.cell(resource, :title, options)).to eq(content)
|
621
|
-
|
622
|
-
options[:url] = nil
|
623
|
-
expect(subject.cell(resource, :title, options)).to eq(content)
|
624
|
-
end
|
625
|
-
end
|
626
|
-
|
627
|
-
context "when cell options :url value is not blank" do
|
628
|
-
it "returns cell with #cell_content output wrapped in a link" do
|
629
|
-
allow(subject).to receive(:cell_content)
|
630
|
-
.with(resource, :title, {a: "x", url: "y"}).and_return("_cell_content_")
|
631
|
-
|
632
|
-
content = '<td><a href="y">_cell_content_</a></td>'
|
633
|
-
expect(subject.cell(resource, :title, {a: "x", url: "y"})).to eq(content)
|
634
|
-
end
|
635
|
-
end
|
636
|
-
end
|
637
|
-
end
|