<commit_before>require 'test_helper'

class GeometryModelControllerTest < ActionDispatch::IntegrationTest

  setup do
    sign_in users(:user1)
    @gm = fixture_file_upload 'launcher.vsp3'
    @gm2 = fixture_file_upload 'launcher.vsp3'
  end

  test "should get geometry models list" do
    get geometry_models_url
    assert_response :success  
  end
  
  test "should assign owner on creation" do
    assert_difference('GeometryModel.count') do
      post geometry_models_url, params: { geometry_model: {title: "Test", attachment_attributes: { data: @gm }} }
    end
    assert GeometryModel.last.owner, users(:user1)  
  end
  
  test "should not destroy geometry model, if not owner" do
    post geometry_models_url, params: { geometry_model: {title: "Test", attachment_attributes: { data: @gm }} }
    sign_out users(:user1)
    sign_in users(:user2)
    assert_difference('GeometryModel.count', 0) do
      delete geometry_model_url(GeometryModel.first)
    end
    assert_redirected_to root_path
    assert_equal 'You are not authorized to perform this action.', flash[:error]
  end  
  
  test "should update the attachment and the title" do
    post geometry_models_url, params: { geometry_model: {title: "Test", attachment_attributes: { data: @gm }} }
    assert_equal "Test", GeometryModel.last.title
    put geometry_model_url(GeometryModel.last), params: { geometry_model: {title: "Test2", attachment_attributes: { data: @gm2 }} }
    assert_equal "Test2", GeometryModel.last.title
  end 
  
end<commit_msg>skip test if no vspscript<commit_after>require 'test_helper'

class GeometryModelControllerTest < ActionDispatch::IntegrationTest

  def vspscript?
    system("which vspscript > /dev/null 2>&1")
  end

  setup do
    sign_in users(:user1)
    @gm = fixture_file_upload 'launcher.vsp3'
    @gm2 = fixture_file_upload 'launcher.vsp3'
  end

  test "should get geometry models list" do
    get geometry_models_url
    assert_response :success  
  end
  
  test "should assign owner on creation" do
    skip unless vspscript?
    assert_difference('GeometryModel.count') do
      post geometry_models_url, params: { geometry_model: {title: "Test", attachment_attributes: { data: @gm }} }
    end
    assert GeometryModel.last.owner, users(:user1)  
  end
  
  test "should not destroy geometry model, if not owner" do
    skip unless vspscript?
    post geometry_models_url, params: { geometry_model: {title: "Test", attachment_attributes: { data: @gm }} }
    sign_out users(:user1)
    sign_in users(:user2)
    assert_difference('GeometryModel.count', 0) do
      delete geometry_model_url(GeometryModel.first)
    end
    assert_redirected_to root_path
    assert_equal 'You are not authorized to perform this action.', flash[:error]
  end  
  
  test "should update the attachment and the title" do
    skip unless vspscript?
    post geometry_models_url, params: { geometry_model: {title: "Test", attachment_attributes: { data: @gm }} }
    assert_equal "Test", GeometryModel.last.title
    put geometry_model_url(GeometryModel.last), params: { geometry_model: {title: "Test2", attachment_attributes: { data: @gm2 }} }
    assert_equal "Test2", GeometryModel.last.title
  end 
  
end
{'fraction_non_alphanumeric': 0.09201497192763568, 'fraction_numerical': 0.007485963817841547, 'mean_word_length': 4.147672552166934, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6433825', 'n_tokens_mistral': 998, 'n_tokens_neox': 959, 'n_words': 275}