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,61 +0,0 @@
|
|
|
1
|
-
require "rails_helper"
|
|
2
|
-
|
|
3
|
-
describe Releaf::Responders, type: :controller do
|
|
4
|
-
subject{ Releaf::ActionController.new }
|
|
5
|
-
|
|
6
|
-
describe "#respond_with" do
|
|
7
|
-
before do
|
|
8
|
-
allow(subject).to receive(:active_responder).and_return(Releaf::Responders::AfterSaveResponder)
|
|
9
|
-
allow(subject).to receive(:request).and_return(request)
|
|
10
|
-
allow(subject).to receive(:content_type).and_return(:html)
|
|
11
|
-
allow(subject).to receive(:action_name).and_return(:save)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
context "when no responder defined within options" do
|
|
15
|
-
it "adds active responder to `responder` options" do
|
|
16
|
-
expect(Releaf::Responders::AfterSaveResponder).to receive(:call)
|
|
17
|
-
subject.respond_with(nil)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context "when responder is defined within options" do
|
|
22
|
-
it "adds active responder to `responder` options" do
|
|
23
|
-
expect(Releaf::Responders::AfterSaveResponder).to_not receive(:call)
|
|
24
|
-
expect(Releaf::Responders::PageNotFoundResponder).to receive(:call)
|
|
25
|
-
subject.respond_with(nil, responder: Releaf::Responders::PageNotFoundResponder)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
describe "#action_responders" do
|
|
31
|
-
it "returns hash with action to responders matching" do
|
|
32
|
-
hash = {
|
|
33
|
-
create: Releaf::Responders::AfterSaveResponder,
|
|
34
|
-
update: Releaf::Responders::AfterSaveResponder,
|
|
35
|
-
confirm_destroy: Releaf::Responders::ConfirmDestroyResponder,
|
|
36
|
-
destroy: Releaf::Responders::DestroyResponder,
|
|
37
|
-
access_denied: Releaf::Responders::AccessDeniedResponder,
|
|
38
|
-
feature_disabled: Releaf::Responders::FeatureDisabledResponder,
|
|
39
|
-
page_not_found: Releaf::Responders::PageNotFoundResponder,
|
|
40
|
-
}
|
|
41
|
-
expect(subject.action_responders).to eq(hash)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
describe "#action_responder" do
|
|
46
|
-
it "returns matching responder for given action" do
|
|
47
|
-
allow(subject).to receive(:action_responders).and_return(a: "x")
|
|
48
|
-
expect(subject.action_responder(:a)).to eq("x")
|
|
49
|
-
allow(subject).to receive(:action_responders).and_return(b: "x")
|
|
50
|
-
expect(subject.action_responder(:a)).to be nil
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
describe "#active_responder" do
|
|
55
|
-
it "returns currect action matching responder" do
|
|
56
|
-
allow(subject).to receive(:action_name).and_return(:save)
|
|
57
|
-
allow(subject).to receive(:action_responder).with(:save).and_return("x")
|
|
58
|
-
expect(subject.active_responder).to eq("x")
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
require "rails_helper"
|
|
2
|
-
|
|
3
|
-
describe Releaf::Root::DefaultControllerResolver do
|
|
4
|
-
let(:controller) { Releaf::RootController.new }
|
|
5
|
-
#let(:request) { instance_double(ActionDispatch::Request) }
|
|
6
|
-
subject { described_class.new(current_controller: controller) }
|
|
7
|
-
|
|
8
|
-
#before do
|
|
9
|
-
#allow( controller ).to receive(:request).and_return(request)
|
|
10
|
-
#end
|
|
11
|
-
|
|
12
|
-
it_behaves_like "an Releaf::Service includer"
|
|
13
|
-
|
|
14
|
-
describe "#call" do
|
|
15
|
-
it "returns first available controller definition path" do
|
|
16
|
-
controller_a_definition = Releaf::ControllerDefinition.new("a")
|
|
17
|
-
controller_b_definition = Releaf::ControllerDefinition.new("b")
|
|
18
|
-
allow(controller_a_definition).to receive(:path).and_return("aa_path")
|
|
19
|
-
allow(controller_b_definition).to receive(:path).and_return("bb_path")
|
|
20
|
-
|
|
21
|
-
allow(Releaf.application.config).to receive(:controllers).and_return(
|
|
22
|
-
"a" => controller_a_definition,
|
|
23
|
-
"b" => controller_b_definition,
|
|
24
|
-
)
|
|
25
|
-
allow(subject).to receive(:controllers).and_return(["a", "b"])
|
|
26
|
-
|
|
27
|
-
expect(subject.call).to eq("aa_path")
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
context "when no controller path is available" do
|
|
31
|
-
it "returns nil" do
|
|
32
|
-
allow(subject).to receive(:controllers).and_return([])
|
|
33
|
-
expect(subject.call).to be nil
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
describe "#controllers" do
|
|
39
|
-
it "returns available controllers from Releaf config" do
|
|
40
|
-
allow(Releaf.application.config).to receive(:available_controllers).and_return("x")
|
|
41
|
-
expect(subject.controllers).to eq("x")
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
require "rails_helper"
|
|
2
|
-
|
|
3
|
-
describe Releaf::Root do
|
|
4
|
-
describe ".configure_component" do
|
|
5
|
-
it "adds new `Releaf::Root::Configuration` configuration with default controller resolver and assigns settings manager" do
|
|
6
|
-
allow(Releaf::Root::Configuration).to receive(:new)
|
|
7
|
-
.with(default_controller_resolver: Releaf::Root::DefaultControllerResolver).and_return("_new")
|
|
8
|
-
expect(Releaf.application.config).to receive(:add_configuration).with("_new")
|
|
9
|
-
expect(Releaf.application.config).to receive(:settings_manager=).with(Releaf::Root::SettingsManager)
|
|
10
|
-
described_class.configure_component
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
require "rails_helper"
|
|
2
|
-
|
|
3
|
-
describe Releaf::Service do
|
|
4
|
-
class DummyServiceIncluder
|
|
5
|
-
include Releaf::Service
|
|
6
|
-
attribute :some, String
|
|
7
|
-
attribute :thing, String
|
|
8
|
-
|
|
9
|
-
def call; end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe ".call" do
|
|
13
|
-
it "initialize new service instance and return `#call` method value" do
|
|
14
|
-
subject = DummyServiceIncluder.new(some: "asd", thing: "asdasd")
|
|
15
|
-
allow(DummyServiceIncluder).to receive(:new).with(some: "x", thing: "y").and_return(subject)
|
|
16
|
-
allow(subject).to receive(:call).and_return("_x_")
|
|
17
|
-
expect(DummyServiceIncluder.call(some: "x", thing: "y")).to eq("_x_")
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
require "rails_helper"
|
|
2
|
-
|
|
3
|
-
describe Releaf::Settings::NormalizeValue do
|
|
4
|
-
let(:subject){ described_class.new(value: "x", input_type: :date) }
|
|
5
|
-
|
|
6
|
-
describe "#call" do
|
|
7
|
-
before do
|
|
8
|
-
allow(subject).to receive(:normalization_method).and_return("normalize_time")
|
|
9
|
-
allow(described_class).to receive(:normalize_time).and_return("a")
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
context "when normalization method exists for given input type" do
|
|
13
|
-
it "returns value normalize with normalization method" do
|
|
14
|
-
expect(subject.call).to eq("a")
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context "when normalization method does not exist for given input type" do
|
|
19
|
-
it "returns non-normalized value" do
|
|
20
|
-
allow(described_class).to receive(:respond_to?).with("normalize_time").and_return(false)
|
|
21
|
-
expect(subject.call).to eq("x")
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
describe "#normalization_method" do
|
|
27
|
-
it "returns normalization method name built from given input type" do
|
|
28
|
-
expect(subject.normalization_method).to eq("normalize_date")
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe ".normalize_decimal" do
|
|
33
|
-
it "returns normalized decimal value" do
|
|
34
|
-
expect(described_class.normalize_decimal("1,12")).to eq(1.12.to_d)
|
|
35
|
-
expect(described_class.normalize_decimal("1.298")).to eq(1.298.to_d)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
describe ".normalize_float" do
|
|
40
|
-
it "returns normalized float value" do
|
|
41
|
-
expect(described_class.normalize_float("1,12")).to eq(1.12.to_f)
|
|
42
|
-
expect(described_class.normalize_float("1.298")).to eq(1.298.to_f)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
describe ".normalize_integer" do
|
|
47
|
-
it "returns normalized integer value" do
|
|
48
|
-
expect(described_class.normalize_integer("1,12")).to eq(1)
|
|
49
|
-
expect(described_class.normalize_integer("4,298")).to eq(4)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
describe ".normalize_time" do
|
|
54
|
-
it "returns value normalized with `Time.parse`" do
|
|
55
|
-
allow(Time).to receive(:parse).with("a").and_return("b")
|
|
56
|
-
expect(described_class.normalize_time("a")).to eq("b")
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
context "when empty value given" do
|
|
60
|
-
it "returns nil" do
|
|
61
|
-
expect(described_class.normalize_time(" ")).to be nil
|
|
62
|
-
expect(described_class.normalize_time("")).to be nil
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
describe ".normalize_date" do
|
|
68
|
-
it "returns value normalized with `Date.parse`" do
|
|
69
|
-
allow(Date).to receive(:parse).with("a").and_return("b")
|
|
70
|
-
expect(described_class.normalize_date("a")).to eq("b")
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
context "when empty value given" do
|
|
74
|
-
it "returns nil" do
|
|
75
|
-
expect(described_class.normalize_date(" ")).to be nil
|
|
76
|
-
expect(described_class.normalize_date("")).to be nil
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
describe ".normalize_datetime" do
|
|
82
|
-
it "returns value normalized with `DateTime.parse`" do
|
|
83
|
-
allow(DateTime).to receive(:parse).with("a").and_return("b")
|
|
84
|
-
expect(described_class.normalize_datetime("a")).to eq("b")
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
context "when empty value given" do
|
|
88
|
-
it "returns nil" do
|
|
89
|
-
expect(described_class.normalize_datetime(" ")).to be nil
|
|
90
|
-
expect(described_class.normalize_datetime("")).to be nil
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
describe ".normalize_boolean" do
|
|
96
|
-
it "returns value compared against string value of `1`" do
|
|
97
|
-
expect(described_class.normalize_boolean("1")).to be true
|
|
98
|
-
expect(described_class.normalize_boolean("0")).to be false
|
|
99
|
-
expect(described_class.normalize_boolean("ewwqe")).to be false
|
|
100
|
-
expect(described_class.normalize_boolean("")).to be false
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
require "rails_helper"
|
|
2
|
-
|
|
3
|
-
describe Releaf::Settings::Register do
|
|
4
|
-
let(:subject){ described_class.new(settings: [{key: "a", type: "boolean"}, {key: "c", type: "text"}]) }
|
|
5
|
-
|
|
6
|
-
describe "#call" do
|
|
7
|
-
it "registers normalized settings items" do
|
|
8
|
-
allow(subject).to receive(:normalize).with(key: "a", type: "boolean").and_return("yy")
|
|
9
|
-
allow(subject).to receive(:normalize).with(key: "c", type: "text").and_return("zz")
|
|
10
|
-
expect(subject).to receive(:register).with("yy")
|
|
11
|
-
expect(subject).to receive(:register).with("zz")
|
|
12
|
-
subject.call
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe "#normalize" do
|
|
17
|
-
before do
|
|
18
|
-
allow(subject.settings_class).to receive(:supported_types).and_return([:boolean, :text])
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "normalizes type valey to symbol" do
|
|
22
|
-
expect(subject.normalize(key: "x", type: "boolean")).to eq(key: "x", type: :boolean)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
context "when no type given" do
|
|
26
|
-
it "sets `:text` as default type" do
|
|
27
|
-
expect(subject.normalize(key: "x")).to eq(key: "x", type: :text)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
context "when unsupported type given" do
|
|
32
|
-
it "raises `Releaf::Error`" do
|
|
33
|
-
allow(subject.settings_class).to receive(:supported_types).and_return([:mp3, :mp4])
|
|
34
|
-
expect{ subject.normalize(key: "x") }.to raise_error(Releaf::Error, "Unsupported settings type: text")
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
context "when dissallowed settings keys given" do
|
|
39
|
-
it "raises `Releaf::Error`" do
|
|
40
|
-
expect{ subject.normalize(key: "x", color: "red") }.to raise_error(Releaf::Error, "Dissallowed settings keys: [:color]")
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
describe "#register" do
|
|
46
|
-
before do
|
|
47
|
-
allow(subject.settings_class).to receive(:[]=)
|
|
48
|
-
allow(subject.settings_class.registry).to receive(:update)
|
|
49
|
-
allow(subject).to receive(:write_default?).with(key: "x", default: "_xx").and_return(true)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it "assigns item to settings registry" do
|
|
53
|
-
expect(subject.settings_class.registry).to receive(:update).with("x" => {key: "x", default: "_xx"})
|
|
54
|
-
subject.register(key: "x", default: "_xx")
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it "stores value to cache and db" do
|
|
58
|
-
expect(subject.settings_class).to receive(:[]=).with("x", "_xx")
|
|
59
|
-
subject.register(key: "x", default: "_xx")
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
context "when default write is not permitted" do
|
|
63
|
-
it "does not store default value to db" do
|
|
64
|
-
allow(subject).to receive(:write_default?).with(key: "x").and_return(false)
|
|
65
|
-
expect(subject).to_not receive(:[]=)
|
|
66
|
-
subject.register(key: "x", default: "_xx")
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
describe "#allowed_keys" do
|
|
72
|
-
it "returns array with `key`, `default`, `type` and `description`" do
|
|
73
|
-
expect(subject.allowed_keys).to eq([:key, :default, :type, :description])
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
describe "#write_default?" do
|
|
78
|
-
before do
|
|
79
|
-
allow(subject).to receive(:table_exists?).and_return(true)
|
|
80
|
-
allow(subject.settings_class).to receive(:find_by).with(var: "xx").and_return(nil)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
context "when database table exists and key does not exist in database" do
|
|
84
|
-
it "returns true" do
|
|
85
|
-
expect(subject.write_default?(key: "xx")).to be true
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
context "when database table exists and key does exist in database" do
|
|
90
|
-
it "returns false" do
|
|
91
|
-
allow(subject.settings_class).to receive(:find_by).with(var: "xx").and_return(Author.new)
|
|
92
|
-
expect(subject.write_default?(key: "xx")).to be false
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
context "when database table does not exists and key does not exist in database" do
|
|
97
|
-
it "returns false" do
|
|
98
|
-
allow(subject).to receive(:table_exists?).and_return(false)
|
|
99
|
-
expect(subject.write_default?(key: "xx")).to be false
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
describe "#table_exists?" do
|
|
105
|
-
before do
|
|
106
|
-
allow(subject.settings_class).to receive(:table_exists?).and_return(true)
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
context "when `ActiveRecord::NoDatabaseError` database does not exist" do
|
|
110
|
-
it "returns false" do
|
|
111
|
-
allow(subject.settings_class).to receive(:table_exists?).and_raise(ActiveRecord::NoDatabaseError, "x")
|
|
112
|
-
expect(subject.table_exists?).to be false
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
context "when table does not exist" do
|
|
117
|
-
it "returns false" do
|
|
118
|
-
allow(subject.settings_class).to receive(:table_exists?).and_return(false)
|
|
119
|
-
expect(subject.table_exists?).to be false
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
context "when table exists" do
|
|
124
|
-
it "returns true" do
|
|
125
|
-
expect(subject.table_exists?).to be true
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
describe "#settings_class" do
|
|
131
|
-
it "returns `Releaf::Settings` class" do
|
|
132
|
-
expect(subject.settings_class).to eq(Releaf::Settings)
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require "rails_helper"
|
|
2
|
-
|
|
3
|
-
describe Releaf::Root::SettingsManager do
|
|
4
|
-
let(:controller){ Releaf::RootController.new }
|
|
5
|
-
let(:cookies){ {"asd.a" => "lalal"} }
|
|
6
|
-
|
|
7
|
-
before do
|
|
8
|
-
allow(controller).to receive(:send).with(:cookies).and_return(cookies)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
describe ".read" do
|
|
12
|
-
it "returns cookies settings for given key" do
|
|
13
|
-
expect(described_class.read(controller: controller, key: "asd.a")).to eq("lalal")
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe ".write" do
|
|
18
|
-
it "writes user settings for given key and value" do
|
|
19
|
-
expect{ described_class.write(controller: controller, key: "asd.a", value: "op") }.to change{ cookies["asd.a"] }.to("op")
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
require "rails_helper"
|
|
2
|
-
|
|
3
|
-
class DummyModel
|
|
4
|
-
include ActiveModel::Validations
|
|
5
|
-
attr_accessor :name, :surname, :age
|
|
6
|
-
validates :name, presence: {error_code: :no_name}
|
|
7
|
-
validates :surname, presence: true
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
describe "Extend ActiveModel validation error with error_code attribute" do
|
|
11
|
-
let(:item) do
|
|
12
|
-
item = DummyModel.new
|
|
13
|
-
item.valid?
|
|
14
|
-
item
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "adds ActiveModel::ErrorMessage as error instead of String" do
|
|
18
|
-
expect(item.errors[:name].first.class).to eq(ActiveModel::ErrorMessage)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "does not owerwrite default error message behaviour" do
|
|
22
|
-
expect(item.errors[:name].first).to eq("can't be blank")
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
context "when validation have :error_code option" do
|
|
26
|
-
it "adds :error_code value as error_code" do
|
|
27
|
-
expect(item.errors[:name].first.error_code).to eq(:no_name)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
context "when validation message is symbol" do
|
|
32
|
-
it "adds message as error_code" do
|
|
33
|
-
expect(item.errors[:surname].first.error_code).to eq(:blank)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context "when validation message is not symbol and don't have :error_code option" do
|
|
38
|
-
it "adds :invalid as error_code" do
|
|
39
|
-
item.errors.add(:age, "no age")
|
|
40
|
-
expect(item.errors[:age].first.error_code).to eq(:invalid)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context "when error with :strict option added" do
|
|
45
|
-
it "raises ActiveModel::StrictValidationFailed error" do
|
|
46
|
-
expect { item.errors.add(:age, :invalid, strict: true) }.to raise_error(ActiveModel::StrictValidationFailed)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
context "when error with :data option is added" do
|
|
51
|
-
it "stores data" do
|
|
52
|
-
item.errors.add(:age, :invalid, data: {foo: :bar})
|
|
53
|
-
expect( item.errors[:age].first.data ).to eq(foo: :bar)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|