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_double_enable_a_group_without_error ⇒ Object
- #test_can_double_enable_an_actor_without_error ⇒ Object
- #test_can_double_enable_percentage_without_error ⇒ Object
- #test_can_double_enable_without_error ⇒ 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_expression_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_all_features ⇒ Object
- #test_can_get_all_features_when_there_are_none ⇒ Object
- #test_can_get_multiple_features ⇒ Object
- #test_can_import_and_export ⇒ Object
- #test_clears_all_the_gate_values_for_the_feature_on_remove ⇒ Object
- #test_clears_other_gate_values_on_enable ⇒ 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_includes_explicitly_disabled_features_when_getting_all_features ⇒ Object
- #test_knows_how_to_get_adapter_from_source ⇒ 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) @feature = @flipper[:stats] @boolean_gate = @feature.gate(:boolean) @group_gate = @feature.gate(:group) @expression_gate = @feature.gate(:expression) @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) do |actor| actor.respond_to?(:early_access?) && actor.early_access? end 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
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 205 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
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 234 def test_can_clear_all_the_gate_values_for_a_feature actor22 = Flipper::Actor.new('22') @adapter.add(@feature) assert_includes @adapter.features, @feature.key assert_equal true, @adapter.enable(@feature, @boolean_gate, Flipper::Types::Boolean.new) assert_equal true, @adapter.enable(@feature, @group_gate, @flipper.group(:admins)) assert_equal true, @adapter.enable(@feature, @actor_gate, Flipper::Types::Actor.new(actor22)) assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(25)) assert_equal true, @adapter.enable(@feature, @time_gate, Flipper::Types::PercentageOfTime.new(45)) assert_equal true, @adapter.clear(@feature) assert_includes @adapter.features, @feature.key assert_equal @adapter.default_config, @adapter.get(@feature) end |
#test_can_disable_percentage_of_actors_gate_many_times_and_consistently_return_values ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 140 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::Types::PercentageOfActors.new(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
166 167 168 169 170 171 172 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 166 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::Types::PercentageOfTime.new(percentage)) result = @adapter.get(@feature) assert_equal percentage.to_s, result[:percentage_of_time] end end |
#test_can_double_enable_a_group_without_error ⇒ Object
300 301 302 303 304 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 300 def test_can_double_enable_a_group_without_error assert_equal true, @adapter.enable(@feature, @group_gate, @flipper.group(:admins)) assert_equal true, @adapter.enable(@feature, @group_gate, @flipper.group(:admins)) assert_equal Set['admins'], @adapter.get(@feature).fetch(:groups) end |
#test_can_double_enable_an_actor_without_error ⇒ Object
293 294 295 296 297 298 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 293 def test_can_double_enable_an_actor_without_error actor = Flipper::Actor.new('Flipper::Actor;22') assert_equal true, @feature.enable(actor) assert_equal true, @feature.enable(actor) assert @feature.enabled?(actor) end |
#test_can_double_enable_percentage_without_error ⇒ Object
306 307 308 309 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 306 def test_can_double_enable_percentage_without_error assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(25)) assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(25)) end |
#test_can_double_enable_without_error ⇒ Object
311 312 313 314 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 311 def test_can_double_enable_without_error assert_equal true, @adapter.enable(@feature, @boolean_gate, Flipper::Types::Boolean.new) assert_equal true, @adapter.enable(@feature, @boolean_gate, Flipper::Types::Boolean.new) end |
#test_can_enable_disable_and_get_value_for_an_actor_gate ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 103 def test_can_enable_disable_and_get_value_for_an_actor_gate actor22 = Flipper::Actor.new('22') actor_asdf = Flipper::Actor.new('asdf') assert_equal true, @feature.enable(actor22) assert_equal true, @feature.enable(actor_asdf) assert @feature.enabled?(actor22) assert @feature.enabled?(actor_asdf) assert_equal true, @feature.disable(actor22) refute @feature.enabled?(actor22) assert @feature.enabled?(actor_asdf) assert_equal true, @feature.disable(actor_asdf) refute @feature.enabled?(actor22) refute @feature.enabled?(actor_asdf) end |
#test_can_enable_disable_and_get_value_for_boolean_gate ⇒ Object
51 52 53 54 55 56 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 51 def test_can_enable_disable_and_get_value_for_boolean_gate assert_equal true, @adapter.enable(@feature, @boolean_gate, Flipper::Types::Boolean.new) assert_equal 'true', @adapter.get(@feature)[:boolean] assert_equal true, @adapter.disable(@feature, @boolean_gate, Flipper::Types::Boolean.new(false)) assert_nil @adapter.get(@feature)[:boolean] end |
#test_can_enable_disable_and_get_value_for_expression_gate ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 69 def test_can_enable_disable_and_get_value_for_expression_gate basic_expression = Flipper.property(:plan).eq("basic") age_expression = Flipper.property(:age).gte(21) any_expression = Flipper.any(basic_expression, age_expression) assert_equal true, @adapter.enable(@feature, @expression_gate, any_expression) result = @adapter.get(@feature) assert_equal any_expression.value, result[:expression] assert_equal true, @adapter.enable(@feature, @expression_gate, basic_expression) result = @adapter.get(@feature) assert_equal basic_expression.value, result[:expression] assert_equal true, @adapter.disable(@feature, @expression_gate, basic_expression) result = @adapter.get(@feature) assert_nil result[:expression] end |
#test_can_enable_disable_and_get_value_for_percentage_of_time_gate ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 148 def test_can_enable_disable_and_get_value_for_percentage_of_time_gate assert_equal true, @adapter.enable(@feature, @time_gate, Flipper::Types::PercentageOfTime.new(10)) result = @adapter.get(@feature) assert_equal '10', result[:percentage_of_time] assert_equal true, @adapter.disable(@feature, @time_gate, Flipper::Types::PercentageOfTime.new(0)) result = @adapter.get(@feature) assert_equal '0', result[:percentage_of_time] end |
#test_can_enable_disable_get_value_for_group_gate ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 87 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
122 123 124 125 126 127 128 129 130 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 122 def test_can_enable_disable_get_value_for_percentage_of_actors_gate assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(15)) result = @adapter.get(@feature) assert_equal '15', result[:percentage_of_actors] assert_equal true, @adapter.disable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(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
132 133 134 135 136 137 138 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 132 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::Types::PercentageOfActors.new(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
158 159 160 161 162 163 164 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 158 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::Types::PercentageOfTime.new(percentage)) result = @adapter.get(@feature) assert_equal percentage.to_s, result[:percentage_of_time] end end |
#test_can_get_all_features ⇒ Object
270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 270 def test_can_get_all_features assert @adapter.add(@flipper[:stats]) assert @adapter.enable(@flipper[:stats], @boolean_gate, Flipper::Types::Boolean.new) assert @adapter.add(@flipper[:search]) @flipper.enable :analytics, Flipper.property(:plan).eq("pro") result = @adapter.get_all assert_instance_of Hash, result assert_equal @adapter.default_config.merge(boolean: 'true'), result["stats"] assert_equal @adapter.default_config, result["search"] assert_equal @adapter.default_config.merge(expression: {"Equal"=>[{"Property"=>["plan"]}, "pro"]}), result["analytics"] end |
#test_can_get_all_features_when_there_are_none ⇒ Object
316 317 318 319 320 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 316 def test_can_get_all_features_when_there_are_none expected = {} assert_equal Set.new, @adapter.features assert_equal expected, @adapter.get_all end |
#test_can_get_multiple_features ⇒ Object
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 254 def test_can_get_multiple_features assert @adapter.add(@flipper[:stats]) assert @adapter.enable(@flipper[:stats], @boolean_gate, Flipper::Types::Boolean.new) assert @adapter.add(@flipper[:search]) result = @adapter.get_multi([@flipper[:stats], @flipper[:search], @flipper[:other]]) assert_instance_of Hash, result stats = result["stats"] search = result["search"] other = result["other"] assert_equal @adapter.default_config.merge(boolean: 'true'), stats assert_equal @adapter.default_config, search assert_equal @adapter.default_config, other end |
#test_can_import_and_export ⇒ Object
332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 332 def test_can_import_and_export adapter = Flipper::Adapters::Memory.new source_flipper = Flipper.new(adapter) source_flipper.enable(:stats) export = adapter.export # some adapters cannot import so if they return false lets assert it # didn't happen if @adapter.import(export) assert @flipper[:stats].enabled? else refute @flipper[:stats].enabled? end end |
#test_clears_all_the_gate_values_for_the_feature_on_remove ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 221 def test_clears_all_the_gate_values_for_the_feature_on_remove actor22 = Flipper::Actor.new('22') assert_equal true, @adapter.enable(@feature, @boolean_gate, Flipper::Types::Boolean.new) assert_equal true, @adapter.enable(@feature, @group_gate, @flipper.group(:admins)) assert_equal true, @adapter.enable(@feature, @actor_gate, Flipper::Types::Actor.new(actor22)) assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(25)) assert_equal true, @adapter.enable(@feature, @time_gate, Flipper::Types::PercentageOfTime.new(45)) assert_equal true, @adapter.remove(@feature) assert_equal @adapter.default_config, @adapter.get(@feature) end |
#test_clears_other_gate_values_on_enable ⇒ Object
322 323 324 325 326 327 328 329 330 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 322 def test_clears_other_gate_values_on_enable actor = Flipper::Actor.new('Flipper::Actor;22') assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(25)) assert_equal true, @adapter.enable(@feature, @time_gate, Flipper::Types::PercentageOfTime.new(25)) assert_equal true, @adapter.enable(@feature, @group_gate, @flipper.group(:admins)) assert_equal true, @adapter.enable(@feature, @actor_gate, Flipper::Types::Actor.new(actor)) assert_equal true, @adapter.enable(@feature, @boolean_gate, Flipper::Types::Boolean.new(true)) assert_equal @adapter.default_config.merge(boolean: "true"), @adapter.get(@feature) end |
#test_converts_boolean_value_to_a_string ⇒ Object
174 175 176 177 178 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 174 def test_converts_boolean_value_to_a_string assert_equal true, @adapter.enable(@feature, @boolean_gate, Flipper::Types::Boolean.new) result = @adapter.get(@feature) assert_equal 'true', result[:boolean] end |
#test_converts_group_value_to_a_string ⇒ Object
187 188 189 190 191 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 187 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
199 200 201 202 203 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 199 def test_converts_percentage_of_actors_integer_value_to_a_string assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(10)) result = @adapter.get(@feature) assert_equal '10', result[:percentage_of_actors] end |
#test_converts_percentage_of_time_integer_value_to_a_string ⇒ Object
193 194 195 196 197 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 193 def test_converts_percentage_of_time_integer_value_to_a_string assert_equal true, @adapter.enable(@feature, @time_gate, Flipper::Types::PercentageOfTime.new(10)) result = @adapter.get(@feature) assert_equal '10', result[:percentage_of_time] end |
#test_converts_the_actor_value_to_a_string ⇒ Object
180 181 182 183 184 185 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 180 def test_converts_the_actor_value_to_a_string actor = Flipper::Actor.new(22) refute @feature.enabled?(actor) @feature.enable_actor actor assert @feature.enabled?(actor) end |
#test_does_not_complain_clearing_a_feature_that_does_not_exist_in_adapter ⇒ Object
250 251 252 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 250 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
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 58 def test_fully_disables_all_enabled_things_when_boolean_gate_disabled actor22 = Flipper::Actor.new('22') assert_equal true, @adapter.enable(@feature, @boolean_gate, Flipper::Types::Boolean.new) assert_equal true, @adapter.enable(@feature, @group_gate, @flipper.group(:admins)) assert_equal true, @adapter.enable(@feature, @actor_gate, Flipper::Types::Actor.new(actor22)) assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(25)) assert_equal true, @adapter.enable(@feature, @time_gate, Flipper::Types::PercentageOfTime.new(45)) assert_equal true, @adapter.disable(@feature, @boolean_gate, Flipper::Types::Boolean.new(false)) assert_equal @adapter.default_config, @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_includes_explicitly_disabled_features_when_getting_all_features ⇒ Object
284 285 286 287 288 289 290 291 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 284 def test_includes_explicitly_disabled_features_when_getting_all_features @flipper.enable(:stats) @flipper.enable(:search) @flipper.disable(:search) result = @adapter.get_all assert_equal %w(search stats), result.keys.sort end |
#test_knows_how_to_get_adapter_from_source ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 38 def test_knows_how_to_get_adapter_from_source adapter = Flipper::Adapters::Memory.new flipper = Flipper.new(adapter) assert_includes adapter.class.from(adapter).class.ancestors, Flipper::Adapter assert_includes adapter.class.from(flipper).class.ancestors, Flipper::Adapter end |
#test_returns_correct_default_values_for_gates_if_none_are_enabled ⇒ Object
46 47 48 49 |
# File 'lib/flipper/test/shared_adapter_test.rb', line 46 def test_returns_correct_default_values_for_gates_if_none_are_enabled assert_equal @adapter.class.default_config, @adapter.get(@feature) assert_equal @adapter.default_config, @adapter.get(@feature) end |