Fixed issue #1488 - Role - Group can't be unchecked.
This commit is contained in:
commit
afb78f2200
7 changed files with 187 additions and 55 deletions
|
@ -460,6 +460,31 @@ class App.ControllerForm extends App.Controller
|
||||||
else
|
else
|
||||||
param[item.name] = value
|
param[item.name] = value
|
||||||
|
|
||||||
|
# verify if we have not checked checkboxes
|
||||||
|
uncheckParam = {}
|
||||||
|
lookupForm.find('input[type=checkbox]').each( (index) ->
|
||||||
|
checked = $(@).attr('checked')
|
||||||
|
name = $(@).attr('name')
|
||||||
|
if name && !checked && (!(name of param) || param[name] is '')
|
||||||
|
if !(name of uncheckParam)
|
||||||
|
uncheckParam[name] = undefined
|
||||||
|
else
|
||||||
|
uncheckParam[name] = []
|
||||||
|
)
|
||||||
|
|
||||||
|
# verify if we have not checked radios
|
||||||
|
lookupForm.find('input[type=radio]').each( (index) ->
|
||||||
|
checked = $(@).attr('checked')
|
||||||
|
name = $(@).attr('name')
|
||||||
|
if name && !checked && !(name of param)
|
||||||
|
uncheckParam[name] = undefined
|
||||||
|
)
|
||||||
|
|
||||||
|
# apply empty checkboxes & radio values to params
|
||||||
|
for key, value of uncheckParam
|
||||||
|
if !(key of param)
|
||||||
|
param[key] = value
|
||||||
|
|
||||||
# data type conversion
|
# data type conversion
|
||||||
for key of param
|
for key of param
|
||||||
|
|
||||||
|
|
|
@ -348,7 +348,7 @@ class App.ChannelChat extends App.ControllerSubContent
|
||||||
params[key] = value
|
params[key] = value
|
||||||
paramString = ''
|
paramString = ''
|
||||||
for key, value of params
|
for key, value of params
|
||||||
if value != ''
|
if !_.isEmpty(value)
|
||||||
if paramString != ''
|
if paramString != ''
|
||||||
# coffeelint: disable=no_unnecessary_double_quotes
|
# coffeelint: disable=no_unnecessary_double_quotes
|
||||||
paramString += ",\n"
|
paramString += ",\n"
|
||||||
|
|
|
@ -55,7 +55,7 @@ class App.ChannelForm extends App.ControllerSubContent
|
||||||
params = @formParam(@$('.js-paramsDesigner'))
|
params = @formParam(@$('.js-paramsDesigner'))
|
||||||
paramString = ''
|
paramString = ''
|
||||||
for key, value of params
|
for key, value of params
|
||||||
if value != ''
|
if !_.isEmpty(value)
|
||||||
if paramString != ''
|
if paramString != ''
|
||||||
paramString += ",\n"
|
paramString += ",\n"
|
||||||
if value == 'true' || value == 'false'
|
if value == 'true' || value == 'false'
|
||||||
|
|
|
@ -22,8 +22,8 @@ returns
|
||||||
groups: :group_names_access_map=,
|
groups: :group_names_access_map=,
|
||||||
group_ids: :group_ids_access_map=
|
group_ids: :group_ids_access_map=
|
||||||
}.each do |param, setter|
|
}.each do |param, setter|
|
||||||
|
next if !params.key?(param)
|
||||||
map = params[param]
|
map = params[param]
|
||||||
next if map.blank?
|
|
||||||
next if !respond_to?(setter)
|
next if !respond_to?(setter)
|
||||||
send(setter, map)
|
send(setter, map)
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,8 +7,8 @@ module HasGroups
|
||||||
|
|
||||||
attr_accessor :group_access_buffer
|
attr_accessor :group_access_buffer
|
||||||
|
|
||||||
after_create :check_group_access_buffer
|
after_create :process_group_access_buffer
|
||||||
after_update :check_group_access_buffer
|
after_update :process_group_access_buffer
|
||||||
|
|
||||||
association_attributes_ignored :groups, group_through_identifier
|
association_attributes_ignored :groups, group_through_identifier
|
||||||
|
|
||||||
|
@ -211,46 +211,58 @@ module HasGroups
|
||||||
end
|
end
|
||||||
|
|
||||||
def groups_access_map_store(map)
|
def groups_access_map_store(map)
|
||||||
map.each do |group_identifier, accesses|
|
fill_group_access_buffer do
|
||||||
# use given key as identifier or look it up
|
Hash(map).each do |group_identifier, accesses|
|
||||||
# via the given block which returns the identifier
|
# use given key as identifier or look it up
|
||||||
group_id = block_given? ? yield(group_identifier) : group_identifier
|
# via the given block which returns the identifier
|
||||||
|
group_id = block_given? ? yield(group_identifier) : group_identifier
|
||||||
|
|
||||||
if !accesses.is_a?(Array)
|
Array(accesses).each do |access|
|
||||||
accesses = [accesses]
|
push_group_access_buffer(
|
||||||
end
|
group_id: group_id,
|
||||||
|
access: access
|
||||||
accesses.each do |access|
|
)
|
||||||
push_group_access_buffer(
|
end
|
||||||
group_id: group_id,
|
|
||||||
access: access
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
check_group_access_buffer if id
|
def fill_group_access_buffer
|
||||||
|
@group_access_buffer = []
|
||||||
|
yield
|
||||||
|
process_group_access_buffer if id
|
||||||
end
|
end
|
||||||
|
|
||||||
def push_group_access_buffer(entry)
|
def push_group_access_buffer(entry)
|
||||||
@group_access_buffer ||= []
|
|
||||||
@group_access_buffer.push(entry)
|
@group_access_buffer.push(entry)
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_group_access_buffer
|
def flush_group_access_buffer
|
||||||
return if group_access_buffer.blank?
|
# group_access_buffer is at least an empty Array
|
||||||
destroy_group_relations
|
# if changes to the map were performed
|
||||||
|
# otherwise it's just an update of other attributes
|
||||||
|
return if group_access_buffer.nil?
|
||||||
|
yield
|
||||||
|
group_access_buffer = nil
|
||||||
|
cache_delete
|
||||||
|
end
|
||||||
|
|
||||||
foreign_key = group_through.foreign_key
|
def process_group_access_buffer
|
||||||
entries = group_access_buffer.collect do |entry|
|
|
||||||
entry[foreign_key] = id
|
flush_group_access_buffer do
|
||||||
entry
|
destroy_group_relations
|
||||||
|
|
||||||
|
break if group_access_buffer.blank?
|
||||||
|
|
||||||
|
foreign_key = group_through.foreign_key
|
||||||
|
entries = group_access_buffer.collect do |entry|
|
||||||
|
entry[foreign_key] = id
|
||||||
|
entry
|
||||||
|
end
|
||||||
|
|
||||||
|
group_through.klass.create!(entries)
|
||||||
end
|
end
|
||||||
|
|
||||||
group_through.klass.create!(entries)
|
|
||||||
|
|
||||||
group_access_buffer = nil
|
|
||||||
|
|
||||||
cache_delete
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@ test("form elements check", function() {
|
||||||
selectmultioption2: [ false, true ],
|
selectmultioption2: [ false, true ],
|
||||||
richtext2: 'lalu <l> lalu',
|
richtext2: 'lalu <l> lalu',
|
||||||
datetime1: Date.parse('2015-01-11T12:40:00Z'),
|
datetime1: Date.parse('2015-01-11T12:40:00Z'),
|
||||||
|
checkbox1: [],
|
||||||
|
checkbox2: '1',
|
||||||
}
|
}
|
||||||
new App.ControllerForm({
|
new App.ControllerForm({
|
||||||
el: el,
|
el: el,
|
||||||
|
@ -33,18 +35,20 @@ test("form elements check", function() {
|
||||||
{ name: 'input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: false, default: defaults['input2'] },
|
{ name: 'input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: false, default: defaults['input2'] },
|
||||||
{ name: 'password1', display: 'Password1', tag: 'input', type: 'password', limit: 100, null: true, default: defaults['password1'] },
|
{ name: 'password1', display: 'Password1', tag: 'input', type: 'password', limit: 100, null: true, default: defaults['password1'] },
|
||||||
{ name: 'password2', display: 'Password2', tag: 'input', type: 'password', limit: 100, null: false, default: defaults['password2'] },
|
{ name: 'password2', display: 'Password2', tag: 'input', type: 'password', limit: 100, null: false, default: defaults['password2'] },
|
||||||
{ name: 'textarea1', display: 'Textarea1', tag: 'textarea', rows: 6, limit: 100, null: true, upload: true, default: defaults['textarea1'] },
|
{ name: 'textarea1', display: 'Textarea1', tag: 'textarea', rows: 6, limit: 100, null: true, upload: true, default: defaults['textarea1'] },
|
||||||
{ name: 'textarea2', display: 'Textarea2', tag: 'textarea', rows: 6, limit: 100, null: false, upload: true, default: defaults['textarea2'] },
|
{ name: 'textarea2', display: 'Textarea2', tag: 'textarea', rows: 6, limit: 100, null: false, upload: true, default: defaults['textarea2'] },
|
||||||
{ name: 'select1', display: 'Select1', tag: 'select', null: true, options: { true: 'internal', false: 'public' }, default: defaults['select1'] },
|
{ name: 'select1', display: 'Select1', tag: 'select', null: true, options: { true: 'internal', false: 'public' }, default: defaults['select1'] },
|
||||||
{ name: 'select2', display: 'Select2', tag: 'select', null: false, options: { true: 'internal', false: 'public' }, default: defaults['select2'] },
|
{ name: 'select2', display: 'Select2', tag: 'select', null: false, options: { true: 'internal', false: 'public' }, default: defaults['select2'] },
|
||||||
{ name: 'selectmulti1', display: 'SelectMulti1', tag: 'select', null: true, multiple: true, options: { true: 'internal', false: 'public' }, default: defaults['selectmulti1'] },
|
{ name: 'selectmulti1', display: 'SelectMulti1', tag: 'select', null: true, multiple: true, options: { true: 'internal', false: 'public' }, default: defaults['selectmulti1'] },
|
||||||
{ name: 'selectmulti2', display: 'SelectMulti2', tag: 'select', null: false, multiple: true, options: { true: 'internal', false: 'public' }, default: defaults['selectmulti2'] },
|
{ name: 'selectmulti2', display: 'SelectMulti2', tag: 'select', null: false, multiple: true, options: { true: 'internal', false: 'public' }, default: defaults['selectmulti2'] },
|
||||||
{ name: 'selectmultioption1', display: 'SelectMultiOption1', tag: 'select', null: true, multiple: true, options: [{ value: true, name: 'internal' }, { value: false, name: 'public' }], default: defaults['selectmultioption1'] },
|
{ name: 'selectmultioption1', display: 'SelectMultiOption1', tag: 'select', null: true, multiple: true, options: [{ value: true, name: 'internal' }, { value: false, name: 'public' }], default: defaults['selectmultioption1'] },
|
||||||
{ name: 'selectmultioption2', display: 'SelectMultiOption2', tag: 'select', null: false, multiple: true, options: [{ value: true, name: 'A' }, { value: 1, name: 'B'}, { value: false, name: 'C' }], default: defaults['selectmultioption2'] },
|
{ name: 'selectmultioption2', display: 'SelectMultiOption2', tag: 'select', null: false, multiple: true, options: [{ value: true, name: 'A' }, { value: 1, name: 'B'}, { value: false, name: 'C' }], default: defaults['selectmultioption2'] },
|
||||||
{ name: 'richtext1', display: 'Richtext1', tag: 'richtext', limit: 100, null: true, upload: true, default: defaults['richtext1'] },
|
{ name: 'richtext1', display: 'Richtext1', tag: 'richtext', limit: 100, null: true, upload: true, default: defaults['richtext1'] },
|
||||||
{ name: 'richtext2', display: 'Richtext2', tag: 'richtext', limit: 100, null: true, upload: true, default: defaults['richtext2'] },
|
{ name: 'richtext2', display: 'Richtext2', tag: 'richtext', limit: 100, null: true, upload: true, default: defaults['richtext2'] },
|
||||||
{ name: 'datetime1', display: 'Datetime1', tag: 'datetime', null: true, default: defaults['datetime1'] },
|
{ name: 'datetime1', display: 'Datetime1', tag: 'datetime', null: true, default: defaults['datetime1'] },
|
||||||
{ name: 'datetime2', display: 'Datetime2', tag: 'datetime', null: false, default: defaults['datetime2'] },
|
{ name: 'datetime2', display: 'Datetime2', tag: 'datetime', null: false, default: defaults['datetime2'] },
|
||||||
|
{ name: 'checkbox1', display: 'Checkbox1', tag: 'checkbox', null: false, default: defaults['checkbox1'], options: { a: 'AA', b: 'BB' } },
|
||||||
|
{ name: 'checkbox2', display: 'Checkbox2', tag: 'checkbox', null: false, default: defaults['checkbox2'], options: { 1: '11' } },
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
autofocus: true
|
autofocus: true
|
||||||
|
@ -100,6 +104,10 @@ test("form elements check", function() {
|
||||||
//equal(el.find('[name="richtext2"]').prop('required'), true, 'check textarea2 required')
|
//equal(el.find('[name="richtext2"]').prop('required'), true, 'check textarea2 required')
|
||||||
equal(el.find('[name="richtext2"]').is(":focus"), false, 'check textarea2 focus')
|
equal(el.find('[name="richtext2"]').is(":focus"), false, 'check textarea2 focus')
|
||||||
|
|
||||||
|
equal(el.find('[name="checkbox1"]').first().is(":checked"), false)
|
||||||
|
equal(el.find('[name="checkbox1"]').last().is(":checked"), false)
|
||||||
|
equal(el.find('[name="checkbox2"]').is(":checked"), true)
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("form params check", function() {
|
test("form params check", function() {
|
||||||
|
@ -134,6 +142,11 @@ test("form params check", function() {
|
||||||
date3: '2015-01-11',
|
date3: '2015-01-11',
|
||||||
active1: true,
|
active1: true,
|
||||||
active2: false,
|
active2: false,
|
||||||
|
checkbox1: [],
|
||||||
|
checkbox2: undefined,
|
||||||
|
checkbox3: 'd',
|
||||||
|
radiobox1: undefined,
|
||||||
|
radiobox2: 'a',
|
||||||
}
|
}
|
||||||
new App.ControllerForm({
|
new App.ControllerForm({
|
||||||
el: el,
|
el: el,
|
||||||
|
@ -155,24 +168,30 @@ test("form params check", function() {
|
||||||
{ name: 'selectmultioption2', display: 'SelectMultiOption2', tag: 'select', null: false, multiple: true, options: [{ value: true, name: 'A' }, { value: 1, name: 'B'}, { value: false, name: 'C' }] },
|
{ name: 'selectmultioption2', display: 'SelectMultiOption2', tag: 'select', null: false, multiple: true, options: [{ value: true, name: 'A' }, { value: 1, name: 'B'}, { value: false, name: 'C' }] },
|
||||||
{ name: 'autocompletion1', display: 'AutoCompletion1', tag: 'autocompletion', null: false, options: { true: 'internal', false: 'public' }, source: [ { label: "Choice1", value: "value1", id: "id1" }, { label: "Choice2", value: "value2", id: "id2" }, ], minLength: 1 },
|
{ name: 'autocompletion1', display: 'AutoCompletion1', tag: 'autocompletion', null: false, options: { true: 'internal', false: 'public' }, source: [ { label: "Choice1", value: "value1", id: "id1" }, { label: "Choice2", value: "value2", id: "id2" }, ], minLength: 1 },
|
||||||
{ name: 'autocompletion2', display: 'AutoCompletion2', tag: 'autocompletion', null: false, options: { true: 'internal', false: 'public' }, source: [ { label: "Choice1", value: "value1", id: "id1" }, { label: "Choice2", value: "value2", id: "id2" }, ], minLength: 1 },
|
{ name: 'autocompletion2', display: 'AutoCompletion2', tag: 'autocompletion', null: false, options: { true: 'internal', false: 'public' }, source: [ { label: "Choice1", value: "value1", id: "id1" }, { label: "Choice2", value: "value2", id: "id2" }, ], minLength: 1 },
|
||||||
{ name: 'richtext1', display: 'Richtext1', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: true, upload: true, default: defaults['richtext1'] },
|
{ name: 'richtext1', display: 'Richtext1', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: true, upload: true, default: defaults['richtext1'] },
|
||||||
{ name: 'richtext2', display: 'Richtext2', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: true, upload: true, default: defaults['richtext2'] },
|
{ name: 'richtext2', display: 'Richtext2', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: true, upload: true, default: defaults['richtext2'] },
|
||||||
{ name: 'richtext3', display: 'Richtext3', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: false, default: defaults['richtext3'] },
|
{ name: 'richtext3', display: 'Richtext3', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: false, default: defaults['richtext3'] },
|
||||||
{ name: 'richtext4', display: 'Richtext4', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: false, default: defaults['richtext4'] },
|
{ name: 'richtext4', display: 'Richtext4', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: false, default: defaults['richtext4'] },
|
||||||
{ name: 'richtext5', display: 'Richtext5', tag: 'richtext', maxlength: 100, null: true, type: 'textonly', multiline: true, upload: true, default: defaults['richtext5'] },
|
{ name: 'richtext5', display: 'Richtext5', tag: 'richtext', maxlength: 100, null: true, type: 'textonly', multiline: true, upload: true, default: defaults['richtext5'] },
|
||||||
{ name: 'richtext6', display: 'Richtext6', tag: 'richtext', maxlength: 100, null: true, type: 'textonly', multiline: true, upload: true, default: defaults['richtext6'] },
|
{ name: 'richtext6', display: 'Richtext6', tag: 'richtext', maxlength: 100, null: true, type: 'textonly', multiline: true, upload: true, default: defaults['richtext6'] },
|
||||||
{ name: 'richtext7', display: 'Richtext7', tag: 'richtext', maxlength: 100, null: true, type: 'textonly', multiline: false, default: defaults['richtext7'] },
|
{ name: 'richtext7', display: 'Richtext7', tag: 'richtext', maxlength: 100, null: true, type: 'textonly', multiline: false, default: defaults['richtext7'] },
|
||||||
{ name: 'richtext8', display: 'Richtext8', tag: 'richtext', maxlength: 100, null: true, type: 'textonly', multiline: false, default: defaults['richtext8'] },
|
{ name: 'richtext8', display: 'Richtext8', tag: 'richtext', maxlength: 100, null: true, type: 'textonly', multiline: false, default: defaults['richtext8'] },
|
||||||
{ name: 'datetime1', display: 'Datetime1', tag: 'datetime', null: true, default: defaults['datetime1'] },
|
{ name: 'datetime1', display: 'Datetime1', tag: 'datetime', null: true, default: defaults['datetime1'] },
|
||||||
{ name: 'datetime2', display: 'Datetime2', tag: 'datetime', null: true, default: defaults['datetime2'] },
|
{ name: 'datetime2', display: 'Datetime2', tag: 'datetime', null: true, default: defaults['datetime2'] },
|
||||||
{ name: 'datetime3', display: 'Datetime3', tag: 'datetime', null: false, default: defaults['datetime3'] },
|
{ name: 'datetime3', display: 'Datetime3', tag: 'datetime', null: false, default: defaults['datetime3'] },
|
||||||
{ name: 'datetime4', display: 'Datetime4', tag: 'datetime', null: false, default: defaults['datetime4'] },
|
{ name: 'datetime4', display: 'Datetime4', tag: 'datetime', null: false, default: defaults['datetime4'] },
|
||||||
{ name: 'date1', display: 'Date1', tag: 'date', null: true, default: defaults['date1'] },
|
{ name: 'date1', display: 'Date1', tag: 'date', null: true, default: defaults['date1'] },
|
||||||
{ name: 'date2', display: 'Date2', tag: 'date', null: true, default: defaults['date2'] },
|
{ name: 'date2', display: 'Date2', tag: 'date', null: true, default: defaults['date2'] },
|
||||||
{ name: 'date3', display: 'Date3', tag: 'date', null: false, default: defaults['date3'] },
|
{ name: 'date3', display: 'Date3', tag: 'date', null: false, default: defaults['date3'] },
|
||||||
{ name: 'date4', display: 'Date4', tag: 'date', null: false, default: defaults['date4'] },
|
{ name: 'date4', display: 'Date4', tag: 'date', null: false, default: defaults['date4'] },
|
||||||
{ name: 'active1', display: 'Active1', tag: 'active', default: defaults['active1'] },
|
{ name: 'active1', display: 'Active1', tag: 'active', default: defaults['active1'] },
|
||||||
{ name: 'active2', display: 'Active2', tag: 'active', default: defaults['active2'] },
|
{ name: 'active2', display: 'Active2', tag: 'active', default: defaults['active2'] },
|
||||||
|
{ name: 'checkbox1', display: 'Checkbox1', tag: 'checkbox', null: false, default: defaults['checkbox1'], options: { a: 'AA', b: 'BB' } },
|
||||||
|
{ name: 'checkbox2', display: 'Checkbox2', tag: 'checkbox', null: false, default: defaults['checkbox2'], options: { 1: '11' } },
|
||||||
|
{ name: 'checkbox3', display: 'Checkbox3', tag: 'checkbox', null: false, default: defaults['checkbox3'], options: { c: 'CC', d: 'DD' } },
|
||||||
|
{ name: 'checkbox4', display: 'Checkbox4', tag: 'checkbox', null: false, default: defaults['checkbox4'], options: { aa: 'AA', bb: 'BB' } },
|
||||||
|
{ name: 'radiobox1', display: 'Radiobox1', tag: 'radio', null: false, default: defaults['radiobox1'], options: { a: 'AA', b: 'BB' } },
|
||||||
|
{ name: 'radiobox2', display: 'Radiobox2', tag: 'radio', null: false, default: defaults['radiobox2'], options: { a: '11' } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
params: defaults,
|
params: defaults,
|
||||||
|
@ -271,6 +290,12 @@ test("form params check", function() {
|
||||||
date4: undefined,
|
date4: undefined,
|
||||||
active1: true,
|
active1: true,
|
||||||
active2: false,
|
active2: false,
|
||||||
|
checkbox1: [],
|
||||||
|
checkbox2: undefined,
|
||||||
|
checkbox3: 'd',
|
||||||
|
checkbox4: [],
|
||||||
|
radiobox1: undefined,
|
||||||
|
radiobox2: 'a',
|
||||||
}
|
}
|
||||||
deepEqual(params, test_params, 'form param check')
|
deepEqual(params, test_params, 'form param check')
|
||||||
|
|
||||||
|
|
|
@ -229,6 +229,19 @@ RSpec.shared_examples 'HasGroups' do
|
||||||
described_class.group_through.klass.count
|
described_class.group_through.klass.count
|
||||||
}.by(3)
|
}.by(3)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'allows empty Hash value' do
|
||||||
|
group_access_instance.group_names_access_map = {
|
||||||
|
group_full.name => 'full',
|
||||||
|
group_read.name => %w[read change],
|
||||||
|
}
|
||||||
|
|
||||||
|
expect do
|
||||||
|
group_access_instance.group_names_access_map = {}
|
||||||
|
end.to change {
|
||||||
|
described_class.group_through.klass.count
|
||||||
|
}.by(-3)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'new instance' do
|
context 'new instance' do
|
||||||
|
@ -256,6 +269,16 @@ RSpec.shared_examples 'HasGroups' do
|
||||||
described_class.group_through.klass.count
|
described_class.group_through.klass.count
|
||||||
}.by(2)
|
}.by(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'allows empty Hash value' do
|
||||||
|
expect do
|
||||||
|
new_group_access_instance.group_names_access_map = {}
|
||||||
|
|
||||||
|
new_group_access_instance.save
|
||||||
|
end.not_to change {
|
||||||
|
described_class.group_through.klass.count
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -284,6 +307,18 @@ RSpec.shared_examples 'HasGroups' do
|
||||||
|
|
||||||
expect(group_access_instance_inactive.group_names_access_map).to be_empty
|
expect(group_access_instance_inactive.group_names_access_map).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns empty map if none is stored' do
|
||||||
|
|
||||||
|
group_access_instance.group_names_access_map = {
|
||||||
|
group_full.name => 'full',
|
||||||
|
group_read.name => 'read',
|
||||||
|
}
|
||||||
|
|
||||||
|
group_access_instance.group_names_access_map = {}
|
||||||
|
|
||||||
|
expect(group_access_instance.group_names_access_map).to be_blank
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context '#group_ids_access_map=' do
|
context '#group_ids_access_map=' do
|
||||||
|
@ -305,7 +340,7 @@ RSpec.shared_examples 'HasGroups' do
|
||||||
}.by(2)
|
}.by(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'stores Hash with String values' do
|
it 'stores Hash with Array<String> values' do
|
||||||
expect do
|
expect do
|
||||||
group_access_instance.group_ids_access_map = {
|
group_access_instance.group_ids_access_map = {
|
||||||
group_full.id => 'full',
|
group_full.id => 'full',
|
||||||
|
@ -315,6 +350,19 @@ RSpec.shared_examples 'HasGroups' do
|
||||||
described_class.group_through.klass.count
|
described_class.group_through.klass.count
|
||||||
}.by(3)
|
}.by(3)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'allows empty Hash value' do
|
||||||
|
group_access_instance.group_ids_access_map = {
|
||||||
|
group_full.id => 'full',
|
||||||
|
group_read.id => %w[read change],
|
||||||
|
}
|
||||||
|
|
||||||
|
expect do
|
||||||
|
group_access_instance.group_ids_access_map = {}
|
||||||
|
end.to change {
|
||||||
|
described_class.group_through.klass.count
|
||||||
|
}.by(-3)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'new instance' do
|
context 'new instance' do
|
||||||
|
@ -342,6 +390,16 @@ RSpec.shared_examples 'HasGroups' do
|
||||||
described_class.group_through.klass.count
|
described_class.group_through.klass.count
|
||||||
}.by(2)
|
}.by(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'allows empty Hash value' do
|
||||||
|
expect do
|
||||||
|
new_group_access_instance.group_ids_access_map = {}
|
||||||
|
|
||||||
|
new_group_access_instance.save
|
||||||
|
end.not_to change {
|
||||||
|
described_class.group_through.klass.count
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -370,6 +428,18 @@ RSpec.shared_examples 'HasGroups' do
|
||||||
|
|
||||||
expect(group_access_instance_inactive.group_ids_access_map).to be_empty
|
expect(group_access_instance_inactive.group_ids_access_map).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns empty map if none is stored' do
|
||||||
|
|
||||||
|
group_access_instance.group_ids_access_map = {
|
||||||
|
group_full.id => 'full',
|
||||||
|
group_read.id => 'read',
|
||||||
|
}
|
||||||
|
|
||||||
|
group_access_instance.group_ids_access_map = {}
|
||||||
|
|
||||||
|
expect(group_access_instance.group_ids_access_map).to be_blank
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context '#associations_from_param' do
|
context '#associations_from_param' do
|
||||||
|
|
Loading…
Reference in a new issue