added ip bans controller

This commit is contained in:
albert
2011-01-14 15:50:17 -05:00
parent 541163685d
commit dceda1b073
8 changed files with 87 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
Factory.define(:ip_ban) do |f|
f.creator {|x| x.association(:user)}
f.reason {Faker::Lorem.words}
f.reason {Faker::Lorem.words.join(" ")}
f.ip_addr "127.0.0.1"
end

View File

@@ -0,0 +1,56 @@
require 'test_helper'
class IpBansControllerTest < ActionController::TestCase
context "The ip bans controller" do
setup do
@admin = Factory.create(:admin_user)
CurrentUser.user = @admin
CurrentUser.ip_addr = "127.0.0.1"
end
context "new action" do
should "render" do
get :new, {}, {:user_id => @admin.id}
assert_response :success
end
end
context "create action" do
should "create a new ip ban" do
assert_difference("IpBan.count", 1) do
post :create, {:ip_ban => {:ip_addr => "1.2.3.4", :reason => "xyz"}}, {:user_id => @admin.id}
end
end
end
context "index action" do
setup do
Factory.create(:ip_ban)
end
should "render" do
get :index, {}, {:user_id => @admin.id}
assert_response :success
end
context "with search parameters" do
should "render" do
get :index, {:search => {:ip_addr_equals => "1.2.3.4"}}, {:user_id => @admin.id}
assert_response :success
end
end
end
context "destroy action" do
setup do
@ip_ban = Factory.create(:ip_ban)
end
should "destroy an ip ban" do
assert_difference("IpBan.count", -1) do
post :destroy, {:id => @ip_ban.id}, {:user_id => @admin.id}
end
end
end
end
end

View File

@@ -22,7 +22,7 @@ class IpBanTest < ActiveSupport::TestCase
should "be able to count any updates from a user, groupiny by IP address" do
CurrentUser.scoped(@user, "1.2.3.4") do
comment = Factory.create(:comment, :body => "aaa")
counts = IpBan.search([comment.creator_id])
counts = IpBan.query([comment.creator_id])
assert_equal([{"ip_addr" => "1.2.3.4", "count" => "1"}], counts["comments"])
end
end