Revisions
-
jvans1 revised this gist
Mar 25, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,7 @@ def initialize(ticket) end def can_confirm? confirmation_errors.clear run_confirmations confirm_errors.any? end -
jvans1 revised this gist
Mar 25, 2014 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ class Ticket < ActiveRecord::Base class TicketConfirmer attr_reader :ticket, :confirmation_errors delegate :user, :grouper :to => :ticket def initialize(ticket) @ticket = ticket @@ -12,10 +12,6 @@ def can_confirm? confirm_errors.any? end private def run_confirmations confirmation_errors << [:user, "can't book a Grouper at this time"] if user.blacklisted? -
jvans1 revised this gist
Mar 25, 2014 . 1 changed file with 0 additions and 9 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,15 +29,6 @@ def run_confirmations belongs_to :user validate :can_confirm , :on => :confirmation private def can_confirm -
jvans1 revised this gist
Mar 25, 2014 . 1 changed file with 33 additions and 25 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,34 @@ class Ticket < ActiveRecord::Base class TicketConfirmer attr_reader :ticket delegate :user, :grouper :to => :ticket def initialize(ticket) @ticket = ticket @confirmation_errors = [] end def can_confirm? run_confirmations confirm_errors.any? end def confirmation_errors @confirmation_errors end private def run_confirmations confirmation_errors << [:user, "can't book a Grouper at this time"] if user.blacklisted? confirmation_errors << [:user, 'are already going to a Grouper on that day'] if user.has_existing_grouper?(grouper) confirmation_errors << [:grouper, 'has already occurred!'] if grouper.full? confirmation_errors << [:grouper, 'has already occurred!'] if grouper.past? confirmation_errors << [:user, 'have already confirmed this ticket'] if confirmed? end end belongs_to :grouper belongs_to :user validate :can_confirm , :on => :confirmation def confirm update confirmed: true if confirmable? @@ -21,23 +40,12 @@ def confirmable? private def can_confirm if (ticket_confirmer = TicketConfirmer.new(self)).can_confirm? ticket_confirmer.confirmation_errors.each do |object, error| errors.add(object, error) end end end end -
dhh created this gist
Mar 20, 2014 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ class Ticket < ActiveRecord::Base belongs_to :grouper belongs_to :user validate :user_cant_be_blacklisted, on: :confirmation validate :user_cant_double_book, on: :confirmation validate :grouper_cant_be_full, on: :confirmation validate :grouper_cant_have_occurred, on: :confirmation validate :ticket_cant_have_been_confirmed, on: :confirmation def confirm update confirmed: true if confirmable? end def confirmable? valid? :confirmation end private def user_cant_be_blacklisted errors.add :user, "can't book a Grouper at this time" if user.blacklisted? end def user_cant_double_book errors.add :user, 'are already going to a Grouper on that day' if user.has_existing_grouper?(grouper) end def grouper_cant_be_full errors.add :grouper, 'has already occurred!' if grouper.full? end def grouper_cant_have_occurred errors.add :grouper, 'has already occurred!' if grouper.past? end def ticket_cant_have_been_confirmed errors.add :user, 'have already confirmed this ticket' if confirmed? end end