-<%= form_for(@mezuro_range, :url => mezuro_configuration_metric_configuration_path(@mezuro_range.mezuro_configuration_id,
- @mezuro_range.metric_configuration_id)) do |f| %>
+<%= form_for(@mezuro_range, :url => mezuro_configuration_metric_configuration_mezuro_ranges_path(@mezuro_configuration_id, @metric_configuration_id)) do |f| %>
<%= render partial: 'form', locals: {f: f} %>
<% end %>
\ No newline at end of file
diff --git a/spec/controllers/mezuro_ranges_spec.rb b/spec/controllers/mezuro_ranges_spec.rb
new file mode 100644
index 0000000..fe5fe58
--- /dev/null
+++ b/spec/controllers/mezuro_ranges_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe MezuroRangesController do
+
+ describe 'new' do
+ let(:mezuro_range) { FactoryGirl.build(:mezuro_range) }
+ let(:mezuro_configuration) { FactoryGirl.build(:mezuro_configuration) }
+ let(:metric_configuration) { FactoryGirl.build(:metric_configuration) }
+
+ before :each do
+ sign_in FactoryGirl.create(:user)
+ end
+
+ context 'when the current user owns the metric configuration' do
+ before :each do
+ subject.expects(:metric_configuration_owner?).returns true
+ MetricConfiguration.expects(:find).with(mezuro_range.metric_configuration_id).returns(metric_configuration)
+ Reading.expects(:readings_of).with(metric_configuration.reading_group_id).returns([])
+ get :new, mezuro_configuration_id: mezuro_configuration.id, metric_configuration_id: mezuro_range.metric_configuration_id
+ end
+
+ it { should respond_with(:success) }
+ it { should render_template(:new) }
+ end
+
+ context "when the current user doesn't owns the metric configuration" do
+ before :each do
+ get :new, mezuro_configuration_id: mezuro_configuration.id, metric_configuration_id: mezuro_range.metric_configuration_id
+ end
+
+ it { should redirect_to(mezuro_configurations_path) }
+ it { should respond_with(:redirect) }
+ end
+ end
+end
\ No newline at end of file
diff --git a/spec/factories/mezuro_ranges.rb b/spec/factories/mezuro_ranges.rb
index 59830e8..b29ee47 100644
--- a/spec/factories/mezuro_ranges.rb
+++ b/spec/factories/mezuro_ranges.rb
@@ -20,6 +20,7 @@ FactoryGirl.define do
self.end 5.1
reading_id 3
comments "Comment"
+ metric_configuration_id 32
trait :another_comment do
comments "Another Comment"
--
libgit2 0.21.2