require "test_helper"
class ApplicationHelperTest < ActionView::TestCase
- fixtures :users, :user_roles
-
def setup
I18n.locale = "en"
end
assert_match /\.hide_unless_administrator /, css
assert_match /\.hide_unless_moderator /, css
- @user = users(:normal_user)
+ @user = create(:user)
css = style_rules
assert_match /\.hidden /, css
assert_no_match /\.hide_unless_logged_in /, css
assert_match /\.hide_if_logged_in /, css
- assert_match /\.hide_if_user_1 /, css
- assert_match /\.show_if_user_1 /, css
+ assert_match /\.hide_if_user_#{@user.id} /, css
+ assert_match /\.show_if_user_#{@user.id} /, css
assert_match /\.hide_unless_administrator /, css
assert_match /\.hide_unless_moderator /, css
- @user = users(:moderator_user)
+ @user = create(:moderator_user)
css = style_rules
assert_match /\.hidden /, css
assert_no_match /\.hide_unless_logged_in /, css
assert_match /\.hide_if_logged_in /, css
- assert_match /\.hide_if_user_5 /, css
- assert_match /\.show_if_user_5 /, css
+ assert_match /\.hide_if_user_#{@user.id} /, css
+ assert_match /\.show_if_user_#{@user.id} /, css
assert_match /\.hide_unless_administrator /, css
assert_no_match /\.hide_unless_moderator /, css
- @user = users(:administrator_user)
+ @user = create(:administrator_user)
css = style_rules
assert_match /\.hidden /, css
assert_no_match /\.hide_unless_logged_in /, css
assert_match /\.hide_if_logged_in /, css
- assert_match /\.hide_if_user_6 /, css
- assert_match /\.show_if_user_6 /, css
+ assert_match /\.hide_if_user_#{@user.id} /, css
+ assert_match /\.show_if_user_#{@user.id} /, css
assert_no_match /\.hide_unless_administrator /, css
assert_match /\.hide_unless_moderator /, css
end
end
def test_if_user
- html = if_user(users(:normal_user)) { "Test 1" }
- assert_dom_equal "<div class=\"hidden show_if_user_1\">Test 1</div>", html
+ user = create(:user)
+
+ html = if_user(user) { "Test 1" }
+ assert_dom_equal "<div class=\"hidden show_if_user_#{user.id}\">Test 1</div>", html
- html = if_user(users(:normal_user), :span) { "Test 2" }
- assert_dom_equal "<span class=\"hidden show_if_user_1\">Test 2</span>", html
+ html = if_user(user, :span) { "Test 2" }
+ assert_dom_equal "<span class=\"hidden show_if_user_#{user.id}\">Test 2</span>", html
html = if_user(nil) { "Test 3" }
assert_nil html
end
def test_unless_user
- html = unless_user(users(:normal_user)) { "Test 1" }
- assert_dom_equal "<div class=\"hide_if_user_1\">Test 1</div>", html
+ user = create(:user)
+
+ html = unless_user(user) { "Test 1" }
+ assert_dom_equal "<div class=\"hide_if_user_#{user.id}\">Test 1</div>", html
- html = unless_user(users(:normal_user), :span) { "Test 2" }
- assert_dom_equal "<span class=\"hide_if_user_1\">Test 2</span>", html
+ html = unless_user(user, :span) { "Test 2" }
+ assert_dom_equal "<span class=\"hide_if_user_#{user.id}\">Test 2</span>", html
html = unless_user(nil) { "Test 3" }
assert_dom_equal "<div>Test 3</div>", html
include ERB::Util
include ApplicationHelper
- fixtures :users
-
def test_note_event
date = Time.new(2014, 3, 5, 21, 37, 45, "+00:00")
+ user = create(:user)
assert_match %r{^Created by anonymous <abbr title='Wed, 05 Mar 2014 21:37:45 \+0000'><span title=" 5 March 2014 at 21:37">.*</span> ago</abbr>$}, note_event("open", date, nil)
- assert_match %r{^Resolved by <a href="/user/test2">test2</a> <abbr title='Wed, 05 Mar 2014 21:37:45 \+0000'><span title=" 5 March 2014 at 21:37">.*</span> ago</abbr>$}, note_event("closed", date, users(:public_user))
+ assert_match %r{^Resolved by <a href="/user/#{URI.encode(user.display_name)}">#{user.display_name}</a> <abbr title='Wed, 05 Mar 2014 21:37:45 \+0000'><span title=" 5 March 2014 at 21:37">.*</span> ago</abbr>$}, note_event("closed", date, user)
end
def test_note_author
+ deleted_user = create(:user, :deleted)
+ user = create(:user)
+
assert_equal "", note_author(nil)
- assert_equal "deleted", note_author(users(:deleted_user))
- assert_equal "<a href=\"/user/test2\">test2</a>", note_author(users(:public_user))
- assert_equal "<a href=\"http://test.host/user/test2\">test2</a>", note_author(users(:public_user), :only_path => false)
+ assert_equal "deleted", note_author(deleted_user)
+ assert_equal "<a href=\"/user/#{URI.encode(user.display_name)}\">#{user.display_name}</a>", note_author(user)
+ assert_equal "<a href=\"http://test.host/user/#{URI.encode(user.display_name)}\">#{user.display_name}</a>", note_author(user, :only_path => false)
end
end
require "test_helper"
class PageLocaleTest < ActionDispatch::IntegrationTest
- fixtures :users
-
def setup
I18n.locale = "en"
stub_hostip_requests
end
def test_defaulting
- user = users(:second_public_user)
+ user = create(:user, :languages => [])
post_via_redirect "/login", :username => user.email, :password => "test"
end
def test_override
- user = users(:german_user)
+ user = create(:user, :languages => ["de"])
get "/diary"
assert_select "html[lang=?]", "en"
require "test_helper"
class UserBlocksTest < ActionDispatch::IntegrationTest
- fixtures :users, :user_roles
-
def auth_header(user, pass)
{ "HTTP_AUTHORIZATION" => format("Basic %s", Base64.encode64("#{user}:#{pass}")) }
end
def test_api_blocked
- blocked_user = users(:public_user)
+ blocked_user = create(:user)
get "/api/#{API_VERSION}/user/details"
assert_response :unauthorized
# now block the user
UserBlock.create(
:user_id => blocked_user.id,
- :creator_id => users(:moderator_user).id,
+ :creator_id => create(:moderator_user).id,
:reason => "testing",
:ends_at => Time.now.getutc + 5.minutes
)
end
def test_api_revoke
- blocked_user = users(:public_user)
- moderator = users(:moderator_user)
+ blocked_user = create(:user)
+ moderator = create(:moderator_user)
block = UserBlock.create(
:user_id => blocked_user.id,
require "test_helper"
class UserCreationTest < ActionDispatch::IntegrationTest
- fixtures :users
-
def setup
I18n.locale = "en"
def test_user_create_submit_duplicate_email
I18n.available_locales.each do |locale|
- dup_email = users(:public_user).email
+ dup_email = create(:user).email
display_name = "#{locale}_new_tester"
assert_difference("User.count", 0) do
assert_difference("ActionMailer::Base.deliveries.size", 0) do
def test_user_create_submit_duplicate_username
I18n.available_locales.each do |locale|
- dup_display_name = users(:public_user).display_name
+ dup_display_name = create(:user).display_name
email = "#{locale}_new_tester"
assert_difference("User.count", 0) do
assert_difference("ActionMailer::Base.deliveries.size", 0) do
require "test_helper"
class UserRolesTest < ActionDispatch::IntegrationTest
- fixtures :users, :user_roles
-
def setup
stub_hostip_requests
end
test "grant" do
- check_fail(:grant, :public_user, :moderator)
+ check_fail(:grant, :user, :moderator)
check_fail(:grant, :moderator_user, :moderator)
check_success(:grant, :administrator_user, :moderator)
end
test "revoke" do
- check_fail(:revoke, :public_user, :moderator)
+ check_fail(:revoke, :user, :moderator)
check_fail(:revoke, :moderator_user, :moderator)
# this other user doesn't have moderator role, so this fails
check_fail(:revoke, :administrator_user, :moderator)
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post "/login", "username" => users(user).email, "password" => "test", :referer => "/"
+ post "/login", "username" => create(user).email, "password" => "test", :referer => "/"
assert_response :redirect
follow_redirect!
assert_response :success
- post "/user/#{users(:second_public_user).display_name}/role/#{role}/#{action}"
- assert_redirected_to :controller => "user", :action => "view", :display_name => users(:second_public_user).display_name
+ target_user = create(:user)
+ post "/user/#{URI.encode(target_user.display_name)}/role/#{role}/#{action}"
+ assert_redirected_to :controller => "user", :action => "view", :display_name => target_user.display_name
reset!
end
assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true"
follow_redirect!
assert_response :success
- post "/login", "username" => users(user).email, "password" => "test", :referer => "/"
+ post "/login", "username" => create(user).email, "password" => "test", :referer => "/"
assert_response :redirect
follow_redirect!
assert_response :success
- post "/user/#{users(:second_public_user).display_name}/role/#{role}/#{action}"
- assert_redirected_to :controller => "user", :action => "view", :display_name => users(:second_public_user).display_name
+ target_user = create(:user)
+ post "/user/#{URI.encode(target_user.display_name)}/role/#{role}/#{action}"
+ assert_redirected_to :controller => "user", :action => "view", :display_name => target_user.display_name
reset!
end