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,12 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::Builders::Template, type: :module do
|
4
|
-
class TemplateClassIncluder
|
5
|
-
include Releaf::Builders::Template
|
6
|
-
end
|
7
|
-
|
8
|
-
it "it assigns template argument to instance 'template' accessor on initialization" do
|
9
|
-
subject = TemplateClassIncluder.new("x")
|
10
|
-
expect(subject.template).to eq("x")
|
11
|
-
end
|
12
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::Builders::ToolboxBuilder, type: :class do
|
4
|
-
class ToolboxBuilderTestHelper < ActionView::Base
|
5
|
-
include Releaf::ButtonHelper
|
6
|
-
include Releaf::ApplicationHelper
|
7
|
-
end
|
8
|
-
|
9
|
-
subject { described_class.new(template) }
|
10
|
-
let(:template){ ToolboxBuilderTestHelper.new(ActionView::LookupContext.new(nil), {}, nil) }
|
11
|
-
|
12
|
-
it "includes Releaf::Builders::Base" do
|
13
|
-
expect(described_class.ancestors).to include(Releaf::Builders::Base)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "includes Releaf::Builders::Template" do
|
17
|
-
expect(described_class.ancestors).to include(Releaf::Builders::Template)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "includes Releaf::Builders::Resource" do
|
21
|
-
expect(described_class.ancestors).to include(Releaf::Builders::Resource)
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#output" do
|
25
|
-
it "returns safely joined items" do
|
26
|
-
allow(subject).to receive(:items).and_return([ '<', ActiveSupport::SafeBuffer.new(">")])
|
27
|
-
expect(subject.output).to eq("<li><</li><li>></li>")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#items" do
|
32
|
-
before{ allow(subject).to receive(:destroy_confirmation_link).and_return("x") }
|
33
|
-
|
34
|
-
context "when no destroy feature is available" do
|
35
|
-
it "returns array with destroy button html" do
|
36
|
-
allow(subject).to receive(:feature_available?).with(:destroy).and_return(true)
|
37
|
-
expect(subject.items).to eq(["x"])
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "when destroy feature is not available" do
|
42
|
-
it "returns empty array" do
|
43
|
-
allow(subject).to receive(:feature_available?).with(:destroy).and_return(false)
|
44
|
-
expect(subject.items).to eq([])
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "#destroy_confirmation_link" do
|
50
|
-
it "returns destroy confirmation link" do
|
51
|
-
allow(subject).to receive(:t).with("Delete").and_return("dlt")
|
52
|
-
allow(subject).to receive(:destroy_confirmation_url).and_return("www.xxx")
|
53
|
-
content = '<a class="button ajaxbox danger" title="dlt" href="www.xxx" data-modal="true">dlt</a>'
|
54
|
-
expect(subject.destroy_confirmation_link).to eq(content)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "#destroy_confirmation_url" do
|
59
|
-
it "returns resource destroy confirmation url with index_path param" do
|
60
|
-
subject.resource = Book.new(id: 99)
|
61
|
-
allow(subject.template).to receive(:url_for).with(action: :confirm_destroy, id: 99, index_path: "y").and_return("x")
|
62
|
-
allow(subject.template).to receive(:controller).and_return(Releaf::ActionController.new)
|
63
|
-
allow(subject.controller).to receive(:index_path).and_return("y")
|
64
|
-
expect(subject.destroy_confirmation_url).to eq("x")
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::Builders::Toolbox, type: :class do
|
4
|
-
class ToolboxTestTemplate < ActionView::Base
|
5
|
-
end
|
6
|
-
|
7
|
-
class UnitTestToolboxBuilder
|
8
|
-
include Releaf::Builders::Base
|
9
|
-
include Releaf::Builders::Template
|
10
|
-
include Releaf::Builders::Toolbox
|
11
|
-
end
|
12
|
-
|
13
|
-
subject { UnitTestToolboxBuilder.new(template) }
|
14
|
-
let(:template){ ToolboxTestTemplate.new(ActionView::LookupContext.new(nil), {}, nil) }
|
15
|
-
let(:resource){ Releaf::Permissions::User.new }
|
16
|
-
|
17
|
-
describe "#toolbox" do
|
18
|
-
context "when the passed object is a new record" do
|
19
|
-
it "returns empty string" do
|
20
|
-
expect(subject.toolbox(resource)).to eq("")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "when the passed object is an existing record" do
|
25
|
-
it "returns toolbox HTML with trigger and without items" do
|
26
|
-
resource.id = 212
|
27
|
-
allow(resource).to receive(:new_record?).and_return(false)
|
28
|
-
allow(subject).to receive(:t).with("Tools").and_return("tls")
|
29
|
-
allow(subject).to receive(:icon).with("ellipsis-v").and_return("<kebab_icon />".html_safe)
|
30
|
-
allow(subject).to receive(:icon).with("caret-up").and_return("<caret_icon />".html_safe)
|
31
|
-
allow(subject).to receive(:action_name).and_return("edit")
|
32
|
-
allow(subject).to receive(:url_for).with({action: :toolbox, id: 212, context: "edit", some_param: 89}).and_return("/toolbox_action")
|
33
|
-
|
34
|
-
expect(subject.toolbox(resource, some_param: 89)).to match_html(%Q[
|
35
|
-
<div class="toolbox" data-url="/toolbox_action">
|
36
|
-
<button class="button trigger only-icon" type="button" title="tls">
|
37
|
-
<kebab_icon />
|
38
|
-
</button>
|
39
|
-
<menu class="toolbox-items" type="toolbar">
|
40
|
-
<caret_icon />
|
41
|
-
<ul></ul>
|
42
|
-
</menu>
|
43
|
-
</div>
|
44
|
-
])
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,125 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::Builders::Utilities::DateFields do
|
4
|
-
describe ".jquery_date_format" do
|
5
|
-
it "returns Ruby date formaters converted to jQuery date formaters" do
|
6
|
-
expect(described_class.jquery_date_format("% %3N %L %M %-d")).to eq("% l l mm d")
|
7
|
-
|
8
|
-
allow(described_class).to receive(:ruby_date_format_regexp).and_return(Regexp.new("%3N"))
|
9
|
-
expect(described_class.jquery_date_format("% %3N %L %M %-d")).to eq("% l %L %M %-d")
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe ".ruby_date_format_regexp" do
|
14
|
-
it "returns Regexp for matching Ruby date formaters" do
|
15
|
-
expect(described_class.ruby_date_format_regexp).to be_instance_of Regexp
|
16
|
-
end
|
17
|
-
|
18
|
-
it "caches compiled regexp" do
|
19
|
-
described_class.class_variable_set(:@@jquery_date_replacement_regexp, nil)
|
20
|
-
expect(Regexp).to receive(:new).and_call_original.once
|
21
|
-
described_class.ruby_date_format_regexp
|
22
|
-
described_class.ruby_date_format_regexp
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe ".format_date_or_time_value" do
|
27
|
-
context "when given value type is :time" do
|
28
|
-
it "format normalized value to default format with `strftime`" do
|
29
|
-
value = Date.parse("15 Jan 2015")
|
30
|
-
time = Time.parse("15 Jan 2015 12:10:04")
|
31
|
-
allow(described_class).to receive(:date_or_time_default_format).with(:time).and_return("%H:%M")
|
32
|
-
allow(described_class).to receive(:normalize_date_or_time_value).with(value, :time).and_return(time)
|
33
|
-
|
34
|
-
expect(described_class.format_date_or_time_value(value, :time)).to eq("12:10")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context "when empty value given" do
|
39
|
-
it "returns given value" do
|
40
|
-
expect(described_class.format_date_or_time_value(nil, :time)).to eq(nil)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "when given value type is other than :time" do
|
45
|
-
it "format normalized value to default format with `I18n.l`" do
|
46
|
-
value = Date.parse("15 Jan 2015")
|
47
|
-
time = Time.parse("15 Jan 2015 12:10:04")
|
48
|
-
|
49
|
-
allow(described_class).to receive(:date_or_time_default_format).with(:date).and_return("_format_")
|
50
|
-
allow(described_class).to receive(:normalize_date_or_time_value).with(value, :date).and_return(time)
|
51
|
-
allow(I18n).to receive(:l).with(time, format: "_format_").and_return("x")
|
52
|
-
expect(described_class.format_date_or_time_value(value, :date)).to eq("x")
|
53
|
-
|
54
|
-
|
55
|
-
allow(described_class).to receive(:date_or_time_default_format).with(:datetime).and_return("_format_")
|
56
|
-
allow(described_class).to receive(:normalize_date_or_time_value).with(value, :datetime).and_return(time)
|
57
|
-
allow(I18n).to receive(:l).with(time, format: "_format_").and_return("y")
|
58
|
-
expect(described_class.format_date_or_time_value(value, :datetime)).to eq("y")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe ".time_format_for_jquery" do
|
64
|
-
it "returns jquery time format" do
|
65
|
-
allow(described_class).to receive(:date_or_time_default_format).with(:time).and_return("xx")
|
66
|
-
allow(described_class).to receive(:jquery_date_format).with("xx").and_return("x")
|
67
|
-
expect(described_class.time_format_for_jquery).to eq("x")
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe ".date_format_for_jquery" do
|
72
|
-
it "returns jquery time format" do
|
73
|
-
allow(described_class).to receive(:date_or_time_default_format).with(:date).and_return("yy")
|
74
|
-
allow(I18n).to receive(:t).with("default", scope: "date.formats", default: "yy").and_return("a")
|
75
|
-
allow(described_class).to receive(:jquery_date_format).with("a").and_return("l")
|
76
|
-
expect(described_class.date_format_for_jquery).to eq("l")
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe ".normalize_date_or_time_value" do
|
81
|
-
context "when :time type given" do
|
82
|
-
it "casts value to time" do
|
83
|
-
value = Date.parse("15 Jan 2015")
|
84
|
-
expect(described_class.normalize_date_or_time_value(value, :time)).to be_instance_of Time
|
85
|
-
expect(described_class.normalize_date_or_time_value(value, :time)).to eq(value.to_time)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "when :datetime type given" do
|
90
|
-
it "casts value to datetime" do
|
91
|
-
value = Time.parse("15 Jan 2015 12:10:04")
|
92
|
-
expect(described_class.normalize_date_or_time_value(value, :datetime)).to be_instance_of DateTime
|
93
|
-
expect(described_class.normalize_date_or_time_value(value, :datetime)).to eq(value.to_datetime)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context "when :time type given" do
|
98
|
-
it "casts value to date" do
|
99
|
-
value = DateTime.parse("15 Jan 2015 12:10:04")
|
100
|
-
expect(described_class.normalize_date_or_time_value(value, :date)).to be_instance_of Date
|
101
|
-
expect(described_class.normalize_date_or_time_value(value, :date)).to eq(value.to_date)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "#date_or_time_default_format" do
|
107
|
-
context "when date format requested requested" do
|
108
|
-
it "returns `%Y-%m-%d`" do
|
109
|
-
expect(described_class.date_or_time_default_format(:date)).to eq("%Y-%m-%d")
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context "when datetime format requested requested" do
|
114
|
-
it "returns `%Y-%m-%d %H:%M`" do
|
115
|
-
expect(described_class.date_or_time_default_format(:datetime)).to eq("%Y-%m-%d %H:%M")
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context "when time format requested requested" do
|
120
|
-
it "returns `%H:%M`" do
|
121
|
-
expect(described_class.date_or_time_default_format(:time)).to eq("%H:%M")
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
@@ -1,318 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::Builders::Utilities::ResolveAttributeFieldMethodName do
|
4
|
-
let(:object){ Book.new }
|
5
|
-
subject{ described_class.new(object: object, attribute_name: "title") }
|
6
|
-
|
7
|
-
describe "#call" do
|
8
|
-
before do
|
9
|
-
allow(subject).to receive(:field_type).and_return("color_picker")
|
10
|
-
end
|
11
|
-
|
12
|
-
it "returns resolved field name method" do
|
13
|
-
expect(subject.call).to eq("releaf_color_picker_field")
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
context "when localized attribute" do
|
18
|
-
it "adds i18n part to returned field name method" do
|
19
|
-
allow(subject).to receive(:localized_attribute?).and_return(true)
|
20
|
-
expect(subject.call).to eq("releaf_color_picker_i18n_field")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "#field_type" do
|
26
|
-
before do
|
27
|
-
allow(subject).to receive(:column_type).and_return("doubleinteger")
|
28
|
-
end
|
29
|
-
|
30
|
-
it "returns first positive resolver name" do
|
31
|
-
allow(subject).to receive(:column_field_type_resolvers).and_return([:text, :item, :richtext])
|
32
|
-
expect(subject).to receive(:text?).and_return(false)
|
33
|
-
expect(subject).to receive(:item?).and_return(true)
|
34
|
-
expect(subject).to_not receive(:richtext?)
|
35
|
-
|
36
|
-
expect(subject.field_type).to eq(:item)
|
37
|
-
end
|
38
|
-
|
39
|
-
context "when no resolvers exists" do
|
40
|
-
it "returns column type" do
|
41
|
-
allow(subject).to receive(:column_field_type_resolvers).and_return([])
|
42
|
-
expect(subject.field_type).to eq("doubleinteger")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#column_type" do
|
48
|
-
let(:column){ Book.columns_hash["id"] }
|
49
|
-
|
50
|
-
before do
|
51
|
-
subject.attribute_name = "birth_date"
|
52
|
-
allow(subject).to receive(:columns_class).and_return(Author)
|
53
|
-
allow(column).to receive(:type).and_return("doubleinteger")
|
54
|
-
end
|
55
|
-
|
56
|
-
it "returns column type from columns class" do
|
57
|
-
allow(Author.columns_hash).to receive(:[]).with("birth_date").and_return(column)
|
58
|
-
expect(subject.column_type).to eq("doubleinteger")
|
59
|
-
end
|
60
|
-
|
61
|
-
context "when attribute does not exists within columns hash" do
|
62
|
-
it "returns `string` as default type" do
|
63
|
-
allow(Author.columns_hash).to receive(:[]).with("birth_date").and_return(nil)
|
64
|
-
expect(subject.column_type).to eq(:string)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
it "caches resolved column type" do
|
69
|
-
expect(Author.columns_hash).to receive(:[]).with("birth_date").and_return(column).twice
|
70
|
-
subject.column_type
|
71
|
-
subject.column_type
|
72
|
-
subject.column_type
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "#columns_class" do
|
77
|
-
context "when non localized attribute" do
|
78
|
-
it "returns object class" do
|
79
|
-
allow(subject).to receive(:localized_attribute?).and_return(false)
|
80
|
-
expect(subject.columns_class).to eq(Book)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "when localized attribute" do
|
85
|
-
it "returns object translations class" do
|
86
|
-
allow(subject).to receive(:localized_attribute?).and_return(true)
|
87
|
-
expect(subject.columns_class).to eq(Book::Translation)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe "#column_field_type_resolvers" do
|
93
|
-
it "returns column type resolvers" do
|
94
|
-
allow(subject).to receive(:column_type).and_return(:text)
|
95
|
-
expect(subject.column_field_type_resolvers).to eq([:link, :richtext, :textarea])
|
96
|
-
|
97
|
-
allow(subject).to receive(:column_type).and_return(:float)
|
98
|
-
expect(subject.column_field_type_resolvers).to eq([])
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe "#localized_attribute?" do
|
103
|
-
context "when object translates" do
|
104
|
-
context "when given attribute translatable" do
|
105
|
-
it "returns true" do
|
106
|
-
subject.attribute_name = :description
|
107
|
-
expect(subject.localized_attribute?).to be true
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "when attribute does not translatable" do
|
112
|
-
it "returns false" do
|
113
|
-
subject.attribute_name = :title
|
114
|
-
expect(subject.localized_attribute?).to be false
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context "when object does not translates" do
|
120
|
-
it "returns false" do
|
121
|
-
subject.object = Releaf::Permissions::User.new
|
122
|
-
subject.attribute_name = :password
|
123
|
-
expect(subject.localized_attribute?).to be false
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "#file?" do
|
129
|
-
context "when attribute name ends with `_uid` and object respond to matching file method" do
|
130
|
-
it "returns true" do
|
131
|
-
subject.attribute_name = "cover_image_uid"
|
132
|
-
expect(subject.file?).to be true
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context "when attribute name hasn't *_uid and object respond to matching file method" do
|
137
|
-
it "returns false" do
|
138
|
-
subject.attribute_name = "genre"
|
139
|
-
expect(subject.file?).to be false
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
context "when attribute name ends with `_uid` and object does not respond to matching file method" do
|
144
|
-
it "returns false" do
|
145
|
-
subject.attribute_name = "cover_asdasdd_uid"
|
146
|
-
expect(subject.file?).to be false
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe "#image?" do
|
152
|
-
context "when attribute name matches image regexp and attribute is file" do
|
153
|
-
it "returns true" do
|
154
|
-
allow(subject).to receive(:file?).and_return(true)
|
155
|
-
%w(thumbnail image photo picture avatar logo banner icon).each do|prefix|
|
156
|
-
subject.attribute_name = "#{prefix}_uid"
|
157
|
-
expect(subject.image?).to be true
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
context "when attribute name matches image regexp and attribute is not file" do
|
163
|
-
it "returns false" do
|
164
|
-
allow(subject).to receive(:file?).and_return(false)
|
165
|
-
%w(thumbnail image photo picture avatar logo banner icon).each do|prefix|
|
166
|
-
subject.attribute_name = "#{prefix}_uid"
|
167
|
-
expect(subject.image?).to be false
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
context "when attribute name does not match image regexp and attribute is file" do
|
173
|
-
it "returns false" do
|
174
|
-
allow(subject).to receive(:file?).and_return(true)
|
175
|
-
%w(thumcbnail idsfmage pdhoto pictdure avdatar lodgo bdanner idcon).each do|prefix|
|
176
|
-
subject.attribute_name = "#{prefix}_uid"
|
177
|
-
expect(subject.image?).to be false
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
describe "#password?" do
|
184
|
-
context "when attribute matches password regexp" do
|
185
|
-
it "returns true" do
|
186
|
-
%w(some_password password_test password pin).each do|attribute_name|
|
187
|
-
subject.attribute_name = attribute_name
|
188
|
-
expect(subject.password?).to be true
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
context "when attribute does not match password regexp" do
|
194
|
-
it "returns false" do
|
195
|
-
%w(some_pasword pasword not_pin pins).each do|attribute_name|
|
196
|
-
subject.attribute_name = attribute_name
|
197
|
-
expect(subject.password?).to be false
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
describe "#email?" do
|
204
|
-
context "when attribute matches email regexp" do
|
205
|
-
it "returns true" do
|
206
|
-
%w(email some_email).each do|attribute_name|
|
207
|
-
subject.attribute_name = attribute_name
|
208
|
-
expect(subject.email?).to be true
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
context "when attribute does not match email regexp" do
|
214
|
-
it "returns false" do
|
215
|
-
%w(email_some mail).each do|attribute_name|
|
216
|
-
subject.attribute_name = attribute_name
|
217
|
-
expect(subject.email?).to be false
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
describe "#link?" do
|
224
|
-
context "when attribute matches link regexp" do
|
225
|
-
it "returns true" do
|
226
|
-
%w(some_url some_link link url).each do|attribute_name|
|
227
|
-
subject.attribute_name = attribute_name
|
228
|
-
expect(subject.link?).to be true
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
context "when attribute does not match link regexp" do
|
234
|
-
it "returns false" do
|
235
|
-
%w(urla linka).each do|attribute_name|
|
236
|
-
subject.attribute_name = attribute_name
|
237
|
-
expect(subject.link?).to be false
|
238
|
-
end
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
describe "#richtext?" do
|
244
|
-
context "when attribute matches richtext regexp" do
|
245
|
-
it "returns true" do
|
246
|
-
%w(some_html html).each do|attribute_name|
|
247
|
-
subject.attribute_name = attribute_name
|
248
|
-
expect(subject.richtext?).to be true
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
context "when attribute does not match richtext regexp" do
|
254
|
-
it "returns false" do
|
255
|
-
%w(htmla ad_htmla).each do|attribute_name|
|
256
|
-
subject.attribute_name = attribute_name
|
257
|
-
expect(subject.richtext?).to be false
|
258
|
-
end
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
describe "#textarea?" do
|
264
|
-
context "when column type is `text`" do
|
265
|
-
it "returns true" do
|
266
|
-
allow(subject).to receive(:column_type).and_return(:text)
|
267
|
-
expect(subject.textarea?).to be true
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
context "when column type is not `text`" do
|
272
|
-
it "returns false" do
|
273
|
-
allow(subject).to receive(:column_type).and_return(:asdasd)
|
274
|
-
expect(subject.textarea?).to be false
|
275
|
-
end
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
describe "#text?" do
|
280
|
-
context "when column type is `string`" do
|
281
|
-
it "returns true" do
|
282
|
-
allow(subject).to receive(:column_type).and_return(:string)
|
283
|
-
expect(subject.text?).to be true
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
context "when column type is not `string`" do
|
288
|
-
it "returns false" do
|
289
|
-
allow(subject).to receive(:column_type).and_return(:asdasd)
|
290
|
-
expect(subject.text?).to be false
|
291
|
-
end
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
describe "#item?" do
|
296
|
-
context "when attribute name ends with `_id` and object has matching association" do
|
297
|
-
it "returns true" do
|
298
|
-
subject.attribute_name = "author_id"
|
299
|
-
expect(subject.item?).to be true
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
context "when attribute name ends with `_id` and object hasn't matching association" do
|
304
|
-
it "returns false" do
|
305
|
-
subject.attribute_name = "author_id"
|
306
|
-
allow(Book).to receive(:reflect_on_association).with(:author).and_return(nil)
|
307
|
-
expect(subject.item?).to be false
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
context "when attribute does not end with `_id`" do
|
312
|
-
it "returns false" do
|
313
|
-
subject.attribute_name = "cover_asdasdd_uid"
|
314
|
-
expect(subject.item?).to be false
|
315
|
-
end
|
316
|
-
end
|
317
|
-
end
|
318
|
-
end
|