[#2281] Handle submissions of invalid values.
This commit is contained in:
1 parent
944cade841
commit
771afdcb8f
2 files changed
+12
-5
No files matched your search
@@ -5,7 +5,7 @@ class OverheadTimeEntryActivityController < ApplicationController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
if params[:custom_field]
|
if params[:custom_field]
|
||||||
@field = TimeEntryActivityCustomField.find(params[:custom_field])
|
@field = TimeEntryActivityCustomField.find_by_id(params[:custom_field])
|
||||||
@values = select_values_for_field(@field)
|
@values = select_values_for_field(@field)
|
||||||
end
|
end
|
||||||
@values ||= []
|
@values ||= []
|
||||||
@@ -18,6 +18,8 @@ class OverheadTimeEntryActivityController < ApplicationController
|
|||||||
private
|
private
|
||||||
|
|
||||||
def select_values_for_field(field)
|
def select_values_for_field(field)
|
||||||
|
return [] if field.nil?
|
||||||
|
|
||||||
if field.field_format == 'list'
|
if field.field_format == 'list'
|
||||||
returning [] do |r|
|
returning [] do |r|
|
||||||
field.possible_values.each do |item|
|
field.possible_values.each do |item|
|
||||||
|
|||||||
@@ -53,6 +53,11 @@ describe OverheadTimeEntryActivityController, "#index as admin in js format" do
|
|||||||
assigns[:values].should be_empty
|
assigns[:values].should be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should handle not finding the Time Entry Activity gracefully' do
|
||||||
|
get :index, :custom_field => -10
|
||||||
|
response.should be_success
|
||||||
|
end
|
||||||
|
|
||||||
it 'should render the values partial' do
|
it 'should render the values partial' do
|
||||||
get :index
|
get :index
|
||||||
response.should render_template('overhead_time_entry_activity/_values')
|
response.should render_template('overhead_time_entry_activity/_values')
|
||||||
@@ -61,7 +66,7 @@ describe OverheadTimeEntryActivityController, "#index as admin in js format" do
|
|||||||
describe 'with a list custom_field parameter' do
|
describe 'with a list custom_field parameter' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@custom_field = mock_model(TimeEntryActivityCustomField, :possible_values => ['A','B','Nil'], :field_format => 'list')
|
@custom_field = mock_model(TimeEntryActivityCustomField, :possible_values => ['A','B','Nil'], :field_format => 'list')
|
||||||
TimeEntryActivityCustomField.stub!(:find).and_return(@custom_field)
|
TimeEntryActivityCustomField.stub!(:find_by_id).and_return(@custom_field)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should assign values to the possible values of the field' do
|
it 'should assign values to the possible values of the field' do
|
||||||
@@ -70,7 +75,7 @@ describe OverheadTimeEntryActivityController, "#index as admin in js format" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'should find the Billing Status field based on the selected custom_field' do
|
it 'should find the Billing Status field based on the selected custom_field' do
|
||||||
TimeEntryActivityCustomField.should_receive(:find).with(@custom_field.id.to_s).and_return(@custom_field)
|
TimeEntryActivityCustomField.should_receive(:find_by_id).with(@custom_field.id.to_s).and_return(@custom_field)
|
||||||
get :index, :custom_field => @custom_field.id
|
get :index, :custom_field => @custom_field.id
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -85,7 +90,7 @@ describe OverheadTimeEntryActivityController, "#index as admin in js format" do
|
|||||||
describe 'with a boolean custom_field parameter' do
|
describe 'with a boolean custom_field parameter' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@custom_field = mock_model(TimeEntryActivityCustomField, :field_format => 'bool')
|
@custom_field = mock_model(TimeEntryActivityCustomField, :field_format => 'bool')
|
||||||
TimeEntryActivityCustomField.stub!(:find).and_return(@custom_field)
|
TimeEntryActivityCustomField.stub!(:find_by_id).and_return(@custom_field)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should assign values to the possible values of the field' do
|
it 'should assign values to the possible values of the field' do
|
||||||
@@ -94,7 +99,7 @@ describe OverheadTimeEntryActivityController, "#index as admin in js format" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'should find the Billing Status field based on the selected custom_field' do
|
it 'should find the Billing Status field based on the selected custom_field' do
|
||||||
TimeEntryActivityCustomField.should_receive(:find).with(@custom_field.id.to_s).and_return(@custom_field)
|
TimeEntryActivityCustomField.should_receive(:find_by_id).with(@custom_field.id.to_s).and_return(@custom_field)
|
||||||
get :index, :custom_field => @custom_field.id
|
get :index, :custom_field => @custom_field.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user