diaspora/spec/models/report_spec.rb
Lukas Matt 8ae89a443b Replaced fake post/comment with existing one
That fixed the correct validation whether a post/comment is gone
after the report was marked as deleted
2014-05-15 07:23:43 -04:00

79 lines
2.3 KiB
Ruby

# 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 => { :post_id => @message.id, :post_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 = {
:post_id => @bob_post.id,
:post_type => 'post',
:text => 'offensive content'
}
@valid_comment_report = {
:post_id => @bob_comment.id,
:post_type => 'comment',
:text => 'offensive content'
}
end
describe '#validation' do
it 'validates that post ID is required' do
@user.reports.build(:post_type => 'post', :text => 'blub').should_not be_valid
end
it 'validates that post type is required' do
@user.reports.build(:post_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