<commit_before>require 'rails_helper'

describe DirectUpload do

  context "configurations" do

    it "should be valid for different kind of combinations when attachment is valid" do
      expect(build(:direct_upload, :proposal, :documents)).to be_valid
      expect(build(:direct_upload, :proposal, :image)).to be_valid
      expect(build(:direct_upload, :budget_investment, :documents)).to be_valid
      expect(build(:direct_upload, :budget_investment, :image)).to be_valid
    end

    it "should not be valid for different kind of combinations with invalid atttachment content types" do
      expect(build(:direct_upload, :proposal, :documents, attachment: File.new("spec/fixtures/files/clippy.png"))).not_to be_valid
      expect(build(:direct_upload, :proposal, :image, attachment: File.new("spec/fixtures/files/empty.pdf"))).not_to be_valid
      expect(build(:direct_upload, :budget_investment, :documents, attachment: File.new("spec/fixtures/files/clippy.png"))).not_to be_valid
      expect(build(:direct_upload, :budget_investment, :image, attachment: File.new("spec/fixtures/files/empty.pdf"))).not_to be_valid
    end

    it "should not be valid without resource_type" do
      expect(build(:direct_upload, :proposal, :documents, resource_type: nil)).not_to be_valid
    end

    it "should not be valid without resource_relation" do
      expect(build(:direct_upload, :proposal, :documents, resource_relation: nil)).not_to be_valid
    end

    it "should not be valid without attachment" do
      expect(build(:direct_upload, :proposal, :documents, attachment: nil)).not_to be_valid
    end

    it "should not be valid without user" do
      expect(build(:direct_upload, :proposal, :documents, user: nil)).not_to be_valid
    end
  end

  context "save_attachment" do
    it "should create all uploaded file versions" do
      proposal_document_direct_upload = build(:direct_upload, :proposal, :documents)

      expect{ proposal_document_direct_upload.save_attachment }.to eq(true)
    end

  end

  context "destroy_attachment" do
    it "should create all uploaded file versions" do

    end

  end


end<commit_msg>Add direct upload model specs<commit_after>require 'rails_helper'

describe DirectUpload do

  context "configurations" do

    it "should be valid for different kind of combinations when attachment is valid" do
      expect(build(:direct_upload, :proposal, :documents)).to be_valid
      expect(build(:direct_upload, :proposal, :image)).to be_valid
      expect(build(:direct_upload, :budget_investment, :documents)).to be_valid
      expect(build(:direct_upload, :budget_investment, :image)).to be_valid
    end

    it "should not be valid for different kind of combinations with invalid atttachment content types" do
      expect(build(:direct_upload, :proposal, :documents, attachment: File.new("spec/fixtures/files/clippy.png"))).not_to be_valid
      expect(build(:direct_upload, :proposal, :image, attachment: File.new("spec/fixtures/files/empty.pdf"))).not_to be_valid
      expect(build(:direct_upload, :budget_investment, :documents, attachment: File.new("spec/fixtures/files/clippy.png"))).not_to be_valid
      expect(build(:direct_upload, :budget_investment, :image, attachment: File.new("spec/fixtures/files/empty.pdf"))).not_to be_valid
    end

    it "should not be valid without resource_type" do
      expect(build(:direct_upload, :proposal, :documents, resource_type: nil)).not_to be_valid
    end

    it "should not be valid without resource_relation" do
      expect(build(:direct_upload, :proposal, :documents, resource_relation: nil)).not_to be_valid
    end

    it "should not be valid without attachment" do
      expect(build(:direct_upload, :proposal, :documents, attachment: nil)).not_to be_valid
    end

    it "should not be valid without user" do
      expect(build(:direct_upload, :proposal, :documents, user: nil)).not_to be_valid
    end
  end

  context "save_attachment" do

    it "should save uploaded file" do
      proposal_document_direct_upload = build(:direct_upload, :proposal, :documents)

      proposal_document_direct_upload.save_attachment

      expect(File.exists?(proposal_document_direct_upload.relation.attachment.path)).to eq(true)
      expect(proposal_document_direct_upload.relation.attachment.path).to include('cached_attachments')
    end

  end

  context "destroy_attachment" do

    it "should remove uploaded file" do
      proposal_document_direct_upload = build(:direct_upload, :proposal, :documents)

      proposal_document_direct_upload.save_attachment
      uploaded_path = proposal_document_direct_upload.relation.attachment.path
      proposal_document_direct_upload.destroy_attachment

      expect(File.exists?(uploaded_path)).to eq(false)
    end

  end

end
{'fraction_non_alphanumeric': 0.09757118927973199, 'fraction_numerical': 0.0, 'mean_word_length': 4.6465721040189125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4718798', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1375, 'n_words': 362}