blob: 82d5d86037e21041268bd4d873cf0fb0e07bd842 (
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
74
75
76
77
78
79
|
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe Report do
before do
#:report => { :item_id => @message.id, :item_type => 'post', :text => 'offensive content' }
@user = bob
@bob_post = @user.post(:status_message, :text => "hello", :to => @user.aspects.first.id)
@bob_comment = @user.comment!(@bob_post, "welcome")
@valid_post_report = {
:item_id => @bob_post.id,
:item_type => 'post',
:text => 'offensive content'
}
@valid_comment_report = {
:item_id => @bob_comment.id,
:item_type => 'comment',
:text => 'offensive content'
}
end
describe '#validation' do
it 'validates that post ID is required' do
@user.reports.build(:item_type => 'post', :text => 'blub').should_not be_valid
end
it 'validates that post type is required' do
@user.reports.build(:item_id => 666, :text => 'blub').should_not be_valid
end
it 'validates that entry does not exist' do
@user.reports.build(@valid_post_report).should be_valid
end
it 'validates that entry does exist' do
@user.reports.create(@valid_post_report)
@user.reports.build(@valid_post_report).should_not be_valid
end
end
describe '#destroy_reported_item' do
before(:each) do
@post_report = @user.reports.create(@valid_post_report)
@comment_report = @user.reports.create(@valid_comment_report)
end
describe '.post' do
it 'should destroy it' do
expect {
@post_report.destroy_reported_item
}.to change { Post.count }.by(-1)
end
it 'should be marked' do
expect {
@post_report.destroy_reported_item
}.to change { Report.where(@valid_post_report).first.reviewed }.to(true).from(false)
end
end
describe '.comment' do
it 'should destroy it' do
expect {
@comment_report.destroy_reported_item
}.to change { Comment.count }.by(-1)
end
it 'should be marked' do
expect {
@comment_report.destroy_reported_item
}.to change { Report.where(@valid_comment_report).first.reviewed }.to(true).from(false)
end
end
end
end
|