Fix up models to use Rails4 find_or_create - warvox - VoIP based wardialing tool, forked from rapid7/warvox.
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit 9daf341c542e2c723c6db741e469251e30768597
 (DIR) parent 8a22b69da25c48aad0b9e211278a787d93419e7b
 (HTM) Author: HD Moore <hd_moore@rapid7.com>
       Date:   Sat, 25 Oct 2014 11:37:48 -0500
       
       Fix up models to use Rails4 find_or_create
       
       Diffstat:
         M app/models/call.rb                  |       8 ++++----
         M app/models/line.rb                  |       2 +-
       
       2 files changed, 5 insertions(+), 5 deletions(-)
       ---
 (DIR) diff --git a/app/models/call.rb b/app/models/call.rb
       @@ -35,7 +35,7 @@ class Call < ActiveRecord::Base
          def matches_all_jobs
        
            #    "AND (( icount(\'{#{fprint.map{|x| x.to_s}.join(",")}}\'::int[] & calls.fprint::int[]) / icount(\'{#{fprint.map{|x| x.to_s}.join(",")}}'::int[])::float ) * 100.0 ) > 10.0 " +
       -    self.find_by_sql([    
       +    self.find_by_sql([
              'SELECT calls.*,  ' +
              "  (( icount(?::int[] & calls.fprint::int[]) / icount(?::int[])::float ) * 100.0 ) AS matchscore " +
              'FROM calls ' +
       @@ -45,7 +45,7 @@ class Call < ActiveRecord::Base
              fprint_map,
              fprint_map,
              self.id
       -      ])    
       +      ])
          end
        
          def fprint_map
       @@ -78,7 +78,7 @@ class Call < ActiveRecord::Base
          end
        
          def media
       -    CallMedium.find_or_create_by_call_id_and_project_id(self[:id], self[:project_id])
       +    CallMedium.where(call_id: self.id, project_id: self.project_id).first_or_create
          end
        
          def media_fields
       @@ -86,7 +86,7 @@ class Call < ActiveRecord::Base
          end
        
          def linked_line
       -    Line.find_or_create_by_number_and_project_id(self[:number], self[:project_id])
       +    Line.where(number: self.number, project_id: self.project_id).first_or_create
          end
        
          def update_linked_line
 (DIR) diff --git a/app/models/line.rb b/app/models/line.rb
       @@ -3,7 +3,7 @@ class Line < ActiveRecord::Base
                belongs_to :project
        
                def set_attribute(name, value, ctype='text/plain')
       -                la = LineAttribute.find_or_create_by_line_id_and_project_id_and_name(self[:id], self[:project_id], name)
       +                la = LineAttribute.where(line_id: self.id, project_id: self.project_id, name: name).first_or_create
                        la.value = value
                        la.ctype = ctype
                        la.save