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_can_get_multiple_features ⇒ 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 23 24 25 26 27 28 29 30 |
# 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) @default_config = { :boolean => nil, :groups => Set.new, :actors => Set.new, :percentage_of_actors => nil, :percentage_of_time => nil, } 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
32 33 34 35 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 32 def teardown super Flipper.unregister_groups end |
#test_can_add_remove_and_list_known_features ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 185 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
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 214 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 @default_config, @adapter.get(@feature) end |
#test_can_disable_percentage_of_actors_gate_many_times_and_consistently_return_values ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 121 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
147 148 149 150 151 152 153 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 147 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
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 84 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
50 51 52 53 54 55 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 50 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
129 130 131 132 133 134 135 136 137 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 129 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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 68 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
103 104 105 106 107 108 109 110 111 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 103 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
113 114 115 116 117 118 119 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 113 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
139 140 141 142 143 144 145 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 139 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_can_get_multiple_features ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 234 def test_can_get_multiple_features assert @adapter.add(@flipper[:stats]) assert @adapter.enable(@flipper[:stats], @boolean_gate, @flipper.boolean) assert @adapter.add(@flipper[:search]) result = @adapter.get_multi([@flipper[:stats], @flipper[:search], @flipper[:other]]) assert_instance_of Hash, result stats, search, other = result.values assert_equal @default_config.merge(boolean: "true"), stats assert_equal @default_config, search assert_equal @default_config, other end |
#test_clears_all_the_gate_values_for_the_feature_on_remove ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 201 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 @default_config, @adapter.get(@feature) end |
#test_converts_boolean_value_to_a_string ⇒ Object
155 156 157 158 159 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 155 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
167 168 169 170 171 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 167 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
179 180 181 182 183 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 179 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
173 174 175 176 177 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 173 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
161 162 163 164 165 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 161 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
230 231 232 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 230 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
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 57 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)) assert_equal @default_config, @adapter.get(@feature) end |
#test_has_included_the_flipper_adapter_module ⇒ Object
42 43 44 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 42 def test_has_included_the_flipper_adapter_module assert_includes @adapter.class.ancestors, Flipper::Adapter end |
#test_has_name_that_is_a_symbol ⇒ Object
37 38 39 40 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 37 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
46 47 48 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 46 def test_returns_correct_default_values_for_gates_if_none_are_enabled assert_equal @default_config, @adapter.get(@feature) end |