aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/admin_comment_controller_spec.rb
blob: f87231e3b364d91c24663c8a7175812e21cb301e (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
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe AdminCommentController do

    describe :edit do

        before do
            @comment = FactoryGirl.create(:comment)
            get :edit, :id => @comment.id
        end

        it 'renders the edit template' do
            expect(response).to render_template('edit')
        end

        it 'gets the comment' do
            assigns[:comment].should == @comment
        end

    end

    describe :update do

        context 'on valid data submission' do

            before do
                @comment = FactoryGirl.create(:comment)
                atts = FactoryGirl.attributes_for(:comment, :body => 'I am new')
                put :update, :id => @comment.id, :comment => atts
            end

            it 'gets the comment' do
                assigns[:comment].should == @comment
            end

            it 'updates the comment' do
                Comment.find(@comment.id).body.should == 'I am new'
            end

            it 'logs the update event' do
                most_recent_event = Comment.find(@comment.id).info_request_events.last
                most_recent_event.event_type.should == 'edit_comment'
                most_recent_event.comment_id.should == @comment.id
            end

            it 'shows a success notice' do
                flash[:notice].should == "Comment successfully updated."
            end

            it 'redirects to the request page' do
                response.should redirect_to(admin_request_path(@comment.info_request))
            end
        end

        context 'on invalid data submission' do

            it 'renders the edit template' do
                @comment = FactoryGirl.create(:comment)
                put :update, :id => @comment.id, :comment => {:body => ''}
                response.should render_template('edit')
            end

        end
    end

end