aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin_holidays_controller.rb18
-rw-r--r--spec/controllers/admin_holidays_controller_spec.rb40
2 files changed, 56 insertions, 2 deletions
diff --git a/app/controllers/admin_holidays_controller.rb b/app/controllers/admin_holidays_controller.rb
index 159148ddb..3d7e0046b 100644
--- a/app/controllers/admin_holidays_controller.rb
+++ b/app/controllers/admin_holidays_controller.rb
@@ -9,6 +9,16 @@ class AdminHolidaysController < AdminController
@holiday = Holiday.find(params[:id])
end
+ def update
+ @holiday = Holiday.find(params[:id])
+ if @holiday.update_attributes(holiday_params)
+ flash[:notice] = 'Holiday successfully updated.'
+ redirect_to admin_holidays_path
+ else
+ render :edit
+ end
+ end
+
private
def get_all_holidays
@@ -16,4 +26,12 @@ class AdminHolidaysController < AdminController
@years = @holidays_by_year.keys.sort.reverse
end
+ def holiday_params(key = :holiday)
+ if params[key]
+ params[key].slice(:description, 'day(1i)', 'day(2i)', 'day(3i)')
+ else
+ {}
+ end
+ end
+
end
diff --git a/spec/controllers/admin_holidays_controller_spec.rb b/spec/controllers/admin_holidays_controller_spec.rb
index 61833b425..7025daa81 100644
--- a/spec/controllers/admin_holidays_controller_spec.rb
+++ b/spec/controllers/admin_holidays_controller_spec.rb
@@ -34,18 +34,54 @@ describe AdminHolidaysController do
before do
@holiday = FactoryGirl.create(:holiday)
+ get :edit, :id => @holiday.id
end
it 'renders the edit template' do
- get :edit, :id => @holiday.id
expect(response).to render_template('edit')
end
it 'gets the holiday in the id param' do
- get :edit, :id => @holiday.id
assigns[:holiday].should == @holiday
end
+ end
+
+ describe :update do
+
+ before do
+ @holiday = FactoryGirl.create(:holiday, :day => Date.new(2010, 1, 1),
+ :description => "Test Holiday")
+ put :update, :id => @holiday.id, :holiday => { :description => 'New Test Holiday' }
+ end
+
+ it 'gets the holiday in the id param' do
+ assigns[:holiday].should == @holiday
+ end
+
+ it 'updates the holiday' do
+ holiday = Holiday.find(@holiday.id).description.should == 'New Test Holiday'
+ end
+
+ it 'shows the admin a success message' do
+ flash[:notice].should == 'Holiday successfully updated.'
+ end
+
+ it 'redirects to the index' do
+ response.should redirect_to admin_holidays_path
+ end
+
+ context 'when there are errors' do
+
+ before do
+ Holiday.any_instance.stub(:update_attributes).and_return(false)
+ put :update, :id => @holiday.id, :holiday => { :description => 'New Test Holiday' }
+ end
+
+ it 'renders the edit template' do
+ expect(response).to render_template('edit')
+ end
+ end
end