aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/admin_holiday_imports_controller_spec.rb
blob: dd23a022febe63e4b8da473da0147e48c1139b55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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