Просмотр исходного кода

Fixed test: Ensure action is performed by current Ticket Owner to mark it as seen.

Thorsten Eckel 4 лет назад
Родитель
Сommit
cdbcb5d853
2 измененных файлов с 4 добавлено и 2 удалено
  1. 1 1
      spec/jobs/ticket_online_notification_seen_job_spec.rb
  2. 3 1
      spec/support/user_info.rb

+ 1 - 1
spec/jobs/ticket_online_notification_seen_job_spec.rb

@@ -12,7 +12,7 @@ RSpec.describe TicketOnlineNotificationSeenJob, type: :job do
     expect(online_notification.reload.seen).to be false
     expect(online_notification.reload.seen).to be false
   end
   end
 
 
-  it 'checks if online notification has been seen' do
+  it 'checks if online notification has been seen', current_user_id: -> { user.id } do
     ticket.state_id = Ticket::State.lookup(name: 'closed').id
     ticket.state_id = Ticket::State.lookup(name: 'closed').id
     ticket.save!
     ticket.save!
 
 

+ 3 - 1
spec/support/user_info.rb

@@ -7,10 +7,12 @@
 # DB ForeignKey violation errors.
 # DB ForeignKey violation errors.
 # If a `:current_user_id` metadata argument is set the initial value for
 # If a `:current_user_id` metadata argument is set the initial value for
 # UserInfo.current_user_id will be set to the arguments given value
 # UserInfo.current_user_id will be set to the arguments given value
+# if it's a Proc it will get evaluated
 RSpec.configure do |config|
 RSpec.configure do |config|
 
 
   config.before(:each) do |example|
   config.before(:each) do |example|
-    UserInfo.current_user_id = example.metadata[:current_user_id]
+    current_user_id = example.metadata[:current_user_id]
+    UserInfo.current_user_id = current_user_id.is_a?(Proc) ? instance_exec(&current_user_id) : current_user_id
   end
   end
 
 
   config.after(:each) do |_example|
   config.after(:each) do |_example|