To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / test / functional / .svn / text-base / files_controller_test.rb.svn-base @ 442:753f1380d6bc

History | View | Annotate | Download (2.26 KB)

1
require File.expand_path('../../test_helper', __FILE__)
2

    
3
class FilesControllerTest < ActionController::TestCase
4
  fixtures :all
5
  
6
  def setup
7
    @controller = FilesController.new
8
    @request    = ActionController::TestRequest.new
9
    @response   = ActionController::TestResponse.new
10
    @request.session[:user_id] = nil
11
    Setting.default_language = 'en'
12
  end
13

    
14
  def test_index
15
    get :index, :project_id => 1
16
    assert_response :success
17
    assert_template 'index'
18
    assert_not_nil assigns(:containers)
19
    
20
    # file attached to the project
21
    assert_tag :a, :content => 'project_file.zip',
22
                   :attributes => { :href => '/attachments/download/8/project_file.zip' }
23
    
24
    # file attached to a project's version
25
    assert_tag :a, :content => 'version_file.zip',
26
                   :attributes => { :href => '/attachments/download/9/version_file.zip' }
27
  end
28

    
29
  def test_create_file
30
    set_tmp_attachments_directory
31
    @request.session[:user_id] = 2
32
    Setting.notified_events = ['file_added']
33
    ActionMailer::Base.deliveries.clear
34
    
35
    assert_difference 'Attachment.count' do
36
      post :create, :project_id => 1, :version_id => '',
37
           :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
38
      assert_response :redirect
39
    end
40
    assert_redirected_to '/projects/ecookbook/files'
41
    a = Attachment.find(:first, :order => 'created_on DESC')
42
    assert_equal 'testfile.txt', a.filename
43
    assert_equal Project.find(1), a.container
44

    
45
    mail = ActionMailer::Base.deliveries.last
46
    assert_kind_of TMail::Mail, mail
47
    assert_equal "[eCookbook] New file", mail.subject
48
    assert mail.body.include?('testfile.txt')
49
  end
50
  
51
  def test_create_version_file
52
    set_tmp_attachments_directory
53
    @request.session[:user_id] = 2
54
    Setting.notified_events = ['file_added']
55
    
56
    assert_difference 'Attachment.count' do
57
      post :create, :project_id => 1, :version_id => '2',
58
           :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
59
      assert_response :redirect
60
    end
61
    assert_redirected_to '/projects/ecookbook/files'
62
    a = Attachment.find(:first, :order => 'created_on DESC')
63
    assert_equal 'testfile.txt', a.filename
64
    assert_equal Version.find(2), a.container
65
  end
66
  
67
end