Project

General

Profile

Download (3.46 KB) Statistics
| Branch: | Tag: | Revision:

root / test / functional / commit_relation_editor_controller_test.rb @ 4:7d3a38ab714a

1
require File.dirname(__FILE__) + '/../test_helper'
2

    
3
class CommitRelationEditorControllerTest < ActionController::TestCase
4
  fixtures :projects, :users, :repositories,
5
    :changesets, :changes, :members, :roles, :issues, :issue_statuses,
6
    :enumerations, :issue_categories, :trackers, :trackers, :projects, :projects_trackers
7

    
8
  def setup
9
    @controller = CommitRelationEditorController.new
10
    @request    = ActionController::TestRequest.new
11
    @response   = ActionController::TestResponse.new
12
    @request.env["HTTP_REFERER"] = '/'
13
    enabled_module = EnabledModule.new
14
    enabled_module.project_id = 1
15
    enabled_module.name = 'commit_relation_editor'
16
    enabled_module.save
17
    enabled_module = EnabledModule.new
18
    enabled_module.project_id = 2
19
    enabled_module.name = 'commit_relation_editor'
20
    enabled_module.save
21

    
22
    User.current = nil
23
    roles = Role.find(:all)
24
    roles.each {|role|
25
      role.permissions << :edit_commit_relation
26
      role.save
27
    }
28
  end
29

    
30
  context "new" do
31
    should "add relation if issue exists." do
32
      @request.session[:user_id] = 1
33
      changeset = Changeset.generate!
34
      project = Project.find(1)
35
      issue = Issue.generate_for_project!(project)
36
      post :new, :id => 1, :changeset_id => changeset.id, :issue_id => issue.id
37
      assert_response :redirect
38
      changeset.reload
39
      assert_equal(1, changeset.issues.length)
40
      assert_equal(issue, changeset.issues[0])
41
      
42
      issue = Issue.generate_for_project!(project)
43
      post :new, :id => 1, :changeset_id => changeset.id, :issue_id => issue.id
44
      assert_response :redirect
45
      changeset.reload
46
      assert_equal(2, changeset.issues.length)
47
      assert_equal(issue, changeset.issues[1])
48
    end
49
    
50
    should "not add relation if issue does not exists." do
51
      @request.session[:user_id] = 1
52
      changeset = Changeset.generate!
53
      project = Project.find(1)
54
      issue = Issue.generate_for_project!(project)
55
      issue_id = issue.id
56
      issue.destroy
57
      post :new, :id => 1, :changeset_id => changeset.id, :issue_id => issue_id
58
      assert_response :redirect
59
      changeset.reload
60
      assert_equal(0, changeset.issues.length)
61
    end
62
    
63
    should "not add relation if issue belongs wrong project." do
64
      @request.session[:user_id] = 1
65
      changeset = Changeset.generate!
66
      project = Project.find(2)
67
      issue = Issue.generate_for_project!(project)
68
      issue_id = issue.id
69
      post :new, :id => 1, :changeset_id => changeset.id, :issue_id => issue_id
70
      assert_response :redirect
71
      changeset.reload
72
      assert_equal(0, changeset.issues.length)
73
    end
74
  end
75
  
76
  context "destroy" do
77
    should "remove relation" do
78
      @request.session[:user_id] = 1
79
      changeset = Changeset.generate!
80
      project = Project.find(1)
81
      issue1 = Issue.generate_for_project!(project)
82
      issue2 = Issue.generate_for_project!(project)
83
      changeset.issues << issue1
84
      changeset.issues << issue2
85
      changeset.save!
86
      get :destroy, :id => 1, :changeset_id => changeset.id, :issue_id => issue1.id
87
      assert_response :redirect
88
      changeset.reload
89
      assert_equal(1, changeset.issues.length)
90
      assert_equal(issue2, changeset.issues[0])
91
      
92
      get :destroy, :id => 1, :changeset_id => changeset.id, :issue_id => issue2.id
93
      assert_response :redirect
94
      changeset.reload
95
      assert_equal(0, changeset.issues.length)
96
    end
97
  end
98

    
99
end
    (1-1/1)