From 03e38214c7f8230df6654069376f3c9ab1f49cc2 Mon Sep 17 00:00:00 2001 From: Daniel Miranda Date: Sun, 17 Apr 2016 23:18:34 -0300 Subject: [PATCH] Update tests to properly handle latest content caching --- features/homepage.feature | 6 +++++- features/step_definitions/kalibro_configuration_steps.rb | 6 ++++++ spec/controllers/home_controller_spec.rb | 39 +++++++++++++++++++++++++++++++-------- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/features/homepage.feature b/features/homepage.feature index dddefaa..55f3182 100644 --- a/features/homepage.feature +++ b/features/homepage.feature @@ -3,9 +3,11 @@ Feature: Homepage As a regular user I want to have in one page useful links to manage my account and session - @kalibro_processor_restart + @kalibro_configurations_restart @kalibro_processor_restart Scenario: Before signing in Given I have a project named "GCC" + And there is a public configuration created named "Test Configuration" + And I have a sample repository named "Test Repository" Then I am at the homepage And I should see "Home" And I should see "Projects" @@ -19,6 +21,8 @@ Feature: Homepage And I should see "Latest repositories" And I should see "Latest configurations" Then I should see "GCC" only "1" times + Then I should see "Test Configuration" only "1" times + Then I should see "Test Repository" only "1" times Scenario: Signed in Given I am a regular user diff --git a/features/step_definitions/kalibro_configuration_steps.rb b/features/step_definitions/kalibro_configuration_steps.rb index 89747df..bd6e90a 100644 --- a/features/step_definitions/kalibro_configuration_steps.rb +++ b/features/step_definitions/kalibro_configuration_steps.rb @@ -87,6 +87,12 @@ Given(/^there is a public configuration created$/) do FactoryGirl.create(:kalibro_configuration_attributes, kalibro_configuration_id: @public_kc.id) end +Given(/^there is a public configuration created named "(.*?)"$/) do |name| + @kalibro_configuration = FactoryGirl.create(:public_kalibro_configuration, name: name) + FactoryGirl.create(:kalibro_configuration_attributes, kalibro_configuration_id: @kalibro_configuration.id) +end + + Given(/^there is a private configuration created$/) do @private_kc = FactoryGirl.create(:another_kalibro_configuration) FactoryGirl.create(:kalibro_configuration_attributes, :private, kalibro_configuration_id: @private_kc.id, user: FactoryGirl.create(:another_user, id: nil, email: "private@email.com")) diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index 0dbd3a3..5760be6 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -1,14 +1,8 @@ require 'rails_helper' describe HomeController, :type => :controller do - context 'Method' do - context '#index' do - before :each do - Project.expects(:latest).with(5).returns([]) - Repository.expects(:latest).with(5).returns([]) - KalibroConfiguration.expects(:latest).with(5).returns([]) - end - + context 'actions' do + context 'index' do describe 'Rendering' do before :each do get :index @@ -41,4 +35,33 @@ describe HomeController, :type => :controller do end end end + + context 'helpers' do + describe 'latest_repositories' do + let(:repositories) { mock } + + it 'should fetch the latest content' do + Repository.expects(:latest).with(5).returns(repositories) + expect(subject.latest_repositories(5)).to be(repositories) + end + end + + describe 'latest_projects' do + let(:projects) { mock } + + it 'should fetch the latest content' do + Project.expects(:latest).with(5).returns(projects) + expect(subject.latest_projects(5)).to be(projects) + end + end + + describe 'latest_configurations' do + let(:configurations) { mock } + + it 'should fetch the latest content' do + KalibroConfiguration.expects(:latest).with(5).returns(configurations) + expect(subject.latest_configurations(5)).to be(configurations) + end + end + end end -- libgit2 0.21.2