some fixes to janitor trials, implemented jan trial controller test

This commit is contained in:
albert
2011-01-14 16:45:10 -05:00
parent dceda1b073
commit 3d5873c182
15 changed files with 206 additions and 29 deletions

View File

@@ -0,0 +1,3 @@
Factory.define(:janitor_trial) do |f|
f.user {|x| x.association(:user)}
end

View File

@@ -1,5 +1,5 @@
Factory.define(:user) do |f|
f.name {Faker::Name.first_name}
f.name {rand(1_000_000).to_s}
f.password "password"
f.password_hash {User.sha1("password")}
f.email {Faker::Internet.email}

View File

@@ -1,6 +1,4 @@
Factory.define(:user_feedback) do |f|
f.user {|x| x.association(:user)}
f.creator {|x| x.association(:user)}
f.is_positive true
f.body {Faker::Lorem.words}
end

View File

@@ -1,8 +1,73 @@
require 'test_helper'
class JanitorTrialsControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
context "The janitor trials controller" do
setup do
@admin = Factory.create(:admin_user)
@user = Factory.create(: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 janitor trial" do
assert_difference("JanitorTrial.count", 1) do
post :create, {:janitor_trial => {:user_id => @user.id}}, {:user_id => @admin.id}
end
end
end
context "promote action" do
setup do
@janitor_trial = Factory.create(:janitor_trial, :user_id => @user.id)
end
should "promote the janitor trial" do
assert_difference("JanitorTrial.count", -1) do
post :promote, {:id => @janitor_trial.id}, {:user_id => @admin.id}
end
@user.reload
assert(@user.is_janitor?)
end
end
context "demote action" do
setup do
@janitor_trial = Factory.create(:janitor_trial, :user_id => @user.id)
end
should "demote the janitor trial" do
assert_difference("JanitorTrial.count", -1) do
post :demote, {:id => @janitor_trial.id}, {:user_id => @admin.id}
end
@user.reload
assert(!@user.is_janitor?)
end
end
context "index action" do
setup do
Factory.create(:janitor_trial)
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 => {:user_name_equals => @user.name}}, {:user_id => @admin.id}
assert_response :success
end
end
end
end
end

View File

@@ -1,23 +1,56 @@
require_relative '../test_helper'
class JanitorTrialTest < ActiveSupport::TestCase
setup do
user = Factory.create(:user)
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end
context "A janitor trial" do
setup do
@admin = Factory.create(:admin_user)
@user = Factory.create(:user)
CurrentUser.user = @admin
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "create a dmail when testing a new janitor" do
admin = Factory.create(:admin_user)
user = Factory.create(:user)
assert_difference("Dmail.count", 2) do
JanitorTrial.create(:user_id => user.id)
context "upon creation" do
should "create a dmail when testing a new janitor" do
assert_difference("Dmail.count", 2) do
JanitorTrial.create(:user_id => @user.id)
end
end
should "toggle the janitor flag on the user" do
janitor_trial = JanitorTrial.create(:user_id => @user.id)
@user.reload
assert(@user.is_janitor?)
end
end
context "upon demotion" do
setup do
@janitor_trial = Factory.create(:janitor_trial, :user_id => @user.id)
end
should "create a negative feedback record" do
assert_difference("UserFeedback.count", 1) do
@janitor_trial.demote!
end
end
end
context "upon promotion" do
setup do
@janitor_trial = Factory.create(:janitor_trial, :user_id => @user.id)
end
should "destroy the trial object" do
assert_difference("JanitorTrial.count", -1) do
@janitor_trial.promote!
end
end
end
end
end