added user test, basic user methods
This commit is contained in:
29
test/factories/user.rb
Normal file
29
test/factories/user.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
Factory.define(:user) do |f|
|
||||
f.name {Faker::Name.first_name}
|
||||
f.password_hash {User.sha1("password")}
|
||||
f.email {Faker::Internet.email}
|
||||
end
|
||||
|
||||
Factory.define(:banned_user) do |f|
|
||||
f.is_banned true
|
||||
end
|
||||
|
||||
Factory.define(:privileged_user) do |f|
|
||||
f.is_privileged true
|
||||
end
|
||||
|
||||
Factory.define(:contributor_user) do |f|
|
||||
f.is_contributor true
|
||||
end
|
||||
|
||||
Factory.define(:janitor_user) do |f|
|
||||
f.is_janitor true
|
||||
end
|
||||
|
||||
Factory.define(:moderator_user) do |f|
|
||||
f.is_moderator true
|
||||
end
|
||||
|
||||
Factory.define(:admin_user) do |f|
|
||||
f.is_admin true
|
||||
end
|
||||
@@ -1,13 +1,12 @@
|
||||
ENV["RAILS_ENV"] = "test"
|
||||
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
||||
require 'shoulda'
|
||||
require 'factory_girl'
|
||||
require 'mocha'
|
||||
require 'faker'
|
||||
require 'rails/test_help'
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
||||
#
|
||||
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
||||
# -- they do not yet inherit this setting
|
||||
fixtures :all
|
||||
Dir[File.expand_path(File.dirname(__FILE__) + "/factories/*.rb")].each {|file| require file}
|
||||
|
||||
# Add more helper methods to be used by all tests here...
|
||||
class ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
8
test/unit/deleted_post_test.rb
Normal file
8
test/unit/deleted_post_test.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class DeletedPostTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
8
test/unit/pending_post_test.rb
Normal file
8
test/unit/pending_post_test.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PendingPostTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
8
test/unit/post_test.rb
Normal file
8
test/unit/post_test.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PostTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
8
test/unit/post_version_test.rb
Normal file
8
test/unit/post_version_test.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PostVersionTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
8
test/unit/tag_test.rb
Normal file
8
test/unit/tag_test.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class TagTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
end
|
||||
end
|
||||
17
test/unit/user_test.rb
Normal file
17
test/unit/user_test.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class UserTest < ActiveSupport::TestCase
|
||||
context "A user" do
|
||||
setup do
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
should "be authenticate" do
|
||||
@user = Factory.create(:user)
|
||||
assert(User.authenticate(@user.name, "password"), "Authentication should have succeeded")
|
||||
assert(!User.authenticate(@user.name, "password2"), "Authentication should not have succeeded")
|
||||
assert(User.authenticate_hash(@user.name, @user.password_hash), "Authentication should have succeeded")
|
||||
assert(!User.authenticate_hash(@user.name, "xxxx"), "Authentication should not have succeeded")
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user