aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/admin_holiday_imports_controller_spec.rb73
-rw-r--r--spec/controllers/admin_holidays_controller_spec.rb192
-rw-r--r--spec/controllers/general_controller_spec.rb29
-rw-r--r--spec/controllers/request_controller_spec.rb2
4 files changed, 295 insertions, 1 deletions
diff --git a/spec/controllers/admin_holiday_imports_controller_spec.rb b/spec/controllers/admin_holiday_imports_controller_spec.rb
new file mode 100644
index 000000000..dd23a022f
--- /dev/null
+++ b/spec/controllers/admin_holiday_imports_controller_spec.rb
@@ -0,0 +1,73 @@
+require 'spec_helper'
+
+describe AdminHolidayImportsController do
+
+ describe :new do
+
+ it 'renders the new template' do
+ get :new
+ expect(response).to render_template('new')
+ end
+
+ it 'creates an import' do
+ get :new
+ assigns[:holiday_import].should be_instance_of(HolidayImport)
+ end
+
+ describe 'if the import is valid' do
+
+ it 'populates the import' do
+ mock_import = mock(HolidayImport, :valid? => true,
+ :populate => nil)
+ HolidayImport.stub!(:new).and_return(mock_import)
+ mock_import.should_receive(:populate)
+ get :new
+ end
+
+ end
+
+ end
+
+ describe :create do
+
+ it 'creates an import' do
+ post :create
+ assigns[:holiday_import].should be_instance_of(HolidayImport)
+ end
+
+ describe 'if the import can be saved' do
+
+ before do
+ mock_import = mock(HolidayImport, :save => true)
+ HolidayImport.stub!(:new).and_return(mock_import)
+ post :create
+ end
+
+ it 'should show a success notice' do
+ flash[:notice].should == 'Holidays successfully imported'
+ end
+
+ it 'should redirect to the index' do
+ response.should redirect_to(admin_holidays_path)
+ end
+
+ end
+
+ describe 'if the import cannot be saved' do
+
+ before do
+ mock_import = mock(HolidayImport, :save => false)
+ HolidayImport.stub!(:new).and_return(mock_import)
+ post :create
+ end
+
+ it 'should render the new template' do
+ expect(response).to render_template('new')
+ end
+
+ end
+
+ end
+
+
+end
diff --git a/spec/controllers/admin_holidays_controller_spec.rb b/spec/controllers/admin_holidays_controller_spec.rb
new file mode 100644
index 000000000..21cb51d29
--- /dev/null
+++ b/spec/controllers/admin_holidays_controller_spec.rb
@@ -0,0 +1,192 @@
+require 'spec_helper'
+
+describe AdminHolidaysController do
+
+ describe :index do
+
+ before do
+ @holiday_one = FactoryGirl.create(:holiday, :day => Date.new(2010, 1, 1))
+ @holiday_two = FactoryGirl.create(:holiday, :day => Date.new(2011, 2, 2))
+ @holiday_three = FactoryGirl.create(:holiday, :day => Date.new(2011, 3, 3))
+ end
+
+ it 'gets a hash of holidays keyed by year' do
+ get :index
+ assigns(:holidays_by_year)[2010].should include(@holiday_one)
+ assigns(:holidays_by_year)[2011].should include(@holiday_two)
+ assigns(:holidays_by_year)[2011].should include(@holiday_three)
+ end
+
+ it 'gets a list of years with holidays' do
+ get :index
+ assigns(:years).should include(2010)
+ assigns(:years).should include(2011)
+ end
+
+ it 'renders the index template' do
+ get :index
+ expect(response).to render_template('index')
+ end
+
+ end
+
+ describe :new do
+
+
+ describe 'when not using ajax' do
+
+ it 'renders the new template' do
+ get :new
+ expect(response).to render_template('new')
+ end
+
+ end
+
+ describe 'when using ajax' do
+
+ it 'renders the new form partial' do
+ xhr :get, :new
+ expect(response).to render_template('new_form')
+ end
+ end
+
+ it 'creates a new holiday' do
+ get :new
+ assigns[:holiday].should be_instance_of(Holiday)
+ end
+
+ end
+
+ describe :create do
+
+ before do
+ @holiday_params = { :description => "New Year's Day",
+ 'day(1i)' => '2010',
+ 'day(2i)' => '1',
+ 'day(3i)' => '1' }
+ post :create, :holiday => @holiday_params
+ end
+
+ it 'creates a new holiday' do
+ assigns(:holiday).description.should == @holiday_params[:description]
+ assigns(:holiday).day.should == Date.new(2010, 1, 1)
+ assigns(:holiday).should be_persisted
+ end
+
+ it 'shows the admin a success message' do
+ flash[:notice].should == 'Holiday successfully created.'
+ 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(:save).and_return(false)
+ post :create, :holiday => @holiday_params
+ end
+
+ it 'renders the new template' do
+ expect(response).to render_template('new')
+ end
+ end
+
+ end
+
+ describe :edit do
+
+ before do
+ @holiday = FactoryGirl.create(:holiday)
+ end
+
+ describe 'when not using ajax' do
+
+ it 'renders the edit template' do
+ get :edit, :id => @holiday.id
+ expect(response).to render_template('edit')
+ end
+
+ end
+
+ describe 'when using ajax' do
+
+ it 'renders the edit form partial' do
+ xhr :get, :edit, :id => @holiday.id
+ expect(response).to render_template('edit_form')
+ end
+
+ 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
+
+ describe :destroy do
+
+ before(:each) do
+ @holiday = FactoryGirl.create(:holiday)
+ delete :destroy, :id => @holiday.id
+ end
+
+ it 'finds the holiday to destroy' do
+ assigns(:holiday).should == @holiday
+ end
+
+ it 'destroys the holiday' do
+ assigns(:holiday).should be_destroyed
+ end
+
+ it 'tells the admin the holiday has been destroyed' do
+ msg = "Holiday successfully destroyed"
+ flash[:notice].should == msg
+ end
+
+ it 'redirects to the index action' do
+ expect(response).to redirect_to(admin_holidays_path)
+ end
+ end
+
+ end
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index c0a9d57d3..4a7a0bb48 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -126,6 +126,35 @@ describe GeneralController, "when showing the frontpage" do
end
+ describe 'when handling logged-in users' do
+
+ before do
+ @user = FactoryGirl.create(:user)
+ session[:user_id] = @user.id
+ end
+
+ it 'should set a time to live on a non "remember me" session' do
+ get :frontpage
+ response.body.should match @user.name
+ session[:ttl].should be_within(1).of(Time.now)
+ end
+
+ it 'should not set a time to live on a "remember me" session' do
+ session[:remember_me] = true
+ get :frontpage
+ response.body.should match @user.name
+ session[:ttl].should be_nil
+ end
+
+ it 'should end a logged-in session whose ttl has expired' do
+ session[:ttl] = Time.now - 4.hours
+ get :frontpage
+ response.should redirect_to signin_path
+ session[:user_id].should be_nil
+ end
+
+ end
+
end
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 4d0070470..ba558cc93 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -2447,7 +2447,7 @@ describe RequestController, "when caching fragments" do
:info_request_id => 132,
:id => 44,
:get_attachments_for_display => nil,
- :html_mask_stuff! => nil,
+ :apply_masks! => nil,
:user_can_view? => true,
:all_can_view? => true)
attachment = FactoryGirl.build(:body_text, :filename => long_name)