Skip to content

Commit 27fc51d

Browse files
committed
Fixed removing conditions in the UI where the value is the empty string
Fixes disqus#55. The API the frontend uses is untested, maybe some tests would have caught it.
1 parent b203c7a commit 27fc51d

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

HISTORY.rst

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Pending Release
1111
* Made ``gargoyle.register()`` usable as a decorator
1212
* Made ``gargoyle.unregister()`` return the boolean value of whether something
1313
was unregistered.
14+
* Fixed removing conditions where the value is the empty string.
1415

1516
1.2.5 (2016-05-09)
1617
------------------

gargoyle/nexus_modules.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def remove_condition(self, request):
276276
field_name = request.POST.get("field")
277277
value = request.POST.get("value")
278278

279-
if not all([key, condition_set_id, field_name, value]):
279+
if not all([key, condition_set_id, field_name]):
280280
raise GargoyleException("Fields cannot be empty")
281281

282282
switch = gargoyle[key]

tests/testapp/test_api.py

+17
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,23 @@ def test_remove_condition(self):
590590
assert not self.gargoyle.is_active('test', user5)
591591
assert not self.gargoyle.is_active('test', user8771)
592592

593+
def test_add_condition_empty(self):
594+
condition_set = 'gargoyle.builtins.UserConditionSet(auth.user)'
595+
596+
switch = Switch.objects.create(key='test', status=SELECTIVE)
597+
switch = self.gargoyle['test']
598+
599+
user_empty = User(email='')
600+
user_non_empty = User(email='[email protected]')
601+
switch.add_condition(
602+
condition_set=condition_set,
603+
field_name='email',
604+
condition='',
605+
)
606+
607+
assert self.gargoyle.is_active('test', user_empty)
608+
assert not self.gargoyle.is_active('test', user_non_empty)
609+
593610
def test_switch_defaults(self):
594611
"""Test that defaults pulled from GARGOYLE_SWITCH_DEFAULTS.
595612

0 commit comments

Comments
 (0)