<commit_before>require File.dirname(__FILE__) + '/../test_helper'

class AttachmentsControllerTest < ActionController::TestCase

  def setup
    @person, @other_person = Person.forge, Person.forge
    @group = Group.create! :name => 'Some Group', :category => 'test'
    @group.memberships.create! :person => @person
    @message = Message.create_with_attachments(
      {:group => @group, :person => @person, :subject => Faker::Lorem.sentence, :body => Faker::Lorem.paragraph},
      [Rack::Test::UploadedFile.new('fixtures/files/attachment.pdf', 'application/pdf', true)]
    )
    @attachment = @message.attachments.first
  end

  should "show an attachment" do
    get :show, {:message_id => @message.id, :id => @attachment.id}, {:logged_in_id => @person.id}
    assert_response :success
  end

  should "not show an attachment unless the person can see what it is attached to" do
    get :show, {:message_id => @message.id, :id => @attachment.id}, {:logged_in_id => @other_person.id}
    assert_response :missing
  end

  should "show the new page attachment form" do
    @admin = Person.forge(:admin => Admin.create(:edit_pages => true))
    get :new, {:page_id => pages(:foo).id}, {:logged_in_id => @admin.id}
    assert_response :success
    assert_equal pages(:foo), assigns(:page)
  end

  should "create a new page attachment" do
    @admin = Person.forge(:admin => Admin.create(:edit_pages => true))
    post :create, {:attachment => {:page_id => pages(:foo).id, :file => Rack::Test::UploadedFile.new(Rails.root.join('test/fixtures/files/attachment.pdf'), 'application/pdf', true)}, :from => edit_page_path(pages(:foo))}, {:logged_in_id => @admin.id}
    assert_redirected_to edit_page_path(pages(:foo))
    assert_equal 1, pages(:foo).attachments.count
  end

  should "not create a page attachment unless user is admin" do
    get :new, {:page_id => pages(:foo).id}, {:logged_in_id => @person.id}<commit_msg>Use full path to fixture file.<commit_after>require File.dirname(__FILE__) + '/../test_helper'

class AttachmentsControllerTest < ActionController::TestCase

  def setup
    @person, @other_person = Person.forge, Person.forge
    @group = Group.create! :name => 'Some Group', :category => 'test'
    @group.memberships.create! :person => @person
    @message = Message.create_with_attachments(
      {:group => @group, :person => @person, :subject => Faker::Lorem.sentence, :body => Faker::Lorem.paragraph},
      [Rack::Test::UploadedFile.new(Rails.root.join('test/fixtures/files/attachment.pdf'), 'application/pdf', true)]
    )
    @attachment = @message.attachments.first
  end

  should "show an attachment" do
    get :show, {:message_id => @message.id, :id => @attachment.id}, {:logged_in_id => @person.id}
    assert_response :success
  end

  should "not show an attachment unless the person can see what it is attached to" do
    get :show, {:message_id => @message.id, :id => @attachment.id}, {:logged_in_id => @other_person.id}
    assert_response :missing
  end

  should "show the new page attachment form" do
    @admin = Person.forge(:admin => Admin.create(:edit_pages => true))
    get :new, {:page_id => pages(:foo).id}, {:logged_in_id => @admin.id}
    assert_response :success
    assert_equal pages(:foo), assigns(:page)
  end

  should "create a new page attachment" do
    @admin = Person.forge(:admin => Admin.create(:edit_pages => true))
    post :create, {:attachment => {:page_id => pages(:foo).id, :file => Rack::Test::UploadedFile.new(Rails.root.join('test/fixtures/files/attachment.pdf'), 'application/pdf', true)}, :from => edit_page_path(pages(:foo))}, {:logged_in_id => @admin.id}
    assert_redirected_to edit_page_path(pages(:foo))
    assert_equal 1, pages(:foo).attachments.count
  end

  should "not create a page attachment unless user is admin" do
    get :new, {:page_id => pages(:foo).id}, {:logged_in_id => @person.id}
{'fraction_non_alphanumeric': 0.15761009528714912, 'fraction_numerical': 0.0005150656708730364, 'mean_word_length': 4.4858757062146895, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, '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': '3305691', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1217, 'n_words': 308}