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.
- 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,78 +0,0 @@
|
|
|
1
|
-
require "rails_helper"
|
|
2
|
-
|
|
3
|
-
describe Releaf::ControllerDefinition do
|
|
4
|
-
subject{ described_class.new(name: "op", controller: "admin/books") }
|
|
5
|
-
|
|
6
|
-
describe ".for" do
|
|
7
|
-
it "returns definition from applicaiton controller config for given controller name" do
|
|
8
|
-
allow(Releaf.application.config).to receive(:controllers).and_return("xxx" => "yyy")
|
|
9
|
-
expect(described_class.for("xxx")).to eq("yyy")
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
describe "#initialize" do
|
|
14
|
-
it "assigns `name` option value" do
|
|
15
|
-
expect(subject.name).to eq("op")
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "assigns `controller` option value to `controller_name`" do
|
|
19
|
-
expect(subject.controller_name).to eq("admin/books")
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
context "when `helper` option value given" do
|
|
23
|
-
it "assigns `helper` option value postfixed with `_path` to helper accessor" do
|
|
24
|
-
subject = described_class.new(controller: "admin/books", helper: "some-route")
|
|
25
|
-
expect(subject.helper).to eq("some-route_path")
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context "when no `helper` option value given" do
|
|
30
|
-
it "does not assign anything to helper accessor" do
|
|
31
|
-
subject = described_class.new(controller: "admin/books")
|
|
32
|
-
expect(subject.helper).to be nil
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context "when no `name` option value given" do
|
|
37
|
-
it "takes `controller` option value as `name` value" do
|
|
38
|
-
subject = described_class.new(controller: "admin/books")
|
|
39
|
-
expect(subject.name).to eq("admin/books")
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
context "when string passed instead of Hash" do
|
|
44
|
-
it "takes string as controller option value" do
|
|
45
|
-
subject = described_class.new("admin/authors")
|
|
46
|
-
expect(subject.controller_name).to eq("admin/authors")
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
describe "#localized_name" do
|
|
52
|
-
it "returns localized name" do
|
|
53
|
-
allow(I18n).to receive(:t).with("op", scope: "admin.controllers").and_return("poiugasd")
|
|
54
|
-
expect(subject.localized_name).to eq("poiugasd")
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
describe "#path" do
|
|
59
|
-
context "when helper exists" do
|
|
60
|
-
it "returns helper value" do
|
|
61
|
-
subject.helper = "new_admin_chapter_path"
|
|
62
|
-
expect(subject.path).to eq("/admin/chapters/new")
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
context "when helper is not set" do
|
|
67
|
-
it "returns controller index path" do
|
|
68
|
-
expect(subject.path).to eq("/admin/books")
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
describe "#group?" do
|
|
74
|
-
it "returns false" do
|
|
75
|
-
expect(subject.group?).to be false
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
require "rails_helper"
|
|
2
|
-
|
|
3
|
-
describe Releaf::ControllerGroupDefinition do
|
|
4
|
-
subject{ described_class.new(name: "xxx", items: [:a, :b]) }
|
|
5
|
-
|
|
6
|
-
before do
|
|
7
|
-
allow(Releaf::ControllerDefinition).to receive(:new).with(:a).and_return("c_a")
|
|
8
|
-
allow(Releaf::ControllerDefinition).to receive(:new).with(:b).and_return("c_b")
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
describe "#initialize" do
|
|
12
|
-
it "assigns `name` option value" do
|
|
13
|
-
expect(subject.name).to eq("xxx")
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "assigns array with initialized `Releaf::ControllerDefinition` items built from `items` option value" do
|
|
17
|
-
expect(subject.controllers).to eq(["c_a", "c_b"])
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe "#localized_name" do
|
|
22
|
-
it "returns localized name" do
|
|
23
|
-
allow(I18n).to receive(:t).with("xxx", scope: "admin.controllers").and_return("poiugasd")
|
|
24
|
-
expect(subject.localized_name).to eq("poiugasd")
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
describe "#group?" do
|
|
29
|
-
it "returns true" do
|
|
30
|
-
expect(subject.group?).to be true
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
require "rails_helper"
|
|
2
|
-
|
|
3
|
-
describe Releaf::DefaultSearchableFields do
|
|
4
|
-
# emulate klass::Translations
|
|
5
|
-
with_model :SearchableObjectTranslations, scope: :all do
|
|
6
|
-
table do |t|
|
|
7
|
-
t.string :name
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
with_model :SearchableObject, scope: :all do
|
|
12
|
-
table do |t|
|
|
13
|
-
t.string :email
|
|
14
|
-
t.string :first_name
|
|
15
|
-
t.string :forename
|
|
16
|
-
t.string :last_name
|
|
17
|
-
t.string :login
|
|
18
|
-
t.string :middle_name
|
|
19
|
-
t.string :name
|
|
20
|
-
t.string :surname
|
|
21
|
-
t.string :title
|
|
22
|
-
t.string :username
|
|
23
|
-
t.string :non_searchable
|
|
24
|
-
t.string :password
|
|
25
|
-
t.integer :size
|
|
26
|
-
t.boolean :bool
|
|
27
|
-
t.text :text
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
model do
|
|
31
|
-
# emulate globalize accessors
|
|
32
|
-
def self.translates?
|
|
33
|
-
true
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
with_model :NonSearchableObject, scope: :all do
|
|
39
|
-
table do |t|
|
|
40
|
-
t.integer :email
|
|
41
|
-
t.integer :first_name
|
|
42
|
-
t.integer :forename
|
|
43
|
-
t.integer :last_name
|
|
44
|
-
t.integer :login
|
|
45
|
-
t.integer :middle_name
|
|
46
|
-
t.integer :name
|
|
47
|
-
t.integer :surname
|
|
48
|
-
t.integer :title
|
|
49
|
-
t.integer :username
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
before(:all) do
|
|
54
|
-
# emulate globalize accessors
|
|
55
|
-
SearchableObject.const_set('Translation', SearchableObjectTranslations)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
subject { described_class.new(SearchableObject) }
|
|
59
|
-
|
|
60
|
-
describe "#possible_field_names" do
|
|
61
|
-
it "returns array of possible field names to search" do
|
|
62
|
-
expect( subject.possible_field_names ).to match_array %w[
|
|
63
|
-
email
|
|
64
|
-
first_name
|
|
65
|
-
forename
|
|
66
|
-
last_name
|
|
67
|
-
login
|
|
68
|
-
middle_name
|
|
69
|
-
name
|
|
70
|
-
surname
|
|
71
|
-
title
|
|
72
|
-
username
|
|
73
|
-
]
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
describe "#find" do
|
|
78
|
-
context "when searchable fields exist" do
|
|
79
|
-
it "returns array of searchable string columns" do
|
|
80
|
-
expect( described_class.new(SearchableObject).find ).to match_array %w[
|
|
81
|
-
email
|
|
82
|
-
first_name
|
|
83
|
-
forename
|
|
84
|
-
last_name
|
|
85
|
-
login
|
|
86
|
-
middle_name
|
|
87
|
-
name
|
|
88
|
-
surname
|
|
89
|
-
title
|
|
90
|
-
username
|
|
91
|
-
] + [translations: %w[name]]
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
context "when searchable fields doesn't exist" do
|
|
96
|
-
it "returns array of searchable string columns" do
|
|
97
|
-
expect( described_class.new(NonSearchableObject).find ).to be_blank
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
describe "#string_columns" do
|
|
103
|
-
it "returns string columsn of model" do
|
|
104
|
-
expect( subject.string_columns ).to match_array %w[
|
|
105
|
-
email
|
|
106
|
-
first_name
|
|
107
|
-
forename
|
|
108
|
-
last_name
|
|
109
|
-
login
|
|
110
|
-
middle_name
|
|
111
|
-
name
|
|
112
|
-
surname
|
|
113
|
-
title
|
|
114
|
-
username
|
|
115
|
-
non_searchable
|
|
116
|
-
password
|
|
117
|
-
]
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
describe "#has_searchable_translated_string_columns?" do
|
|
122
|
-
context "when #klass isn't translated" do
|
|
123
|
-
it "returns false" do
|
|
124
|
-
allow(SearchableObject).to receive(:translates?).and_return(false)
|
|
125
|
-
expect( subject.has_searchable_translated_string_columns? ).to eq false
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
context "when #klass is translated and has translated searchable columns" do
|
|
130
|
-
it "returns true" do
|
|
131
|
-
expect( subject.has_searchable_translated_string_columns? ).to eq true
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
context "when #klass is translated but has no translated searchable columns" do
|
|
136
|
-
it "returns false" do
|
|
137
|
-
allow( subject ).to receive(:searchable_translated_string_columns).and_return([])
|
|
138
|
-
expect( subject.has_searchable_translated_string_columns? ).to eq false
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
describe "#searchable_translated_string_columns" do
|
|
145
|
-
it "returns translated string columns of klass::Translation" do
|
|
146
|
-
expect( subject.searchable_translated_string_columns ).to match_array %w[name]
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
it "caches result" do
|
|
150
|
-
searchable_fields = double(described_class)
|
|
151
|
-
expect( searchable_fields ).to receive(:find).once.and_return []
|
|
152
|
-
|
|
153
|
-
subject # init subject
|
|
154
|
-
|
|
155
|
-
allow( described_class ).to receive(:new).with(SearchableObject::Translation).and_return(searchable_fields)
|
|
156
|
-
|
|
157
|
-
subject.searchable_translated_string_columns
|
|
158
|
-
subject.searchable_translated_string_columns
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
end
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
require "rails_helper"
|
|
2
|
-
|
|
3
|
-
describe Releaf::InstanceCache, type: :class do
|
|
4
|
-
class InstanceCacheIncluder
|
|
5
|
-
include Releaf::InstanceCache
|
|
6
|
-
cache_instance_methods :some_value, :another_value
|
|
7
|
-
cache_instance_method :one_more_another_value
|
|
8
|
-
|
|
9
|
-
def calculated_value
|
|
10
|
-
instance_cache(:calculated_value) do
|
|
11
|
-
some_value
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def some_value
|
|
16
|
-
1 + 2
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def another_value
|
|
20
|
-
"xx"
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def one_more_another_value
|
|
24
|
-
"yy"
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
subject{ InstanceCacheIncluder.new }
|
|
29
|
-
|
|
30
|
-
it "keeps previously defined `method_added` method" do
|
|
31
|
-
class InstanceCacheIncluder2
|
|
32
|
-
cattr_accessor :test_value
|
|
33
|
-
|
|
34
|
-
def self.method_added(method_name)
|
|
35
|
-
self.test_value = method_name if method_name == :some_value
|
|
36
|
-
end
|
|
37
|
-
include Releaf::InstanceCache
|
|
38
|
-
cache_instance_method :some_value
|
|
39
|
-
|
|
40
|
-
def some_value
|
|
41
|
-
:xx
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
subject = InstanceCacheIncluder2.new
|
|
46
|
-
expect(InstanceCacheIncluder2.test_value).to eq(:some_value)
|
|
47
|
-
allow(subject).to receive(:instance_cache_original_some_value).and_return(:yyy).once
|
|
48
|
-
expect(subject.some_value).to eq(:yyy)
|
|
49
|
-
subject.some_value
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
describe ".instance_cache_original_method_name" do
|
|
53
|
-
it "returns name of uncached original method name" do
|
|
54
|
-
expect(subject.class.instance_cache_original_method_name(:some_method)).to eq("instance_cache_original_some_method")
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
describe "#instance_cache" do
|
|
59
|
-
it "stores block value to instance cache store" do
|
|
60
|
-
expect{ subject.calculated_value }.to change{ subject.instance_cache_store[:calculated_value] }.to(3)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it "returns returns value when caching happen" do
|
|
64
|
-
expect(subject.calculated_value).to eq(3)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
it "returns cached value when called second time" do
|
|
68
|
-
subject.calculated_value
|
|
69
|
-
expect(subject.calculated_value).to eq(3)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "does not evaluate block twice when called second time" do
|
|
73
|
-
expect(subject).to receive(:some_value).and_call_original.once
|
|
74
|
-
subject.calculated_value
|
|
75
|
-
subject.calculated_value
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
describe "#reset_instance_cache" do
|
|
80
|
-
it "assigns empty hash to instance hash store" do
|
|
81
|
-
subject.instance_cache_store[:x] = 1
|
|
82
|
-
expect{ subject.reset_instance_cache }.to change{ subject.instance_cache_store }.from(x: 1).to({})
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
describe ".cache_instance_methods" do
|
|
87
|
-
it "adds cache wrapper for all given methods" do
|
|
88
|
-
expect(subject.class.cached_instance_methods).to eq([:some_value, :another_value, :one_more_another_value])
|
|
89
|
-
|
|
90
|
-
allow(subject).to receive(:instance_cache_original_another_value).and_return("xxx").once
|
|
91
|
-
expect(subject).to receive(:instance_cache) do|x, &block|
|
|
92
|
-
expect(block.call).to eq("xxx")
|
|
93
|
-
end.and_return("yyy")
|
|
94
|
-
|
|
95
|
-
expect(subject.another_value).to eq("yyy")
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
require "rails_helper"
|
|
2
|
-
|
|
3
|
-
describe Releaf::ResourceBase do
|
|
4
|
-
subject{ described_class.new(Book) }
|
|
5
|
-
|
|
6
|
-
describe "#initialize" do
|
|
7
|
-
it "assigns given class to resource class accessor" do
|
|
8
|
-
expect(subject.resource_class).to eq(Book)
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe "#excluded_attributes" do
|
|
13
|
-
it "returns array with id, created_at and updated_as" do
|
|
14
|
-
expect(subject.excluded_attributes).to eq(["id", "created_at", "updated_at"])
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
describe "#localized_attributes?" do
|
|
19
|
-
context "when resource class has globalize support" do
|
|
20
|
-
it "returns true" do
|
|
21
|
-
expect(subject.localized_attributes?).to be true
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
context "when resource class does not have globalize support" do
|
|
26
|
-
it "returns false" do
|
|
27
|
-
allow(subject.resource_class).to receive(:translates?).and_return(false)
|
|
28
|
-
expect(subject.localized_attributes?).to be false
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
describe "#localized_attributes" do
|
|
34
|
-
before do
|
|
35
|
-
allow(subject.resource_class).to receive(:translated_attribute_names).and_return([:title, :summary])
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "caches returned result" do
|
|
39
|
-
expect(subject).to receive(:localized_attributes?).and_return(true).once
|
|
40
|
-
subject.localized_attributes
|
|
41
|
-
subject.localized_attributes
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context "when resource has localized attributes" do
|
|
45
|
-
it "returns array of all localized attributes params" do
|
|
46
|
-
allow(subject).to receive(:localized_attributes?).and_return(true)
|
|
47
|
-
expect(subject.localized_attributes).to eq(["title", "summary"])
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
context "when resource has no localized attributes" do
|
|
52
|
-
it "returns empty array" do
|
|
53
|
-
allow(subject).to receive(:localized_attributes?).and_return(false)
|
|
54
|
-
expect(subject.localized_attributes).to eq([])
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
describe "#associations_attributes" do
|
|
60
|
-
it "returns array with associations attributes within hashes" do
|
|
61
|
-
association_1 = subject.resource_class.reflections["chapters"]
|
|
62
|
-
association_2 = subject.resource_class.reflections["sequels"]
|
|
63
|
-
|
|
64
|
-
allow(subject).to receive(:associations).and_return([association_1, association_2])
|
|
65
|
-
allow(subject).to receive(:association_attributes).with(association_1).and_return(["a", "b"])
|
|
66
|
-
allow(subject).to receive(:association_attributes).with(association_2).and_return(["c", "d"])
|
|
67
|
-
|
|
68
|
-
expect(subject.associations_attributes).to eq([{chapters: ["a", "b"]}, {sequels: ["c", "d"]}])
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
describe "#association_attributes" do
|
|
73
|
-
it "returns association params without association excluded attributes" do
|
|
74
|
-
association = subject.resource_class.reflections["chapters"]
|
|
75
|
-
allow(described_class).to receive(:new).with(association.klass).and_call_original
|
|
76
|
-
allow_any_instance_of(described_class).to receive(:values).and_return(["a", "b", "c"])
|
|
77
|
-
allow(subject).to receive(:association_excluded_attributes).and_return(["b"])
|
|
78
|
-
expect(subject.association_attributes(association)).to eq(["a", "c"])
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
describe "#association_excluded_attributes" do
|
|
83
|
-
it "returns `foreign_key` and polymorphic association type key (if exists) casted to strings" do
|
|
84
|
-
association = subject.resource_class.reflections["chapters"]
|
|
85
|
-
allow(association).to receive(:foreign_key).and_return(:b)
|
|
86
|
-
expect(subject.association_excluded_attributes(association)).to eq(["b"])
|
|
87
|
-
|
|
88
|
-
allow(association).to receive(:type).and_return("x")
|
|
89
|
-
expect(subject.association_excluded_attributes(association)).to eq(["b", "x"])
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
describe "#values" do
|
|
94
|
-
before do
|
|
95
|
-
allow(subject).to receive(:associations_attributes).and_return(["x", "y"])
|
|
96
|
-
allow(subject).to receive(:base_attributes).and_return(["a", "b"])
|
|
97
|
-
allow(subject).to receive(:localized_attributes).and_return(["c", "d"])
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it "returns resource base and localized attributes array alongside associations params" do
|
|
101
|
-
expect(subject.values).to eq(["a", "b", "c", "d", "x", "y"])
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
it "excludes all excludable base and localized attributes from returned array" do
|
|
105
|
-
allow(subject).to receive(:excluded_attributes).and_return(["a", "d", "x"])
|
|
106
|
-
expect(subject.values).to eq(["b", "c", "x", "y"])
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
context "when `include_associations` is false" do
|
|
110
|
-
it "does not include association params" do
|
|
111
|
-
expect(subject.values(include_associations: false)).to eq(["a", "b", "c", "d"])
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
describe "#base_attributes" do
|
|
117
|
-
it "returns array of resource columns" do
|
|
118
|
-
allow(subject.resource_class).to receive(:column_names).and_return(["a", "b", "c"])
|
|
119
|
-
expect(subject.base_attributes).to eq(["a", "b", "c"])
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
describe "#associations" do
|
|
124
|
-
it "returns array with includable associations" do
|
|
125
|
-
reflections = subject.resource_class.reflections
|
|
126
|
-
allow(subject).to receive(:includable_association?).with(reflections["releaf_richtext_attachments"]).and_return(false)
|
|
127
|
-
allow(subject).to receive(:includable_association?).with(reflections["chapters"]).and_return(true)
|
|
128
|
-
allow(subject).to receive(:includable_association?).with(reflections["book_sequels"]).and_return(false)
|
|
129
|
-
allow(subject).to receive(:includable_association?).with(reflections["sequels"]).and_return(true)
|
|
130
|
-
allow(subject).to receive(:includable_association?).with(reflections["author"]).and_return(false)
|
|
131
|
-
allow(subject).to receive(:includable_association?).with(reflections["translations"]).and_return(false)
|
|
132
|
-
|
|
133
|
-
expect(subject.associations).to eq([reflections["chapters"], reflections["sequels"]])
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
describe "#includable_association?" do
|
|
138
|
-
let(:association){ subject.resource_class.reflections["chapters"] }
|
|
139
|
-
|
|
140
|
-
context "when given association type is includable, association is not excluded, not `ThroughReflection` and has nested_attributes for it" do
|
|
141
|
-
it "returns true" do
|
|
142
|
-
expect(subject.includable_association?(association)).to be true
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
context "when given association is not :has_many" do
|
|
147
|
-
it "returns false" do
|
|
148
|
-
allow(subject).to receive(:includable_association_types).and_return([:a, :b])
|
|
149
|
-
expect(subject.includable_association?(association)).to be false
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
context "when given association is `ThroughReflection`" do
|
|
154
|
-
it "returns false" do
|
|
155
|
-
allow(association).to receive(:class).and_return(ActiveRecord::Reflection::ThroughReflection)
|
|
156
|
-
expect(subject.includable_association?(association)).to be false
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
context "when given association has no nested_attributes for it" do
|
|
161
|
-
it "returns false" do
|
|
162
|
-
allow(subject.resource_class).to receive(:nested_attributes_options).and_return({})
|
|
163
|
-
expect(subject.includable_association?(association)).to be false
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
context "when given association is within excluded associations" do
|
|
168
|
-
it "returns false" do
|
|
169
|
-
allow(subject).to receive(:excluded_associations).and_return([:chapters])
|
|
170
|
-
expect(subject.includable_association?(association)).to be false
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
describe "#includable_association_types" do
|
|
176
|
-
it "returns array with `:has_many` and `:has_one` as includable association types" do
|
|
177
|
-
expect(subject.includable_association_types).to eq([:has_many, :has_one])
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
describe "#excluded_associations" do
|
|
182
|
-
it "returns array with `translations`" do
|
|
183
|
-
expect(subject.excluded_associations).to eq([:translations])
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
describe ".title" do
|
|
188
|
-
let(:resource){ Releaf::Permissions::User.new(name: "a", surname: "b") }
|
|
189
|
-
it "tries all `title_methods` methods and returns first existing method result" do
|
|
190
|
-
allow(described_class).to receive(:title_methods).and_return([:to_s, :id, :releaf_title])
|
|
191
|
-
allow(resource).to receive(:to_s).and_return("x")
|
|
192
|
-
allow(resource).to receive(:id).and_return("zz")
|
|
193
|
-
allow(resource).to receive(:releaf_title).and_return("yy")
|
|
194
|
-
|
|
195
|
-
allow(resource).to receive(:respond_to?).with(:to_s).and_return(false)
|
|
196
|
-
allow(resource).to receive(:respond_to?).with(:id).and_return(false)
|
|
197
|
-
allow(resource).to receive(:respond_to?).with(:releaf_title).and_return(true)
|
|
198
|
-
expect(described_class.title(resource)).to eq("yy")
|
|
199
|
-
|
|
200
|
-
allow(resource).to receive(:respond_to?).with(:to_s).and_return(false)
|
|
201
|
-
allow(resource).to receive(:respond_to?).with(:id).and_return(true)
|
|
202
|
-
expect(resource).to_not receive(:respond_to?).with(:releaf_title)
|
|
203
|
-
expect(described_class.title(resource)).to eq("zz")
|
|
204
|
-
end
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
describe ".title_methods" do
|
|
208
|
-
it "returns array of methods for trying cast resource to text" do
|
|
209
|
-
expect(described_class.title_methods).to eq([:releaf_title, :name, :title, :to_s])
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
end
|