diff --git a/app/controllers/mezuro_ranges_controller.rb b/app/controllers/mezuro_ranges_controller.rb index 9f7183a..7ed7145 100644 --- a/app/controllers/mezuro_ranges_controller.rb +++ b/app/controllers/mezuro_ranges_controller.rb @@ -1,9 +1,8 @@ include OwnershipAuthentication class MezuroRangesController < ApplicationController - - before_action :authenticate_user!, except: [:show, :index] - before_action :metric_configuration_owner?, except: [:index] + before_action :authenticate_user!, except: [:show] + before_action :metric_configuration_owner?, only: [:new, :create] def new @mezuro_range = MezuroRange.new @@ -26,9 +25,6 @@ class MezuroRangesController < ApplicationController def update end - def index - end - def edit end diff --git a/spec/controllers/metric_configurations_controller_spec.rb b/spec/controllers/metric_configurations_controller_spec.rb index d2b6226..df10549 100644 --- a/spec/controllers/metric_configurations_controller_spec.rb +++ b/spec/controllers/metric_configurations_controller_spec.rb @@ -56,7 +56,7 @@ describe MetricConfigurationsController do sign_in FactoryGirl.create(:user) end - context 'when the current user owns the reading group' do + context 'when the current user owns the metric configuration' do before :each do subject.expects(:mezuro_configuration_owner?).returns true end diff --git a/spec/controllers/mezuro_ranges_spec.rb b/spec/controllers/mezuro_ranges_spec.rb index fe5fe58..c2bcb6f 100644 --- a/spec/controllers/mezuro_ranges_spec.rb +++ b/spec/controllers/mezuro_ranges_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe MezuroRangesController do - describe 'new' do let(:mezuro_range) { FactoryGirl.build(:mezuro_range) } let(:mezuro_configuration) { FactoryGirl.build(:mezuro_configuration) } @@ -32,4 +31,43 @@ describe MezuroRangesController do it { should respond_with(:redirect) } end end -end \ No newline at end of file + + describe 'create' do + let(:mezuro_range_params) { Hash[FactoryGirl.attributes_for(:mezuro_range).map { |k,v| [k.to_s, v.to_s] }] } #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with symbols and integers + let(:mezuro_configuration) { FactoryGirl.build(:mezuro_configuration) } + let(:metric_configuration) { FactoryGirl.build(:metric_configuration) } + let(:mezuro_range) { FactoryGirl.build(:mezuro_range) } + + before do + sign_in FactoryGirl.create(:user) + end + + context 'when the current user owns the mezuro range' do + before :each do + subject.expects(:metric_configuration_owner?).returns true + end + + context 'with valid fields' do + before :each do + MezuroRange.any_instance.expects(:save).returns(true) + + post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params + end + + it { should respond_with(:redirect) } + end + + context 'with invalid fields' do + before :each do + MezuroRange.any_instance.expects(:save).returns(false) + MetricConfiguration.expects(:find).with(metric_configuration.id).returns(metric_configuration) + Reading.expects(:readings_of).with(metric_configuration.reading_group_id).returns([]) + + post :create, mezuro_configuration_id: mezuro_configuration.id, metric_configuration_id: metric_configuration.id, mezuro_range: mezuro_range_params + end + + it { should render_template(:new) } + end + end + end +end -- libgit2 0.21.2