Sha256: 5f5b37a02b44db7d80b8a57c6bf4fb406317c73f613639296460f14b4d96e193

Contents?: true

Size: 1.76 KB

Versions: 15

Compression:

Stored size: 1.76 KB

Contents

require 'test_helper'

class BindingTest < MiniTest::Spec
  Binding = Representable::Binding
  let (:render_nil_definition) { Representable::Definition.new(:song, :render_nil => true) }

  describe "#skipable_empty_value?" do
    let (:binding) { Binding.new(render_nil_definition) }

    # don't skip when present.
    it { binding.skipable_empty_value?("Disconnect, Disconnect").must_equal false }

    # don't skip when it's nil and render_nil: true
    it { binding.skipable_empty_value?(nil).must_equal false }

    # skip when nil and :render_nil undefined.
    it { Binding.new(Representable::Definition.new(:song)).skipable_empty_value?(nil).must_equal true }

    # don't skip when nil and :render_nil undefined.
    it { Binding.new(Representable::Definition.new(:song)).skipable_empty_value?("Fatal Flu").must_equal false }
  end


  describe "#default_for" do
    let (:definition) { Representable::Definition.new(:song, :default => "Insider") }
    let (:binding) { Binding.new(definition) }

    # return value when value present.
    it { binding.default_for("Black And Blue").must_equal "Black And Blue" }

    # return false when value false.
    it { binding.default_for(false).must_equal false }

    # return default when value nil.
    it { binding.default_for(nil).must_equal "Insider" }

    # return nil when value nil and render_nil: true.
    it { Binding.new(render_nil_definition).default_for(nil).must_equal nil }

    # return nil when value nil and render_nil: true, even when :default is set" do
    it { Binding.new(Representable::Definition.new(:song, :render_nil => true, :default => "The Quest")).default_for(nil).must_equal nil }

    # return nil if no :default
    it { Binding.new(Representable::Definition.new(:song)).default_for(nil).must_equal nil }
  end
end

Version data entries

15 entries across 11 versions & 1 rubygems

Version Path
representable-3.0.3 test/binding_test.rb
representable-3.0.2 test/binding_test.rb
representable-3.0.1 test/binding_test.rb
representable-3.0.0 test/binding_test.rb
representable-2.4.1 test/binding_test.rb
representable-2.4.1 test-with-deprecations/binding_test.rb
representable-2.4.0 test-with-deprecations/binding_test.rb
representable-2.4.0 test/binding_test.rb
representable-2.4.0.rc5 test/binding_test.rb
representable-2.4.0.rc5 test-with-deprecations/binding_test.rb
representable-2.4.0.rc4 test/binding_test.rb
representable-2.4.0.rc4 test-with-deprecations/binding_test.rb
representable-2.4.0.rc3 test/binding_test.rb
representable-2.4.0.rc2 test/binding_test.rb
representable-2.4.0.rc1 test/binding_test.rb