From d81bf00ecd8bdfcddf50e4881428c917253326fe Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 10 Jan 2013 11:06:09 -0800 Subject: Add test for showing user. --- users/test/functional/users_controller_test.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'users/test') diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb index 1fa1462..1f6c868 100644 --- a/users/test/functional/users_controller_test.rb +++ b/users/test/functional/users_controller_test.rb @@ -9,12 +9,31 @@ class UsersControllerTest < ActionController::TestCase assert_response :success end + test "failed show without login" do + user = find_record User + get :show, :id => user.id + assert_response :redirect + assert_redirected_to login_path + end + + test "user can see user" do + user = find_record User, + :email => nil, + :email_forward => nil, + :email_aliases => [], + :created_at => Time.now, + :updated_at => Time.now, + :most_recent_tickets => [] + login user + get :show, :id => user.id + assert_response :success + end + test "should create new user" do user = stub_record User User.expects(:create).with(user.params).returns(user) post :create, :user => user.params, :format => :json - assert_nil session[:user_id] assert_json_response user assert_response :success -- cgit v1.2.3 From 1cf4cc5c8d571b571367a08f5e201be868289ed1 Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 16 Jan 2013 13:16:38 +0100 Subject: using subdomain for api requests properly --- users/test/integration/api/account_flow_test.rb | 11 ++++++++--- users/test/integration/api/python/flow_with_srp.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'users/test') diff --git a/users/test/integration/api/account_flow_test.rb b/users/test/integration/api/account_flow_test.rb index b9e2a4e..268fb5e 100644 --- a/users/test/integration/api/account_flow_test.rb +++ b/users/test/integration/api/account_flow_test.rb @@ -22,7 +22,7 @@ class AccountFlowTest < ActiveSupport::TestCase :password_verifier => @srp.verifier.to_s(16), :password_salt => @srp.salt.to_s(16) } - post '/1/users.json', :user => @user_params + post 'http://api.lvh.me:3000/1/users.json', :user => @user_params @user = User.find_by_param(@login) end @@ -33,7 +33,10 @@ class AccountFlowTest < ActiveSupport::TestCase # this test wraps the api and implements the interface the ruby-srp client. def handshake(login, aa) - post "/1/sessions.json", :login => login, 'A' => aa.to_s(16), :format => :json + post "http://api.lvh.me:3000/1/sessions.json", + :login => login, + 'A' => aa.to_s(16), + :format => :json response = JSON.parse(last_response.body) if response['errors'] raise RECORD_NOT_FOUND.new(response['errors']) @@ -43,7 +46,9 @@ class AccountFlowTest < ActiveSupport::TestCase end def validate(m) - put "/1/sessions/" + @login + '.json', :client_auth => m.to_s(16), :format => :json + put "http://api.lvh.me:3000/1/sessions/" + @login + '.json', + :client_auth => m.to_s(16), + :format => :json return JSON.parse(last_response.body) end diff --git a/users/test/integration/api/python/flow_with_srp.py b/users/test/integration/api/python/flow_with_srp.py index f28aeda..df83dfb 100755 --- a/users/test/integration/api/python/flow_with_srp.py +++ b/users/test/integration/api/python/flow_with_srp.py @@ -16,7 +16,7 @@ def id_generator(size=6, chars=string.ascii_uppercase + string.digits): return ''.join(random.choice(chars) for x in range(size)) # using globals for a start -server = 'http://localhost:3000/1' +server = 'http://api.lvh.me:3000/1' login = id_generator() password = id_generator() + id_generator() -- cgit v1.2.3 From cce882a42cc0c139b75d932ea8ee42525e4fdb32 Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 17 Jan 2013 12:35:48 -0800 Subject: Should be able to create a user when not logged in. This isn't ready to merge, as there is an issue with logging in as an admin in the test. --- users/test/functional/users_controller_test.rb | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'users/test') diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb index 46db4d1..8c584ef 100644 --- a/users/test/functional/users_controller_test.rb +++ b/users/test/functional/users_controller_test.rb @@ -10,10 +10,12 @@ class UsersControllerTest < ActionController::TestCase end test "failed show without login" do - user = find_record :user + user = FactoryGirl.build(:user) + user.save get :show, :id => user.id assert_response :redirect assert_redirected_to login_path + user.destroy end test "user can see user" do @@ -42,7 +44,7 @@ class UsersControllerTest < ActionController::TestCase assert_response :success end - + test "user cannot see other user" do user = find_record :user, :email => nil, @@ -57,6 +59,26 @@ class UsersControllerTest < ActionController::TestCase assert_access_denied end + test "show for non-existing user" do + nonid = 'thisisnotanexistinguserid' + + # when unauthenticated: + get :show, :id => nonid + assert_access_denied(true, false) + + # when authenticated but not admin: + login + get :show, :id => nonid + assert_access_denied + + # when authenticated as admin: + # TODO: THIS IS failing to login and have admin? return true in users_controller. Will look into it later. + login :is_admin => true + get :show, :id => nonid + assert_response :redirect + assert_equal({:alert => "No such user."}, flash.to_hash) + assert_redirected_to users_path + end test "should create new user" do user_attribs = record_attributes_for :user -- cgit v1.2.3 From 444dbca4054ccfb7a82bb4df2a6369959ef6c9b2 Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 18 Jan 2013 07:38:13 +0100 Subject: minor: smalles fix ever - is_admin? has a questionmark --- users/test/functional/users_controller_test.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'users/test') diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb index 8c584ef..9fb06c9 100644 --- a/users/test/functional/users_controller_test.rb +++ b/users/test/functional/users_controller_test.rb @@ -72,8 +72,7 @@ class UsersControllerTest < ActionController::TestCase assert_access_denied # when authenticated as admin: - # TODO: THIS IS failing to login and have admin? return true in users_controller. Will look into it later. - login :is_admin => true + login :is_admin? => true get :show, :id => nonid assert_response :redirect assert_equal({:alert => "No such user."}, flash.to_hash) -- cgit v1.2.3