Commit 03e38214c7f8230df6654069376f3c9ab1f49cc2
Committed by
Diego Araújo
1 parent
f893cf3d
Exists in
colab
and in
2 other branches
Update tests to properly handle latest content caching
Unit tests cannot expects that models will always be fetched. But to make sure things are still well tested, verify the existence of a configuration, project and repository in the homepage feature.
Showing
3 changed files
with
42 additions
and
9 deletions
Show diff stats
features/homepage.feature
... | ... | @@ -3,9 +3,11 @@ Feature: Homepage |
3 | 3 | As a regular user |
4 | 4 | I want to have in one page useful links to manage my account and session |
5 | 5 | |
6 | - @kalibro_processor_restart | |
6 | + @kalibro_configurations_restart @kalibro_processor_restart | |
7 | 7 | Scenario: Before signing in |
8 | 8 | Given I have a project named "GCC" |
9 | + And there is a public configuration created named "Test Configuration" | |
10 | + And I have a sample repository named "Test Repository" | |
9 | 11 | Then I am at the homepage |
10 | 12 | And I should see "Home" |
11 | 13 | And I should see "Projects" |
... | ... | @@ -19,6 +21,8 @@ Feature: Homepage |
19 | 21 | And I should see "Latest repositories" |
20 | 22 | And I should see "Latest configurations" |
21 | 23 | Then I should see "GCC" only "1" times |
24 | + Then I should see "Test Configuration" only "1" times | |
25 | + Then I should see "Test Repository" only "1" times | |
22 | 26 | |
23 | 27 | Scenario: Signed in |
24 | 28 | Given I am a regular user | ... | ... |
features/step_definitions/kalibro_configuration_steps.rb
... | ... | @@ -87,6 +87,12 @@ Given(/^there is a public configuration created$/) do |
87 | 87 | FactoryGirl.create(:kalibro_configuration_attributes, kalibro_configuration_id: @public_kc.id) |
88 | 88 | end |
89 | 89 | |
90 | +Given(/^there is a public configuration created named "(.*?)"$/) do |name| | |
91 | + @kalibro_configuration = FactoryGirl.create(:public_kalibro_configuration, name: name) | |
92 | + FactoryGirl.create(:kalibro_configuration_attributes, kalibro_configuration_id: @kalibro_configuration.id) | |
93 | +end | |
94 | + | |
95 | + | |
90 | 96 | Given(/^there is a private configuration created$/) do |
91 | 97 | @private_kc = FactoryGirl.create(:another_kalibro_configuration) |
92 | 98 | FactoryGirl.create(:kalibro_configuration_attributes, :private, kalibro_configuration_id: @private_kc.id, user: FactoryGirl.create(:another_user, id: nil, email: "private@email.com")) | ... | ... |
spec/controllers/home_controller_spec.rb
1 | 1 | require 'rails_helper' |
2 | 2 | |
3 | 3 | describe HomeController, :type => :controller do |
4 | - context 'Method' do | |
5 | - context '#index' do | |
6 | - before :each do | |
7 | - Project.expects(:latest).with(5).returns([]) | |
8 | - Repository.expects(:latest).with(5).returns([]) | |
9 | - KalibroConfiguration.expects(:latest).with(5).returns([]) | |
10 | - end | |
11 | - | |
4 | + context 'actions' do | |
5 | + context 'index' do | |
12 | 6 | describe 'Rendering' do |
13 | 7 | before :each do |
14 | 8 | get :index |
... | ... | @@ -41,4 +35,33 @@ describe HomeController, :type => :controller do |
41 | 35 | end |
42 | 36 | end |
43 | 37 | end |
38 | + | |
39 | + context 'helpers' do | |
40 | + describe 'latest_repositories' do | |
41 | + let(:repositories) { mock } | |
42 | + | |
43 | + it 'should fetch the latest content' do | |
44 | + Repository.expects(:latest).with(5).returns(repositories) | |
45 | + expect(subject.latest_repositories(5)).to be(repositories) | |
46 | + end | |
47 | + end | |
48 | + | |
49 | + describe 'latest_projects' do | |
50 | + let(:projects) { mock } | |
51 | + | |
52 | + it 'should fetch the latest content' do | |
53 | + Project.expects(:latest).with(5).returns(projects) | |
54 | + expect(subject.latest_projects(5)).to be(projects) | |
55 | + end | |
56 | + end | |
57 | + | |
58 | + describe 'latest_configurations' do | |
59 | + let(:configurations) { mock } | |
60 | + | |
61 | + it 'should fetch the latest content' do | |
62 | + KalibroConfiguration.expects(:latest).with(5).returns(configurations) | |
63 | + expect(subject.latest_configurations(5)).to be(configurations) | |
64 | + end | |
65 | + end | |
66 | + end | |
44 | 67 | end | ... | ... |