Module: Flipper::Test::SharedAdapterTests
- Defined in:
- lib/flipper/test/shared_adapter_test.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #teardown ⇒ Object
- #test_can_add_remove_and_list_known_features ⇒ Object
- #test_can_clear_all_the_gate_values_for_a_feature ⇒ Object
- #test_can_disable_percentage_of_actors_gate_many_times_and_consistently_return_values ⇒ Object
- #test_can_disable_percentage_of_time_gate_many_times_and_consistently_return_values ⇒ Object
- #test_can_enable_disable_and_get_value_for_an_actor_gate ⇒ Object
- #test_can_enable_disable_and_get_value_for_boolean_gate ⇒ Object
- #test_can_enable_disable_and_get_value_for_percentage_of_time_gate ⇒ Object
- #test_can_enable_disable_get_value_for_group_gate ⇒ Object
- #test_can_enable_disable_get_value_for_percentage_of_actors_gate ⇒ Object
- #test_can_enable_percentage_of_actors_gate_many_times_and_consistently_return_values ⇒ Object
- #test_can_enable_percentage_of_time_gate_many_times_and_consistently_return_values ⇒ Object
- #test_clears_all_the_gate_values_for_the_feature_on_remove ⇒ Object
- #test_converts_boolean_value_to_a_string ⇒ Object
- #test_converts_group_value_to_a_string ⇒ Object
- #test_converts_percentage_of_actors_integer_value_to_a_string ⇒ Object
- #test_converts_percentage_of_time_integer_value_to_a_string ⇒ Object
- #test_converts_the_actor_value_to_a_string ⇒ Object
- #test_does_not_complain_clearing_a_feature_that_does_not_exist_in_adapter ⇒ Object
- #test_fully_disables_all_enabled_things_when_boolean_gate_disabled ⇒ Object
- #test_has_included_the_flipper_adapter_module ⇒ Object
- #test_has_name_that_is_a_symbol ⇒ Object
- #test_returns_correct_default_values_for_gates_if_none_are_enabled ⇒ Object
Instance Method Details
#setup ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 4 def setup super @flipper = Flipper.new(@adapter) @actor_class = Struct.new(:flipper_id) @feature = @flipper[:stats] @boolean_gate = @feature.gate(:boolean) @group_gate = @feature.gate(:group) @actor_gate = @feature.gate(:actor) @actors_gate = @feature.gate(:percentage_of_actors) @time_gate = @feature.gate(:percentage_of_time) Flipper.register(:admins) do |actor| actor.respond_to?(:admin?) && actor.admin? end Flipper.register(:early_access) { |actor| actor.respond_to?(:early_access?) && actor.early_access? } end |
#teardown ⇒ Object
24 25 26 27 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 24 def teardown super Flipper.unregister_groups end |
#test_can_add_remove_and_list_known_features ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 191 def test_can_add_remove_and_list_known_features assert_equal Set.new, @adapter.features assert_equal true, @adapter.add(@flipper[:stats]) assert_equal Set['stats'], @adapter.features assert_equal true, @adapter.add(@flipper[:search]) assert_equal Set['stats', 'search'], @adapter.features assert_equal true, @adapter.remove(@flipper[:stats]) assert_equal Set['search'], @adapter.features assert_equal true, @adapter.remove(@flipper[:search]) assert_equal Set.new, @adapter.features end |
#test_can_clear_all_the_gate_values_for_a_feature ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 226 def test_can_clear_all_the_gate_values_for_a_feature actor_22 = @actor_class.new('22') @adapter.add(@feature) assert_includes @adapter.features, @feature.key assert_equal true, @adapter.enable(@feature, @boolean_gate, @flipper.boolean) assert_equal true, @adapter.enable(@feature, @group_gate, @flipper.group(:admins)) assert_equal true, @adapter.enable(@feature, @actor_gate, @flipper.actor(actor_22)) assert_equal true, @adapter.enable(@feature, @actors_gate, @flipper.actors(25)) assert_equal true, @adapter.enable(@feature, @time_gate, @flipper.time(45)) assert_equal true, @adapter.clear(@feature) assert_includes @adapter.features, @feature.key assert_equal @adapter.get(@feature), { :boolean => nil, :groups => Set.new, :actors => Set.new, :percentage_of_actors => nil, :percentage_of_time => nil, } end |
#test_can_disable_percentage_of_actors_gate_many_times_and_consistently_return_values ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 127 def test_can_disable_percentage_of_actors_gate_many_times_and_consistently_return_values (1..100).each do |percentage| assert_equal true, @adapter.disable(@feature, @actors_gate, @flipper.actors(percentage)) result = @adapter.get(@feature) assert_equal percentage.to_s, result[:percentage_of_actors] end end |
#test_can_disable_percentage_of_time_gate_many_times_and_consistently_return_values ⇒ Object
153 154 155 156 157 158 159 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 153 def test_can_disable_percentage_of_time_gate_many_times_and_consistently_return_values (1..100).each do |percentage| assert_equal true, @adapter.disable(@feature, @time_gate, @flipper.time(percentage)) result = @adapter.get(@feature) assert_equal percentage.to_s, result[:percentage_of_time] end end |
#test_can_enable_disable_and_get_value_for_an_actor_gate ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 90 def test_can_enable_disable_and_get_value_for_an_actor_gate actor_22 = @actor_class.new('22') actor_asdf = @actor_class.new('asdf') assert_equal true, @adapter.enable(@feature, @actor_gate, @flipper.actor(actor_22)) assert_equal true, @adapter.enable(@feature, @actor_gate, @flipper.actor(actor_asdf)) result = @adapter.get(@feature) assert_equal Set['22', 'asdf'], result[:actors] assert true, @adapter.disable(@feature, @actor_gate, @flipper.actor(actor_22)) result = @adapter.get(@feature) assert_equal Set['asdf'], result[:actors] assert_equal true, @adapter.disable(@feature, @actor_gate, @flipper.actor(actor_asdf)) result = @adapter.get(@feature) assert_equal Set.new, result[:actors] end |
#test_can_enable_disable_and_get_value_for_boolean_gate ⇒ Object
49 50 51 52 53 54 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 49 def test_can_enable_disable_and_get_value_for_boolean_gate assert_equal true, @adapter.enable(@feature, @boolean_gate, @flipper.boolean) assert_equal 'true', @adapter.get(@feature)[:boolean] assert_equal true, @adapter.disable(@feature, @boolean_gate, @flipper.boolean(false)) assert_equal nil, @adapter.get(@feature)[:boolean] end |
#test_can_enable_disable_and_get_value_for_percentage_of_time_gate ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 135 def test_can_enable_disable_and_get_value_for_percentage_of_time_gate assert_equal true, @adapter.enable(@feature, @time_gate, @flipper.time(10)) result = @adapter.get(@feature) assert_equal '10', result[:percentage_of_time] assert_equal true, @adapter.disable(@feature, @time_gate, @flipper.time(0)) result = @adapter.get(@feature) assert_equal '0', result[:percentage_of_time] end |
#test_can_enable_disable_get_value_for_group_gate ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 74 def test_can_enable_disable_get_value_for_group_gate assert_equal true, @adapter.enable(@feature, @group_gate, @flipper.group(:admins)) assert_equal true, @adapter.enable(@feature, @group_gate, @flipper.group(:early_access)) result = @adapter.get(@feature) assert_equal Set['admins', 'early_access'], result[:groups] assert_equal true, @adapter.disable(@feature, @group_gate, @flipper.group(:early_access)) result = @adapter.get(@feature) assert_equal Set['admins'], result[:groups] assert_equal true, @adapter.disable(@feature, @group_gate, @flipper.group(:admins)) result = @adapter.get(@feature) assert_equal Set.new, result[:groups] end |
#test_can_enable_disable_get_value_for_percentage_of_actors_gate ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 109 def test_can_enable_disable_get_value_for_percentage_of_actors_gate assert_equal true, @adapter.enable(@feature, @actors_gate, @flipper.actors(15)) result = @adapter.get(@feature) assert_equal '15', result[:percentage_of_actors] assert_equal true, @adapter.disable(@feature, @actors_gate, @flipper.actors(0)) result = @adapter.get(@feature) assert_equal '0', result[:percentage_of_actors] end |
#test_can_enable_percentage_of_actors_gate_many_times_and_consistently_return_values ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 119 def test_can_enable_percentage_of_actors_gate_many_times_and_consistently_return_values (1..100).each do |percentage| assert_equal true, @adapter.enable(@feature, @actors_gate, @flipper.actors(percentage)) result = @adapter.get(@feature) assert_equal percentage.to_s, result[:percentage_of_actors] end end |
#test_can_enable_percentage_of_time_gate_many_times_and_consistently_return_values ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 145 def test_can_enable_percentage_of_time_gate_many_times_and_consistently_return_values (1..100).each do |percentage| assert_equal true, @adapter.enable(@feature, @time_gate, @flipper.time(percentage)) result = @adapter.get(@feature) assert_equal percentage.to_s, result[:percentage_of_time] end end |
#test_clears_all_the_gate_values_for_the_feature_on_remove ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 207 def test_clears_all_the_gate_values_for_the_feature_on_remove actor_22 = @actor_class.new('22') assert_equal true, @adapter.enable(@feature, @boolean_gate, @flipper.boolean) assert_equal true, @adapter.enable(@feature, @group_gate, @flipper.group(:admins)) assert_equal true, @adapter.enable(@feature, @actor_gate, @flipper.actor(actor_22)) assert_equal true, @adapter.enable(@feature, @actors_gate, @flipper.actors(25)) assert_equal true, @adapter.enable(@feature, @time_gate, @flipper.time(45)) assert_equal true, @adapter.remove(@feature) assert_equal @adapter.get(@feature), { :boolean => nil, :groups => Set.new, :actors => Set.new, :percentage_of_actors => nil, :percentage_of_time => nil, } end |
#test_converts_boolean_value_to_a_string ⇒ Object
161 162 163 164 165 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 161 def test_converts_boolean_value_to_a_string assert_equal true, @adapter.enable(@feature, @boolean_gate, @flipper.boolean) result = @adapter.get(@feature) assert_equal 'true', result[:boolean] end |
#test_converts_group_value_to_a_string ⇒ Object
173 174 175 176 177 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 173 def test_converts_group_value_to_a_string assert_equal true, @adapter.enable(@feature, @group_gate, @flipper.group(:admins)) result = @adapter.get(@feature) assert_equal Set['admins'], result[:groups] end |
#test_converts_percentage_of_actors_integer_value_to_a_string ⇒ Object
185 186 187 188 189 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 185 def test_converts_percentage_of_actors_integer_value_to_a_string assert_equal true, @adapter.enable(@feature, @actors_gate, @flipper.actors(10)) result = @adapter.get(@feature) assert_equal '10', result[:percentage_of_actors] end |
#test_converts_percentage_of_time_integer_value_to_a_string ⇒ Object
179 180 181 182 183 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 179 def test_converts_percentage_of_time_integer_value_to_a_string assert_equal true, @adapter.enable(@feature, @time_gate, @flipper.time(10)) result = @adapter.get(@feature) assert_equal '10', result[:percentage_of_time] end |
#test_converts_the_actor_value_to_a_string ⇒ Object
167 168 169 170 171 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 167 def test_converts_the_actor_value_to_a_string assert_equal true, @adapter.enable(@feature, @actor_gate, @flipper.actor(@actor_class.new(22))) result = @adapter.get(@feature) assert_equal Set['22'], result[:actors] end |
#test_does_not_complain_clearing_a_feature_that_does_not_exist_in_adapter ⇒ Object
248 249 250 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 248 def test_does_not_complain_clearing_a_feature_that_does_not_exist_in_adapter assert_equal true, @adapter.clear(@flipper[:stats]) end |
#test_fully_disables_all_enabled_things_when_boolean_gate_disabled ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 56 def test_fully_disables_all_enabled_things_when_boolean_gate_disabled actor_22 = @actor_class.new('22') assert_equal true, @adapter.enable(@feature, @boolean_gate, @flipper.boolean) assert_equal true, @adapter.enable(@feature, @group_gate, @flipper.group(:admins)) assert_equal true, @adapter.enable(@feature, @actor_gate, @flipper.actor(actor_22)) assert_equal true, @adapter.enable(@feature, @actors_gate, @flipper.actors(25)) assert_equal true, @adapter.enable(@feature, @time_gate, @flipper.time(45)) assert_equal true, @adapter.disable(@feature, @boolean_gate, @flipper.boolean(false)) expected = { :boolean => nil, :groups => Set.new, :actors => Set.new, :percentage_of_actors => nil, :percentage_of_time => nil, } assert_equal expected, @adapter.get(@feature) end |
#test_has_included_the_flipper_adapter_module ⇒ Object
34 35 36 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 34 def test_has_included_the_flipper_adapter_module assert_includes @adapter.class.ancestors, Flipper::Adapter end |
#test_has_name_that_is_a_symbol ⇒ Object
29 30 31 32 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 29 def test_has_name_that_is_a_symbol refute_empty @adapter.name assert_kind_of Symbol, @adapter.name end |
#test_returns_correct_default_values_for_gates_if_none_are_enabled ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 38 def test_returns_correct_default_values_for_gates_if_none_are_enabled expected = { :boolean => nil, :groups => Set.new, :actors => Set.new, :percentage_of_actors => nil, :percentage_of_time => nil, } assert_equal expected, @adapter.get(@feature) end |