issues_spec.rb 7.3 KB
Newer Older
G
gitlabhq 已提交
1 2 3 4 5
require 'spec_helper'

describe "Issues" do
  let(:project) { Factory :project }

N
Nihad Abbasov 已提交
6
  before do
G
gitlabhq 已提交
7
    login_as :user
G
fixes  
gitlabhq 已提交
8 9
    @user2 = Factory :user

G
gitlabhq 已提交
10
    project.add_access(@user, :read, :write)
G
fixes  
gitlabhq 已提交
11
    project.add_access(@user2, :read, :write)
G
gitlabhq 已提交
12 13 14
  end

  describe "GET /issues" do
N
Nihad Abbasov 已提交
15
    before do
G
gitlabhq 已提交
16 17 18 19 20 21 22 23 24 25
      @issue = Factory :issue,
        :author => @user,
        :assignee => @user,
        :project => project

      visit project_issues_path(project)
    end

    subject { page }

D
Dmitriy Zaporozhets 已提交
26
    it { should have_content(@issue.title[0..20]) }
G
gitlabhq 已提交
27 28 29
    it { should have_content(@issue.project.name) }
    it { should have_content(@issue.assignee.name) }

N
Nihad Abbasov 已提交
30 31 32 33 34 35
    it "should render atom feed" do
      visit project_issues_path(project, :atom)

      page.response_headers['Content-Type'].should have_content("application/atom+xml")
      page.body.should have_selector("title", :text => "#{project.name} issues")
      page.body.should have_selector("author email", :text => @issue.author_email)
36 37 38 39 40 41 42 43 44 45
      page.body.should have_selector("entry summary", :text => @issue.title)
    end

    it "should render atom feed via private token" do
      logout
      visit project_issues_path(project, :atom, :private_token => @user.private_token)

      page.response_headers['Content-Type'].should have_content("application/atom+xml")
      page.body.should have_selector("title", :text => "#{project.name} issues")
      page.body.should have_selector("author email", :text => @issue.author_email)
N
Nihad Abbasov 已提交
46 47 48
      page.body.should have_selector("entry summary", :text => @issue.title)
    end

N
Nihad Abbasov 已提交
49 50
    describe "Destroy" do
      before do
G
gitlabhq 已提交
51 52 53 54 55 56
        # admin access to remove issue
        @user.users_projects.destroy_all
        project.add_access(@user, :read, :write, :admin)
        visit project_issues_path(project)
      end

N
Nihad Abbasov 已提交
57
      it "should remove entry" do
G
gitlabhq 已提交
58 59 60 61 62 63
        expect {
          click_link "destroy_issue_#{@issue.id}"
        }.to change { Issue.count }.by(-1)
      end
    end

N
Nihad Abbasov 已提交
64 65
    describe "statuses", :js => true do
      before do
G
gitlabhq 已提交
66 67 68 69 70 71 72
        @closed_issue = Factory :issue,
          :author => @user,
          :assignee => @user,
          :project => project,
          :closed => true
      end

N
Nihad Abbasov 已提交
73
      it "should show only open" do
G
fixes  
gitlabhq 已提交
74
        should have_content(@issue.title[0..25])
G
gitlabhq 已提交
75 76 77
        should have_no_content(@closed_issue.title)
      end

N
Nihad Abbasov 已提交
78
      it "should show only closed" do
G
gitlabhq 已提交
79 80
        choose "closed_issues"
        should have_no_content(@issue.title)
G
fixes  
gitlabhq 已提交
81
        should have_content(@closed_issue.title[0..25])
G
gitlabhq 已提交
82 83
      end

N
Nihad Abbasov 已提交
84
      it "should show all" do
G
gitlabhq 已提交
85
        choose "all_issues"
G
fixes  
gitlabhq 已提交
86 87
        should have_content(@issue.title[0..25])
        should have_content(@closed_issue.title[0..25])
G
gitlabhq 已提交
88 89 90 91
      end
    end
  end

N
Nihad Abbasov 已提交
92 93
  describe "New issue", :js => true do
    before do
G
gitlabhq 已提交
94 95 96 97
      visit project_issues_path(project)
      click_link "New Issue"
    end

98
    it "should open new issue form" do
D
Dmitriy Zaporozhets 已提交
99
      page.should have_content("New Issue")
G
gitlabhq 已提交
100 101
    end

N
Nihad Abbasov 已提交
102
    describe "fill in" do
N
Nihad Abbasov 已提交
103
      describe 'assign to me' do
G
fixes  
gitlabhq 已提交
104 105
        before do
          fill_in "issue_title", :with => "bug 345"
106 107
          page.execute_script("$('#issue_assignee_id').show();")
          select @user.name, :from => "issue_assignee_id" 
G
fixes  
gitlabhq 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
        end

        it { expect { click_button "Save" }.to change {Issue.count}.by(1) }

        it "should add new issue to table" do
          click_button "Save"

          page.should_not have_content("Add new issue")
          page.should have_content @user.name
          page.should have_content "bug 345"
          page.should have_content project.name
        end

        it "should call send mail" do
          Notify.should_not_receive(:new_issue_email)
          click_button "Save"
        end
G
gitlabhq 已提交
125 126
      end

N
Nihad Abbasov 已提交
127
      describe 'assign to other' do
G
fixes  
gitlabhq 已提交
128 129
        before do
          fill_in "issue_title", :with => "bug 345"
130 131
          page.execute_script("$('#issue_assignee_id').show();")
          select @user2.name, :from => "issue_assignee_id" 
G
fixes  
gitlabhq 已提交
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
        end

        it { expect { click_button "Save" }.to change {Issue.count}.by(1) }

        it "should add new issue to table" do
          click_button "Save"

          page.should_not have_content("Add new issue")
          page.should have_content @user2.name
          page.should have_content "bug 345"
          page.should have_content project.name
        end

        it "should call send mail" do
          Notify.should_receive(:new_issue_email).and_return(stub(:deliver => true))
          click_button "Save"
        end

        it "should send valid email to user with email & password" do
          click_button "Save"
          issue = Issue.last
          email = ActionMailer::Base.deliveries.last
          email.subject.should have_content("New Issue was created")
          email.body.should have_content(issue.title)
          email.body.should have_content(issue.assignee.name)
        end
G
gitlabhq 已提交
158 159 160 161 162

      end
    end
  end

N
Nihad Abbasov 已提交
163
  describe "Show issue" do
G
gitlabhq 已提交
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    before do
      @issue = Factory :issue,
        :author => @user,
        :assignee => @user,
        :project => project

      visit project_issue_path(project, @issue)
    end

    it "should have valid show page for issue" do
      page.should have_content @issue.title
      page.should have_content @user.name
    end
  end

N
Nihad Abbasov 已提交
179 180
  describe "Edit issue", :js => true do
    before do
G
gitlabhq 已提交
181 182 183 184 185
      @issue = Factory :issue,
        :author => @user,
        :assignee => @user,
        :project => project
      visit project_issues_path(project)
D
Dmitriy Zaporozhets 已提交
186
      page.execute_script("$('.action-links').css('display', 'block');")
G
gitlabhq 已提交
187 188 189
      click_link "Edit"
    end

N
Nihad Abbasov 已提交
190
    it "should open new issue popup" do
G
gitlabhq 已提交
191 192 193
      page.should have_content("Issue ##{@issue.id}")
    end

N
Nihad Abbasov 已提交
194
    describe "fill in" do
G
gitlabhq 已提交
195 196 197 198 199 200
      before do
        fill_in "issue_title", :with => "bug 345"
      end

      it { expect { click_button "Save" }.to_not change {Issue.count} }

N
Nihad Abbasov 已提交
201
      it "should update issue fields" do
G
gitlabhq 已提交
202 203 204 205 206 207 208 209 210
        click_button "Save"

        page.should_not have_content("Issue ##{@issue.id}")
        page.should have_content @user.name
        page.should have_content "bug 345"
        page.should have_content project.name
      end
    end
  end
A
Adam Leonard 已提交
211 212 213 214 215

  describe "Search issue", :js => true do
    before do
      ['foobar', 'foobar2', 'gitlab'].each do |title|
        @issue = Factory :issue,
216
          :author   => @user,
A
Adam Leonard 已提交
217
          :assignee => @user,
218 219
          :project  => project,
          :title    => title
A
Adam Leonard 已提交
220 221 222
        @issue.save
      end
    end
N
Nihad Abbasov 已提交
223

224 225 226 227 228
    it "should be able to search on different statuses" do
      @issue = Issue.first
      @issue.closed = true
      @issue.save

A
Adam Leonard 已提交
229
      visit project_issues_path(project)
230 231
      choose 'closed_issues'
      fill_in 'issue_search', :with => 'foobar'
N
Nihad Abbasov 已提交
232

233 234 235 236 237
      page.should have_content 'foobar'
      page.should_not have_content 'foobar2'
      page.should_not have_content 'gitlab'
    end

N
Nihad Abbasov 已提交
238
    it "should search for term and return the correct results" do
239 240 241
      visit project_issues_path(project)
      fill_in 'issue_search', :with => 'foobar'

A
Adam Leonard 已提交
242 243 244 245 246
      page.should have_content 'foobar'
      page.should have_content 'foobar2'
      page.should_not have_content 'gitlab'
    end

247 248 249 250 251 252 253 254 255 256 257
    it "should return all results if term has been cleared" do
      visit project_issues_path(project)
      fill_in "issue_search", :with => "foobar"
      # Because fill_in, :with => "" triggers nothing we need to trigger a keyup event
      page.execute_script("$('.issue_search').val('').keyup();");

      page.should have_content 'foobar'
      page.should have_content 'foobar2'
      page.should have_content 'gitlab'
    end
  end
G
gitlabhq 已提交
258
end