<commit_before>require 'test_helper'

class MultiVersionTest < Zena::Unit::TestCase

  def defaults
    { :name => 'hello',
      :parent_id => nodes_id(:zena) }
  end

  context 'A visitor without write access' do
    setup do
      login(:anon)
    end

    should 'see a publication in her language' do
      node = secure!(Node) { nodes(:opening) }
      assert_equal versions_id(:opening_en), node.version.id
    end

    should 'see a publication in the selected language' do
      visitor.lang = 'fr'
      node = secure!(Node) { nodes(:opening) }
      assert_equal versions_id(:opening_fr), node.version.id
    end

    should 'see a publication in the reference lang if there are none for the current language' do
      visitor.lang = 'de'
      node = secure!(Node) { nodes(:opening) }
      assert_equal 'fr', node.ref_lang
      assert_equal versions_id(:opening_fr), node.version.id
    end

    context 'when there is only a redaction for the current language' do
      setup do
        login(:tiger)
        visitor.lang = 'fr'
        version = secure!(Version) { versions(:opening_fr) }
        node = version.node
        assert node.destroy_version
        assert_equal [:opening_red_fr, :opening_en].map{|s| versions_id(s)}.sort, node.versions.map{|v| v.id}.sort
        login(:anon)
      end

      should 'see a default publication' do
        node = secure!(Node) { nodes(:opening) }
        assert_equal versions_id(:opening_en), node.version.id
      end
    end
  end # A visitor without write access

  context 'A visitor with write access' do
    setup do

    end

    should 'description' do

    end
  end

  context 'A visitor with read and drive access' do
    setup do

    end

    should 'description' do

    end
  end


  def test_find_version
    login(:tiger) # can_drive
    node = secure!(Node) { nodes(:lake) }<commit_msg>Started to write version finding rules in multiversion_test.<commit_after>require 'test_helper'

class MultiVersionTest < Zena::Unit::TestCase

  def defaults
    { :name => 'hello',
      :parent_id => nodes_id(:zena) }
  end

  # =========== FIND VERSION TESTS =============

  context 'A visitor without write access' do
    setup do
      login(:anon)
    end

    should 'see a publication in her language' do
      node = secure!(Node) { nodes(:opening) }
      assert_equal versions_id(:opening_en), node.version.id
    end

    should 'see a publication in the selected language' do
      visitor.lang = 'fr'
      node = secure!(Node) { nodes(:opening) }
      assert_equal versions_id(:opening_fr), node.version.id
    end

    should 'see a publication in the reference lang if there are none for the current language' do
      visitor.lang = 'de'
      node = secure!(Node) { nodes(:opening) }
      assert_equal 'fr', node.ref_lang
      assert_equal versions_id(:opening_fr), node.version.id
    end

    context 'when there is only a redaction for the current language' do
      setup do
        login(:tiger)
        version = secure!(Version) { versions(:opening_fr) }
        node = version.node
        assert node.destroy_version
        assert_equal [:opening_red_fr, :opening_en].map{|s| versions_id(s)}.sort, node.versions.map{|v| v.id}.sort
        login(:anon)
      end

      should 'see a default publication' do
        node = secure!(Node) { nodes(:opening) }
        assert_equal versions_id(:opening_en), node.version.id
      end
    end
  end # A visitor without write access

  context 'A visitor with write access' do
    setup do
      login(:ant)
    end

    should 'see a publication in the selected language' do
      visitor.lang = 'en'
      node = secure!(Node) { nodes(:opening) }
      assert_equal versions_id(:opening_en), node.version.id
    end

    should 'see a redaction in her language' do
      node = secure!(Node) { nodes(:opening) }
      assert_equal versions_id(:opening_red_fr), node.version.id
    end

    should 'see a publication in the reference lang if there are none for the current language' do
      visitor.lang = 'de'
      node = secure!(Node) { nodes(:opening) }
      assert_equal 'fr', node.ref_lang
      assert_equal versions_id(:opening_fr), node.version.id
    end

    context 'in a language not supported' do
      setup do
        login(:tiger)
        version = secure!(Version) { versions(:opening_fr) }
        node = version.node
        assert node.destroy_version
        assert_equal [:opening_red_fr, :opening_en].map{|s| versions_id(s)}.sort, node.versions.map{|v| v.id}.sort
        login(:ant)
      end

      should 'see any publication if there are none for the current language and the reference language' do
        visitor.lang = 'de'
        node = secure!(Node) { nodes(:opening) }
        assert_equal versions_id(:opening_en), node.version.id
      end
    end

    should 'see a redaction if there are no publications' do
      visitor.lang = 'de'
      node = secure!(Node) { nodes(:crocodiles) }
      assert_equal versions_id(:crocodiles_en), node.version.id
    end
  end # A visitor with write access


  # =========== UPDATE VERSION TESTS =============


  # =========== OLD TESTS TO REWRITE =============

  def test_find_version
    login(:tiger) # can_drive
    node = secure!(Node) { nodes(:lake) }
{'fraction_non_alphanumeric': 0.10814393939393939, 'fraction_numerical': 0.0, 'mean_word_length': 2.8047550432276656, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '7224655', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1528, 'n_words': 485}