Sha256: 28694201751eab095f533bbf0fd2fcc05d45400c60f18b023777b9867f707098

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

require_relative "helper"

class SettingsTest < Minitest::Test
  def setup
    @app = Class.new(Tynn)
  end

  def test_set_and_get
    @app.set(:foo, "foo")

    assert_equal "foo", @app.settings[:foo]
  end

  def test_set_hash
    @app.set(:foo, bar: "bar")

    assert_equal "bar", @app.settings[:foo][:bar]
  end

  def test_set_hash_with_merge
    @app.set(:foo, foo: "foo", bar: "bar")
    @app.set(:foo, bar: "foo", baz: "baz")

    assert_equal "foo", @app.settings[:foo][:foo]
    assert_equal "foo", @app.settings[:foo][:bar]
    assert_equal "baz", @app.settings[:foo][:baz]
  end

  def test_set_hash_without_merge
    @app.set(:foo, bar: "bar")
    @app.set!(:foo, baz: "baz")

    assert_equal nil, @app.settings[:foo][:bar]
    assert_equal "baz", @app.settings[:foo][:baz]
  end

  def test_inheritance
    @app.set(:foo, "foo")

    @child1 = Class.new(@app)
    @child2 = Class.new(@child1)

    assert_equal "foo", @child1.settings[:foo]
    assert_equal "foo", @child2.settings[:foo]

    @child2.set(:foo, "bar")

    assert_equal "foo", @child1.settings[:foo]
    assert_equal "bar", @child2.settings[:foo]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tynn-2.0.0.alpha test/settings_test.rb