Commit 391fb93c691a143ee0ee5902e08173b84dfb01f8

Authored by Diego Camarinha
2 parents 6b6c23b9 83767467

Merge pull request #166 from beatrizrezener/issue31

RepositoriesController test coverage #31
features/repository/show/metric_results.feature
... ... @@ -38,8 +38,21 @@ Feature: Repository metric results
38 38 When I visit the repository show page
39 39 And I click the "Metric Results" h3
40 40 And I see a sample metric's name
41   - Then I should see "Missing range"
  41 + Then I should see "Missing range"
  42 +
  43 + @kalibro_restart @kalibro_processor_restart @javascript
  44 + Scenario: Should show the error message when the process fails
  45 + Given I am a regular user
  46 + And I am signed in
  47 + And I have a sample project
  48 + And I have a sample configuration with native metrics
  49 + And I have a sample of an invalid repository within the sample project
  50 + And I start to process that repository
  51 + And I wait up for a error processing
  52 + When I visit the repository show page
  53 + And I click the "Metric Results" h3
  54 + Then I should see "Repository process returned with error. There are no metric results."
42 55  
43 56 # TODO: Scenario: Should show the graphic of a given metric
44 57 # It was getting really difficult to test this because of Poltergeist's timeouts
45   - # so we gave up on this for now
46 58 \ No newline at end of file
  59 + # so we gave up on this for now
... ...
features/step_definitions/repository_steps.rb
... ... @@ -34,6 +34,11 @@ Given(/^I have a sample repository within the sample project named "(.+)"$/) do
34 34 configuration_id: @mezuro_configuration.id, id: nil, name: name})
35 35 end
36 36  
  37 +Given(/^I have a sample of an invalid repository within the sample project$/) do
  38 + @repository = FactoryGirl.create(:repository, {project_id: @project.id,
  39 + configuration_id: @mezuro_configuration.id, id: nil, address: "https://invalidrepository.git"})
  40 +end
  41 +
37 42 Given(/^I start to process that repository$/) do
38 43 @repository.process
39 44 end
... ... @@ -50,6 +55,18 @@ Given(/^I wait up for a ready processing$/) do
50 55 end
51 56 end
52 57  
  58 +Given(/^I wait up for a error processing$/) do
  59 + unless Processing.last_processing_state_of(@repository.id) == "ERROR"
  60 + while(true)
  61 + if Processing.last_processing_state_of(@repository.id) == "ERROR"
  62 + break
  63 + else
  64 + sleep(10)
  65 + end
  66 + end
  67 + end
  68 +end
  69 +
53 70 Given(/^I am at the New Repository page$/) do
54 71 visit new_project_repository_path(@project.id)
55 72 end
... ...
spec/controllers/repositories_controller_spec.rb
... ... @@ -4,29 +4,39 @@ describe RepositoriesController, :type => :controller do
4 4 let(:project) { FactoryGirl.build(:project) }
5 5  
6 6 describe 'new' do
7   - before :each do
8   - sign_in FactoryGirl.create(:user) #TODO create a context when there's no user logged in
9   - end
10   -
11   - context 'when the current user owns the project' do
  7 + context 'with an User logged in' do
12 8 before :each do
13   - Repository.expects(:repository_types).returns([])
14   - subject.expects(:project_owner?).returns true
  9 + sign_in FactoryGirl.create(:user)
  10 + end
15 11  
16   - get :new, project_id: project.id.to_s
  12 + context 'when the current user owns the project' do
  13 + before :each do
  14 + Repository.expects(:repository_types).returns([])
  15 + subject.expects(:project_owner?).returns true
  16 +
  17 + get :new, project_id: project.id.to_s
  18 + end
  19 +
  20 + it { is_expected.to respond_with(:success) }
  21 + it { is_expected.to render_template(:new) }
17 22 end
18 23  
19   - it { is_expected.to respond_with(:success) }
20   - it { is_expected.to render_template(:new) }
  24 + context "when the current user doesn't owns the project" do
  25 + before :each do
  26 + get :new, project_id: project.id.to_s
  27 + end
  28 +
  29 + it { is_expected.to redirect_to(projects_url) }
  30 + it { is_expected.to respond_with(:redirect) }
  31 + end
21 32 end
22 33  
23   - context "when the current user doesn't owns the project" do
  34 + context 'with no user logged in' do
24 35 before :each do
25 36 get :new, project_id: project.id.to_s
26 37 end
27 38  
28   - it { is_expected.to redirect_to(projects_url) }
29   - it { is_expected.to respond_with(:redirect) }
  39 + it { is_expected.to redirect_to new_user_session_path }
30 40 end
31 41 end
32 42  
... ...