Commit 6534f0eabadb2d0d07d1f4b0914460432e872f9c
1 parent
fbc36e89
Exists in
colab
and in
4 other branches
Project as a KalibroClient subclass
Showing
6 changed files
with
10 additions
and
172 deletions
Show diff stats
Gemfile.lock
1 | 1 | GIT |
2 | + remote: https://github.com/mezuro/kalibro_client | |
3 | + revision: cd1f8d931432a7257d0fe1abcacdaf50b8fd3976 | |
4 | + specs: | |
5 | + kalibro_client (0.0.1) | |
6 | + activeresource (~> 4.0.0) | |
7 | + | |
8 | +GIT | |
2 | 9 | remote: https://github.com/seyhunak/twitter-bootstrap-rails.git |
3 | 10 | revision: 67f160dd2ff5cc7cd843a17866c3b6bc8e7f2794 |
4 | 11 | specs: |
... | ... | @@ -8,13 +15,6 @@ GIT |
8 | 15 | rails (>= 3.1) |
9 | 16 | railties (>= 3.1) |
10 | 17 | |
11 | -GIT | |
12 | - remote: https://github.com/mezuro/kalibro_client | |
13 | - revision: cd1f8d931432a7257d0fe1abcacdaf50b8fd3976 | |
14 | - specs: | |
15 | - kalibro_client (0.0.1) | |
16 | - activeresource (~> 4.0.0) | |
17 | - | |
18 | 18 | GEM |
19 | 19 | remote: https://rubygems.org/ |
20 | 20 | specs: | ... | ... |
app/models/project.rb
1 | -require "validators/kalibro_uniqueness_validator.rb" | |
2 | - | |
3 | -class Project < KalibroGatekeeperClient::Entities::Project | |
4 | - include KalibroRecord | |
5 | - | |
6 | - attr_accessor :name | |
7 | - validates :name, presence: true, kalibro_uniqueness: true | |
8 | - | |
9 | - def repositories | |
10 | - Repository.repositories_of(self.id) | |
11 | - end | |
12 | - | |
1 | +class Project < KalibroClient::Processor::Project | |
13 | 2 | def self.latest(count = 1) |
14 | 3 | all.sort { |a,b| b.id <=> a.id }.first(count) |
15 | 4 | end | ... | ... |
spec/controllers/projects_controller_spec.rb
... | ... | @@ -27,13 +27,11 @@ describe ProjectsController, :type => :controller do |
27 | 27 | |
28 | 28 | context 'rendering the show' do |
29 | 29 | before :each do |
30 | - Project.expects(:exists?).returns(true) | |
31 | - | |
32 | 30 | post :create, :project => subject_params |
33 | 31 | end |
34 | 32 | |
35 | 33 | it 'should redirect to the show view' do |
36 | - expect(response).to redirect_to project_path(project) | |
34 | + expect(response).to redirect_to project_path(project.id) | |
37 | 35 | end |
38 | 36 | end |
39 | 37 | |
... | ... | @@ -234,12 +232,11 @@ describe ProjectsController, :type => :controller do |
234 | 232 | |
235 | 233 | context 'rendering the show' do |
236 | 234 | before :each do |
237 | - Project.expects(:exists?).returns(true) | |
238 | 235 | post :update, :id => @subject.id, :project => @subject_params |
239 | 236 | end |
240 | 237 | |
241 | 238 | it 'should redirect to the show view' do |
242 | - expect(response).to redirect_to project_path(@subject) | |
239 | + expect(response).to redirect_to project_path(@subject.id) | |
243 | 240 | end |
244 | 241 | end |
245 | 242 | ... | ... |
spec/models/project_spec.rb
... | ... | @@ -2,17 +2,6 @@ require 'rails_helper' |
2 | 2 | |
3 | 3 | describe Project, :type => :model do |
4 | 4 | describe 'methods' do |
5 | - describe 'persisted?' do | |
6 | - before :each do | |
7 | - @subject = FactoryGirl.build(:project) | |
8 | - Project.expects(:exists?).with(@subject.id).returns(false) | |
9 | - end | |
10 | - | |
11 | - it 'should return false' do | |
12 | - expect(@subject.persisted?).to eq(false) | |
13 | - end | |
14 | - end | |
15 | - | |
16 | 5 | describe 'latest' do |
17 | 6 | before :each do |
18 | 7 | @qt = FactoryGirl.build(:project) |
... | ... | @@ -31,63 +20,5 @@ describe Project, :type => :model do |
31 | 20 | end |
32 | 21 | end |
33 | 22 | end |
34 | - | |
35 | - describe 'update' do | |
36 | - before :each do | |
37 | - @qt = FactoryGirl.build(:project) | |
38 | - @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 | |
39 | - end | |
40 | - | |
41 | - context 'with valid attributes' do | |
42 | - before :each do | |
43 | - @qt.expects(:save).returns(true) | |
44 | - end | |
45 | - | |
46 | - it 'should return true' do | |
47 | - expect(@qt.update(@qt_params)).to eq(true) | |
48 | - end | |
49 | - end | |
50 | - | |
51 | - context 'with invalid attributes' do | |
52 | - before :each do | |
53 | - @qt.expects(:save).returns(false) | |
54 | - end | |
55 | - | |
56 | - it 'should return false' do | |
57 | - expect(@qt.update(@qt_params)).to eq(false) | |
58 | - end | |
59 | - end | |
60 | - end | |
61 | - | |
62 | - describe 'repositories' do | |
63 | - subject { FactoryGirl.build(:project) } | |
64 | - let(:repository) { FactoryGirl.build(:repository) } | |
65 | - | |
66 | - it 'should call repositories_of on the Repository model' do | |
67 | - Repository.expects(:repositories_of).with(subject.id).returns([repository]) | |
68 | - | |
69 | - expect(subject.repositories).to include(repository) | |
70 | - end | |
71 | - end | |
72 | - end | |
73 | - | |
74 | - describe 'validations' do | |
75 | - subject {FactoryGirl.build(:project)} | |
76 | - context 'active model validations' do | |
77 | - before :each do | |
78 | - Project.expects(:all).at_least_once.returns([]) | |
79 | - end | |
80 | - it { is_expected.to validate_presence_of(:name) } | |
81 | - end | |
82 | - | |
83 | - context 'kalibro validations' do | |
84 | - before :each do | |
85 | - Project.expects(:request).returns(42) | |
86 | - end | |
87 | - | |
88 | - it 'should validate uniqueness' do | |
89 | - subject.save | |
90 | - end | |
91 | - end | |
92 | 23 | end |
93 | 24 | end | ... | ... |
spec/models/validators/kalibro_uniqueness_validator_spec.rb
... | ... | @@ -1,35 +0,0 @@ |
1 | -require 'rails_helper' | |
2 | -require 'validators/range_overlapping_validator' | |
3 | - | |
4 | -describe KalibroUniquenessValidator, :type => :model do | |
5 | - pending 'waiting for kalibro configurations integration' do | |
6 | - describe 'methods' do | |
7 | - describe 'validate_each' do | |
8 | - context 'without saved projects' do | |
9 | - before :each do | |
10 | - Project.expects(:all).returns([]) | |
11 | - Project.expects(:request).returns(42) | |
12 | - end | |
13 | - | |
14 | - subject { FactoryGirl.build(:project) } | |
15 | - it 'should contain no errors' do | |
16 | - subject.save | |
17 | - expect(subject.errors).to be_empty | |
18 | - end | |
19 | - end | |
20 | - | |
21 | - context 'with name already taken by another project' do | |
22 | - before :each do | |
23 | - @subject = FactoryGirl.build(:project) | |
24 | - Project.expects(:all).returns([FactoryGirl.build(:project, id: @subject.id + 1)]) | |
25 | - end | |
26 | - | |
27 | - it 'should contain errors' do | |
28 | - @subject.save | |
29 | - expect(@subject.errors[:name]).to eq(["There is already a Project with name #{@subject.name}! Please, choose another one."]) | |
30 | - end | |
31 | - end | |
32 | - end | |
33 | - end | |
34 | - end | |
35 | -end |
spec/models/validators/range_overlapping_validator_spec.rb
... | ... | @@ -1,44 +0,0 @@ |
1 | -require 'rails_helper' | |
2 | - | |
3 | -describe RangeOverlappingValidator, :type => :model do | |
4 | - pending 'waiting for kalibro configurations integration' do | |
5 | - describe 'methods' do | |
6 | - describe 'validate' do | |
7 | - let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } | |
8 | - let(:range) { FactoryGirl.build(:mezuro_range, beginning: '-INF', end: 0.0, metric_configuration_id: metric_configuration.id) } | |
9 | - | |
10 | - before :each do | |
11 | - BeginningUniquenessValidator.any_instance.stubs(:validate_each) | |
12 | - GreaterThanBeginningValidator.any_instance.stubs(:validate_each) | |
13 | - end | |
14 | - | |
15 | - context 'not overlapping' do | |
16 | - let!(:not_overlapping_range) { FactoryGirl.build(:mezuro_range, id: 31, beginning: 0.0, end: 'INF', metric_configuration_id: metric_configuration.id) } | |
17 | - | |
18 | - before :each do | |
19 | - MezuroRange.expects(:ranges_of).with(metric_configuration.id).returns([range, not_overlapping_range]) | |
20 | - end | |
21 | - | |
22 | - it 'is expected to not return errors' do | |
23 | - range.save | |
24 | - expect(range.errors).to be_empty | |
25 | - end | |
26 | - end | |
27 | - | |
28 | - | |
29 | - context 'overlapping' do | |
30 | - let!(:overlapping_range) { FactoryGirl.build(:mezuro_range, id: 31, beginning: '-INF', end: 'INF', metric_configuration_id: metric_configuration.id) } | |
31 | - | |
32 | - before :each do | |
33 | - MezuroRange.expects(:ranges_of).with(metric_configuration.id).returns([range, overlapping_range]) | |
34 | - end | |
35 | - | |
36 | - it 'is expected to return errors' do | |
37 | - range.save | |
38 | - expect(range.errors[:beginning]).to eq(["There is already a #{range.class} within these boundaries! Please, choose another interval."]) | |
39 | - end | |
40 | - end | |
41 | - end | |
42 | - end | |
43 | - end | |
44 | -end |