From f3f42086e9f325560444f42c6b54269546114167 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 11 Dec 2012 13:01:24 +0100 Subject: make sure can login twice --- users/app/controllers/sessions_controller.rb | 1 + users/app/controllers/v1/sessions_controller.rb | 1 + users/test/integration/api/account_flow_test.rb | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/users/app/controllers/sessions_controller.rb b/users/app/controllers/sessions_controller.rb index bc910b5..0345fbd 100644 --- a/users/app/controllers/sessions_controller.rb +++ b/users/app/controllers/sessions_controller.rb @@ -11,6 +11,7 @@ class SessionsController < ApplicationController end def create + logout if logged_in? authenticate! end diff --git a/users/app/controllers/v1/sessions_controller.rb b/users/app/controllers/v1/sessions_controller.rb index 5b4a13b..27d10fb 100644 --- a/users/app/controllers/v1/sessions_controller.rb +++ b/users/app/controllers/v1/sessions_controller.rb @@ -12,6 +12,7 @@ module V1 end def create + logout if logged_in? authenticate! end diff --git a/users/test/integration/api/account_flow_test.rb b/users/test/integration/api/account_flow_test.rb index e425c35..7636f2b 100644 --- a/users/test/integration/api/account_flow_test.rb +++ b/users/test/integration/api/account_flow_test.rb @@ -62,6 +62,14 @@ class AccountFlowTest < ActiveSupport::TestCase assert server_auth["M2"] end + test "duplicate login does not break things" do + server_auth = @srp.authenticate(self) + server_auth = @srp.authenticate(self) + assert last_response.successful? + assert_nil server_auth["errors"] + assert server_auth["M2"] + end + test "signup and wrong password login attempt" do srp = SRP::Client.new(@login, "wrong password") server_auth = srp.authenticate(self) -- cgit v1.2.3 From 728a4c0df4c0957f4402a5f0dd517b1bff77d7d1 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 17 Dec 2012 09:21:22 +0100 Subject: fixed all user functional tests --- users/test/functional/users_controller_test.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb index 1840a72..79c22c4 100644 --- a/users/test/functional/users_controller_test.rb +++ b/users/test/functional/users_controller_test.rb @@ -35,7 +35,10 @@ class UsersControllerTest < ActionController::TestCase end test "should get edit view" do - user = find_record User, :email => nil, :email_forward => nil + user = find_record User, + :email => nil, + :email_forward => nil, + :email_aliases => [] login user get :edit, :id => user.id @@ -45,7 +48,9 @@ class UsersControllerTest < ActionController::TestCase test "should process updated params" do user = find_record User - user.expects(:update_attributes).with(user.params).returns(true) + user.expects(:attributes=).with(user.params) + user.expects(:changed?).returns(true) + user.expects(:save).returns(true) login user put :update, :user => user.params, :id => user.id, :format => :json @@ -57,7 +62,9 @@ class UsersControllerTest < ActionController::TestCase test "admin can update user" do user = find_record User - user.expects(:update_attributes).with(user.params).returns(true) + user.expects(:attributes=).with(user.params) + user.expects(:changed?).returns(true) + user.expects(:save).returns(true) login :is_admin? => true put :update, :user => user.params, :id => user.id, :format => :json -- cgit v1.2.3 From c76891bf7d53d63b7d3bec885ba79100eecbf65e Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 17 Dec 2012 09:47:57 +0100 Subject: small fix to the tickets functional test --- help/test/functional/tickets_controller_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/help/test/functional/tickets_controller_test.rb b/help/test/functional/tickets_controller_test.rb index 592bd8c..14ca335 100644 --- a/help/test/functional/tickets_controller_test.rb +++ b/help/test/functional/tickets_controller_test.rb @@ -176,14 +176,14 @@ class TicketsControllerTest < ActionController::TestCase login :is_admin? => true, :email => nil - get :index, {:admin_status => "mine", :open_status => "open"} + get :index, {:admin_status => "all", :open_status => "open"} assert assigns(:all_tickets).count > 1 # at least 2 tickets # if we close one ticket, the admin should have 1 less open ticket they admin assert_difference('assigns[:all_tickets].count', -1) do assigns(:tickets).first.close assigns(:tickets).first.save - get :index, {:admin_status => "mine", :open_status => "open"} + get :index, {:admin_status => "all", :open_status => "open"} end testticket = Ticket.create :title => 'temp testytest' -- cgit v1.2.3 From 23111a9ca31177c324101b8cd31a9ae0e67f9504 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 17 Dec 2012 09:53:38 +0100 Subject: fixed inclusion of stub record helper --- users/test/functional/users_controller_test.rb | 1 - users/test/support/auth_test_helper.rb | 3 +-- users/test/support/stub_record_helper.rb | 4 ++++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb index 79c22c4..ce17500 100644 --- a/users/test/functional/users_controller_test.rb +++ b/users/test/functional/users_controller_test.rb @@ -1,7 +1,6 @@ require 'test_helper' class UsersControllerTest < ActionController::TestCase - include StubRecordHelper test "should get new" do get :new diff --git a/users/test/support/auth_test_helper.rb b/users/test/support/auth_test_helper.rb index 6a82f24..c9f5612 100644 --- a/users/test/support/auth_test_helper.rb +++ b/users/test/support/auth_test_helper.rb @@ -1,5 +1,4 @@ module AuthTestHelper - include StubRecordHelper extend ActiveSupport::Concern # Controller will fetch current user from warden. @@ -24,7 +23,7 @@ module AuthTestHelper assert_equal({:alert => "Not authorized"}, flash.to_hash) # todo: eventually probably eliminate separate conditions assert_redirected_to login_path if !logged_in - assert_redirected_to root_path if logged_in + assert_redirected_to root_path if logged_in else assert flash[:alert].blank? end diff --git a/users/test/support/stub_record_helper.rb b/users/test/support/stub_record_helper.rb index 2e1a533..1be419a 100644 --- a/users/test/support/stub_record_helper.rb +++ b/users/test/support/stub_record_helper.rb @@ -39,3 +39,7 @@ module StubRecordHelper end end + +class ActionController::TestCase + include StubRecordHelper +end -- cgit v1.2.3 From 6b9ceba75230705a073cf7ba6439c07e29a57be3 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 17 Dec 2012 10:09:00 +0100 Subject: split up and fixed ticket functional tests --- help/test/functional/tickets_controller_test.rb | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/help/test/functional/tickets_controller_test.rb b/help/test/functional/tickets_controller_test.rb index 14ca335..b29fa17 100644 --- a/help/test/functional/tickets_controller_test.rb +++ b/help/test/functional/tickets_controller_test.rb @@ -118,7 +118,7 @@ class TicketsControllerTest < ActionController::TestCase login User.last ticket = Ticket.find('stubtestticketid') - ticket.created_by = User.last.id # TODO: hacky, but confirms it is their ticket + ticket.created_by = @current_user.id # TODO: hacky, but confirms it is their ticket ticket.save #they should be able to comment if it is their ticket: @@ -185,16 +185,24 @@ class TicketsControllerTest < ActionController::TestCase assigns(:tickets).first.save get :index, {:admin_status => "all", :open_status => "open"} end + end + + test "admin_status mine vs all" do testticket = Ticket.create :title => 'temp testytest' + login :is_admin? => true, :email => nil - # test admin_status 'mine' vs 'all' get :index, {:admin_status => "all", :open_status => "open"} assert assigns(:all_tickets).include?(testticket) get :index, {:admin_status => "mine", :open_status => "open"} assert !assigns(:all_tickets).include?(testticket) + end + + test "commenting on a ticket adds to tickets that are mine" do + testticket = Ticket.create :title => 'temp testytest' + login :is_admin? => true, :email => nil - # admin should have one more ticket if a new tick gets an admin comment + get :index, {:admin_status => "mine", :open_status => "open"} assert_difference('assigns[:all_tickets].count') do put :update, :id => testticket.id, :ticket => {:comments_attributes => {"0" => {"body" =>"NEWER comment"}}} get :index, {:admin_status => "mine", :open_status => "open"} @@ -205,10 +213,12 @@ class TicketsControllerTest < ActionController::TestCase assert_equal assigns(:ticket).comments.last.posted_by, @current_user.id assigns(:ticket).destroy + end - # test ordering + test "admin ticket ordering" do - get :index, {:admin_status => "mine", :open_status => "open", :sort_order => 'created_at_desc'} + login :is_admin? => true, :email => nil + get :index, {:admin_status => "all", :open_status => "open", :sort_order => 'created_at_desc'} # this will consider all tickets, not just those on first page first_tick = assigns(:all_tickets).all.first @@ -216,7 +226,7 @@ class TicketsControllerTest < ActionController::TestCase assert first_tick.created_at > last_tick.created_at # and now reverse order: - get :index, {:admin_status => "mine", :open_status => "open", :sort_order => 'created_at_asc'} + get :index, {:admin_status => "all", :open_status => "open", :sort_order => 'created_at_asc'} assert_equal first_tick, assigns(:all_tickets).last assert_equal last_tick, assigns(:all_tickets).first -- cgit v1.2.3