aboutsummaryrefslogtreecommitdiffstats
path: root/spec/requests/refinery/admin/blog/comments_spec.rb
blob: a0213f620d15a87699daf9edcf91dcb5cb74ecbd (plain) (blame)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
require "spec_helper"

module Refinery
  describe "AdminBlogComments" do
    login_refinery_user
    
    describe "#index" do      
      context "when has no new unapproved comments" do
        before(:each) do 
          BlogComment.delete_all
          visit refinery_admin_blog_comments_path
        end          
        
        it "should list no comments" do
          visit refinery_admin_blog_comments_path
                    
          page.should have_content('there are no new comments')
        end
      end
      
      context "when has new unapproved comments" do
        let!(:blog_comment) { FactoryGirl.create(:blog_comment) }
        before(:each) { visit refinery_admin_blog_comments_path }
  
        it "should list comments" do
          page.should have_content(blog_comment.body)
          page.should have_content(blog_comment.name)
        end
        
        it "should allow me to approve a comment" do
          click_link "Approve this comment"
          
          page.should have_content("has been approved")
        end
        
        it "should allow me to reject a comment" do
          click_link "Reject this comment"
          
          page.should have_content("has been rejected")
        end
      end
    end
    
    describe "#approved" do      
      context "when has no approved comments" do
        before(:each) do
          BlogComment.delete_all
          visit approved_refinery_admin_blog_comments_path
        end
        
        it "should list no comments" do          
          page.should have_content('there are no approved comments')
        end
      end
      
      context "when has approved comments" do
        let!(:blog_comment) do
          FactoryGirl.create(:blog_comment,
                             :state => 'approved')
        end
        before(:each) { visit approved_refinery_admin_blog_comments_path }
        
        it "should list comments" do          
          page.should have_content(blog_comment.body)
          page.should have_content(blog_comment.name)
        end
        
        it "should allow me to reject a comment" do
          click_link "Reject this comment"
          
          page.should have_content("has been rejected")
        end
      end
    end
    
    describe "#rejected" do      
      context "when has no rejected comments" do
        before(:each) do
          BlogComment.delete_all
          visit rejected_refinery_admin_blog_comments_path
        end
        
        it "should list no comments" do          
          page.should have_content('there are no rejected comments')
        end
      end
      
      context "when has rejected comments" do
        let!(:blog_comment) do
          FactoryGirl.create(:blog_comment,
                             :state => 'rejected')
        end
        before(:each) { visit rejected_refinery_admin_blog_comments_path }
        
        it "should list comments" do          
          page.should have_content(blog_comment.body)
          page.should have_content(blog_comment.name)
        end
        
        it "should allow me to approve a comment" do
          click_link "Approve this comment"
          
          page.should have_content("has been approved")
        end
      end
    end
    
    describe "#show" do
      let!(:blog_comment) { FactoryGirl.create(:blog_comment) }
      before(:each) { visit refinery_admin_blog_comment_path(blog_comment) }
      
      it "should display the comment" do
        page.should have_content(blog_comment.body)
        page.should have_content(blog_comment.name)
      end
      
      it "should allow me to approve the comment" do
        click_link "Approve this comment"
        
        page.should have_content("has been approved")
      end
    end
  end
end