File tree Expand file tree Collapse file tree 3 files changed +9
-7
lines changed Expand file tree Collapse file tree 3 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,9 @@ class Client
3131    # @return [Array] Custom response callbacks 
3232    attr_reader  :callbacks 
3333
34-     attr_reader  :ticket_fields_metadata 
34+     def  ticket_fields_metadata 
35+       @ticket_fields_metadata  ||= [ ] 
36+     end 
3537
3638    # Handles resources such as 'tickets'. Any options are passed to the underlying collection, except reload which disregards 
3739    # memoization and creates a new Collection instance. 
Original file line number Diff line number Diff line change @@ -473,19 +473,19 @@ def initialize(ticket, _arr)
473473
474474      def  []( key ) 
475475        raise  "Cannot find custom field #{ key }   unless 
476-           @ticket . instance_variable_get ( "@client" ) . instance_variable_get ( "@ ticket_fields_metadata" ) 
476+           @ticket . instance_variable_get ( "@client" ) . ticket_fields_metadata 
477477        # Trap read access 
478-         fld  =  @ticket . instance_variable_get ( "@client" ) . instance_variable_get ( "@ ticket_fields_metadata" ) . find  {  |val | val [ :title ]  == key  } 
478+         fld  =  @ticket . instance_variable_get ( "@client" ) . ticket_fields_metadata . find  {  |val | val [ :title ]  == key  } 
479479        raise  "Cannot find custom field #{ key }   unless  fld 
480480        cf  =  @ticket . custom_fields . find  {  |h | h [ :id ]  == fld [ :id ]  } 
481481        cf  ? cf [ :value ]  : nil 
482482      end 
483483
484484      def  []=( key ,  value ) 
485485        raise  "Cannot find custom field #{ key }   unless 
486-           @ticket . instance_variable_get ( "@client" ) . instance_variable_get ( "@ ticket_fields_metadata" ) 
486+           @ticket . instance_variable_get ( "@client" ) . ticket_fields_metadata 
487487        # Trap write access 
488-         fld  =  @ticket . instance_variable_get ( "@client" ) . instance_variable_get ( "@ ticket_fields_metadata" ) . find  {  |val | val [ :title ]  == key  } 
488+         fld  =  @ticket . instance_variable_get ( "@client" ) . ticket_fields_metadata . find  {  |val | val [ :title ]  == key  } 
489489        raise  "Cannot find custom field #{ key }   unless  fld 
490490        cf  =  @ticket . custom_fields . find  {  |h | h [ :id ]  == fld [ :id ]  }  if  @ticket . custom_fields 
491491        if  cf 
Original file line number Diff line number Diff line change 1010  end 
1111  let ( :client )  do 
1212    double ( "Client" ) . tap  do  |c |
13-       allow ( c ) . to  receive ( :instance_variable_get  ) . with ( "@ ticket_fields_metadata" ) . and_return ( field_metadata ) 
13+       allow ( c ) . to  receive ( :ticket_fields_metadata ) . and_return ( field_metadata ) 
1414    end 
1515  end 
1616  let ( :ticket )  do 
@@ -85,7 +85,7 @@ def t.custom_fields
8585
8686  describe  "[] and []= with missing ticket_fields_metadata"  do 
8787    before  do 
88-       allow ( client ) . to  receive ( :instance_variable_get  ) . with ( "@ ticket_fields_metadata" ) . and_return ( nil ) 
88+       allow ( client ) . to  receive ( :ticket_fields_metadata ) . and_return ( nil ) 
8989    end 
9090
9191    it  "raises error for [] when ticket_fields_metadata is missing"  do 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments