post flag functional test
This commit is contained in:
0
app/controllers/post_appeals_controller_test.rb
Normal file
0
app/controllers/post_appeals_controller_test.rb
Normal file
22
app/views/post_flags/index.html.erb
Normal file
22
app/views/post_flags/index.html.erb
Normal file
@@ -0,0 +1,22 @@
|
||||
<div id="c-post-flags">
|
||||
<div id="a-index">
|
||||
<table width="100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Post</th>
|
||||
<th>Creator</th>
|
||||
<th>Reason</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @post_flags.each do |post_flag| %>
|
||||
<tr>
|
||||
<td><%= PostPresenter.preview(post_flag.post) %></td>
|
||||
<td><%= link_to post_flag.creator.name, user_path(post_flag.creator) %></td>
|
||||
<td><%= format_text post_flag.reason %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
3
test/factories/post_appeal.rb
Normal file
3
test/factories/post_appeal.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
Factory.define(:post_appeal) do |f|
|
||||
f.reason "xxx"
|
||||
end
|
||||
3
test/factories/post_flag.rb
Normal file
3
test/factories/post_flag.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
Factory.define(:post_flag) do |f|
|
||||
f.reason "xxx"
|
||||
end
|
||||
56
test/functional/post_flags_controller_test.rb
Normal file
56
test/functional/post_flags_controller_test.rb
Normal file
@@ -0,0 +1,56 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PostFlagsControllerTest < ActionController::TestCase
|
||||
context "The post flags controller" do
|
||||
setup do
|
||||
@user = Factory.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "new action" do
|
||||
should "render" do
|
||||
get :new, {}, {:user_id => @user.id}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
@post = Factory.create(:post)
|
||||
@post_flag = Factory.create(:post_flag, :post => @post)
|
||||
end
|
||||
|
||||
should "render" do
|
||||
get :index, {}, {:user_id => @user.id}
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
context "with search parameters" do
|
||||
should "render" do
|
||||
get :index, {:search => {:post_id_equals => @post_flag.post_id}}, {:user_id => @user.id}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
setup do
|
||||
@post = Factory.create(:post)
|
||||
end
|
||||
|
||||
should "create a new flag" do
|
||||
assert_difference("PostFlag.count", 1) do
|
||||
post :create, {:format => "js", :post_flag => {:post_id => @post.id, :reason => "xxx"}}, {:user_id => @user.id}
|
||||
assert_not_nil(assigns(:post_flag))
|
||||
assert_equal([], assigns(:post_flag).errors.full_messages)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user