Commit 2f2ddebbea79702bc566609a8d03be4ba1588ef8
1 parent
a487b5b9
Exists in
colab
and in
4 other branches
MezuroConfiguration using KalibroClient class
Showing
3 changed files
with
16 additions
and
106 deletions
Show diff stats
app/models/mezuro_configuration.rb
| 1 | -require "validators/kalibro_uniqueness_validator.rb" | |
| 2 | - | |
| 3 | -class MezuroConfiguration < KalibroGatekeeperClient::Entities::Configuration | |
| 4 | - include KalibroRecord | |
| 5 | - | |
| 6 | - attr_accessor :name | |
| 7 | - validates :name, presence: true, kalibro_uniqueness: true | |
| 8 | - | |
| 9 | - def metric_configurations | |
| 10 | - MetricConfiguration.metric_configurations_of(self.id) | |
| 11 | - end | |
| 12 | -end | |
| 1 | +class MezuroConfiguration < KalibroClient::Configurations::KalibroConfiguration; end | ... | ... |
spec/controllers/mezuro_configurations_controller_spec.rb
| ... | ... | @@ -27,13 +27,11 @@ describe MezuroConfigurationsController, :type => :controller do |
| 27 | 27 | |
| 28 | 28 | context 'rendering the show' do |
| 29 | 29 | before :each do |
| 30 | - MezuroConfiguration.expects(:exists?).returns(true) | |
| 31 | - | |
| 32 | 30 | post :create, :mezuro_configuration => subject_params |
| 33 | 31 | end |
| 34 | 32 | |
| 35 | 33 | it 'should redirect to the show view' do |
| 36 | - expect(response).to redirect_to mezuro_configuration_path(mezuro_configuration) | |
| 34 | + expect(response).to redirect_to mezuro_configuration_path(mezuro_configuration.id) | |
| 37 | 35 | end |
| 38 | 36 | end |
| 39 | 37 | |
| ... | ... | @@ -194,10 +192,8 @@ describe MezuroConfigurationsController, :type => :controller do |
| 194 | 192 | end |
| 195 | 193 | |
| 196 | 194 | describe 'update' do |
| 197 | - before do | |
| 198 | - @subject = FactoryGirl.build(:mezuro_configuration) | |
| 199 | - @subject_params = Hash[FactoryGirl.attributes_for(:mezuro_configuration).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 | |
| 200 | - end | |
| 195 | + let(:mezuro_configuration) {FactoryGirl.build(:mezuro_configuration)} | |
| 196 | + let(:mezuro_configuration_params) {Hash[FactoryGirl.attributes_for(:mezuro_configuration).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 | |
| 201 | 197 | |
| 202 | 198 | context 'when the user is logged in' do |
| 203 | 199 | before do |
| ... | ... | @@ -209,31 +205,29 @@ describe MezuroConfigurationsController, :type => :controller do |
| 209 | 205 | @ownership = FactoryGirl.build(:mezuro_configuration_ownership) |
| 210 | 206 | @ownerships = [] |
| 211 | 207 | |
| 212 | - @ownerships.expects(:find_by_mezuro_configuration_id).with("#{@subject.id}").returns(@ownership) | |
| 208 | + @ownerships.expects(:find_by_mezuro_configuration_id).with("#{mezuro_configuration.id}").returns(@ownership) | |
| 213 | 209 | User.any_instance.expects(:mezuro_configuration_ownerships).at_least_once.returns(@ownerships) |
| 214 | 210 | end |
| 215 | 211 | |
| 216 | 212 | context 'with valid fields' do |
| 217 | 213 | before :each do |
| 218 | - subject.expects(:find_resource).with(MezuroConfiguration, @subject.id).returns(@subject) | |
| 219 | - MezuroConfiguration.any_instance.expects(:update).with(@subject_params).returns(true) | |
| 214 | + subject.expects(:find_resource).with(MezuroConfiguration, mezuro_configuration.id).returns(mezuro_configuration) | |
| 215 | + MezuroConfiguration.any_instance.expects(:update).with(mezuro_configuration_params).returns(true) | |
| 220 | 216 | end |
| 221 | 217 | |
| 222 | 218 | context 'rendering the show' do |
| 223 | 219 | before :each do |
| 224 | - MezuroConfiguration.expects(:exists?).returns(true) | |
| 225 | - | |
| 226 | - post :update, :id => @subject.id, :mezuro_configuration => @subject_params | |
| 220 | + post :update, :id => mezuro_configuration.id, :mezuro_configuration => mezuro_configuration_params | |
| 227 | 221 | end |
| 228 | 222 | |
| 229 | 223 | it 'should redirect to the show view' do |
| 230 | - expect(response).to redirect_to mezuro_configuration_path(@subject) | |
| 224 | + expect(response).to redirect_to mezuro_configuration_path(mezuro_configuration.id) | |
| 231 | 225 | end |
| 232 | 226 | end |
| 233 | 227 | |
| 234 | 228 | context 'without rendering the show view' do |
| 235 | 229 | before :each do |
| 236 | - post :update, :id => @subject.id, :mezuro_configuration => @subject_params | |
| 230 | + post :update, :id => mezuro_configuration.id, :mezuro_configuration => mezuro_configuration_params | |
| 237 | 231 | end |
| 238 | 232 | |
| 239 | 233 | it { is_expected.to respond_with(:redirect) } |
| ... | ... | @@ -242,10 +236,10 @@ describe MezuroConfigurationsController, :type => :controller do |
| 242 | 236 | |
| 243 | 237 | context 'with an invalid field' do |
| 244 | 238 | before :each do |
| 245 | - subject.expects(:find_resource).with(MezuroConfiguration, @subject.id).returns(@subject) | |
| 246 | - MezuroConfiguration.any_instance.expects(:update).with(@subject_params).returns(false) | |
| 239 | + subject.expects(:find_resource).with(MezuroConfiguration, mezuro_configuration.id).returns(mezuro_configuration) | |
| 240 | + MezuroConfiguration.any_instance.expects(:update).with(mezuro_configuration_params).returns(false) | |
| 247 | 241 | |
| 248 | - post :update, :id => @subject.id, :mezuro_configuration => @subject_params | |
| 242 | + post :update, :id => mezuro_configuration.id, :mezuro_configuration => mezuro_configuration_params | |
| 249 | 243 | end |
| 250 | 244 | |
| 251 | 245 | it { is_expected.to render_template(:edit) } |
| ... | ... | @@ -254,16 +248,16 @@ describe MezuroConfigurationsController, :type => :controller do |
| 254 | 248 | |
| 255 | 249 | context 'when the user does not own the mezuro_configuration' do |
| 256 | 250 | before :each do |
| 257 | - post :update, :id => @subject.id, :mezuro_configuration => @subject_params | |
| 251 | + post :update, :id => mezuro_configuration.id, :mezuro_configuration => mezuro_configuration_params | |
| 258 | 252 | end |
| 259 | 253 | |
| 260 | - it { is_expected.to redirect_to mezuro_configurations_path(@subject.id) } | |
| 254 | + it { is_expected.to redirect_to mezuro_configurations_path(mezuro_configuration.id) } | |
| 261 | 255 | end |
| 262 | 256 | end |
| 263 | 257 | |
| 264 | 258 | context 'with no user logged in' do |
| 265 | 259 | before :each do |
| 266 | - post :update, :id => @subject.id, :mezuro_configuration => @subject_params | |
| 260 | + post :update, :id => mezuro_configuration.id, :mezuro_configuration => mezuro_configuration_params | |
| 267 | 261 | end |
| 268 | 262 | |
| 269 | 263 | it { is_expected.to redirect_to new_user_session_path } | ... | ... |
spec/models/mezuro_configuration_spec.rb
| ... | ... | @@ -1,73 +0,0 @@ |
| 1 | -require 'rails_helper' | |
| 2 | - | |
| 3 | -describe MezuroConfiguration, :type => :model do | |
| 4 | - subject { FactoryGirl.build(:mezuro_configuration) } | |
| 5 | - describe 'methods' do | |
| 6 | - describe 'persisted?' do | |
| 7 | - before :each do | |
| 8 | - MezuroConfiguration.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 | - describe 'update' do | |
| 17 | - before :each do | |
| 18 | - @subject_params = Hash[FactoryGirl.attributes_for(:mezuro_configuration).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 | |
| 19 | - end | |
| 20 | - | |
| 21 | - context 'with valid attributes' do | |
| 22 | - before :each do | |
| 23 | - subject.expects(:save).returns(true) | |
| 24 | - end | |
| 25 | - | |
| 26 | - it 'should return true' do | |
| 27 | - expect(subject.update(@subject_params)).to eq(true) | |
| 28 | - end | |
| 29 | - end | |
| 30 | - | |
| 31 | - context 'with invalid attributes' do | |
| 32 | - before :each do | |
| 33 | - subject.expects(:save).returns(false) | |
| 34 | - end | |
| 35 | - | |
| 36 | - it 'should return false' do | |
| 37 | - expect(subject.update(@subject_params)).to eq(false) | |
| 38 | - end | |
| 39 | - end | |
| 40 | - end | |
| 41 | - | |
| 42 | - describe 'metric_configurations' do | |
| 43 | - subject { FactoryGirl.build(:mezuro_configuration) } | |
| 44 | - let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } | |
| 45 | - | |
| 46 | - it 'should call metric_configurations_of on the Metric Configuration model' do | |
| 47 | - MetricConfiguration.expects(:metric_configurations_of).with(subject.id).returns([metric_configuration]) | |
| 48 | - | |
| 49 | - expect(subject.metric_configurations).to include(metric_configuration) | |
| 50 | - end | |
| 51 | - end | |
| 52 | - end | |
| 53 | - | |
| 54 | - describe 'validations' do | |
| 55 | - context 'active model validations' do | |
| 56 | - before :each do | |
| 57 | - MezuroConfiguration.expects(:all).at_least_once.returns([]) | |
| 58 | - end | |
| 59 | - it { is_expected.to validate_presence_of(:name) } | |
| 60 | - end | |
| 61 | - | |
| 62 | - context 'kalibro validations' do | |
| 63 | - before :each do | |
| 64 | - MezuroConfiguration.expects(:request).returns(42) | |
| 65 | - end | |
| 66 | - | |
| 67 | - it 'should validate uniqueness' do | |
| 68 | - KalibroUniquenessValidator.any_instance.expects(:validate_each).with(subject, :name, subject.name) | |
| 69 | - subject.save | |
| 70 | - end | |
| 71 | - end | |
| 72 | - end | |
| 73 | -end |