<commit_before>require 'test_helper'

class StudiesControllerTest < ActionController::TestCase

  fixtures :all

  include AuthenticatedTestHelper
  include RestTestCases

  def setup
    login_as(:quentin)
    @object=Factory :study, :policy => Factory(:public_policy)
  end

  test "should get index" do
    get :index
    assert_response :success
    assert_not_nil assigns(:studies)
  end
  
  def test_title
    get :index
    assert_select "title",:text=>/The Sysmo SEEK Studies.*/, :count=>1
  end

  test "should get show" do
    get :show, :id=>studies(:metabolomics_study)
    assert_response :success
    assert_not_nil assigns(:study)
  end

  test "should get new" do
    get :new
    assert_response :success
    assert_not_nil assigns(:study)
  end

  test "should get new with investigation predefined" do
    inv = investigations(:metabolomics_investigation)

    assert inv.can_edit?,"model owner should be able to edit this investigation"
    get :new, :investigation_id=>inv
    assert_response :success

    assert_select "select#project_id" do
      assert_select "option[selected='selected'][value=?]",inv.project.id
    end
    assert_select "select#study_investigation_id" do
      assert_select "option[selected='selected'][value=?]",inv.id
    end
  end

  test "should not allow linking to an investigation from a project you are not a member of" do
    login_as(:owner_of_my_first_sop)
    inv = investigations(:metabolomics_investigation)
    assert !inv.project.people.include?(people(:person_for_owner_of_my_first_sop)), "this person should not be a member of the investigations project"
    assert !inv.can_edit?(users(:owner_of_my_first_sop))
    get :new, :investigation_id=>inv
    assert_response :success

    assert_select "select#project_id" do<commit_msg>fixed test by changing logged in user.<commit_after>require 'test_helper'

class StudiesControllerTest < ActionController::TestCase

  fixtures :all

  include AuthenticatedTestHelper
  include RestTestCases

  def setup
    login_as(:quentin)
    @object=Factory :study, :policy => Factory(:public_policy)
  end

  test "should get index" do
    get :index
    assert_response :success
    assert_not_nil assigns(:studies)
  end
  
  def test_title
    get :index
    assert_select "title",:text=>/The Sysmo SEEK Studies.*/, :count=>1
  end

  test "should get show" do
    get :show, :id=>studies(:metabolomics_study)
    assert_response :success
    assert_not_nil assigns(:study)
  end

  test "should get new" do
    get :new
    assert_response :success
    assert_not_nil assigns(:study)
  end

  test "should get new with investigation predefined" do
    login_as :model_owner
    inv = investigations(:metabolomics_investigation)

    assert inv.can_edit?,"model owner should be able to edit this investigation"
    get :new, :investigation_id=>inv
    assert_response :success

    assert_select "select#project_id" do
      assert_select "option[selected='selected'][value=?]",inv.project.id
    end
    assert_select "select#study_investigation_id" do
      assert_select "option[selected='selected'][value=?]",inv.id
    end
  end

  test "should not allow linking to an investigation from a project you are not a member of" do
    login_as(:owner_of_my_first_sop)
    inv = investigations(:metabolomics_investigation)
    assert !inv.project.people.include?(people(:person_for_owner_of_my_first_sop)), "this person should not be a member of the investigations project"
    assert !inv.can_edit?(users(:owner_of_my_first_sop))
    get :new, :investigation_id=>inv
    assert_response :success

    assert_select "select#project_id" do
{'fraction_non_alphanumeric': 0.08509470216854241, 'fraction_numerical': 0.0005489980785067252, 'mean_word_length': 4.343108504398827, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '7139171', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1087, 'n_words': 305}