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,70 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
feature "Settings", js: true do
|
3
|
-
scenario "edit settings" do
|
4
|
-
values = [
|
5
|
-
{key: "content.updated_at", default: Time.parse("2014-07-01 14:33:59"), description: "Content update time", type: :time},
|
6
|
-
{key: "content.updated", default: true, description: "Content is updated?", type: :boolean},
|
7
|
-
{key: "content.rating", default: 5.65, type: :decimal},
|
8
|
-
{key: "content.title", default: "some"},
|
9
|
-
{key: "content.date", default: DateTime.parse("2015-05-02"), type: "date"},
|
10
|
-
{key: "content.textarea", type: :textarea},
|
11
|
-
{key: "content.richtext", type: :richtext},
|
12
|
-
]
|
13
|
-
Releaf::Settings.destroy_all
|
14
|
-
Releaf::Settings.register(*values)
|
15
|
-
auth_as_user
|
16
|
-
|
17
|
-
visit releaf_settings_path
|
18
|
-
expect(page).to have_number_of_resources(7)
|
19
|
-
expect(page).to have_css(".table.releaf\\/settings tbody tr:first-child td:first-child", text: "content.date")
|
20
|
-
expect(page).to have_css(".table.releaf\\/settings tbody tr:first-child td:nth-child(2)", text: /^Sat, 02 May 2015 00:00:00 \+0000$/)
|
21
|
-
expect(page).to have_css(".table.releaf\\/settings tbody tr:last-child td:first-child", text: "content.updated_at")
|
22
|
-
|
23
|
-
search "content.updated"
|
24
|
-
expect(page).to have_number_of_resources(2)
|
25
|
-
|
26
|
-
click_link "content.updated_at"
|
27
|
-
update_resource do
|
28
|
-
fill_in "Content update time", with: '2014-04-01 12:33:59'
|
29
|
-
end
|
30
|
-
|
31
|
-
click_link "Back to list"
|
32
|
-
expect(page).to have_content("12:33")
|
33
|
-
expect(Releaf::Settings["content.updated_at"]).to eq(Time.parse("2014-04-01 12:33:59"))
|
34
|
-
|
35
|
-
click_link "content.updated"
|
36
|
-
expect(page).to have_field("Content is updated?")
|
37
|
-
expect(page).to have_css(".field input[type='checkbox'][checked='checked']")
|
38
|
-
|
39
|
-
visit releaf_settings_path
|
40
|
-
|
41
|
-
click_link "content.rating"
|
42
|
-
expect(page).to have_field("Value")
|
43
|
-
expect(page).to have_css(".field input[type='number'][value='5.65']")
|
44
|
-
|
45
|
-
click_link "Back to list"
|
46
|
-
|
47
|
-
click_link "content.textarea"
|
48
|
-
expect(page).to have_field("Value")
|
49
|
-
expect(page).to have_css(".field textarea[name='resource[value]']")
|
50
|
-
|
51
|
-
update_resource do
|
52
|
-
fill_in "Value", with: "AA\nBB\nCC\nDD\n"
|
53
|
-
end
|
54
|
-
click_link "Back to list"
|
55
|
-
|
56
|
-
expect(Releaf::Settings["content.textarea"]).to eq("AA\r\nBB\r\nCC\r\nDD\r\n")
|
57
|
-
expect(page).to have_content("AA BB CC DD")
|
58
|
-
|
59
|
-
click_link "content.richtext"
|
60
|
-
wait_for_all_richtexts
|
61
|
-
|
62
|
-
update_resource do
|
63
|
-
fill_in_richtext "Value", with: "<p>EE<br/>FF</p>\nGG\n<b>HH</b>\n"
|
64
|
-
end
|
65
|
-
click_link "Back to list"
|
66
|
-
|
67
|
-
expect(Releaf::Settings["content.richtext"]).to eq("<p>EE<br />\r\nFF</p>\r\n\r\n<p>GG <b>HH</b></p>\r\n")
|
68
|
-
expect(page).to have_content("EE FF GG HH")
|
69
|
-
end
|
70
|
-
end
|
data/spec/features/title_spec.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
feature "Controller title" do
|
3
|
-
scenario "shows only application title" do
|
4
|
-
visit releaf_root_path
|
5
|
-
expect(page.title).to eq("Dummy")
|
6
|
-
end
|
7
|
-
|
8
|
-
scenario "shows only controller and application title" do
|
9
|
-
auth_as_user
|
10
|
-
visit releaf_permissions_user_profile_path
|
11
|
-
expect(page.title).to eq("Releaf/permissions/profile - Dummy")
|
12
|
-
end
|
13
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
-
|
2
|
-
field_name: 'meta_description'
|
3
|
-
field_type: 'boolean'
|
4
|
-
apply_to: '*'
|
5
|
-
default: 'common stuff'
|
6
|
-
deny_for: 'Text'
|
7
|
-
|
8
|
-
-
|
9
|
-
field_name: 'meta_copyright'
|
10
|
-
field_type: 'text'
|
11
|
-
apply_to: ['Text', 'ContactsController']
|
12
|
-
levels: [1]
|
13
|
-
|
14
|
-
-
|
15
|
-
field_name: 'other_attribute'
|
16
|
-
field_type: 'text'
|
17
|
-
apply_to: 'ContactsController'
|
data/spec/fixtures/cs.png
DELETED
Binary file
|
Binary file
|
data/spec/fixtures/unicorn.jpg
DELETED
Binary file
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe Releaf::ApplicationHelper do
|
4
|
-
describe "#releaf_table" do
|
5
|
-
it "returns table builder output for collection and resource class with given options" do
|
6
|
-
builder = Releaf::Permissions::Users::TableBuilder
|
7
|
-
collection = "collection"
|
8
|
-
|
9
|
-
allow(builder).to receive(:new).with(collection, TextPage, subject, toolbox: false).and_call_original
|
10
|
-
allow_any_instance_of(builder).to receive(:output).and_return("table")
|
11
|
-
|
12
|
-
expect(releaf_table(collection, TextPage, builder: builder, toolbox: false)).to eq("table")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "#merge_attributes" do
|
17
|
-
it "makes deep merge second over first hash" do
|
18
|
-
expect(helper.merge_attributes({a: {b: "c"}, d: "e"}, {a: {b: "č"}, f: "x"})).to eq(a: {b: "č"}, d: "e", f: "x")
|
19
|
-
end
|
20
|
-
|
21
|
-
it "merges class values from both hashes" do
|
22
|
-
expect(helper.merge_attributes({class: ["a", "b"]}, {})[:class]).to eq(["a", "b"])
|
23
|
-
expect(helper.merge_attributes({}, {class: "d c"})[:class]).to eq(["d c"])
|
24
|
-
expect(helper.merge_attributes({class: ["a", "b"]}, {class: "d c"})[:class]).to eq(["a", "b", "d c"])
|
25
|
-
end
|
26
|
-
|
27
|
-
it "removes empty class values on merging" do
|
28
|
-
expect(helper.merge_attributes({class: ["a", nil, "b"]}, {class: ["", "c"]})[:class]).to eq(["a", "b", "c"])
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#i18n_options_for_select" do
|
33
|
-
Color = Struct.new(:id, :to_s)
|
34
|
-
let(:helper) do
|
35
|
-
helper = instance_double(Releaf::ActionController)
|
36
|
-
helper.extend Releaf::ApplicationHelper
|
37
|
-
helper.extend ActionView::Helpers
|
38
|
-
|
39
|
-
helper
|
40
|
-
end
|
41
|
-
|
42
|
-
before do
|
43
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "admin.xx.colors-red")
|
44
|
-
translation.i18n_entry_translation.create(locale: "en", text: "Color red")
|
45
|
-
Releaf::I18nDatabase::Backend.reset_cache
|
46
|
-
allow(helper).to receive(:controller_scope_name).and_return("admin.xx")
|
47
|
-
end
|
48
|
-
|
49
|
-
context "when array of string" do
|
50
|
-
it "returns translated options" do
|
51
|
-
input = ["red", "green", "blue"]
|
52
|
-
output = ['<option value="red">Color red</option>', '<option selected="selected" value="green">green</option>', '<option value="blue">blue</option>'].join("\n")
|
53
|
-
expect(helper.i18n_options_for_select(input, "green", "colors")).to eq(output)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when hash" do
|
58
|
-
it "returns translated options" do
|
59
|
-
input = {"red" => "r", "green" => "g", "blue" => "b"}
|
60
|
-
output = ['<option value="r">Color red</option>', '<option selected="selected" value="g">green</option>', '<option value="b">blue</option>'].join("\n")
|
61
|
-
expect(helper.i18n_options_for_select(input, "g", "colors")).to eq(output)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "when array of string for another translation scope" do
|
66
|
-
it "returns translated options" do
|
67
|
-
input = ["red", "green", "blue"]
|
68
|
-
output = ['<option value="red">red</option>', '<option selected="selected" value="green">green</option>', '<option value="blue">blue</option>'].join("\n")
|
69
|
-
expect(helper.i18n_options_for_select(input, "green", "colors", {:scope => "admin.products"})).to eq(output)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,146 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe Releaf::ButtonHelper do
|
4
|
-
|
5
|
-
describe "#releaf_button" do
|
6
|
-
|
7
|
-
it "returns an HTML button element with title, icon, text and optional extra attributes" do
|
8
|
-
output = '<button class="button with-icon danger secondary" title="escape><this" type="button" autocomplete="off" data-x="escape<this>too"><i class="fa fa-plus"></i>escape><this</button>'
|
9
|
-
expect(helper.releaf_button("escape><this", "plus", class: [ :danger, "secondary" ], 'data-x' => 'escape<this>too' )).to eq(output)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "uses #releaf_button_attributes and #releaf_button_content to collect button attributes and content" do
|
13
|
-
processed_attributes = { attr: :value, data: { attrx: "valuex" } }
|
14
|
-
|
15
|
-
expect(helper).to receive(:releaf_button_attributes).with("foo", "bar", {} ).and_return(processed_attributes)
|
16
|
-
expect(helper).to receive(:releaf_button_content).with("foo", "bar", processed_attributes).and_return("button content")
|
17
|
-
|
18
|
-
expect(helper.releaf_button("foo", "bar")).to eq('<button attr="value" data-attrx="valuex">button content</button>')
|
19
|
-
end
|
20
|
-
|
21
|
-
context "when href is given in attributes" do
|
22
|
-
|
23
|
-
it "returns a link element instead of a button" do
|
24
|
-
html = '<a class="button with-icon" title="x" href="http://example.com/?a&b"><i class="fa fa-plus"></i>x</a>'
|
25
|
-
expect(helper.releaf_button("x", "plus", href: "http://example.com/?a&b")).to eq(html)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "returns a link element even if the given href is blank" do
|
29
|
-
html = '<a class="button with-icon" title="x"><i class="fa fa-plus"></i>x</a>'
|
30
|
-
expect(helper.releaf_button("x", "plus", href: nil)).to eq(html)
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "#releaf_button_attributes" do
|
38
|
-
|
39
|
-
it "returns a hash of attributes" do
|
40
|
-
expect(helper.releaf_button_attributes( :text_foo, :icon_bar )).to be_a Hash
|
41
|
-
end
|
42
|
-
|
43
|
-
it "adds button class" do
|
44
|
-
expect(helper.releaf_button_attributes( :text_foo, :icon_bar )[:class]).to include( "button" )
|
45
|
-
end
|
46
|
-
|
47
|
-
it "sets title attribute to given text" do
|
48
|
-
expect(helper.releaf_button_attributes( :text_foo, :icon_bar )).to include( title: :text_foo )
|
49
|
-
end
|
50
|
-
|
51
|
-
context "when href attribute given" do
|
52
|
-
it "does not set type attribute" do
|
53
|
-
expect(helper.releaf_button_attributes( :text_foo, :icon_bar, href: :baz )).to_not include( :type )
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when href attribute not given" do
|
58
|
-
it "sets type attribute to button" do
|
59
|
-
expect(helper.releaf_button_attributes( :text_foo, :icon_bar )).to include( type: :button )
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "when icon given" do
|
64
|
-
|
65
|
-
context "when text also given" do
|
66
|
-
it "adds with-icon class" do
|
67
|
-
expect(helper.releaf_button_attributes( :text_foo, :icon_bar )[:class]).to include( "with-icon" )
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "when text not given" do
|
72
|
-
it "adds only-icon class" do
|
73
|
-
expect(helper.releaf_button_attributes( nil, :icon_bar )[:class]).to include( "only-icon" )
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
context "when extra attributes given" do
|
80
|
-
|
81
|
-
it "includes given custom attributes with the default ones" do
|
82
|
-
expect(helper.releaf_button_attributes( :text_foo, :icon_bar, data: { x: "y" })).to include( class: ["button", "with-icon"], data: { x: "y" } )
|
83
|
-
end
|
84
|
-
|
85
|
-
it "overwrites default attributes if needed" do
|
86
|
-
expect(helper.releaf_button_attributes( :text_foo, :icon_bar, type: :submit, title: "custom")).to include( type: :submit, title: "custom" )
|
87
|
-
end
|
88
|
-
|
89
|
-
it "combines given class names with the deault ones" do
|
90
|
-
expect(helper.releaf_button_attributes( :text_foo, :icon_bar, class: "danger") ).to include( class: ["button", "with-icon", "danger"] )
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
describe "#releaf_button_content" do
|
99
|
-
|
100
|
-
let(:icon_html) { '<i class="fa fa-icon_bar"></i>' }
|
101
|
-
|
102
|
-
it "returns an html-safe buffer" do
|
103
|
-
expect(helper.releaf_button_content( :text_foo, :icon_bar )).to be_a ActiveSupport::SafeBuffer
|
104
|
-
end
|
105
|
-
|
106
|
-
context "when text and icon given" do
|
107
|
-
it "returns icon HTML followed by given text" do
|
108
|
-
expect(helper.releaf_button_content( "escape<this>text", :icon_bar )).to eq(icon_html + 'escape<this>text')
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
context "when only text given" do
|
113
|
-
it "returns given text" do
|
114
|
-
expect(helper.releaf_button_content( "escape<this>text", nil )).to eq('escape<this>text')
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
context "when only icon given" do
|
119
|
-
|
120
|
-
context "when title attribute is present" do
|
121
|
-
it "returns icon HTML" do
|
122
|
-
expect(helper.releaf_button_content( nil, :icon_bar, title: "foo" )).to eq(icon_html)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context "when title attribute is not present" do
|
127
|
-
|
128
|
-
it "raises an ArgumentError" do
|
129
|
-
expect{ helper.releaf_button_content(nil, :icon_bar, title: "") }.to raise_error(ArgumentError, "Title is required for icon-only buttons")
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|
133
|
-
|
134
|
-
end
|
135
|
-
|
136
|
-
|
137
|
-
context "when both text and icon are blank" do
|
138
|
-
it "raises an ArgumentError" do
|
139
|
-
expect{ helper.releaf_button_content(nil, nil ) }.to raise_error(ArgumentError, "Either text or icon is required for buttons")
|
140
|
-
expect{ helper.releaf_button_content("", "" ) }.to raise_error(ArgumentError, "Either text or icon is required for buttons")
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
end
|
145
|
-
|
146
|
-
end
|
@@ -1,171 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe Releaf::ActionController::Features do
|
4
|
-
let(:subject){ DummyActionControllerFeaturesIncluder.new }
|
5
|
-
|
6
|
-
class DummyActionControllerFeaturesIncluder < Releaf::ActionController
|
7
|
-
include Releaf::ActionController::Features
|
8
|
-
include Releaf::Responders
|
9
|
-
def params
|
10
|
-
{action: "some_action"}
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#verify_feature_availability!" do
|
15
|
-
before do
|
16
|
-
allow(subject).to receive(:action_feature).with("some_action").and_return(:feature_name)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "adds itself to before filters" do
|
20
|
-
before_actions = subject._process_action_callbacks.select{|f| f.kind == :before}.map{|f| f.filter }
|
21
|
-
expect(before_actions).to include(:verify_controller_access!)
|
22
|
-
end
|
23
|
-
|
24
|
-
context "when no feature defined for action" do
|
25
|
-
it "doesn no raise `Releaf::FeatureDisabled` exception" do
|
26
|
-
allow(subject).to receive(:action_feature).with("some_action").and_return(nil)
|
27
|
-
expect{ subject.verify_feature_availability! }.to_not raise_error
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "when current feature is available" do
|
32
|
-
it "doesn no raise `Releaf::FeatureDisabled` exception" do
|
33
|
-
allow(subject).to receive(:feature_available?).with(:feature_name).and_return(true)
|
34
|
-
expect{ subject.verify_feature_availability! }.to_not raise_error
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context "when current feature is not available" do
|
39
|
-
it "raises `Releaf::FeatureDisabled` exception with stringified feature name" do
|
40
|
-
allow(subject).to receive(:feature_available?).with(:feature_name).and_return(false)
|
41
|
-
expect{ subject.verify_feature_availability! }.to raise_error(Releaf::FeatureDisabled, "feature_name")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#action_feature" do
|
47
|
-
before do
|
48
|
-
allow(subject).to receive(:action_features).and_return(create: "xxx", te: "kkk")
|
49
|
-
end
|
50
|
-
|
51
|
-
it "returns matching feature for given action from action features" do
|
52
|
-
expect(subject.action_feature(:create)).to eq("xxx")
|
53
|
-
end
|
54
|
-
|
55
|
-
it "symbolize given action name" do
|
56
|
-
expect(subject.action_feature("te")).to eq("kkk")
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "#features" do
|
61
|
-
it "returns array instance" do
|
62
|
-
expect(subject.features).to be_instance_of Array
|
63
|
-
end
|
64
|
-
|
65
|
-
it "returned array contains features as symbols" do
|
66
|
-
subject.features.each do|feature_name|
|
67
|
-
expect(feature_name).to be_instance_of Symbol
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "#action_features" do
|
73
|
-
it "returns instance of `Hash`" do
|
74
|
-
expect(subject.action_features).to be_instance_of(Hash)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "returns hash with action and feature mapp as symbols" do
|
78
|
-
subject.action_features.each_pair do|action_name, feature_name|
|
79
|
-
expect(action_name).to be_instance_of(Symbol)
|
80
|
-
expect(feature_name).to be_instance_of(Symbol)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "when `show` feature is available" do
|
85
|
-
it "returns show to show feature mapping" do
|
86
|
-
allow(subject).to receive(:feature_available?).with(:show).and_return(true)
|
87
|
-
expect(subject.action_features[:show]).to eq(:show)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context "when `show` feature is not available" do
|
92
|
-
it "returns show to edit feature mapping" do
|
93
|
-
allow(subject).to receive(:feature_available?).with(:show).and_return(false)
|
94
|
-
expect(subject.action_features[:show]).to eq(:edit)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "#feature_disabled" do
|
100
|
-
before do
|
101
|
-
allow(subject).to receive(:action_responder).with(:feature_disabled).and_return("_res")
|
102
|
-
end
|
103
|
-
|
104
|
-
it "adds itself as rescue handler from `Releaf::FeatureDisabled` exception" do
|
105
|
-
expect(Hash[subject.rescue_handlers]["Releaf::FeatureDisabled"]).to eq(:feature_disabled)
|
106
|
-
end
|
107
|
-
|
108
|
-
it "calls disabled feature responder" do
|
109
|
-
expect(subject).to receive(:respond_with).with(nil, responder: "_res")
|
110
|
-
subject.feature_disabled(Releaf::FeatureDisabled.new("xx"))
|
111
|
-
end
|
112
|
-
|
113
|
-
it "assigns @feature instance variable from exception message" do
|
114
|
-
allow(subject).to receive(:respond_with)
|
115
|
-
expect{ subject.feature_disabled(Releaf::FeatureDisabled.new("xx")) }.to change{ subject.instance_variable_get(:@feature) }
|
116
|
-
.to("xx")
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe "#feature_available?" do
|
121
|
-
it "adds itself as helper" do
|
122
|
-
expect(subject._helper_methods).to include(:feature_available?)
|
123
|
-
end
|
124
|
-
|
125
|
-
it "returns whether feature is defined within features variable" do
|
126
|
-
allow(subject).to receive(:features).and_return([:edit])
|
127
|
-
expect(subject.feature_available?(:create)).to be false
|
128
|
-
|
129
|
-
allow(subject).to receive(:features).and_return([:edit, :create])
|
130
|
-
expect(subject.feature_available?(:create)).to be true
|
131
|
-
end
|
132
|
-
|
133
|
-
context "when `search` feature requested" do
|
134
|
-
it "also checks whether `index` feature is enabled" do
|
135
|
-
allow(subject).to receive(:feature_available?).with(:search).and_call_original
|
136
|
-
allow(subject).to receive(:feature_available?).with(:index).and_return(false)
|
137
|
-
|
138
|
-
allow(subject).to receive(:features).and_return([:edit])
|
139
|
-
expect(subject.feature_available?(:search)).to be false
|
140
|
-
|
141
|
-
allow(subject).to receive(:features).and_return([:edit, :search])
|
142
|
-
expect(subject.feature_available?(:search)).to be false
|
143
|
-
|
144
|
-
allow(subject).to receive(:feature_available?).with(:index).and_return(true)
|
145
|
-
expect(subject.feature_available?(:search)).to be true
|
146
|
-
|
147
|
-
allow(subject).to receive(:features).and_return([:edit])
|
148
|
-
expect(subject.feature_available?(:search)).to be false
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context "when `create_another` feature requested" do
|
153
|
-
it "also checks whether `create` feature is enabled" do
|
154
|
-
allow(subject).to receive(:feature_available?).with(:create_another).and_call_original
|
155
|
-
allow(subject).to receive(:feature_available?).with(:create).and_return(false)
|
156
|
-
|
157
|
-
allow(subject).to receive(:features).and_return([:edit])
|
158
|
-
expect(subject.feature_available?(:create_another)).to be false
|
159
|
-
|
160
|
-
allow(subject).to receive(:features).and_return([:edit, :create_another])
|
161
|
-
expect(subject.feature_available?(:create_another)).to be false
|
162
|
-
|
163
|
-
allow(subject).to receive(:feature_available?).with(:create).and_return(true)
|
164
|
-
expect(subject.feature_available?(:create_another)).to be true
|
165
|
-
|
166
|
-
allow(subject).to receive(:features).and_return([:edit])
|
167
|
-
expect(subject.feature_available?(:create_another)).to be false
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|