<commit_before>require 'test_helper'


class ChangeProjectToProjectsTest < ActionController::IntegrationTest
  ASSETS_WITH_MULTIPLE_PROJECTS = %w[data_files events investigations models publications sops samples specimens presentations]

  def setup
    User.current_user = Factory(:user, :login => 'test')
    post '/sessions/create', :login => 'test', :password => '<PASSWORD>'
    @is_vl=Seek::Config.is_virtualliver
    Seek::Config.is_virtualliver = true
  end

  def teardown
    Seek::Config.is_virtualliver=@is_vl
  end

  test 'form allows setting project_ids' do
    #TODO: update publications edit/new
    ASSETS_WITH_MULTIPLE_PROJECTS.each do |type_name|
      p type_name
      p 'new'
      get "/#{type_name}/new"
      assert_select "form select[name=?]", "#{type_name.singularize}[project_ids][]"

      p 'edit'
      get "/#{type_name}/#{Factory(type_name.singularize.to_sym, :policy => Factory(:public_policy)).id}/edit"
        assert_select "form select[name=?]", "#{type_name.singularize}[project_ids][]"
    end
  end

  test 'choosing my project in the sharing form adds permissions for each project' do
    #publications are skipped, because they don't have a sharing form
    ASSETS_WITH_MULTIPLE_PROJECTS.reject { |t| t=='publications' }.each do |type_name|
      p type_name
      item = Factory(type_name.singularize.to_sym, :contributor => User.current_user)
      item.projects = [Factory(:project), Factory(:project)]

      post "/#{type_name}/update/#{item.id}", :sharing=>{"access_type_#{Policy::ALL_SYSMO_USERS}"=>Policy::VISIBLE, :sharing_scope=>Policy::ALL_SYSMO_USERS, :your_proj_access_type => Policy::ACCESSIBLE}
      item.reload
      assert_equal 2, item.policy.permissions.count
    end
  end
end<commit_msg>removed debugging puts' from test<commit_after>require 'test_helper'


class ChangeProjectToProjectsTest < ActionController::IntegrationTest
  ASSETS_WITH_MULTIPLE_PROJECTS = %w[data_files events investigations models publications sops samples specimens presentations]

  def setup
    User.current_user = Factory(:user, :login => 'test')
    post '/sessions/create', :login => 'test', :password => '<PASSWORD>'
    @is_vl=Seek::Config.is_virtualliver
    Seek::Config.is_virtualliver = true
  end

  def teardown
    Seek::Config.is_virtualliver=@is_vl
  end

  test 'form allows setting project_ids' do
    #TODO: update publications edit/new
    ASSETS_WITH_MULTIPLE_PROJECTS.each do |type_name|
      get "/#{type_name}/new"
      assert_select "form select[name=?]", "#{type_name.singularize}[project_ids][]"

      get "/#{type_name}/#{Factory(type_name.singularize.to_sym, :policy => Factory(:public_policy)).id}/edit"
        assert_select "form select[name=?]", "#{type_name.singularize}[project_ids][]"
    end
  end

  test 'choosing my project in the sharing form adds permissions for each project' do
    #publications are skipped, because they don't have a sharing form
    ASSETS_WITH_MULTIPLE_PROJECTS.reject { |t| t=='publications' }.each do |type_name|
      item = Factory(type_name.singularize.to_sym, :contributor => User.current_user)
      item.projects = [Factory(:project), Factory(:project)]

      post "/#{type_name}/update/#{item.id}", :sharing=>{"access_type_#{Policy::ALL_SYSMO_USERS}"=>Policy::VISIBLE, :sharing_scope=>Policy::ALL_SYSMO_USERS, :your_proj_access_type => Policy::ACCESSIBLE}
      item.reload
      assert_equal 2, item.policy.permissions.count
    end
  end
end
{'fraction_non_alphanumeric': 0.12330349408027722, 'fraction_numerical': 0.0005775339301183945, 'mean_word_length': 4.725619834710744, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, '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': '3221271', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1102, 'n_words': 239}