diff --git a/Gemfile.lock b/Gemfile.lock index d125f9f..a18803f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,4 +1,11 @@ GIT + remote: https://github.com/mezuro/kalibro_client + revision: cd1f8d931432a7257d0fe1abcacdaf50b8fd3976 + specs: + kalibro_client (0.0.1) + activeresource (~> 4.0.0) + +GIT remote: https://github.com/seyhunak/twitter-bootstrap-rails.git revision: 67f160dd2ff5cc7cd843a17866c3b6bc8e7f2794 specs: @@ -8,13 +15,6 @@ GIT rails (>= 3.1) railties (>= 3.1) -GIT - remote: https://github.com/mezuro/kalibro_client - revision: cd1f8d931432a7257d0fe1abcacdaf50b8fd3976 - specs: - kalibro_client (0.0.1) - activeresource (~> 4.0.0) - GEM remote: https://rubygems.org/ specs: diff --git a/app/models/project.rb b/app/models/project.rb index acf47c0..612db14 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,15 +1,4 @@ -require "validators/kalibro_uniqueness_validator.rb" - -class Project < KalibroGatekeeperClient::Entities::Project - include KalibroRecord - - attr_accessor :name - validates :name, presence: true, kalibro_uniqueness: true - - def repositories - Repository.repositories_of(self.id) - end - +class Project < KalibroClient::Processor::Project def self.latest(count = 1) all.sort { |a,b| b.id <=> a.id }.first(count) end diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 7e5748c..c5d9807 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -27,13 +27,11 @@ describe ProjectsController, :type => :controller do context 'rendering the show' do before :each do - Project.expects(:exists?).returns(true) - post :create, :project => subject_params end it 'should redirect to the show view' do - expect(response).to redirect_to project_path(project) + expect(response).to redirect_to project_path(project.id) end end @@ -234,12 +232,11 @@ describe ProjectsController, :type => :controller do context 'rendering the show' do before :each do - Project.expects(:exists?).returns(true) post :update, :id => @subject.id, :project => @subject_params end it 'should redirect to the show view' do - expect(response).to redirect_to project_path(@subject) + expect(response).to redirect_to project_path(@subject.id) end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index e7bf391..bf8b3d3 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2,17 +2,6 @@ require 'rails_helper' describe Project, :type => :model do describe 'methods' do - describe 'persisted?' do - before :each do - @subject = FactoryGirl.build(:project) - Project.expects(:exists?).with(@subject.id).returns(false) - end - - it 'should return false' do - expect(@subject.persisted?).to eq(false) - end - end - describe 'latest' do before :each do @qt = FactoryGirl.build(:project) @@ -31,63 +20,5 @@ describe Project, :type => :model do end end end - - describe 'update' do - before :each do - @qt = FactoryGirl.build(:project) - @qt_params = Hash[FactoryGirl.attributes_for(:project).map { |k,v| [k.to_s, v.to_s] }] #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers - end - - context 'with valid attributes' do - before :each do - @qt.expects(:save).returns(true) - end - - it 'should return true' do - expect(@qt.update(@qt_params)).to eq(true) - end - end - - context 'with invalid attributes' do - before :each do - @qt.expects(:save).returns(false) - end - - it 'should return false' do - expect(@qt.update(@qt_params)).to eq(false) - end - end - end - - describe 'repositories' do - subject { FactoryGirl.build(:project) } - let(:repository) { FactoryGirl.build(:repository) } - - it 'should call repositories_of on the Repository model' do - Repository.expects(:repositories_of).with(subject.id).returns([repository]) - - expect(subject.repositories).to include(repository) - end - end - end - - describe 'validations' do - subject {FactoryGirl.build(:project)} - context 'active model validations' do - before :each do - Project.expects(:all).at_least_once.returns([]) - end - it { is_expected.to validate_presence_of(:name) } - end - - context 'kalibro validations' do - before :each do - Project.expects(:request).returns(42) - end - - it 'should validate uniqueness' do - subject.save - end - end end end diff --git a/spec/models/validators/kalibro_uniqueness_validator_spec.rb b/spec/models/validators/kalibro_uniqueness_validator_spec.rb deleted file mode 100644 index 6c200c1..0000000 --- a/spec/models/validators/kalibro_uniqueness_validator_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'rails_helper' -require 'validators/range_overlapping_validator' - -describe KalibroUniquenessValidator, :type => :model do - pending 'waiting for kalibro configurations integration' do - describe 'methods' do - describe 'validate_each' do - context 'without saved projects' do - before :each do - Project.expects(:all).returns([]) - Project.expects(:request).returns(42) - end - - subject { FactoryGirl.build(:project) } - it 'should contain no errors' do - subject.save - expect(subject.errors).to be_empty - end - end - - context 'with name already taken by another project' do - before :each do - @subject = FactoryGirl.build(:project) - Project.expects(:all).returns([FactoryGirl.build(:project, id: @subject.id + 1)]) - end - - it 'should contain errors' do - @subject.save - expect(@subject.errors[:name]).to eq(["There is already a Project with name #{@subject.name}! Please, choose another one."]) - end - end - end - end - end -end diff --git a/spec/models/validators/range_overlapping_validator_spec.rb b/spec/models/validators/range_overlapping_validator_spec.rb deleted file mode 100644 index 26c7701..0000000 --- a/spec/models/validators/range_overlapping_validator_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'rails_helper' - -describe RangeOverlappingValidator, :type => :model do - pending 'waiting for kalibro configurations integration' do - describe 'methods' do - describe 'validate' do - let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } - let(:range) { FactoryGirl.build(:mezuro_range, beginning: '-INF', end: 0.0, metric_configuration_id: metric_configuration.id) } - - before :each do - BeginningUniquenessValidator.any_instance.stubs(:validate_each) - GreaterThanBeginningValidator.any_instance.stubs(:validate_each) - end - - context 'not overlapping' do - let!(:not_overlapping_range) { FactoryGirl.build(:mezuro_range, id: 31, beginning: 0.0, end: 'INF', metric_configuration_id: metric_configuration.id) } - - before :each do - MezuroRange.expects(:ranges_of).with(metric_configuration.id).returns([range, not_overlapping_range]) - end - - it 'is expected to not return errors' do - range.save - expect(range.errors).to be_empty - end - end - - - context 'overlapping' do - let!(:overlapping_range) { FactoryGirl.build(:mezuro_range, id: 31, beginning: '-INF', end: 'INF', metric_configuration_id: metric_configuration.id) } - - before :each do - MezuroRange.expects(:ranges_of).with(metric_configuration.id).returns([range, overlapping_range]) - end - - it 'is expected to return errors' do - range.save - expect(range.errors[:beginning]).to eq(["There is already a #{range.class} within these boundaries! Please, choose another interval."]) - end - end - end - end - end -end -- libgit2 0.21.2