Commit 6233fb6b5d4732729b5bd734357f47fa42d34ed3

Authored by Dmitriy Zaporozhets
2 parents 4782163c b6f249dc

Merge pull request #1446 from NARKOZ/refactoring

specs DRY up
spec/requests/api/issues_spec.rb
... ... @@ -9,12 +9,14 @@ describe Gitlab::API do
9 9 before { project.add_access(user, :read) }
10 10  
11 11 describe "GET /issues" do
12   - it "should return authentication error" do
13   - get api("/issues")
14   - response.status.should == 401
  12 + context "when unauthenticated" do
  13 + it "should return authentication error" do
  14 + get api("/issues")
  15 + response.status.should == 401
  16 + end
15 17 end
16 18  
17   - describe "authenticated GET /issues" do
  19 + context "when authenticated" do
18 20 it "should return an array of issues" do
19 21 get api("/issues", user)
20 22 response.status.should == 200
... ...
spec/requests/api/projects_spec.rb
... ... @@ -13,12 +13,14 @@ describe Gitlab::API do
13 13 before { project.add_access(user, :read) }
14 14  
15 15 describe "GET /projects" do
16   - it "should return authentication error" do
17   - get api("/projects")
18   - response.status.should == 401
  16 + context "when unauthenticated" do
  17 + it "should return authentication error" do
  18 + get api("/projects")
  19 + response.status.should == 401
  20 + end
19 21 end
20 22  
21   - describe "authenticated GET /projects" do
  23 + context "when authenticated" do
22 24 it "should return an array of projects" do
23 25 get api("/projects", user)
24 26 response.status.should == 200
... ...
spec/requests/api/users_spec.rb
... ... @@ -6,12 +6,14 @@ describe Gitlab::API do
6 6 let(:user) { Factory :user }
7 7  
8 8 describe "GET /users" do
9   - it "should return authentication error" do
10   - get api("/users")
11   - response.status.should == 401
  9 + context "when unauthenticated" do
  10 + it "should return authentication error" do
  11 + get api("/users")
  12 + response.status.should == 401
  13 + end
12 14 end
13 15  
14   - describe "authenticated GET /users" do
  16 + context "when authenticated" do
15 17 it "should return an array of users" do
16 18 get api("/users", user)
17 19 response.status.should == 200
... ...
spec/requests/atom/dashboard_issues_spec.rb
1 1 require 'spec_helper'
2 2  
3   -describe "User Issues Dashboard" do
  3 +describe "Dashboard Issues Feed" do
4 4 describe "GET /issues" do
5   - before do
  5 + let!(:user) { Factory :user }
  6 + let!(:project1) { Factory :project }
  7 + let!(:project2) { Factory :project }
  8 + let!(:issue1) { Factory :issue, author: user, assignee: user, project: project1 }
  9 + let!(:issue2) { Factory :issue, author: user, assignee: user, project: project2 }
6 10  
7   - login_as :user
8   -
9   - @project1 = Factory :project
10   -
11   - @project2 = Factory :project
12   -
13   - @project1.add_access(@user, :read, :write)
14   - @project2.add_access(@user, :read, :write)
15   -
16   - @issue1 = Factory :issue,
17   - author: @user,
18   - assignee: @user,
19   - project: @project1
20   -
21   - @issue2 = Factory :issue,
22   - author: @user,
23   - assignee: @user,
24   - project: @project2
25   -
26   - visit dashboard_issues_path
27   - end
28   -
29   - describe "atom feed", js: false do
  11 + describe "atom feed" do
30 12 it "should render atom feed via private token" do
31   - logout
32   - visit dashboard_issues_path(:atom, private_token: @user.private_token)
  13 + visit dashboard_issues_path(:atom, private_token: user.private_token)
33 14  
34 15 page.response_headers['Content-Type'].should have_content("application/atom+xml")
35   - page.body.should have_selector("title", text: "#{@user.name} issues")
36   - page.body.should have_selector("author email", text: @issue1.author_email)
37   - page.body.should have_selector("entry summary", text: @issue1.title)
38   - page.body.should have_selector("author email", text: @issue2.author_email)
39   - page.body.should have_selector("entry summary", text: @issue2.title)
  16 + page.body.should have_selector("title", text: "#{user.name} issues")
  17 + page.body.should have_selector("author email", text: issue1.author_email)
  18 + page.body.should have_selector("entry summary", text: issue1.title)
  19 + page.body.should have_selector("author email", text: issue2.author_email)
  20 + page.body.should have_selector("entry summary", text: issue2.title)
40 21 end
41 22 end
42 23 end
... ...
spec/requests/atom/dashboard_spec.rb
1 1 require 'spec_helper'
2 2  
3   -describe "User Dashboard" do
4   - before { login_as :user }
5   -
  3 +describe "Dashboard Feed" do
6 4 describe "GET /" do
7   - before do
8   - @project = Factory :project, owner: @user
9   - @project.add_access(@user, :read)
10   - visit dashboard_path
11   - end
  5 + let!(:user) { Factory :user }
12 6  
13   - it "should render projects atom feed via private token" do
14   - logout
15   -
16   - visit dashboard_path(:atom, private_token: @user.private_token)
17   - page.body.should have_selector("feed title")
  7 + context "projects atom feed via private token" do
  8 + it "should render projects atom feed" do
  9 + visit dashboard_path(:atom, private_token: user.private_token)
  10 + page.body.should have_selector("feed title")
  11 + end
18 12 end
19 13  
20   - it "should not render projects page via private token" do
21   - logout
22   -
23   - visit dashboard_path(private_token: @user.private_token)
24   - current_path.should == new_user_session_path
  14 + context "projects page via private token" do
  15 + it "should redirect to login page" do
  16 + visit dashboard_path(private_token: user.private_token)
  17 + current_path.should == new_user_session_path
  18 + end
25 19 end
26 20 end
27 21 end
... ...
spec/requests/atom/issues_spec.rb
1 1 require 'spec_helper'
2 2  
3   -describe "Issues" do
4   - let(:project) { Factory :project }
5   -
6   - before do
7   - login_as :user
8   - project.add_access(@user, :read, :write)
9   - end
10   -
  3 +describe "Issues Feed" do
11 4 describe "GET /issues" do
12   - before do
13   - @issue = Factory :issue,
14   - author: @user,
15   - assignee: @user,
16   - project: project
17   -
18   - visit project_issues_path(project)
19   - end
20   -
21   - it "should render atom feed" do
22   - visit project_issues_path(project, :atom)
23   -
24   - page.response_headers['Content-Type'].should have_content("application/atom+xml")
25   - page.body.should have_selector("title", text: "#{project.name} issues")
26   - page.body.should have_selector("author email", text: @issue.author_email)
27   - page.body.should have_selector("entry summary", text: @issue.title)
  5 + let!(:user) { Factory :user }
  6 + let!(:project) { Factory :project, owner: user }
  7 + let!(:issue) { Factory :issue, author: user, project: project }
  8 +
  9 + before { project.add_access(user, :read, :write) }
  10 +
  11 + context "when authenticated" do
  12 + it "should render atom feed" do
  13 + login_with user
  14 + visit project_issues_path(project, :atom)
  15 +
  16 + page.response_headers['Content-Type'].should have_content("application/atom+xml")
  17 + page.body.should have_selector("title", text: "#{project.name} issues")
  18 + page.body.should have_selector("author email", text: issue.author_email)
  19 + page.body.should have_selector("entry summary", text: issue.title)
  20 + end
28 21 end
29 22  
30   - it "should render atom feed via private token" do
31   - logout
32   - visit project_issues_path(project, :atom, private_token: @user.private_token)
  23 + context "when authenticated via private token" do
  24 + it "should render atom feed" do
  25 + visit project_issues_path(project, :atom, private_token: user.private_token)
33 26  
34   - page.response_headers['Content-Type'].should have_content("application/atom+xml")
35   - page.body.should have_selector("title", text: "#{project.name} issues")
36   - page.body.should have_selector("author email", text: @issue.author_email)
37   - page.body.should have_selector("entry summary", text: @issue.title)
  27 + page.response_headers['Content-Type'].should have_content("application/atom+xml")
  28 + page.body.should have_selector("title", text: "#{project.name} issues")
  29 + page.body.should have_selector("author email", text: issue.author_email)
  30 + page.body.should have_selector("entry summary", text: issue.title)
  31 + end
38 32 end
39 33 end
40 34 end
... ...