# frozen_string_literal: true

require 'test_helper'

module Upgrow
  class SchemaTest < ActiveSupport::TestCase
    setup do
      @schema = Schema.new(:name, :email)
    end

    test '#attribute_names is empty by default' do
      assert_empty Schema.new.attribute_names
    end

    test '#attribute_names returns the values from the Schema initialization' do
      assert_equal [:name, :email], @schema.attribute_names
    end

    test '#attribute_names ignores duplicates' do
      schema = Schema.new(:name, :email, :name)
      assert_equal [:name, :email], schema.attribute_names
    end

    test '#attribute defines an extra attribute' do
      @schema.attribute(:phone)

      assert_equal [:name, :email, :phone], @schema.attribute_names
    end

    test '#attribute does not define the same attribute twice' do
      @schema.attribute(:name)

      assert_equal [:name, :email], @schema.attribute_names
    end

    test '#dup creates a Schema with independent attribute names' do
      new_schema = @schema.dup
      new_schema.attribute(:phone)

      assert_equal [:name, :email], @schema.attribute_names
      assert_equal [:name, :email, :phone], new_schema.attribute_names
    end
  end
end