class TeamMembership < ActiveRecord::Base
  belongs_to :team
  belongs_to :user
  belongs_to :inviter, class_name: 'User', foreign_key: :inviter_id

  validates :user, uniqueness: { scope: :team }
  scope :confirmed, ->{ where(confirmed: true) }
  scope :for_team,-> (team_id) {where(team_id: team_id)}

  before_create do
    if confirmed.nil?
      self.confirmed = false
    end
    true
  end

  def confirm!
    self.confirmed = true
    save
  end

  def self.destroy_for_team(id)
    self.for_team(id).map(&:destroy)
  end

end

class TeamMembership < ActiveRecord::Base
  belongs_to :team
  belongs_to :user
  belongs_to :inviter, class_name: 'User', foreign_key: :inviter_id

  validates :user, uniqueness: { scope: :team }
  scope :confirmed, ->{ where(confirmed: true) }
  scope :for_team,-> (team_id) {where(team_id: team_id)}

  before_create do
    self.confirmed = false
    true
  end

  def confirm!
    self.confirmed = true
    save
  end

  def self.destroy_for_team(id)
    self.for_team(id).map(&:destroy)
  end

end

--- 
+++ 
@@ -8,7 +8,9 @@
   scope :for_team,-> (team_id) {where(team_id: team_id)}
 
   before_create do
-    self.confirmed = false
+    if confirmed.nil?
+      self.confirmed = false
+    end
     true
   end
 
Allow setting confirmed on team membership at creation time
