Commit fba174e9bc4e4ef5c0c4d6a4282f37e5265b87e2

Authored by Robert Speicher
1 parent 852b9c28

Cleanup spec/support folder and spec/spec_helper

Changes:
* Move spec/monkeypatch to spec/support
* Remove unused support/shared_examples
* Move support/api to support/api_helpers to match module name
* Move support/login to support/login_helpers to match module name
* Move API specs to requests/api (convention over configuration)
* Remove unused support/js_patch
* Simplify login_as helper
* Move DatabaseCleaner stuff to its own support file
* Remove unnecessary configuration and requires from spec_helper
features/step_definitions/project/projects_steps.rb
1   -include LoginMacros
  1 +include LoginHelpers
2 2  
3 3 Given /^I signin as a user$/ do
4 4 login_as :user
... ...
features/support/env.rb
... ... @@ -7,9 +7,9 @@ require 'cucumber/rails'
7 7 require 'webmock/cucumber'
8 8 WebMock.allow_net_connect!
9 9  
10   -require Rails.root.join 'spec/monkeypatch'
11 10 require Rails.root.join 'spec/factories'
12   -require Rails.root.join 'spec/support/login'
  11 +require Rails.root.join 'spec/support/monkeypatch'
  12 +require Rails.root.join 'spec/support/login_helpers'
13 13 require Rails.root.join 'spec/support/valid_commit'
14 14  
15 15 Capybara.default_selector = :css
... ...
spec/api/issues_spec.rb
... ... @@ -1,71 +0,0 @@
1   -require 'spec_helper'
2   -
3   -describe Gitlab::API do
4   - let(:user) { Factory :user }
5   - let!(:project) { Factory :project, owner: user }
6   - let!(:issue) { Factory :issue, author: user, assignee: user, project: project }
7   - before { project.add_access(user, :read) }
8   -
9   - describe "GET /issues" do
10   - it "should return authentication error" do
11   - get "#{api_prefix}/issues"
12   - response.status.should == 401
13   - end
14   -
15   - describe "authenticated GET /issues" do
16   - it "should return an array of issues" do
17   - get "#{api_prefix}/issues?private_token=#{user.private_token}"
18   - response.status.should == 200
19   - json_response.should be_an Array
20   - json_response.first['title'].should == issue.title
21   - end
22   - end
23   - end
24   -
25   - describe "GET /projects/:id/issues" do
26   - it "should return project issues" do
27   - get "#{api_prefix}/projects/#{project.code}/issues?private_token=#{user.private_token}"
28   - response.status.should == 200
29   - json_response.should be_an Array
30   - json_response.first['title'].should == issue.title
31   - end
32   - end
33   -
34   - describe "GET /projects/:id/issues/:issue_id" do
35   - it "should return a project issue by id" do
36   - get "#{api_prefix}/projects/#{project.code}/issues/#{issue.id}?private_token=#{user.private_token}"
37   - response.status.should == 200
38   - json_response['title'].should == issue.title
39   - end
40   - end
41   -
42   - describe "POST /projects/:id/issues" do
43   - it "should create a new project issue" do
44   - post "#{api_prefix}/projects/#{project.code}/issues?private_token=#{user.private_token}",
45   - title: 'new issue', labels: 'label, label2'
46   - response.status.should == 201
47   - json_response['title'].should == 'new issue'
48   - json_response['description'].should be_nil
49   - json_response['labels'].should == ['label', 'label2']
50   - end
51   - end
52   -
53   - describe "PUT /projects/:id/issues/:issue_id" do
54   - it "should update a project issue" do
55   - put "#{api_prefix}/projects/#{project.code}/issues/#{issue.id}?private_token=#{user.private_token}",
56   - title: 'updated title', labels: 'label2', closed: 1
57   - response.status.should == 200
58   - json_response['title'].should == 'updated title'
59   - json_response['labels'].should == ['label2']
60   - json_response['closed'].should be_true
61   - end
62   - end
63   -
64   - describe "DELETE /projects/:id/issues/:issue_id" do
65   - it "should delete a project issue" do
66   - expect {
67   - delete "#{api_prefix}/projects/#{project.code}/issues/#{issue.id}?private_token=#{user.private_token}"
68   - }.to change { Issue.count }.by(-1)
69   - end
70   - end
71   -end
spec/api/projects_spec.rb
... ... @@ -1,136 +0,0 @@
1   -require 'spec_helper'
2   -
3   -describe Gitlab::API do
4   - let(:user) { Factory :user }
5   - let!(:project) { Factory :project, owner: user }
6   - let!(:snippet) { Factory :snippet, author: user, project: project, title: 'example' }
7   - before { project.add_access(user, :read) }
8   -
9   - describe "GET /projects" do
10   - it "should return authentication error" do
11   - get "#{api_prefix}/projects"
12   - response.status.should == 401
13   - end
14   -
15   - describe "authenticated GET /projects" do
16   - it "should return an array of projects" do
17   - get "#{api_prefix}/projects?private_token=#{user.private_token}"
18   - response.status.should == 200
19   - json_response.should be_an Array
20   - json_response.first['name'].should == project.name
21   - json_response.first['owner']['email'].should == user.email
22   - end
23   - end
24   - end
25   -
26   - describe "GET /projects/:id" do
27   - it "should return a project by id" do
28   - get "#{api_prefix}/projects/#{project.id}?private_token=#{user.private_token}"
29   - response.status.should == 200
30   - json_response['name'].should == project.name
31   - json_response['owner']['email'].should == user.email
32   - end
33   -
34   - it "should return a project by code name" do
35   - get "#{api_prefix}/projects/#{project.code}?private_token=#{user.private_token}"
36   - response.status.should == 200
37   - json_response['name'].should == project.name
38   - end
39   -
40   - it "should return a 404 error if not found" do
41   - get "#{api_prefix}/projects/42?private_token=#{user.private_token}"
42   - response.status.should == 404
43   - json_response['message'].should == '404 Not found'
44   - end
45   - end
46   -
47   - describe "GET /projects/:id/repository/branches" do
48   - it "should return an array of project branches" do
49   - get "#{api_prefix}/projects/#{project.code}/repository/branches?private_token=#{user.private_token}"
50   - response.status.should == 200
51   - json_response.should be_an Array
52   - json_response.first['name'].should == project.repo.heads.sort_by(&:name).first.name
53   - end
54   - end
55   -
56   - describe "GET /projects/:id/repository/branches/:branch" do
57   - it "should return the branch information for a single branch" do
58   - get "#{api_prefix}/projects/#{project.code}/repository/branches/new_design?private_token=#{user.private_token}"
59   - response.status.should == 200
60   -
61   - json_response['name'].should == 'new_design'
62   - json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1'
63   - end
64   - end
65   -
66   - describe "GET /projects/:id/repository/tags" do
67   - it "should return an array of project tags" do
68   - get "#{api_prefix}/projects/#{project.code}/repository/tags?private_token=#{user.private_token}"
69   - response.status.should == 200
70   - json_response.should be_an Array
71   - json_response.first['name'].should == project.repo.tags.sort_by(&:name).reverse.first.name
72   - end
73   - end
74   -
75   - describe "GET /projects/:id/snippets/:snippet_id" do
76   - it "should return a project snippet" do
77   - get "#{api_prefix}/projects/#{project.code}/snippets/#{snippet.id}?private_token=#{user.private_token}"
78   - response.status.should == 200
79   - json_response['title'].should == snippet.title
80   - end
81   - end
82   -
83   - describe "POST /projects/:id/snippets" do
84   - it "should create a new project snippet" do
85   - post "#{api_prefix}/projects/#{project.code}/snippets?private_token=#{user.private_token}",
86   - title: 'api test', file_name: 'sample.rb', code: 'test'
87   - response.status.should == 201
88   - json_response['title'].should == 'api test'
89   - end
90   - end
91   -
92   - describe "PUT /projects/:id/snippets" do
93   - it "should update an existing project snippet" do
94   - put "#{api_prefix}/projects/#{project.code}/snippets/#{snippet.id}?private_token=#{user.private_token}",
95   - code: 'updated code'
96   - response.status.should == 200
97   - json_response['title'].should == 'example'
98   - snippet.reload.content.should == 'updated code'
99   - end
100   - end
101   -
102   - describe "DELETE /projects/:id/snippets/:snippet_id" do
103   - it "should delete existing project snippet" do
104   - expect {
105   - delete "#{api_prefix}/projects/#{project.code}/snippets/#{snippet.id}?private_token=#{user.private_token}"
106   - }.to change { Snippet.count }.by(-1)
107   - end
108   - end
109   -
110   - describe "GET /projects/:id/snippets/:snippet_id/raw" do
111   - it "should get a raw project snippet" do
112   - get "#{api_prefix}/projects/#{project.code}/snippets/#{snippet.id}/raw?private_token=#{user.private_token}"
113   - response.status.should == 200
114   - end
115   - end
116   -
117   - describe "GET /projects/:id/:sha/blob" do
118   - it "should get the raw file contents" do
119   - get "#{api_prefix}/projects/#{project.code}/repository/commits/master/blob?filepath=README.md&private_token=#{user.private_token}"
120   -
121   - response.status.should == 200
122   - end
123   -
124   - it "should return 404 for invalid branch_name" do
125   - get "#{api_prefix}/projects/#{project.code}/repository/commits/invalid_branch_name/blob?filepath=README.md&private_token=#{user.private_token}"
126   -
127   - response.status.should == 404
128   - end
129   -
130   - it "should return 404 for invalid file" do
131   - get "#{api_prefix}/projects/#{project.code}/repository/commits/master/blob?filepath=README.invalid&private_token=#{user.private_token}"
132   -
133   - response.status.should == 404
134   - end
135   - end
136   -end
spec/api/users_spec.rb
... ... @@ -1,37 +0,0 @@
1   -require 'spec_helper'
2   -
3   -describe Gitlab::API do
4   - let(:user) { Factory :user }
5   -
6   - describe "GET /users" do
7   - it "should return authentication error" do
8   - get "#{api_prefix}/users"
9   - response.status.should == 401
10   - end
11   -
12   - describe "authenticated GET /users" do
13   - it "should return an array of users" do
14   - get "#{api_prefix}/users?private_token=#{user.private_token}"
15   - response.status.should == 200
16   - json_response.should be_an Array
17   - json_response.first['email'].should == user.email
18   - end
19   - end
20   - end
21   -
22   - describe "GET /users/:id" do
23   - it "should return a user by id" do
24   - get "#{api_prefix}/users/#{user.id}?private_token=#{user.private_token}"
25   - response.status.should == 200
26   - json_response['email'].should == user.email
27   - end
28   - end
29   -
30   - describe "GET /user" do
31   - it "should return current user" do
32   - get "#{api_prefix}/user?private_token=#{user.private_token}"
33   - response.status.should == 200
34   - json_response['email'].should == user.email
35   - end
36   - end
37   -end
spec/monkeypatch.rb
... ... @@ -1,51 +0,0 @@
1   -# Stubbing Project <-> git host path
2   -# create project using Factory only
3   -class Project
4   - def update_repository
5   - true
6   - end
7   -
8   - def destroy_repository
9   - true
10   - end
11   -
12   - def path_to_repo
13   - File.join(Rails.root, "tmp", "tests", path)
14   - end
15   -
16   - def satellite
17   - @satellite ||= FakeSatellite.new
18   - end
19   -end
20   -
21   -class Key
22   - def update_repository
23   - true
24   - end
25   -
26   - def repository_delete_key
27   - true
28   - end
29   -end
30   -
31   -class UsersProject
32   - def update_repository
33   - true
34   - end
35   -end
36   -
37   -class FakeSatellite
38   - def exists?
39   - true
40   - end
41   -
42   - def create
43   - true
44   - end
45   -end
46   -
47   -class ProtectedBranch
48   - def update_repository
49   - true
50   - end
51   -end
spec/requests/api/issues_spec.rb 0 → 100644
... ... @@ -0,0 +1,71 @@
  1 +require 'spec_helper'
  2 +
  3 +describe Gitlab::API do
  4 + let(:user) { Factory :user }
  5 + let!(:project) { Factory :project, owner: user }
  6 + let!(:issue) { Factory :issue, author: user, assignee: user, project: project }
  7 + before { project.add_access(user, :read) }
  8 +
  9 + describe "GET /issues" do
  10 + it "should return authentication error" do
  11 + get "#{api_prefix}/issues"
  12 + response.status.should == 401
  13 + end
  14 +
  15 + describe "authenticated GET /issues" do
  16 + it "should return an array of issues" do
  17 + get "#{api_prefix}/issues?private_token=#{user.private_token}"
  18 + response.status.should == 200
  19 + json_response.should be_an Array
  20 + json_response.first['title'].should == issue.title
  21 + end
  22 + end
  23 + end
  24 +
  25 + describe "GET /projects/:id/issues" do
  26 + it "should return project issues" do
  27 + get "#{api_prefix}/projects/#{project.code}/issues?private_token=#{user.private_token}"
  28 + response.status.should == 200
  29 + json_response.should be_an Array
  30 + json_response.first['title'].should == issue.title
  31 + end
  32 + end
  33 +
  34 + describe "GET /projects/:id/issues/:issue_id" do
  35 + it "should return a project issue by id" do
  36 + get "#{api_prefix}/projects/#{project.code}/issues/#{issue.id}?private_token=#{user.private_token}"
  37 + response.status.should == 200
  38 + json_response['title'].should == issue.title
  39 + end
  40 + end
  41 +
  42 + describe "POST /projects/:id/issues" do
  43 + it "should create a new project issue" do
  44 + post "#{api_prefix}/projects/#{project.code}/issues?private_token=#{user.private_token}",
  45 + title: 'new issue', labels: 'label, label2'
  46 + response.status.should == 201
  47 + json_response['title'].should == 'new issue'
  48 + json_response['description'].should be_nil
  49 + json_response['labels'].should == ['label', 'label2']
  50 + end
  51 + end
  52 +
  53 + describe "PUT /projects/:id/issues/:issue_id" do
  54 + it "should update a project issue" do
  55 + put "#{api_prefix}/projects/#{project.code}/issues/#{issue.id}?private_token=#{user.private_token}",
  56 + title: 'updated title', labels: 'label2', closed: 1
  57 + response.status.should == 200
  58 + json_response['title'].should == 'updated title'
  59 + json_response['labels'].should == ['label2']
  60 + json_response['closed'].should be_true
  61 + end
  62 + end
  63 +
  64 + describe "DELETE /projects/:id/issues/:issue_id" do
  65 + it "should delete a project issue" do
  66 + expect {
  67 + delete "#{api_prefix}/projects/#{project.code}/issues/#{issue.id}?private_token=#{user.private_token}"
  68 + }.to change { Issue.count }.by(-1)
  69 + end
  70 + end
  71 +end
... ...
spec/requests/api/projects_spec.rb 0 → 100644
... ... @@ -0,0 +1,136 @@
  1 +require 'spec_helper'
  2 +
  3 +describe Gitlab::API do
  4 + let(:user) { Factory :user }
  5 + let!(:project) { Factory :project, owner: user }
  6 + let!(:snippet) { Factory :snippet, author: user, project: project, title: 'example' }
  7 + before { project.add_access(user, :read) }
  8 +
  9 + describe "GET /projects" do
  10 + it "should return authentication error" do
  11 + get "#{api_prefix}/projects"
  12 + response.status.should == 401
  13 + end
  14 +
  15 + describe "authenticated GET /projects" do
  16 + it "should return an array of projects" do
  17 + get "#{api_prefix}/projects?private_token=#{user.private_token}"
  18 + response.status.should == 200
  19 + json_response.should be_an Array
  20 + json_response.first['name'].should == project.name
  21 + json_response.first['owner']['email'].should == user.email
  22 + end
  23 + end
  24 + end
  25 +
  26 + describe "GET /projects/:id" do
  27 + it "should return a project by id" do
  28 + get "#{api_prefix}/projects/#{project.id}?private_token=#{user.private_token}"
  29 + response.status.should == 200
  30 + json_response['name'].should == project.name
  31 + json_response['owner']['email'].should == user.email
  32 + end
  33 +
  34 + it "should return a project by code name" do
  35 + get "#{api_prefix}/projects/#{project.code}?private_token=#{user.private_token}"
  36 + response.status.should == 200
  37 + json_response['name'].should == project.name
  38 + end
  39 +
  40 + it "should return a 404 error if not found" do
  41 + get "#{api_prefix}/projects/42?private_token=#{user.private_token}"
  42 + response.status.should == 404
  43 + json_response['message'].should == '404 Not found'
  44 + end
  45 + end
  46 +
  47 + describe "GET /projects/:id/repository/branches" do
  48 + it "should return an array of project branches" do
  49 + get "#{api_prefix}/projects/#{project.code}/repository/branches?private_token=#{user.private_token}"
  50 + response.status.should == 200
  51 + json_response.should be_an Array
  52 + json_response.first['name'].should == project.repo.heads.sort_by(&:name).first.name
  53 + end
  54 + end
  55 +
  56 + describe "GET /projects/:id/repository/branches/:branch" do
  57 + it "should return the branch information for a single branch" do
  58 + get "#{api_prefix}/projects/#{project.code}/repository/branches/new_design?private_token=#{user.private_token}"
  59 + response.status.should == 200
  60 +
  61 + json_response['name'].should == 'new_design'
  62 + json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1'
  63 + end
  64 + end
  65 +
  66 + describe "GET /projects/:id/repository/tags" do
  67 + it "should return an array of project tags" do
  68 + get "#{api_prefix}/projects/#{project.code}/repository/tags?private_token=#{user.private_token}"
  69 + response.status.should == 200
  70 + json_response.should be_an Array
  71 + json_response.first['name'].should == project.repo.tags.sort_by(&:name).reverse.first.name
  72 + end
  73 + end
  74 +
  75 + describe "GET /projects/:id/snippets/:snippet_id" do
  76 + it "should return a project snippet" do
  77 + get "#{api_prefix}/projects/#{project.code}/snippets/#{snippet.id}?private_token=#{user.private_token}"
  78 + response.status.should == 200
  79 + json_response['title'].should == snippet.title
  80 + end
  81 + end
  82 +
  83 + describe "POST /projects/:id/snippets" do
  84 + it "should create a new project snippet" do
  85 + post "#{api_prefix}/projects/#{project.code}/snippets?private_token=#{user.private_token}",
  86 + title: 'api test', file_name: 'sample.rb', code: 'test'
  87 + response.status.should == 201
  88 + json_response['title'].should == 'api test'
  89 + end
  90 + end
  91 +
  92 + describe "PUT /projects/:id/snippets" do
  93 + it "should update an existing project snippet" do
  94 + put "#{api_prefix}/projects/#{project.code}/snippets/#{snippet.id}?private_token=#{user.private_token}",
  95 + code: 'updated code'
  96 + response.status.should == 200
  97 + json_response['title'].should == 'example'
  98 + snippet.reload.content.should == 'updated code'
  99 + end
  100 + end
  101 +
  102 + describe "DELETE /projects/:id/snippets/:snippet_id" do
  103 + it "should delete existing project snippet" do
  104 + expect {
  105 + delete "#{api_prefix}/projects/#{project.code}/snippets/#{snippet.id}?private_token=#{user.private_token}"
  106 + }.to change { Snippet.count }.by(-1)
  107 + end
  108 + end
  109 +
  110 + describe "GET /projects/:id/snippets/:snippet_id/raw" do
  111 + it "should get a raw project snippet" do
  112 + get "#{api_prefix}/projects/#{project.code}/snippets/#{snippet.id}/raw?private_token=#{user.private_token}"
  113 + response.status.should == 200
  114 + end
  115 + end
  116 +
  117 + describe "GET /projects/:id/:sha/blob" do
  118 + it "should get the raw file contents" do
  119 + get "#{api_prefix}/projects/#{project.code}/repository/commits/master/blob?filepath=README.md&private_token=#{user.private_token}"
  120 +
  121 + response.status.should == 200
  122 + end
  123 +
  124 + it "should return 404 for invalid branch_name" do
  125 + get "#{api_prefix}/projects/#{project.code}/repository/commits/invalid_branch_name/blob?filepath=README.md&private_token=#{user.private_token}"
  126 +
  127 + response.status.should == 404
  128 + end
  129 +
  130 + it "should return 404 for invalid file" do
  131 + get "#{api_prefix}/projects/#{project.code}/repository/commits/master/blob?filepath=README.invalid&private_token=#{user.private_token}"
  132 +
  133 + response.status.should == 404
  134 + end
  135 + end
  136 +end
... ...
spec/requests/api/users_spec.rb 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +require 'spec_helper'
  2 +
  3 +describe Gitlab::API do
  4 + let(:user) { Factory :user }
  5 +
  6 + describe "GET /users" do
  7 + it "should return authentication error" do
  8 + get "#{api_prefix}/users"
  9 + response.status.should == 401
  10 + end
  11 +
  12 + describe "authenticated GET /users" do
  13 + it "should return an array of users" do
  14 + get "#{api_prefix}/users?private_token=#{user.private_token}"
  15 + response.status.should == 200
  16 + json_response.should be_an Array
  17 + json_response.first['email'].should == user.email
  18 + end
  19 + end
  20 + end
  21 +
  22 + describe "GET /users/:id" do
  23 + it "should return a user by id" do
  24 + get "#{api_prefix}/users/#{user.id}?private_token=#{user.private_token}"
  25 + response.status.should == 200
  26 + json_response['email'].should == user.email
  27 + end
  28 + end
  29 +
  30 + describe "GET /user" do
  31 + it "should return current user" do
  32 + get "#{api_prefix}/user?private_token=#{user.private_token}"
  33 + response.status.should == 200
  34 + json_response['email'].should == user.email
  35 + end
  36 + end
  37 +end
... ...
spec/spec_helper.rb
... ... @@ -9,10 +9,8 @@ require File.expand_path(&quot;../../config/environment&quot;, __FILE__)
9 9 require 'rspec/rails'
10 10 require 'capybara/rails'
11 11 require 'capybara/rspec'
12   -require 'capybara/dsl'
13 12 require 'webmock/rspec'
14 13 require 'factories'
15   -require 'monkeypatch'
16 14 require 'email_spec'
17 15 require 'headless'
18 16  
... ... @@ -23,10 +21,13 @@ Dir[Rails.root.join(&quot;spec/support/**/*.rb&quot;)].each {|f| require f}
23 21 # Use capybara-webkit
24 22 Capybara.javascript_driver = :webkit
25 23  
  24 +WebMock.disable_net_connect!(allow_localhost: true)
  25 +
26 26 RSpec.configure do |config|
27 27 config.mock_with :rspec
28 28  
29   - config.include LoginMacros
  29 + config.include LoginHelpers, type: :request
  30 + config.include ApiHelpers, type: :request
30 31  
31 32 # If you're not using ActiveRecord, or you'd prefer not to run each of your
32 33 # examples within a transaction, remove the following line or assign false
... ... @@ -38,35 +39,9 @@ RSpec.configure do |config|
38 39 headless.start
39 40 end
40 41  
41   - config.before :each, type: :integration do
42   - DeviseSessionMock.disable
43   - end
44   -
45 42 config.before do
46   - if example.metadata[:js]
47   - DatabaseCleaner.strategy = :truncation
48   - Capybara::Selenium::Driver::DEFAULT_OPTIONS[:resynchronize] = true
49   - else
50   - DatabaseCleaner.strategy = :transaction
51   - end
52   -
53   - DatabaseCleaner.start
54   -
55   - WebMock.disable_net_connect!(allow_localhost: true)
56   -
57 43 # !!! Observers disabled by default in tests
58   - #
59   - # Use next code to enable observers
60   - # before(:each) { ActiveRecord::Base.observers.enable(:all) }
61   - #
62   - ActiveRecord::Base.observers.disable :all
63   - end
64   -
65   - config.after do
66   - DatabaseCleaner.clean
  44 + ActiveRecord::Base.observers.disable(:all)
  45 + # ActiveRecord::Base.observers.enable(:all)
67 46 end
68   -
69   - config.include RSpec::Rails::RequestExampleGroup, type: :request, example_group: {
70   - file_path: /spec\/api/
71   - }
72 47 end
... ...
spec/support/api.rb
... ... @@ -1,7 +0,0 @@
1   -def api_prefix
2   - "/api/#{Gitlab::API::VERSION}"
3   -end
4   -
5   -def json_response
6   - JSON.parse(response.body)
7   -end
spec/support/api_helpers.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +module ApiHelpers
  2 + def api_prefix
  3 + "/api/#{Gitlab::API::VERSION}"
  4 + end
  5 +
  6 + def json_response
  7 + JSON.parse(response.body)
  8 + end
  9 +end
... ...
spec/support/db_cleaner.rb 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +require 'database_cleaner'
  2 +
  3 +RSpec.configure do |config|
  4 + config.before do
  5 + if example.metadata[:js]
  6 + DatabaseCleaner.strategy = :truncation
  7 + Capybara::Selenium::Driver::DEFAULT_OPTIONS[:resynchronize] = true
  8 + else
  9 + DatabaseCleaner.strategy = :transaction
  10 + end
  11 +
  12 + DatabaseCleaner.start
  13 + end
  14 +
  15 + config.after do
  16 + DatabaseCleaner.clean
  17 + end
  18 +end
... ...
spec/support/js_patch.rb
... ... @@ -1,6 +0,0 @@
1   -module JsPatch
2   - def confirm_js_popup
3   - page.evaluate_script("window.alert = function(msg) { return true; }")
4   - page.evaluate_script("window.confirm = function(msg) { return true; }")
5   - end
6   -end
spec/support/login.rb
... ... @@ -1,30 +0,0 @@
1   -module LoginMacros
2   - def login_as role
3   - @user = User.create(email: "user#{User.count}@mail.com",
4   - name: "John Smith",
5   - password: "123456",
6   - password_confirmation: "123456",
7   - skype: 'user_skype')
8   -
9   - if role == :admin
10   - @user.admin = true
11   - @user.save!
12   - end
13   -
14   - visit new_user_session_path
15   - fill_in "user_email", with: @user.email
16   - fill_in "user_password", with: "123456"
17   - click_button "Sign in"
18   - end
19   -
20   - def login_with(user)
21   - visit new_user_session_path
22   - fill_in "user_email", with: user.email
23   - fill_in "user_password", with: "123456"
24   - click_button "Sign in"
25   - end
26   -
27   - def logout
28   - click_link "Logout" rescue nil
29   - end
30   -end
spec/support/login_helpers.rb 0 → 100644
... ... @@ -0,0 +1,23 @@
  1 +module LoginHelpers
  2 + # Internal: Create and log in as a user of the specified role
  3 + #
  4 + # role - User role (e.g., :admin, :user)
  5 + def login_as(role)
  6 + @user = Factory(role)
  7 + login_with(@user)
  8 + end
  9 +
  10 + # Internal: Login as the specified user
  11 + #
  12 + # user - User instance to login with
  13 + def login_with(user)
  14 + visit new_user_session_path
  15 + fill_in "user_email", with: user.email
  16 + fill_in "user_password", with: "123456"
  17 + click_button "Sign in"
  18 + end
  19 +
  20 + def logout
  21 + click_link "Logout" rescue nil
  22 + end
  23 +end
... ...
spec/support/monkeypatch.rb 0 → 100644
... ... @@ -0,0 +1,51 @@
  1 +# Stubbing Project <-> git host path
  2 +# create project using Factory only
  3 +class Project
  4 + def update_repository
  5 + true
  6 + end
  7 +
  8 + def destroy_repository
  9 + true
  10 + end
  11 +
  12 + def path_to_repo
  13 + File.join(Rails.root, "tmp", "tests", path)
  14 + end
  15 +
  16 + def satellite
  17 + @satellite ||= FakeSatellite.new
  18 + end
  19 +end
  20 +
  21 +class Key
  22 + def update_repository
  23 + true
  24 + end
  25 +
  26 + def repository_delete_key
  27 + true
  28 + end
  29 +end
  30 +
  31 +class UsersProject
  32 + def update_repository
  33 + true
  34 + end
  35 +end
  36 +
  37 +class FakeSatellite
  38 + def exists?
  39 + true
  40 + end
  41 +
  42 + def create
  43 + true
  44 + end
  45 +end
  46 +
  47 +class ProtectedBranch
  48 + def update_repository
  49 + true
  50 + end
  51 +end
... ...
spec/support/shared_examples.rb
... ... @@ -1,16 +0,0 @@
1   -shared_examples_for :project_side_pane do
2   - subject { page }
3   - it { should have_content((@project || project).name) }
4   - it { should have_content("Commits") }
5   - it { should have_content("Files") }
6   -end
7   -
8   -shared_examples_for :tree_view do
9   - subject { page }
10   -
11   - it "should have Tree View of project" do
12   - should have_content("app")
13   - should have_content("History")
14   - should have_content("Gemfile")
15   - end
16   -end