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,18 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::Builders::Collection, type: :module do
|
4
|
-
class CollectionIncluder
|
5
|
-
include Releaf::Builders::Base
|
6
|
-
include Releaf::Builders::Template
|
7
|
-
include Releaf::Builders::Collection
|
8
|
-
end
|
9
|
-
class CollectionTestHelper < ActionView::Base
|
10
|
-
end
|
11
|
-
|
12
|
-
it "it assigns template collection instance variable to instance 'collection' accessor on initialization" do
|
13
|
-
template = CollectionTestHelper.new(ActionView::LookupContext.new(nil), {}, nil)
|
14
|
-
template.instance_variable_set("@collection", "x")
|
15
|
-
subject = CollectionIncluder.new(template)
|
16
|
-
expect(subject.collection).to eq("x")
|
17
|
-
end
|
18
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::Builders::ConfirmDestroyDialogBuilder, type: :class do
|
4
|
-
class ConfirmDestroyDialogTestHelper < ActionView::Base
|
5
|
-
include FontAwesome::Rails::IconHelper
|
6
|
-
include Releaf::ButtonHelper
|
7
|
-
include Releaf::ApplicationHelper
|
8
|
-
|
9
|
-
def protect_against_forgery?
|
10
|
-
true
|
11
|
-
end
|
12
|
-
|
13
|
-
def form_authenticity_token
|
14
|
-
"xxx"
|
15
|
-
end
|
16
|
-
|
17
|
-
def request_forgery_protection_token
|
18
|
-
"yyy"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:template){ ConfirmDestroyDialogTestHelper.new(ActionView::LookupContext.new(nil), {}, nil) }
|
23
|
-
let(:object){ Book.new(id: 99, title: "book title") }
|
24
|
-
let(:subject){ described_class.new(template) }
|
25
|
-
|
26
|
-
before do
|
27
|
-
subject.resource = object
|
28
|
-
allow(subject.template).to receive(:controller).and_return(Releaf::ActionController.new)
|
29
|
-
allow(subject.controller).to receive(:index_path).and_return("y")
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#question_content" do
|
33
|
-
it "localized destroy question" do
|
34
|
-
allow(subject).to receive(:t).with("Do you want to delete the following object?").and_return("xx")
|
35
|
-
expect(subject.question_content).to eq("xx")
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "#description_content" do
|
40
|
-
it "returns `resource_title` value" do
|
41
|
-
allow(subject).to receive(:resource_title).with(object).and_return("xx")
|
42
|
-
expect(subject.description_content).to eq("xx")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#section_body" do
|
47
|
-
it "returns destroy description content" do
|
48
|
-
content = '<div class="body"><i class="fa fa-trash-o"></i><div class="question">Do you want to delete the following object?</div><div class="description">book title</div></div>'
|
49
|
-
expect(subject.section_body).to eq(content)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#confirm_method" do
|
54
|
-
it "returns :delete" do
|
55
|
-
expect(subject.confirm_method).to eq(:delete)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "#icon_name" do
|
60
|
-
it "returns trash icon" do
|
61
|
-
expect(subject.icon_name).to eq("trash-o")
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "#confirm_url" do
|
66
|
-
it "returns resource destroy url" do
|
67
|
-
allow(subject.template).to receive(:url_for).with(action: 'destroy', id: 99, index_path: "y").and_return("x")
|
68
|
-
expect(subject.confirm_url).to eq("x")
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::Builders::ConfirmDialogBuilder, type: :class do
|
4
|
-
class ConfirmDestroyDialogTestHelper < ActionView::Base
|
5
|
-
include FontAwesome::Rails::IconHelper
|
6
|
-
include Releaf::ButtonHelper
|
7
|
-
include Releaf::ApplicationHelper
|
8
|
-
|
9
|
-
def protect_against_forgery?
|
10
|
-
true
|
11
|
-
end
|
12
|
-
|
13
|
-
def form_authenticity_token
|
14
|
-
"xxx"
|
15
|
-
end
|
16
|
-
|
17
|
-
def request_forgery_protection_token
|
18
|
-
"yyy"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class ConfirmDialogBuilderInheriter < Releaf::Builders::ConfirmDialogBuilder
|
23
|
-
def confirm_url; end
|
24
|
-
def icon_name; end
|
25
|
-
def question_content; end
|
26
|
-
def description_content; end
|
27
|
-
def confirm_method; end
|
28
|
-
end
|
29
|
-
|
30
|
-
let(:template){ ConfirmDestroyDialogTestHelper.new(ActionView::LookupContext.new(nil), {}, nil) }
|
31
|
-
let(:object){ Book.new(id: 99, title: "book title") }
|
32
|
-
let(:subject){ ConfirmDialogBuilderInheriter.new(template) }
|
33
|
-
|
34
|
-
before do
|
35
|
-
subject.resource = object
|
36
|
-
allow(subject.template).to receive(:controller).and_return(Releaf::ActionController.new)
|
37
|
-
allow(subject.controller).to receive(:index_path).and_return("y")
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "#section_body" do
|
41
|
-
it "returns destroy description content" do
|
42
|
-
allow(subject).to receive(:section_body_blocks).and_return(["a", "b"])
|
43
|
-
content = '<div class="body">ab</div>'
|
44
|
-
expect(subject.section_body).to eq(content)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "#section_body_blocks" do
|
49
|
-
it "returns section body blocks" do
|
50
|
-
allow(subject).to receive(:icon_name).and_return("circle")
|
51
|
-
allow(subject).to receive(:question_content).and_return("question")
|
52
|
-
allow(subject).to receive(:description_content).and_return("description")
|
53
|
-
|
54
|
-
allow(subject).to receive(:icon).with("circle").and_return("ikon")
|
55
|
-
allow(subject).to receive(:tag).with(:div, "question", class: "question").and_return("question")
|
56
|
-
allow(subject).to receive(:tag).with(:div, "description", class: "description").and_return("description")
|
57
|
-
expect(subject.section_body_blocks).to eq(["ikon", "question", "description"])
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#section_attributes" do
|
62
|
-
it "adds `confirm` class" do
|
63
|
-
expect(subject.section_attributes[:class]).to include("confirm")
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "#footer_primary_tools" do
|
68
|
-
it "returns array with cancel and confirm forms" do
|
69
|
-
allow(subject).to receive(:cancel_button).and_return("a")
|
70
|
-
allow(subject).to receive(:confirm_button).and_return("b")
|
71
|
-
expect(subject.footer_primary_tools).to eq(["a", "b"])
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe "#confirm_form_options" do
|
76
|
-
it "returns confirm form options" do
|
77
|
-
allow(subject).to receive(:confirm_url).and_return("x")
|
78
|
-
allow(subject).to receive(:confirm_method).and_return("tt")
|
79
|
-
expect(subject.confirm_form_options).to eq(builder: Releaf::Builders::FormBuilder, url: "x", as: :resource, method: "tt")
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe "#confirm_button" do
|
84
|
-
it "returns confirm button" do
|
85
|
-
allow(subject).to receive(:t).with("Yes").and_return("Yess")
|
86
|
-
allow(subject).to receive(:button).with("Yess", "check", class: "danger", type: "submit").and_return("x")
|
87
|
-
expect(subject.confirm_button).to eq("x")
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "#cancel_path" do
|
92
|
-
it "returns index path" do
|
93
|
-
allow(subject).to receive(:index_path).and_return("x")
|
94
|
-
expect(subject.cancel_path).to eq("x")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "#cancel_button" do
|
99
|
-
it "returns cancel button" do
|
100
|
-
allow(subject).to receive(:cancel_path).and_return("xasd")
|
101
|
-
allow(subject).to receive(:t).with("No").and_return("Noo")
|
102
|
-
allow(subject).to receive(:button).with("Noo", "ban", class: "secondary", data: {type: "cancel"}, href: "xasd")
|
103
|
-
.and_return("x")
|
104
|
-
expect(subject.cancel_button).to eq("x")
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,322 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::Builders::EditBuilder, type: :class do
|
4
|
-
class TranslationsEditBuilderTestHelper < ActionView::Base
|
5
|
-
include Releaf::ApplicationHelper
|
6
|
-
include Releaf::ButtonHelper
|
7
|
-
include FontAwesome::Rails::IconHelper
|
8
|
-
|
9
|
-
def protect_against_forgery?
|
10
|
-
true
|
11
|
-
end
|
12
|
-
def form_authenticity_token(_)
|
13
|
-
"xxx"
|
14
|
-
end
|
15
|
-
|
16
|
-
def request_forgery_protection_token
|
17
|
-
"yyy"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
let(:template){ TranslationsEditBuilderTestHelper.new(ActionView::LookupContext.new(nil), {}, nil) }
|
22
|
-
let(:subject){ described_class.new(template) }
|
23
|
-
let(:controller){ Releaf::ActionController.new }
|
24
|
-
let(:resource){ Book.new }
|
25
|
-
|
26
|
-
before do
|
27
|
-
allow(template).to receive(:controller).and_return(controller)
|
28
|
-
allow(controller).to receive(:action_name).and_return(:edit)
|
29
|
-
allow(subject).to receive(:resource).and_return(resource)
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#section_content" do
|
33
|
-
before do
|
34
|
-
allow(subject).to receive(:section_attributes).and_return(a: "b")
|
35
|
-
allow(subject).to receive(:form_options).and_return(url: "xxx", builder: Releaf::Builders::FormBuilder)
|
36
|
-
allow(subject).to receive(:index_path_preserver).and_return("_index_path_")
|
37
|
-
allow(subject).to receive(:section_blocks).and_return(["_section_","_blocks_"])
|
38
|
-
end
|
39
|
-
|
40
|
-
it "returns section with index url preserver and section blocks" do
|
41
|
-
expect(subject.section_content).to eq('<form class="new_book" id="new_book" action="xxx" accept-charset="UTF-8" method="post"><input type="hidden" name="yyy" value="xxx" />_index_path__section__blocks_</form>')
|
42
|
-
end
|
43
|
-
|
44
|
-
it "assigns form instance to builder" do
|
45
|
-
expect{ subject.section_content }.to change{ subject.form }.from(nil)
|
46
|
-
expect(subject.form).to be_instance_of Releaf::Builders::FormBuilder
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "#index_path_preserver" do
|
51
|
-
it "returns hidden index url input" do
|
52
|
-
allow(subject).to receive(:params).and_return(index_path: "?asd=23&lf=dd")
|
53
|
-
result = '<input type="hidden" name="index_path" id="index_path" value="?asd=23&lf=dd" />'
|
54
|
-
expect(subject.index_path_preserver).to eq(result)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "#section_body_blocks" do
|
59
|
-
it "returns array with error notices and form fields" do
|
60
|
-
allow(subject).to receive(:error_notices).and_return("err")
|
61
|
-
allow(subject).to receive(:form_fields).and_return("fields")
|
62
|
-
expect(subject.section_body_blocks).to eq(["err", "fields"])
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "#error_notices" do
|
67
|
-
|
68
|
-
before do
|
69
|
-
allow(subject).to receive(:error_notices_header).and_return("<error_notice_header />".html_safe)
|
70
|
-
end
|
71
|
-
|
72
|
-
context "when errors exists" do
|
73
|
-
|
74
|
-
it "returns errors block" do
|
75
|
-
resource.valid?
|
76
|
-
|
77
|
-
expect(subject.error_notices).to match_html(%Q[
|
78
|
-
<div class="form-error-box">
|
79
|
-
<error_notice_header />
|
80
|
-
<ul>
|
81
|
-
<li class="error">Title can't be blank</li>
|
82
|
-
</ul>
|
83
|
-
</div>
|
84
|
-
])
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context "when no errors present" do
|
89
|
-
it "returns nil" do
|
90
|
-
expect(subject.error_notices).to be nil
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe "#error_notices_header" do
|
96
|
-
it "returns validation errors notices header" do
|
97
|
-
resource.valid?
|
98
|
-
expect(subject.error_notices_header).to eq('<strong>1 validation error occured:</strong>')
|
99
|
-
|
100
|
-
resource.title = "xx"
|
101
|
-
resource.valid?
|
102
|
-
expect(subject.error_notices_header).to eq('<strong>0 validation errors occured:</strong>')
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe "#footer_primary_tools" do
|
107
|
-
before do
|
108
|
-
allow(subject).to receive(:save_button).and_return("_svbtn_")
|
109
|
-
allow(subject).to receive(:save_and_create_another_button).and_return("_svacrbtn_")
|
110
|
-
end
|
111
|
-
|
112
|
-
context "when create_another is availble" do
|
113
|
-
it "returns an array with save_and_create_another and save buttons" do
|
114
|
-
allow(subject).to receive(:create_another_available?).and_return true
|
115
|
-
expect(subject.footer_primary_tools).to eq(["_svacrbtn_", "_svbtn_"])
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context "when create_another is not available" do
|
120
|
-
it "returns an array with save button" do
|
121
|
-
allow(subject).to receive(:create_another_available?).and_return false
|
122
|
-
expect(subject.footer_primary_tools).to eq(["_svbtn_"])
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "#create_another_available?" do
|
129
|
-
context "when editing an existing record" do
|
130
|
-
let(:resource){ FactoryBot.create(:book) }
|
131
|
-
|
132
|
-
context "when controller has create_another feature enabled" do
|
133
|
-
it "returns false" do
|
134
|
-
expect(subject.create_another_available?).to be false
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
context "when controller has create_another feature disabled" do
|
139
|
-
it "returns false" do
|
140
|
-
expect(subject.create_another_available?).to be false
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context "when creating a new record" do
|
146
|
-
context "when controller has create_another feature enabled" do
|
147
|
-
it "returns true" do
|
148
|
-
expect(subject.create_another_available?).to be true
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context "when controller has create_another feature disabled" do
|
153
|
-
it "returns false" do
|
154
|
-
allow(controller).to receive(:feature_available?).with(:create_another).and_return false
|
155
|
-
expect(subject.create_another_available?).to be false
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
context "when resource is not present" do
|
161
|
-
let(:resource){ nil }
|
162
|
-
it "returns false" do
|
163
|
-
expect(subject.create_another_available?).to be false
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
end
|
168
|
-
|
169
|
-
describe "#save_and_create_another_button" do
|
170
|
-
it "returns save and create button" do
|
171
|
-
allow(template).to receive(:fa_icon).with("plus").and_return('<plus_icon />'.html_safe)
|
172
|
-
allow(subject).to receive(:t).with("Save and create another").and_return("Save and ccrr")
|
173
|
-
expect(subject.save_and_create_another_button).to match_html(%Q[
|
174
|
-
<button class="button with-icon secondary" title="Save and ccrr" type="submit" autocomplete="off" name="after_save" value="create_another" data-type="ok" data-disable="true">
|
175
|
-
<plus_icon />
|
176
|
-
Save and ccrr
|
177
|
-
</button>
|
178
|
-
])
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
describe "#form_options" do
|
183
|
-
it "returns form options" do
|
184
|
-
allow(subject).to receive(:form_builder_class).and_return("CustomFormBuilderClassHere")
|
185
|
-
allow(subject).to receive(:form_url).and_return("/some-url-here")
|
186
|
-
allow(subject).to receive(:form_attributes).and_return(some: "options_here")
|
187
|
-
allow(subject).to receive(:resource_name).and_return(:author)
|
188
|
-
|
189
|
-
options = {
|
190
|
-
builder: "CustomFormBuilderClassHere",
|
191
|
-
as: :author,
|
192
|
-
url: "/some-url-here",
|
193
|
-
html: {some: "options_here"}
|
194
|
-
}
|
195
|
-
expect(subject.form_options).to eq(options)
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
describe "#form_url" do
|
200
|
-
it "returns form url built from form action and resource id" do
|
201
|
-
resource.id = 23
|
202
|
-
allow(subject).to receive(:form_action).and_return("upd")
|
203
|
-
allow(subject).to receive(:url_for).with(action: "upd", id: 23).and_return("/res/new")
|
204
|
-
expect(subject.form_url).to eq("/res/new")
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
describe "#form_action" do
|
209
|
-
context "when new resource" do
|
210
|
-
it "returns `create`" do
|
211
|
-
allow(resource).to receive(:new_record?).and_return(true)
|
212
|
-
expect(subject.form_action).to eq("create")
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
context "when persisted resource" do
|
217
|
-
it "returns `update`" do
|
218
|
-
allow(resource).to receive(:new_record?).and_return(false)
|
219
|
-
expect(subject.form_action).to eq("update")
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
describe "#resource_name" do
|
225
|
-
it "returns `:resource`" do
|
226
|
-
expect(subject.resource_name).to eq(:resource)
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
describe "#form_url" do
|
231
|
-
it "returns form builder class" do
|
232
|
-
allow(subject).to receive(:builder_class).with(:form).and_return("x")
|
233
|
-
expect(subject.form_builder_class).to eq("x")
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
describe "#form_identifier" do
|
238
|
-
before do
|
239
|
-
allow(subject).to receive(:resource_name).and_return(:book)
|
240
|
-
end
|
241
|
-
|
242
|
-
context "when resource has persistance check method and it's persisted" do
|
243
|
-
it "returns resource name prefixed with `edit-`" do
|
244
|
-
allow(resource).to receive(:persisted?).and_return(true)
|
245
|
-
expect(subject.form_identifier).to eq("edit-book")
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
context "when resource has persistance check method and it's not persisted" do
|
250
|
-
it "returns resource name prefixed with `new-`" do
|
251
|
-
allow(resource).to receive(:persisted?).and_return(false)
|
252
|
-
expect(subject.form_identifier).to eq("new-book")
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
context "when resource has no persistance check method" do
|
257
|
-
it "returns resource name prefixed with `update-`" do
|
258
|
-
allow(subject).to receive(:resource).and_return(String.new)
|
259
|
-
expect(subject.form_identifier).to eq("edit-book")
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
describe "#form_classes" do
|
265
|
-
before do
|
266
|
-
allow(subject).to receive(:form_identifier).and_return("xx")
|
267
|
-
end
|
268
|
-
|
269
|
-
it "returns array with form identifier" do
|
270
|
-
expect(subject.form_classes).to eq(["xx"])
|
271
|
-
end
|
272
|
-
|
273
|
-
context "when object has any errors" do
|
274
|
-
it "adds has-error class to returned array" do
|
275
|
-
resource.title = nil
|
276
|
-
resource.valid?
|
277
|
-
expect(subject.form_classes).to eq(["xx", "has-error"])
|
278
|
-
end
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
describe "#form_attributes" do
|
283
|
-
it "returns form attributes" do
|
284
|
-
allow(subject).to receive(:form_identifier).and_return("xx")
|
285
|
-
allow(subject).to receive(:form_classes).and_return(["a", "b"])
|
286
|
-
|
287
|
-
attributes = {
|
288
|
-
multipart: true,
|
289
|
-
novalidate: "",
|
290
|
-
class: ["a", "b"],
|
291
|
-
id: "xx",
|
292
|
-
data: {
|
293
|
-
"remote"=>true,
|
294
|
-
"remote-validation"=>true,
|
295
|
-
"type"=>:json
|
296
|
-
}
|
297
|
-
}
|
298
|
-
expect(subject.form_attributes).to eq(attributes)
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
describe "#save_button" do
|
303
|
-
it "returns save button" do
|
304
|
-
allow(subject).to receive(:button)
|
305
|
-
.with("to_list", "check", {class: "primary", data: {type: "ok", disable: true}, type: "submit"})
|
306
|
-
.and_return("_btn_")
|
307
|
-
allow(subject).to receive(:t).with("Save").and_return("to_list")
|
308
|
-
expect(subject.save_button).to eq("_btn_")
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
describe "#form_fields" do
|
313
|
-
it "returns form `releaf_fields` output for form `field_names` casted to array" do
|
314
|
-
form = Releaf::Builders::FormBuilder.new(:book, Book.new, template, {})
|
315
|
-
subject.form = form
|
316
|
-
allow(form).to receive(:field_names).and_return({a: 1, b: 2})
|
317
|
-
allow(form).to receive(:releaf_fields).with([[:a, 1], [:b, 2]]).and_return(:x)
|
318
|
-
|
319
|
-
expect(subject.form_fields).to eq(:x)
|
320
|
-
end
|
321
|
-
end
|
322
|
-
end
|