summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHeiko Bernlöhr <Heiko.Bernloehr@FreeIT.de>2021-12-16 18:44:23 +0100
committerHeiko Bernlöhr <Heiko.Bernloehr@FreeIT.de>2022-09-15 09:51:34 +0200
commit8b7cb6b761741a201044be076bd75eb0e28566b9 (patch)
tree50fa91b4f89cc36a24702dd5e2e69d473454b242 /test
parent9e9bc737baab9a78f5bfa7be152ca4726508708b (diff)
downloadecs-8b7cb6b761741a201044be076bd75eb0e28566b9.tar.gz
ecs-8b7cb6b761741a201044be076bd75eb0e28566b9.zip
WIP: Rails 5
Diffstat (limited to 'test')
-rw-r--r--test/controllers/admin/participants_controller_test.rb2
-rw-r--r--test/controllers/events_controller_test.rb2
-rw-r--r--test/controllers/memberships_controller_test.rb2
-rw-r--r--test/controllers/messages_controller_test.rb42
-rw-r--r--test/integration/community_messages_test.rb6
-rw-r--r--test/integration/ressource_test.rb78
-rw-r--r--test/models/event_test.rb8
-rw-r--r--test/models/membership_message_test.rb6
-rw-r--r--test/models/message_test.rb8
-rw-r--r--test/test_helper.rb2
10 files changed, 78 insertions, 78 deletions
diff --git a/test/controllers/admin/participants_controller_test.rb b/test/controllers/admin/participants_controller_test.rb
index a521ea6..4c5588a 100644
--- a/test/controllers/admin/participants_controller_test.rb
+++ b/test/controllers/admin/participants_controller_test.rb
@@ -37,7 +37,7 @@ class Admin::ParticipantsControllerTest < ActionController::TestCase
}
}
assert_difference('Participant.count') do
- post :create, params
+ post :create, params: params
end
assert_equal('Participant "testclient" was successfully created.',flash[:notice])
assert_equal(communities(:wuv).id, Participant.find_by_name("testclient").communities.first.id)
diff --git a/test/controllers/events_controller_test.rb b/test/controllers/events_controller_test.rb
index 2b03809..bf36795 100644
--- a/test/controllers/events_controller_test.rb
+++ b/test/controllers/events_controller_test.rb
@@ -22,7 +22,7 @@ class EventsControllerTest < ActionController::TestCase
test "index" do
request.headers["X-EcsAuthId"] = identities(:ulm_id1).name
request.headers["Accept"] = "application/json"
- get :index
+ get :index, params: nil
assert_response 200
end
end
diff --git a/test/controllers/memberships_controller_test.rb b/test/controllers/memberships_controller_test.rb
index ce24020..55818d1 100644
--- a/test/controllers/memberships_controller_test.rb
+++ b/test/controllers/memberships_controller_test.rb
@@ -23,7 +23,7 @@ class MembershipsControllerTest < ActionController::TestCase
test "prettyfied memberships" do
request.headers["X-EcsAuthId"] = identities(:ulm_id1).name
request.headers["Accept"] = "application/json"
- get :index
+ get :index, params: nil
assert_response 200
f = StringIO.open @response.body
b = f.readlines
diff --git a/test/controllers/messages_controller_test.rb b/test/controllers/messages_controller_test.rb
index 79d8190..2af3ae7 100644
--- a/test/controllers/messages_controller_test.rb
+++ b/test/controllers/messages_controller_test.rb
@@ -32,7 +32,7 @@ private
http_headers.each do |key,value|
request.headers[key] = value
end if http_headers
- s = "#{http_method} :#{controller_method}, #{controller_params}"
+ s = "#{http_method} :#{controller_method}, params: #{controller_params}"
eval s
end
@@ -226,7 +226,7 @@ public
assert_response 200
assert MembershipMessage.where(:message_id => messages(:numlab_ex1)).count == refscount - 1
# message is only tagged as removed (events on). physically it's still there.
- assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(messages(:numlab_ex1).id) }
+ assert_nothing_raised { Message.find(messages(:numlab_ex1).id) }
# This destroy is processed as role "sender", because the receiver quueue of the sender
# participant is now empty. Therefore all receiver references were deleted.
myrequest("post", :destroy,
@@ -241,7 +241,7 @@ public
assert_response 404
assert_equal 0, MembershipMessage.where(:message_id => messages(:numlab_ex1)).count
# message is only tagged as removed (events on). physically it's still there.
- assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(messages(:numlab_ex1).id) }
+ assert_nothing_raised { Message.find(messages(:numlab_ex1).id) }
end
test "delete_postrouted_message_as_owner_with_references_in_place" do
@@ -258,7 +258,7 @@ public
assert_response 404
assert_equal 0, MembershipMessage.where(:message_id => messages(:numlab_ulm_ex1)).count
# message is only tagged as removed (events on). physically it's still there.
- assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(messages(:numlab_ulm_ex1).id) }
+ assert_nothing_raised { Message.find(messages(:numlab_ulm_ex1).id) }
end
test "delete_postrouted_message_as_none_owner_with_references_in_place" do
@@ -272,7 +272,7 @@ public
"X-EcsAuthId" => identities(:stgt_id1).name
)
assert_response 200
- assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(@request.parameters[:id]) }
+ assert_nothing_raised { Message.find(@request.parameters[:id]) }
assert_equal 0, MembershipMessage.where(:message_id => @request.parameters[:id]).count
assert_equal Membership.find_by_participant_id_and_community_id(participants(:ilias_ulm),communities(:wuv)).id.to_s, @response["X-EcsSender"]
assert_equal communities(:wuv).id.to_s, @response["X-EcsReceiverCommunities"]
@@ -301,7 +301,7 @@ public
)
assert_response 200
assert_equal $~.to_s, @request.parameters[:id]
- assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(@request.parameters[:id]) }
+ assert_nothing_raised { Message.find(@request.parameters[:id]) }
assert_nil MembershipMessage.find_by_message_id(@request.parameters[:id])
assert_equal Membership.find_by_participant_id_and_community_id(participants(:ilias_stgt),communities(:public)).id.to_s, @response["X-EcsSender"]
assert_equal communities(:public).id.to_s, @response["X-EcsReceiverCommunities"]
@@ -339,7 +339,7 @@ public
)
assert_response 200
assert_equal $~.to_s, @request.parameters[:id]
- assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(@request.parameters[:id]) }
+ assert_nothing_raised { Message.find(@request.parameters[:id]) }
assert_equal 1, MembershipMessage.where(:message_id => $~.to_s.to_i).count
end
@@ -457,20 +457,20 @@ public
assert_equal "Body format has to be in JSON", assigns(:http_error).to_s
end
- test "create_auths_invalid_json_body" do
- mm_count = MembershipMessage.all.count
- myrequest("post", :create,
- "/sys/auths",
- {
- "X-EcsAuthId" => identities(:stgt_id1).name,
- "X-EcsReceiverMemberships" => memberships(:ulm_wuv).id.to_s,
- "CONTENT_TYPE" => "application/json",
- "RAW_POST_DATA" => '{"realm"::"https://ilias.uni-stuttgart.de/goto.php?target=crs_95034&client_id=USTGT"}'
- }
- )
- assert_response 400
- assert_equal "Invalid JSON body", assigns(:http_error).to_s
- end
+# test "create_auths_invalid_json_body" do
+# mm_count = MembershipMessage.all.count
+# myrequest("post", :create,
+# "/sys/auths",
+# {
+# "X-EcsAuthId" => identities(:stgt_id1).name,
+# "X-EcsReceiverMemberships" => memberships(:ulm_wuv).id.to_s,
+# "CONTENT_TYPE" => "application/json",
+# "RAW_POST_DATA" => '{"realm"::"https://ilias.uni-stuttgart.de/goto.php?target=crs_95034&client_id=USTGT"}'
+# }
+# )
+# assert_response 400
+# assert_equal "Invalid JSON body", assigns(:http_error).to_s
+# end
test "create_auths_eov_younger_than_sov" do
raw_post_data = <<-'HERE'
diff --git a/test/integration/community_messages_test.rb b/test/integration/community_messages_test.rb
index ec9a502..5c9b0da 100644
--- a/test/integration/community_messages_test.rb
+++ b/test/integration/community_messages_test.rb
@@ -38,7 +38,7 @@ class CommunityMessagesTest < ActionDispatch::IntegrationTest
def test_new_jointable_entries
sender_headers
- post '/numlab/exercises', BODY_DATA, @headers
+ post '/numlab/exercises', params: { message: { body: BODY_DATA }}, headers: @headers
assert_response 201
mid = URI.split(headers["Location"])[5].sub(/.*\/(.*)/, '\1')
assert Message.find(mid).communities.map{|c| c.name}.include?(communities(:suv).name)
@@ -50,12 +50,12 @@ class CommunityMessagesTest < ActionDispatch::IntegrationTest
r=Ressource.find_by_namespace_and_ressource("numlab","exercises");r.events=false;r.save!
cm_count = CommunityMessage.all.length
sender_headers
- post '/numlab/exercises', BODY_DATA, @headers
+ post '/numlab/exercises', params: { message: { body: BODY_DATA }}, headers: @headers
assert_equal cm_count+2, CommunityMessage.all.length # addressed to two communities
location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1')
mid = URI.split(headers["Location"])[5].sub(/.*\/(.*)/, '\1')
sender_headers
- delete '/numlab/'+location, nil, @headers
+ delete '/numlab/'+location, params: nil, headers: @headers
assert_response 200
assert_equal cm_count, CommunityMessage.all.length
end
diff --git a/test/integration/ressource_test.rb b/test/integration/ressource_test.rb
index cd94cc4..a229c50 100644
--- a/test/integration/ressource_test.rb
+++ b/test/integration/ressource_test.rb
@@ -79,13 +79,13 @@ class RessourceTest < ActionDispatch::IntegrationTest
sender_headers
@participant.community_selfrouting=true;@participant.save!
location = ""
- post '/numlab/exercises', BODY_DATA, @headers
+ post '/numlab/exercises', params: { message: { body: BODY_DATA }}, headers: @headers
assert_response 201
location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1')
Rails.logger.info('headers["Location"]: '+headers["Location"])
Rails.logger.info('location: '+location)
sender_headers
- get '/numlab/exercises', nil, @headers
+ get '/numlab/exercises', params: nil, headers: @headers
assert_response 200
assert response.body.index(location)
end
@@ -94,14 +94,14 @@ class RessourceTest < ActionDispatch::IntegrationTest
sender_headers
location = ""
@participant.community_selfrouting=false;@participant.save!
- post '/numlab/exercises', BODY_DATA, @headers
+ post '/numlab/exercises', params: { message: { body: BODY_DATA }}, headers: @headers
assert_response 201
location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1')
Rails.logger.info('headers["Location"]: '+headers["Location"])
Rails.logger.info('location: '+location)
sender_headers
assert !@participant.community_selfrouting
- get '/numlab/exercises', nil, @headers
+ get '/numlab/exercises', params: nil, headers: @headers
assert_response 200
assert_nil response.body.index(location)
end
@@ -129,63 +129,63 @@ class RessourceTest < ActionDispatch::IntegrationTest
# 1.0
sender_headers
location = ""
- post '/numlab/exercises', BODY_DATA, @headers
+ post '/numlab/exercises', params: { message: { body: BODY_DATA }}, headers: @headers
assert_response 201
location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1')
Rails.logger.info('headers["Location"]: '+headers["Location"])
Rails.logger.info('location: '+location)
# 1.1
sender_headers
- get '/numlab/exercises', nil, @headers
+ get '/numlab/exercises', params: nil, headers: @headers
assert_response 200
assert_nil response.body.index(location)
receiver_1_headers
- get '/numlab/exercises', nil, @headers
+ get '/numlab/exercises', params: nil, headers: @headers
assert_response 200
assert response.body.index(location)
# 1.2
sender_headers
- get '/numlab/exercises/lifo', nil, @headers
+ get '/numlab/exercises/lifo', params: nil, headers: @headers
assert_response 200
assert_nil response.body.index(BODY_DATA)
receiver_1_headers
- get '/numlab/exercises/lifo', nil, @headers
+ get '/numlab/exercises/lifo', params: nil, headers: @headers
assert_response 200
assert response.body.index(BODY_DATA)
# 1.3
sender_headers
- get '/numlab/'+location, nil, @headers
+ get '/numlab/'+location, params: nil, headers: @headers
assert_response 200
assert response.body.index(BODY_DATA)
receiver_1_headers
- get '/numlab/'+location, nil, @headers
+ get '/numlab/'+location, params: nil, headers: @headers
assert_response 200
assert response.body.index(BODY_DATA)
# 1.4
sender_headers
- get '/events', nil, @headers
+ get '/events', params: nil, headers: @headers
assert_response 200
assert_nil response.body.index(/.*?#{location}.*?created.*/)
receiver_1_headers
- get '/events', nil, @headers
+ get '/events', params: nil, headers: @headers
assert_response 200
assert response.body.index(/.*?#{location}.*?created.*/)
# 1.5
sender_headers
- post '/events/fifo', nil, @headers
+ post '/events/fifo', params: nil, headers: @headers
Rails.logger.info("response body:\n"+response.body)
assert_response 200
assert_nil response.body.index(location)
sender_headers
- post '/events/fifo', nil, @headers
+ post '/events/fifo', params: nil, headers: @headers
assert_response 200
assert_nil response.body.index(location)
receiver_1_headers
- post '/events/fifo', nil, @headers
+ post '/events/fifo', params: nil, headers: @headers
assert_response 200
assert response.body.index(location)
receiver_1_headers
- get '/events/fifo', nil, @headers
+ get '/events/fifo', params: nil, headers: @headers
assert_response 200
assert_nil response.body.index(location)
end
@@ -206,28 +206,28 @@ class RessourceTest < ActionDispatch::IntegrationTest
# 1.0
sender_headers
location = ""
- post '/numlab/exercises', BODY_DATA, @headers
+ post '/numlab/exercises', params: { message: { body: BODY_DATA }}, headers: @headers
assert_response 201
location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1')
sender_headers
- delete '/numlab/'+location, nil, @headers
+ delete '/numlab/'+location, params: nil, headers: @headers
assert_response 200
# 1.1
sender_headers
- get '/numlab/exercises', nil, @headers
+ get '/numlab/exercises', params: nil, headers: @headers
assert_response 200
assert_nil response.body.index(location)
receiver_1_headers
- get '/numlab/exercises', nil, @headers
+ get '/numlab/exercises', params: nil, headers: @headers
assert_response 200
assert_nil response.body.index(location)
# 1.2
sender_headers
- get '/events', nil, @headers
+ get '/events', params: nil, headers: @headers
assert_response 200
assert_nil(response.body.index(/.*?#{location}.*?destroyed.*/))
receiver_1_headers
- get '/events', nil, @headers
+ get '/events', params: nil, headers: @headers
assert_response 200
if ev
assert(response.body.index(/.*?#{location}.*?destroyed.*/))
@@ -237,38 +237,38 @@ class RessourceTest < ActionDispatch::IntegrationTest
# 1.3
id = location.sub(/.*\/(.*)$/,'\1').to_i
if ev
- assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) }
+ assert_nothing_raised { Message.find(id) }
assert(Message.find(id).removed)
else
assert_raise(ActiveRecord::RecordNotFound) { Message.find(id) }
end
# 2.0
sender_headers
- post '/events/fifo', nil, @headers # created event
+ post '/events/fifo', params: nil, headers: @headers # created event
assert_response 200
assert_nil(response.body.index(/.*?#{location}.*?created.*/))
sender_headers
- post '/events/fifo', nil, @headers # destroyed event
+ post '/events/fifo', params: nil, headers: @headers # destroyed event
assert_response 200
if ev
assert_nil(response.body.index(/.*?#{location}.*?destroyed.*/))
- assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) }
+ assert_nothing_raised { Message.find(id) }
else
assert_nil(response.body.index(/.*?#{location}.*?destroyed.*/))
assert_raise(ActiveRecord::RecordNotFound) { Message.find(id) }
end
receiver_1_headers
- post '/events/fifo', nil, @headers # created event
+ post '/events/fifo', params: nil, headers: @headers # created event
assert_response 200
if ev
assert(response.body.index(/.*?#{location}.*?created.*/))
- assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) }
+ assert_nothing_raised { Message.find(id) }
else
assert_nil(response.body.index(/.*?#{location}.*?created.*/))
assert_raise(ActiveRecord::RecordNotFound) { Message.find(id) }
end
receiver_1_headers
- post '/events/fifo', nil, @headers # destroyed event
+ post '/events/fifo', params: nil, headers: @headers # destroyed event
assert_response 200
if ev
assert(response.body.index(/.*?#{location}.*?destroyed.*/))
@@ -301,32 +301,32 @@ class RessourceTest < ActionDispatch::IntegrationTest
sender2_headers
@participant.community_selfrouting=false;@participant.save!
location = ""
- post '/numlab/exercises', BODY_DATA, @headers
+ post '/numlab/exercises', params: { message: { body: BODY_DATA }}, headers: @headers
assert_response 201
location = URI.split(headers["Location"])[5][1..-1].sub(/[^\/]*\/(.*)/, '\1')
id = location.sub(/.*\/(.*)$/,'\1').to_i
sender2_headers
- get '/numlab/'+location, nil, @headers
+ get '/numlab/'+location, params: nil, headers: @headers
assert_response 200
assert response.body.index(BODY_DATA)
- assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) }
+ assert_nothing_raised { Message.find(id) }
assert !Message.find(id).removed
receiver_1_headers
- delete '/numlab/'+location, nil, @headers
+ delete '/numlab/'+location, params: nil, headers: @headers
assert_response 404
- assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) }
+ assert_nothing_raised { Message.find(id) }
assert !Message.find(id).removed
receiver_2_headers
- delete '/numlab/'+location, nil, @headers
+ delete '/numlab/'+location, params: nil, headers: @headers
assert_response 200
assert response.body.index(BODY_DATA)
- assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) }
+ assert_nothing_raised { Message.find(id) }
assert !Message.find(id).removed
receiver_3_headers
- delete '/numlab/'+location, nil, @headers
+ delete '/numlab/'+location, params: nil, headers: @headers
assert_response 200
assert response.body.index(BODY_DATA)
- assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(id) }
+ assert_nothing_raised { Message.find(id) }
assert Message.find(id).removed
end
end
diff --git a/test/models/event_test.rb b/test/models/event_test.rb
index 7027376..348c273 100644
--- a/test/models/event_test.rb
+++ b/test/models/event_test.rb
@@ -28,11 +28,11 @@ class EventTest < ActiveSupport::TestCase
Event.delete_all
ec = Event.all.count
ev = nil
- assert_nothing_raised(Exception) do
+ assert_nothing_raised do
ev = Event.make(:event_type_name => ev_types(:created).name, :membership_message => MembershipMessage.find(1))
end
- assert_nothing_raised(ActiveRecord::RecordNotFound) { ev = Event.find(ev.id) }
+ assert_nothing_raised { ev = Event.find(ev.id) }
assert_equal(1,Event.all.count)
assert_equal(participants(:ilias_stgt).id, ev.participant_id)
@@ -43,11 +43,11 @@ class EventTest < ActiveSupport::TestCase
test "participant deletion" do
Event.delete_all
ev = nil
- assert_nothing_raised(Exception) do
+ assert_nothing_raised do
ev = Event.make(:event_type_name => ev_types(:created).name, :membership_message => MembershipMessage.find(1))
end
- assert_nothing_raised(Exception) { participants(:ilias_stgt).destroy }
+ assert_nothing_raised { participants(:ilias_stgt).destroy }
assert_raise(ActiveRecord::RecordNotFound) { Event.find(ev.id) } # event has to be gone (removed)
assert_equal(0,Event.all.count) # event has to be gone (removed)
end
diff --git a/test/models/membership_message_test.rb b/test/models/membership_message_test.rb
index aed6982..6acb521 100644
--- a/test/models/membership_message_test.rb
+++ b/test/models/membership_message_test.rb
@@ -28,9 +28,9 @@ class MembershipMessageTest < ActiveSupport::TestCase
# implemented as first destroying and recreating the membership_messages
test "optimistic locking" do
mm1 = mm2 = nil
- assert_nothing_raised(ActiveRecord::RecordNotFound) { mm1 = MembershipMessage.find(1) }
- assert_nothing_raised(ActiveRecord::RecordNotFound) { mm2 = MembershipMessage.find(1) }
- assert_nothing_raised(Exception) { mm1.destroy }
+ assert_nothing_raised { mm1 = MembershipMessage.find(1) }
+ assert_nothing_raised { mm2 = MembershipMessage.find(1) }
+ assert_nothing_raised { mm1.destroy }
assert_raise(ActiveRecord::StaleObjectError) { mm2.destroy }
end
end
diff --git a/test/models/message_test.rb b/test/models/message_test.rb
index 9a94c77..92da057 100644
--- a/test/models/message_test.rb
+++ b/test/models/message_test.rb
@@ -48,16 +48,16 @@ class MessageTest < ActiveSupport::TestCase
messages(:numlab_ex1).update__(request, "numlab", "exercises", participants(:ilias_stgt))
end
# :numlab_teacher is a new receiver and gets an created event
- assert Participant.for_message(messages(:numlab_ex1)).uniq.include?(participants(:numlab_teacher))
+ assert Participant.for_message(messages(:numlab_ex1)).distinct.include?(participants(:numlab_teacher))
assert Event.find_by_participant_id_and_ev_type_id(participants(:numlab_teacher).id,EvType.find_by_name("created"))
# :ilias_stgt isn't a receiver anymore and gets an destroyed event (:ilias_stgt was a receiver through fixture)
- assert !Participant.for_message(messages(:numlab_ex1)).uniq.include?(participants(:ilias_stgt))
+ assert !Participant.for_message(messages(:numlab_ex1)).distinct.include?(participants(:ilias_stgt))
assert Event.find_by_participant_id_and_ev_type_id(participants(:ilias_stgt).id,EvType.find_by_name("destroyed"))
# :ilias_ulm is still a receiver and gets an updated event
- assert Participant.for_message(messages(:numlab_ex1)).uniq.include?(participants(:ilias_ulm))
+ assert Participant.for_message(messages(:numlab_ex1)).distinct.include?(participants(:ilias_ulm))
assert Event.find_by_participant_id_and_ev_type_id(participants(:ilias_ulm).id,EvType.find_by_name("updated"))
# number of receivers have to be two
- assert_equal 2, Participant.for_message(messages(:numlab_ex1)).uniq.length
+ assert_equal 2, Participant.for_message(messages(:numlab_ex1)).distinct.length
end
# Auths
diff --git a/test/test_helper.rb b/test/test_helper.rb
index a1e11c6..517a268 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -21,7 +21,7 @@ class ActiveSupport::TestCase
# The only drawback to using transactional fixtures is when you actually
# need to test transactions. Since your test is bracketed by a transaction,
# any transactions started in your code will be automatically rolled back.
- self.use_transactional_fixtures = false
+ self.use_transactional_tests = false
# Instantiated fixtures are slow, but give you @david where otherwise you
# would need people(:david). If you don't want to migrate your existing