mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-16 04:08:08 +01:00
Make the UsersController more RESTy. It now supports retrieving a list of users or a particular as XML (available to admins only).
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@412 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
b1b03b2c8a
commit
ef2d93542e
7 changed files with 79 additions and 38 deletions
|
|
@ -1,6 +1,5 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'users_controller'
|
||||
require 'user'
|
||||
|
||||
# Re-raise errors caught by the controller.
|
||||
class UsersController; def rescue_action(e) raise e end; end
|
||||
|
|
@ -34,6 +33,9 @@ class UsersControllerTest < Test::Unit::TestCase
|
|||
login_as @admin_user
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_equal "TRACKS::Manage Users", assigns['page_title']
|
||||
assert_equal 3, assigns['total_users']
|
||||
assert_equal "/users", session['return-to']
|
||||
end
|
||||
|
||||
def test_destroy_user
|
||||
|
|
@ -154,7 +156,6 @@ class UsersControllerTest < Test::Unit::TestCase
|
|||
|
||||
def assert_number_of_users_is_unchanged
|
||||
assert_equal User.count, @num_users_in_fixture
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ require 'users_controller'
|
|||
# Re-raise errors caught by the controller.
|
||||
class UsersController; def rescue_action(e) raise e end; end
|
||||
|
||||
class CreateUserControllerTest < ActionController::IntegrationTest
|
||||
class UsersXmlApiTest < ActionController::IntegrationTest
|
||||
fixtures :users
|
||||
|
||||
@@foobar_postdata = "<request><login>foo</login><password>bar</password></request>"
|
||||
|
|
@ -73,9 +73,30 @@ class CreateUserControllerTest < ActionController::IntegrationTest
|
|||
def test_fails_with_get_verb
|
||||
authenticated_get_xml "/users", users(:admin_user).login, 'abracadabra', {}
|
||||
end
|
||||
|
||||
def test_get_users_as_xml
|
||||
get '/users.xml', {}, basic_auth_headers()
|
||||
#puts @response.body
|
||||
assert_response :success
|
||||
assert_tag :tag => "users",
|
||||
:children => { :count => 3, :only => { :tag => "user" } }
|
||||
assert_no_tag :tag => "password"
|
||||
end
|
||||
|
||||
def test_get_user_as_xml
|
||||
get "/users/#{users(:other_user).login}.xml", {}, basic_auth_headers()
|
||||
puts @response.body
|
||||
assert_response :success
|
||||
assert_tag :tag => "user"
|
||||
assert_no_tag :tag => "password"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def basic_auth_headers(username = users(:admin_user).login, password = 'abracadabra')
|
||||
{'AUTHORIZATION' => "Basic " + Base64.encode64("#{username}:#{password}") }
|
||||
end
|
||||
|
||||
def authenticated_post_xml_to_user_create(postdata = @@foobar_postdata, user = users(:admin_user).login, password = 'abracadabra', headers = {})
|
||||
authenticated_post_xml "/users", user, password, postdata, headers
|
||||
end
|
||||
10
tracks/test/selenium/login/first_run_shows_signup.rsel
Normal file
10
tracks/test/selenium/login/first_run_shows_signup.rsel
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
setup :clear_tables => [:users, :preferences]
|
||||
open '/'
|
||||
assert_title 'exact:TRACKS::Sign up as the admin user'
|
||||
type "user_login", "admin"
|
||||
type "user_password", "abracadabra"
|
||||
type "user_password_confirmation", "abracadabra"
|
||||
click_and_wait "signup"
|
||||
assert_title 'exact:TRACKS::Login'
|
||||
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
|
||||
assert_title 'exact:TRACKS::List tasks'
|
||||
|
|
@ -138,5 +138,10 @@ class UserTest < Test::Unit::TestCase
|
|||
def test_prefs_is_short_for_preference
|
||||
assert_equal @admin_user.preference, @admin_user.prefs
|
||||
end
|
||||
|
||||
def test_to_param_returns_login
|
||||
assert_equal @admin_user.login, @admin_user.to_param
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue