<commit_before>require "test_helper"

class UnnestTest < MiniTest::Spec
  class Twin < Disposable::Twin
    property :content do
      property :id, nice: "yes"
      collection :ids, status: "healthy"

      property :email do
      end
    end

    unnest :id,    from: :content
    unnest :ids,   from: :content
    unnest :email, from: :content
  end

  it "copies property option" do
    Twin.definitions.get(:id).extend(Declarative::Inspect).inspect.must_equal %{#<Disposable::Twin::Definition: @options={:nice=>\"yes\", :private_name=>:id, :name=>\"id\", :readable=>false, :writeable=>false}>}
    Twin.definitions.get(:ids).extend(Declarative::Inspect).inspect.must_equal %{#<Disposable::Twin::Definition: @options={:status=>\"healthy\", :collection=>true, :private_name=>:ids, :name=>\"ids\", :readable=>false, :writeable=>false}>}
    # also copies :nested.
    Twin.definitions.get(:email).extend(Declarative::Inspect).inspect.must_equal %{#<Disposable::Twin::Definition: @options={:private_name=>:email, :nested=>#<Class:>, :name=>\"email\", :readable=>false, :writeable=>false}>}
  end
end<commit_msg>add test for unnest.<commit_after>require "test_helper"

class UnnestTest < MiniTest::Spec
  class Twin < Disposable::Twin
    property :content do
      property :id, nice: "yes"
      collection :ids, status: "healthy"

      property :email do
      end
    end

    unnest :id,    from: :content
    unnest :ids,   from: :content
    unnest :email, from: :content
  end

  it "copies property option" do
    Twin.definitions.get(:id).extend(Declarative::Inspect).inspect.must_equal %{#<Disposable::Twin::Definition: @options={:nice=>\"yes\", :private_name=>:id, :name=>\"id\", :readable=>false, :writeable=>false}>}
    Twin.definitions.get(:ids).extend(Declarative::Inspect).inspect.must_equal %{#<Disposable::Twin::Definition: @options={:status=>\"healthy\", :collection=>true, :private_name=>:ids, :name=>\"ids\", :readable=>false, :writeable=>false}>}
    # also copies :nested.
    Twin.definitions.get(:email).extend(Declarative::Inspect).inspect.must_equal %{#<Disposable::Twin::Definition: @options={:private_name=>:email, :nested=>#<Class:>, :name=>\"email\", :readable=>false, :writeable=>false}>}
  end

  it "exposes accessors on top-level twin" do
    twin = Twin.new(OpenStruct.new(content: OpenStruct.new()))

    twin.email.must_equal nil
    twin.email= 2
    twin.email.model.must_equal 2


    twin.id.must_equal nil
    twin.id = 1
    twin.id.must_equal 1
  end
end
{'fraction_non_alphanumeric': 0.1781150159744409, 'fraction_numerical': 0.001597444089456869, 'mean_word_length': 4.839160839160839, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3592957', 'n_tokens_mistral': 873, 'n_tokens_neox': 829, 'n_words': 163}