flapjack 0.7.6 → 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +4 -0
 - data/lib/flapjack/data/contact.rb +5 -2
 - data/lib/flapjack/data/message.rb +9 -6
 - data/lib/flapjack/data/notification.rb +7 -6
 - data/lib/flapjack/data/notification_rule.rb +34 -22
 - data/lib/flapjack/gateways/api.rb +13 -4
 - data/lib/flapjack/version.rb +1 -1
 - data/spec/lib/flapjack/data/message_spec.rb +27 -3
 - data/spec/lib/flapjack/data/notification_spec.rb +53 -4
 - data/spec/lib/flapjack/gateways/api_spec.rb +53 -53
 - metadata +4 -4
 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -1,5 +1,9 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ## Flapjack Changelog
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            # 0.7.7 - 2012-05-22
         
     | 
| 
      
 4 
     | 
    
         
            +
            - Bug: relax notification rule validations somewhat gh-185 (@jessereynolds)
         
     | 
| 
      
 5 
     | 
    
         
            +
            - Chore: log notification rule validation errors from api gh-183 (@jessereynolds)
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
       3 
7 
     | 
    
         
             
            # 0.7.6 - 2013-05-20
         
     | 
| 
       4 
8 
     | 
    
         
             
            - Bug: Problems with email notifications (no name, text part missing fields) gh-158 (@ali-graham)
         
     | 
| 
       5 
9 
     | 
    
         | 
| 
         @@ -171,9 +171,12 @@ module Flapjack 
     | 
|
| 
       171 
171 
     | 
    
         
             
                    }.compact
         
     | 
| 
       172 
172 
     | 
    
         
             
                  end
         
     | 
| 
       173 
173 
     | 
    
         | 
| 
       174 
     | 
    
         
            -
                  def add_notification_rule(rule_data)
         
     | 
| 
      
 174 
     | 
    
         
            +
                  def add_notification_rule(rule_data, opts = {})
         
     | 
| 
      
 175 
     | 
    
         
            +
                    if logger = opts[:logger]
         
     | 
| 
      
 176 
     | 
    
         
            +
                      logger.debug("add_notification_rule: contact_id: #{self.id} (#{self.id.class})")
         
     | 
| 
      
 177 
     | 
    
         
            +
                    end
         
     | 
| 
       175 
178 
     | 
    
         
             
                    Flapjack::Data::NotificationRule.add(rule_data.merge(:contact_id => self.id),
         
     | 
| 
       176 
     | 
    
         
            -
                      :redis => @redis)
         
     | 
| 
      
 179 
     | 
    
         
            +
                      :redis => @redis, :logger => opts[:logger])
         
     | 
| 
       177 
180 
     | 
    
         
             
                  end
         
     | 
| 
       178 
181 
     | 
    
         | 
| 
       179 
182 
     | 
    
         
             
                  def delete_notification_rule(rule)
         
     | 
| 
         @@ -4,6 +4,9 @@ 
     | 
|
| 
       4 
4 
     | 
    
         
             
            # from which individual 'Message' objects are created, one for each
         
     | 
| 
       5 
5 
     | 
    
         
             
            # contact+media recipient.
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
      
 7 
     | 
    
         
            +
            require 'flapjack/data/contact'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'flapjack/data/notification'
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
       7 
10 
     | 
    
         
             
            module Flapjack
         
     | 
| 
       8 
11 
     | 
    
         
             
              module Data
         
     | 
| 
       9 
12 
     | 
    
         
             
                class Message
         
     | 
| 
         @@ -17,9 +20,9 @@ module Flapjack 
     | 
|
| 
       17 
20 
     | 
    
         
             
                  def id
         
     | 
| 
       18 
21 
     | 
    
         
             
                    return @id if @id
         
     | 
| 
       19 
22 
     | 
    
         
             
                    t = Time.now
         
     | 
| 
       20 
     | 
    
         
            -
                    # FIXME: consider  
     | 
| 
      
 23 
     | 
    
         
            +
                    # FIXME: consider using a UUID here
         
     | 
| 
       21 
24 
     | 
    
         
             
                    # this is planned to be used as part of alert history keys
         
     | 
| 
       22 
     | 
    
         
            -
                    @id = self.object_id.to_i 
     | 
| 
      
 25 
     | 
    
         
            +
                    @id = "#{self.object_id.to_i}-#{t.to_i}.#{t.tv_usec}"
         
     | 
| 
       23 
26 
     | 
    
         
             
                  end
         
     | 
| 
       24 
27 
     | 
    
         | 
| 
       25 
28 
     | 
    
         
             
                  def contents
         
     | 
| 
         @@ -27,12 +30,12 @@ module Flapjack 
     | 
|
| 
       27 
30 
     | 
    
         
             
                         'address'            => address,
         
     | 
| 
       28 
31 
     | 
    
         
             
                         'id'                 => id}
         
     | 
| 
       29 
32 
     | 
    
         
             
                    if contact
         
     | 
| 
       30 
     | 
    
         
            -
                      c. 
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 33 
     | 
    
         
            +
                      c.update('contact_id'         => contact.id,
         
     | 
| 
      
 34 
     | 
    
         
            +
                               'contact_first_name' => contact.first_name,
         
     | 
| 
      
 35 
     | 
    
         
            +
                               'contact_last_name'  => contact.last_name)
         
     | 
| 
       33 
36 
     | 
    
         
             
                    end
         
     | 
| 
       34 
37 
     | 
    
         
             
                    c['duration'] = duration if duration
         
     | 
| 
       35 
     | 
    
         
            -
                    c. 
     | 
| 
      
 38 
     | 
    
         
            +
                    c.update(notification.contents) if notification
         
     | 
| 
       36 
39 
     | 
    
         
             
                  end
         
     | 
| 
       37 
40 
     | 
    
         | 
| 
       38 
41 
     | 
    
         
             
                private
         
     | 
| 
         @@ -1,5 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #!/usr/bin/env ruby
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            require 'flapjack/data/contact'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'flapjack/data/event'
         
     | 
| 
       3 
5 
     | 
    
         
             
            require 'flapjack/data/message'
         
     | 
| 
       4 
6 
     | 
    
         | 
| 
       5 
7 
     | 
    
         
             
            module Flapjack
         
     | 
| 
         @@ -19,15 +21,14 @@ module Flapjack 
     | 
|
| 
       19 
21 
     | 
    
         
             
                    return [] if contacts.nil?
         
     | 
| 
       20 
22 
     | 
    
         
             
                    @messages ||= contacts.collect {|contact|
         
     | 
| 
       21 
23 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                       # will simplify the executive logic
         
     | 
| 
      
 24 
     | 
    
         
            +
                      # TODO move the message filtering logic from executive into this
         
     | 
| 
      
 25 
     | 
    
         
            +
                      # class and apply here, don't generate message if it won't be sent
         
     | 
| 
       25 
26 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
                      contact.media. 
     | 
| 
      
 27 
     | 
    
         
            +
                      contact.media.each_pair.inject([]) { |ret, (k, v)|
         
     | 
| 
       27 
28 
     | 
    
         
             
                        m = Flapjack::Data::Message.for_contact(:contact => contact)
         
     | 
| 
       28 
29 
     | 
    
         
             
                        m.notification = self
         
     | 
| 
       29 
     | 
    
         
            -
                        m.medium  =  
     | 
| 
       30 
     | 
    
         
            -
                        m.address =  
     | 
| 
      
 30 
     | 
    
         
            +
                        m.medium  = k
         
     | 
| 
      
 31 
     | 
    
         
            +
                        m.address = v
         
     | 
| 
       31 
32 
     | 
    
         
             
                        ret << m
         
     | 
| 
       32 
33 
     | 
    
         
             
                        ret
         
     | 
| 
       33 
34 
     | 
    
         
             
                      }
         
     | 
| 
         @@ -37,13 +37,13 @@ module Flapjack 
     | 
|
| 
       37 
37 
     | 
    
         
             
                    raise "Redis connection not set" unless redis = options[:redis]
         
     | 
| 
       38 
38 
     | 
    
         | 
| 
       39 
39 
     | 
    
         
             
                    rule_id = SecureRandom.uuid
         
     | 
| 
       40 
     | 
    
         
            -
                    self.add_or_update(rule_data.merge(:id => rule_id),  
     | 
| 
      
 40 
     | 
    
         
            +
                    self.add_or_update(rule_data.merge(:id => rule_id), options)
         
     | 
| 
       41 
41 
     | 
    
         
             
                    self.find_by_id(rule_id, :redis => redis)
         
     | 
| 
       42 
42 
     | 
    
         
             
                  end
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
                  def update(rule_data)
         
     | 
| 
       45 
     | 
    
         
            -
                    return false unless self.class.add_or_update(rule_data.merge(:id => @id),
         
     | 
| 
       46 
     | 
    
         
            -
                      :redis => @redis)
         
     | 
| 
      
 44 
     | 
    
         
            +
                  def update(rule_data, opts = {})
         
     | 
| 
      
 45 
     | 
    
         
            +
                    return false unless self.class.add_or_update({:contact_id => @contact_id}.merge(rule_data.merge(:id => @id)),
         
     | 
| 
      
 46 
     | 
    
         
            +
                      :redis => @redis, :logger => opts[:logger])
         
     | 
| 
       47 
47 
     | 
    
         
             
                    refresh
         
     | 
| 
       48 
48 
     | 
    
         
             
                    true
         
     | 
| 
       49 
49 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -108,6 +108,11 @@ module Flapjack 
     | 
|
| 
       108 
108 
     | 
    
         
             
                  def self.add_or_update(rule_data, options = {})
         
     | 
| 
       109 
109 
     | 
    
         
             
                    redis = options[:redis]
         
     | 
| 
       110 
110 
     | 
    
         
             
                    raise "a redis connection must be supplied" unless redis
         
     | 
| 
      
 111 
     | 
    
         
            +
                    logger = options[:logger]
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                    # make some assumptions about the incoming data
         
     | 
| 
      
 114 
     | 
    
         
            +
                    rule_data[:warning_blackhole]  = rule_data[:warning_blackhole] || false
         
     | 
| 
      
 115 
     | 
    
         
            +
                    rule_data[:critical_blackhole] = rule_data[:critical_blackhole] || false
         
     | 
| 
       111 
116 
     | 
    
         | 
| 
       112 
117 
     | 
    
         
             
                    return unless self.validate_data(rule_data, options)
         
     | 
| 
       113 
118 
     | 
    
         | 
| 
         @@ -123,6 +128,7 @@ module Flapjack 
     | 
|
| 
       123 
128 
     | 
    
         
             
                      :warning_blackhole  => rule_data[:warning_blackhole],
         
     | 
| 
       124 
129 
     | 
    
         
             
                      :critical_blackhole => rule_data[:critical_blackhole],
         
     | 
| 
       125 
130 
     | 
    
         
             
                    }
         
     | 
| 
      
 131 
     | 
    
         
            +
                    logger.debug("NotificationRule#add_or_update json_rule_data: #{json_rule_data.inspect}") if logger
         
     | 
| 
       126 
132 
     | 
    
         | 
| 
       127 
133 
     | 
    
         
             
                    redis.sadd("contact_notification_rules:#{json_rule_data[:contact_id]}",
         
     | 
| 
       128 
134 
     | 
    
         
             
                               json_rule_data[:id])
         
     | 
| 
         @@ -200,14 +206,16 @@ module Flapjack 
     | 
|
| 
       200 
206 
     | 
    
         
             
                    validations = {proc { d.has_key?(:id) } =>
         
     | 
| 
       201 
207 
     | 
    
         
             
                                   "id not set",
         
     | 
| 
       202 
208 
     | 
    
         | 
| 
       203 
     | 
    
         
            -
                                   proc { d.has_key?(:entities)  
     | 
| 
       204 
     | 
    
         
            -
                                          d[:entities]. 
     | 
| 
       205 
     | 
    
         
            -
             
     | 
| 
      
 209 
     | 
    
         
            +
                                   proc { !d.has_key?(:entities) ||
         
     | 
| 
      
 210 
     | 
    
         
            +
                                          ( d[:entities].nil? ||
         
     | 
| 
      
 211 
     | 
    
         
            +
                                            d[:entities].is_a?(Array) &&
         
     | 
| 
      
 212 
     | 
    
         
            +
                                            d[:entities].all? {|e| e.is_a?(String)} ) } =>
         
     | 
| 
       206 
213 
     | 
    
         
             
                                   "entities must be a list of strings",
         
     | 
| 
       207 
214 
     | 
    
         | 
| 
       208 
     | 
    
         
            -
                                   proc { d.has_key?(:entity_tags)  
     | 
| 
       209 
     | 
    
         
            -
                                          d[:entity_tags]. 
     | 
| 
       210 
     | 
    
         
            -
             
     | 
| 
      
 215 
     | 
    
         
            +
                                   proc { !d.has_key?(:entity_tags) ||
         
     | 
| 
      
 216 
     | 
    
         
            +
                                          ( d[:entity_tags].nil? ||
         
     | 
| 
      
 217 
     | 
    
         
            +
                                            d[:entity_tags].is_a?(Array) &&
         
     | 
| 
      
 218 
     | 
    
         
            +
                                            d[:entity_tags].all? {|et| et.is_a?(String)} ) } =>
         
     | 
| 
       211 
219 
     | 
    
         
             
                                   "entity_tags must be a list of strings",
         
     | 
| 
       212 
220 
     | 
    
         | 
| 
       213 
221 
     | 
    
         
             
                                   proc { (d.has_key?(:entities) &&
         
     | 
| 
         @@ -218,29 +226,32 @@ module Flapjack 
     | 
|
| 
       218 
226 
     | 
    
         
             
                                           (d[:entity_tags].size > 0)) } =>
         
     | 
| 
       219 
227 
     | 
    
         
             
                                   "entities or entity tags must have at least one value",
         
     | 
| 
       220 
228 
     | 
    
         | 
| 
       221 
     | 
    
         
            -
                                   proc { d.has_key?(:time_restrictions)  
     | 
| 
       222 
     | 
    
         
            -
                                          d[:time_restrictions]. 
     | 
| 
       223 
     | 
    
         
            -
                                             
     | 
| 
       224 
     | 
    
         
            -
             
     | 
| 
      
 229 
     | 
    
         
            +
                                   proc { !d.has_key?(:time_restrictions) ||
         
     | 
| 
      
 230 
     | 
    
         
            +
                                          ( d[:time_restrictions].nil? ||
         
     | 
| 
      
 231 
     | 
    
         
            +
                                            d[:time_restrictions].all? {|tr|
         
     | 
| 
      
 232 
     | 
    
         
            +
                                              !!prepare_time_restriction(symbolize(tr))
         
     | 
| 
      
 233 
     | 
    
         
            +
                                            } )
         
     | 
| 
       225 
234 
     | 
    
         
             
                                        } =>
         
     | 
| 
       226 
235 
     | 
    
         
             
                                   "time restrictions are invalid",
         
     | 
| 
       227 
236 
     | 
    
         | 
| 
       228 
237 
     | 
    
         
             
                                   # TODO should the media types be checked against a whitelist?
         
     | 
| 
       229 
     | 
    
         
            -
                                   proc { d.has_key?(:warning_media)  
     | 
| 
       230 
     | 
    
         
            -
                                          d[:warning_media]. 
     | 
| 
       231 
     | 
    
         
            -
             
     | 
| 
      
 238 
     | 
    
         
            +
                                   proc { !d.has_key?(:warning_media) ||
         
     | 
| 
      
 239 
     | 
    
         
            +
                                          ( d[:warning_media].nil? ||
         
     | 
| 
      
 240 
     | 
    
         
            +
                                            d[:warning_media].is_a?(Array) &&
         
     | 
| 
      
 241 
     | 
    
         
            +
                                            d[:warning_media].all? {|et| et.is_a?(String)} ) } =>
         
     | 
| 
       232 
242 
     | 
    
         
             
                                   "warning_media must be a list of strings",
         
     | 
| 
       233 
243 
     | 
    
         | 
| 
       234 
     | 
    
         
            -
                                   proc { d.has_key?(:critical_media)  
     | 
| 
       235 
     | 
    
         
            -
                                          d[:critical_media]. 
     | 
| 
       236 
     | 
    
         
            -
             
     | 
| 
      
 244 
     | 
    
         
            +
                                   proc { !d.has_key?(:critical_media) ||
         
     | 
| 
      
 245 
     | 
    
         
            +
                                          ( d[:critical_media].nil? ||
         
     | 
| 
      
 246 
     | 
    
         
            +
                                            d[:critical_media].is_a?(Array) &&
         
     | 
| 
      
 247 
     | 
    
         
            +
                                            d[:critical_media].all? {|et| et.is_a?(String)} ) } =>
         
     | 
| 
       237 
248 
     | 
    
         
             
                                   "critical_media must be a list of strings",
         
     | 
| 
       238 
249 
     | 
    
         | 
| 
       239 
     | 
    
         
            -
                                   proc { d.has_key?(:warning_blackhole)  
     | 
| 
      
 250 
     | 
    
         
            +
                                   proc { !d.has_key?(:warning_blackhole) ||
         
     | 
| 
       240 
251 
     | 
    
         
             
                                          [TrueClass, FalseClass].include?(d[:warning_blackhole].class) } =>
         
     | 
| 
       241 
252 
     | 
    
         
             
                                   "warning_blackhole must be true or false",
         
     | 
| 
       242 
253 
     | 
    
         | 
| 
       243 
     | 
    
         
            -
                                   proc { d.has_key?(:critical_blackhole)  
     | 
| 
      
 254 
     | 
    
         
            +
                                   proc { !d.has_key?(:critical_blackhole) ||
         
     | 
| 
       244 
255 
     | 
    
         
             
                                          [TrueClass, FalseClass].include?(d[:critical_blackhole].class) } =>
         
     | 
| 
       245 
256 
     | 
    
         
             
                                   "critical_blackhole must be true or false",
         
     | 
| 
       246 
257 
     | 
    
         
             
                                  }
         
     | 
| 
         @@ -255,6 +266,7 @@ module Flapjack 
     | 
|
| 
       255 
266 
     | 
    
         
             
                    if logger = options[:logger]
         
     | 
| 
       256 
267 
     | 
    
         
             
                      error_str = errors.join(", ")
         
     | 
| 
       257 
268 
     | 
    
         
             
                      logger.info "validation error: #{error_str}"
         
     | 
| 
      
 269 
     | 
    
         
            +
                      logger.debug "rule failing validations: #{d.inspect}"
         
     | 
| 
       258 
270 
     | 
    
         
             
                    end
         
     | 
| 
       259 
271 
     | 
    
         
             
                    false
         
     | 
| 
       260 
272 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -339,13 +339,16 @@ module Flapjack 
     | 
|
| 
       339 
339 
     | 
    
         
             
                      return error(403, "post cannot be used for update, do a put instead")
         
     | 
| 
       340 
340 
     | 
    
         
             
                    end
         
     | 
| 
       341 
341 
     | 
    
         | 
| 
      
 342 
     | 
    
         
            +
                    logger.debug("post /notification_rules data: ")
         
     | 
| 
      
 343 
     | 
    
         
            +
                    logger.debug(params.inspect)
         
     | 
| 
      
 344 
     | 
    
         
            +
             
     | 
| 
       342 
345 
     | 
    
         
             
                    find_contact(params[:contact_id]) do |contact|
         
     | 
| 
       343 
346 
     | 
    
         | 
| 
       344 
347 
     | 
    
         
             
                      rule_data = hashify(:entities, :entity_tags,
         
     | 
| 
       345 
348 
     | 
    
         
             
                        :warning_media, :critical_media, :time_restrictions,
         
     | 
| 
       346 
349 
     | 
    
         
             
                        :warning_blackhole, :critical_blackhole) {|k| [k, params[k]]}
         
     | 
| 
       347 
350 
     | 
    
         | 
| 
       348 
     | 
    
         
            -
                      unless rule = contact.add_notification_rule(rule_data)
         
     | 
| 
      
 351 
     | 
    
         
            +
                      unless rule = contact.add_notification_rule(rule_data, :logger => logger)
         
     | 
| 
       349 
352 
     | 
    
         
             
                        return error(403, "invalid notification rule data")
         
     | 
| 
       350 
353 
     | 
    
         
             
                      end
         
     | 
| 
       351 
354 
     | 
    
         
             
                      rule.to_json
         
     | 
| 
         @@ -356,6 +359,9 @@ module Flapjack 
     | 
|
| 
       356 
359 
     | 
    
         
             
                  # https://github.com/flpjck/flapjack/wiki/API#wiki-put_notification_rules_id
         
     | 
| 
       357 
360 
     | 
    
         
             
                  put('/notification_rules/:id') do
         
     | 
| 
       358 
361 
     | 
    
         
             
                    content_type :json
         
     | 
| 
      
 362 
     | 
    
         
            +
                    logger.debug("put /notification_rules/#{params[:id]} data: ")
         
     | 
| 
      
 363 
     | 
    
         
            +
                    logger.debug(params.inspect)
         
     | 
| 
      
 364 
     | 
    
         
            +
             
     | 
| 
       359 
365 
     | 
    
         
             
                    find_rule(params[:id]) do |rule|
         
     | 
| 
       360 
366 
     | 
    
         
             
                      find_contact(rule.contact_id) do |contact|
         
     | 
| 
       361 
367 
     | 
    
         | 
| 
         @@ -363,7 +369,7 @@ module Flapjack 
     | 
|
| 
       363 
369 
     | 
    
         
             
                          :warning_media, :critical_media, :time_restrictions,
         
     | 
| 
       364 
370 
     | 
    
         
             
                          :warning_blackhole, :critical_blackhole) {|k| [k, params[k]]}
         
     | 
| 
       365 
371 
     | 
    
         | 
| 
       366 
     | 
    
         
            -
                        unless rule.update(rule_data)
         
     | 
| 
      
 372 
     | 
    
         
            +
                        unless rule.update(rule_data, :logger => logger)
         
     | 
| 
       367 
373 
     | 
    
         
             
                          return error(403, "invalid notification rule data")
         
     | 
| 
       368 
374 
     | 
    
         
             
                        end
         
     | 
| 
       369 
375 
     | 
    
         
             
                        rule.to_json
         
     | 
| 
         @@ -374,7 +380,9 @@ module Flapjack 
     | 
|
| 
       374 
380 
     | 
    
         
             
                  # Deletes a notification rule
         
     | 
| 
       375 
381 
     | 
    
         
             
                  # https://github.com/flpjck/flapjack/wiki/API#wiki-put_notification_rules_id
         
     | 
| 
       376 
382 
     | 
    
         
             
                  delete('/notification_rules/:id') do
         
     | 
| 
      
 383 
     | 
    
         
            +
                    logger.debug("delete /notification_rules/#{params[:id]}")
         
     | 
| 
       377 
384 
     | 
    
         
             
                    find_rule(params[:id]) do |rule|
         
     | 
| 
      
 385 
     | 
    
         
            +
                      logger.debug("rule to delete: #{rule.inspect}, contact_id: #{rule.contact_id}")
         
     | 
| 
       378 
386 
     | 
    
         
             
                      find_contact(rule.contact_id) do |contact|
         
     | 
| 
       379 
387 
     | 
    
         
             
                        contact.delete_notification_rule(rule)
         
     | 
| 
       380 
388 
     | 
    
         
             
                        status 204
         
     | 
| 
         @@ -560,6 +568,7 @@ module Flapjack 
     | 
|
| 
       560 
568 
     | 
    
         
             
                  end
         
     | 
| 
       561 
569 
     | 
    
         | 
| 
       562 
570 
     | 
    
         
             
                  not_found do
         
     | 
| 
      
 571 
     | 
    
         
            +
                    logger.debug("in not_found :-(")
         
     | 
| 
       563 
572 
     | 
    
         
             
                    error(404, "not routable")
         
     | 
| 
       564 
573 
     | 
    
         
             
                  end
         
     | 
| 
       565 
574 
     | 
    
         | 
| 
         @@ -587,13 +596,13 @@ module Flapjack 
     | 
|
| 
       587 
596 
     | 
    
         | 
| 
       588 
597 
     | 
    
         
             
                  # following a callback-heavy pattern -- feels like nodejs :)
         
     | 
| 
       589 
598 
     | 
    
         
             
                  def find_contact(contact_id, &block)
         
     | 
| 
       590 
     | 
    
         
            -
                    contact = Flapjack::Data::Contact.find_by_id(contact_id, :redis => redis)
         
     | 
| 
      
 599 
     | 
    
         
            +
                    contact = Flapjack::Data::Contact.find_by_id(contact_id.to_s, :redis => redis, :logger => logger)
         
     | 
| 
       591 
600 
     | 
    
         
             
                    return(yield(contact)) if contact
         
     | 
| 
       592 
601 
     | 
    
         
             
                    error(404, "could not find contact with id '#{contact_id}'")
         
     | 
| 
       593 
602 
     | 
    
         
             
                  end
         
     | 
| 
       594 
603 
     | 
    
         | 
| 
       595 
604 
     | 
    
         
             
                  def find_rule(rule_id, &block)
         
     | 
| 
       596 
     | 
    
         
            -
                    rule = Flapjack::Data::NotificationRule.find_by_id(rule_id, :redis => redis)
         
     | 
| 
      
 605 
     | 
    
         
            +
                    rule = Flapjack::Data::NotificationRule.find_by_id(rule_id, :redis => redis, :logger => logger)
         
     | 
| 
       597 
606 
     | 
    
         
             
                    return(yield(rule)) if rule
         
     | 
| 
       598 
607 
     | 
    
         
             
                    error(404, "could not find notification rule with id '#{rule_id}'")
         
     | 
| 
       599 
608 
     | 
    
         
             
                  end
         
     | 
    
        data/lib/flapjack/version.rb
    CHANGED
    
    
| 
         @@ -3,10 +3,34 @@ require 'flapjack/data/message' 
     | 
|
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            describe Flapjack::Data::Message do
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
               
     | 
| 
      
 6 
     | 
    
         
            +
              let(:contact) { mock(Flapjack::Data::Contact) }
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
              it "assigns itself an ID"
         
     | 
| 
      
 8 
     | 
    
         
            +
              it "assigns itself an ID" do
         
     | 
| 
      
 9 
     | 
    
         
            +
                message = Flapjack::Data::Message.for_contact(:contact => contact)
         
     | 
| 
      
 10 
     | 
    
         
            +
                mid = message.id
         
     | 
| 
      
 11 
     | 
    
         
            +
                mid.should_not be_nil
         
     | 
| 
      
 12 
     | 
    
         
            +
                mid.should be_a(String)
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
       9 
14 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
              it "returns its contained data"
         
     | 
| 
      
 15 
     | 
    
         
            +
              it "returns its contained data" do
         
     | 
| 
      
 16 
     | 
    
         
            +
                notification = mock(Flapjack::Data::Notification)
         
     | 
| 
      
 17 
     | 
    
         
            +
                notification.should_receive(:contents).and_return('notification' => 'contents')
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                message = Flapjack::Data::Message.for_contact(:contact => contact)
         
     | 
| 
      
 20 
     | 
    
         
            +
                message.notification = notification
         
     | 
| 
      
 21 
     | 
    
         
            +
                message.medium = 'email'
         
     | 
| 
      
 22 
     | 
    
         
            +
                message.address = 'jja@example.com'
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                contact.should_receive(:id).and_return('23')
         
     | 
| 
      
 25 
     | 
    
         
            +
                contact.should_receive(:first_name).and_return('James')
         
     | 
| 
      
 26 
     | 
    
         
            +
                contact.should_receive(:last_name).and_return('Jameson')
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                message.contents.should include('notification' => 'contents',
         
     | 
| 
      
 29 
     | 
    
         
            +
                                                'contact_id' => '23',
         
     | 
| 
      
 30 
     | 
    
         
            +
                                                'contact_first_name' => 'James',
         
     | 
| 
      
 31 
     | 
    
         
            +
                                                'contact_last_name' => 'Jameson',
         
     | 
| 
      
 32 
     | 
    
         
            +
                                                'media' => 'email',
         
     | 
| 
      
 33 
     | 
    
         
            +
                                                'address' => 'jja@example.com')
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
       11 
35 
     | 
    
         | 
| 
       12 
36 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,12 +1,61 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'flapjack/data/notification'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            describe Flapjack::Data::Notification do
         
     | 
| 
      
 4 
     | 
    
         
            +
            describe Flapjack::Data::Notification, :redis => true do
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
               
     | 
| 
      
 6 
     | 
    
         
            +
              let(:event) { mock(Flapjack::Data::Event) }
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
               
     | 
| 
      
 8 
     | 
    
         
            +
              let(:contact) { mock(Flapjack::Data::Contact) }
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
              it " 
     | 
| 
      
 10 
     | 
    
         
            +
              it "generates a notification for an event" do
         
     | 
| 
      
 11 
     | 
    
         
            +
                notification = Flapjack::Data::Notification.for_event(event, :type => 'problem',
         
     | 
| 
      
 12 
     | 
    
         
            +
                  :max_notified_severity => nil)
         
     | 
| 
      
 13 
     | 
    
         
            +
                notification.should_not be_nil
         
     | 
| 
      
 14 
     | 
    
         
            +
                notification.event.should == event
         
     | 
| 
      
 15 
     | 
    
         
            +
                notification.type.should == 'problem'
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              it "generates messages for contacts" do
         
     | 
| 
      
 19 
     | 
    
         
            +
                notification = Flapjack::Data::Notification.for_event(event, :type => 'problem',
         
     | 
| 
      
 20 
     | 
    
         
            +
                  :max_notified_severity => nil)
         
     | 
| 
      
 21 
     | 
    
         
            +
                contact.should_receive(:media).and_return('email' => 'example@example.com',
         
     | 
| 
      
 22 
     | 
    
         
            +
                                                          'sms'   => '0123456789')
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                messages = notification.messages(:contacts => [contact])
         
     | 
| 
      
 25 
     | 
    
         
            +
                messages.should_not be_nil
         
     | 
| 
      
 26 
     | 
    
         
            +
                messages.should have(2).items
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                messages.first.notification.should == notification
         
     | 
| 
      
 29 
     | 
    
         
            +
                messages.first.contact.should == contact
         
     | 
| 
      
 30 
     | 
    
         
            +
                messages.first.medium.should == 'email'
         
     | 
| 
      
 31 
     | 
    
         
            +
                messages.first.address.should == 'example@example.com'
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                messages.last.notification.should == notification
         
     | 
| 
      
 34 
     | 
    
         
            +
                messages.last.contact.should == contact
         
     | 
| 
      
 35 
     | 
    
         
            +
                messages.last.medium.should  == 'sms'
         
     | 
| 
      
 36 
     | 
    
         
            +
                messages.last.address.should == '0123456789'
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
              it "returns its contained data" do
         
     | 
| 
      
 40 
     | 
    
         
            +
                notification = Flapjack::Data::Notification.for_event(event, :type => 'problem',
         
     | 
| 
      
 41 
     | 
    
         
            +
                  :max_notified_severity => nil)
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                t = Time.now.to_i
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                event.should_receive(:id).and_return('example.com:ping')
         
     | 
| 
      
 46 
     | 
    
         
            +
                event.should_receive(:state).and_return('ok')
         
     | 
| 
      
 47 
     | 
    
         
            +
                event.should_receive(:summary).and_return('Shiny & happy')
         
     | 
| 
      
 48 
     | 
    
         
            +
                event.should_receive(:time).and_return(t)
         
     | 
| 
      
 49 
     | 
    
         
            +
                event.should_receive(:duration).and_return(nil)
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                notification.contents.should == {'event_id'              => 'example.com:ping',
         
     | 
| 
      
 52 
     | 
    
         
            +
                                                 'state'                 => 'ok',
         
     | 
| 
      
 53 
     | 
    
         
            +
                                                 'summary'               => 'Shiny & happy',
         
     | 
| 
      
 54 
     | 
    
         
            +
                                                 'time'                  => t,
         
     | 
| 
      
 55 
     | 
    
         
            +
                                                 'duration'              => nil,
         
     | 
| 
      
 56 
     | 
    
         
            +
                                                 'notification_type'     => 'problem',
         
     | 
| 
      
 57 
     | 
    
         
            +
                                                 'max_notified_severity' => nil}
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
       11 
60 
     | 
    
         | 
| 
       12 
61 
     | 
    
         
             
            end
         
     | 
| 
         @@ -536,7 +536,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       536 
536 
     | 
    
         
             
              it "returns the core information of a specified contact" do
         
     | 
| 
       537 
537 
     | 
    
         
             
                contact.should_receive(:to_json).and_return(contact_core.to_json)
         
     | 
| 
       538 
538 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       539 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 539 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       540 
540 
     | 
    
         | 
| 
       541 
541 
     | 
    
         
             
                get "/contacts/#{contact.id}"
         
     | 
| 
       542 
542 
     | 
    
         
             
                last_response.should be_ok
         
     | 
| 
         @@ -545,7 +545,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       545 
545 
     | 
    
         | 
| 
       546 
546 
     | 
    
         
             
              it "does not return information for a contact that does not exist" do
         
     | 
| 
       547 
547 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       548 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 548 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       549 
549 
     | 
    
         | 
| 
       550 
550 
     | 
    
         
             
                get "/contacts/#{contact.id}"
         
     | 
| 
       551 
551 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -559,7 +559,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       559 
559 
     | 
    
         | 
| 
       560 
560 
     | 
    
         
             
                contact.should_receive(:notification_rules).and_return(notification_rules)
         
     | 
| 
       561 
561 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       562 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 562 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       563 
563 
     | 
    
         | 
| 
       564 
564 
     | 
    
         
             
                get "/contacts/#{contact.id}/notification_rules"
         
     | 
| 
       565 
565 
     | 
    
         
             
                last_response.should be_ok
         
     | 
| 
         @@ -568,7 +568,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       568 
568 
     | 
    
         | 
| 
       569 
569 
     | 
    
         
             
              it "does not list notification rules for a contact that does not exist" do
         
     | 
| 
       570 
570 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       571 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 571 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       572 
572 
     | 
    
         | 
| 
       573 
573 
     | 
    
         
             
                get "/contacts/#{contact.id}/notification_rules"
         
     | 
| 
       574 
574 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -577,7 +577,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       577 
577 
     | 
    
         
             
              it "returns a specified notification rule" do
         
     | 
| 
       578 
578 
     | 
    
         
             
                notification_rule.should_receive(:to_json).and_return('"rule_1"')
         
     | 
| 
       579 
579 
     | 
    
         
             
                Flapjack::Data::NotificationRule.should_receive(:find_by_id).
         
     | 
| 
       580 
     | 
    
         
            -
                  with(notification_rule.id, :redis => redis).and_return(notification_rule)
         
     | 
| 
      
 580 
     | 
    
         
            +
                  with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
         
     | 
| 
       581 
581 
     | 
    
         | 
| 
       582 
582 
     | 
    
         
             
                get "/notification_rules/#{notification_rule.id}"
         
     | 
| 
       583 
583 
     | 
    
         
             
                last_response.should be_ok
         
     | 
| 
         @@ -586,7 +586,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       586 
586 
     | 
    
         | 
| 
       587 
587 
     | 
    
         
             
              it "does not return a notification rule that does not exist" do
         
     | 
| 
       588 
588 
     | 
    
         
             
                Flapjack::Data::NotificationRule.should_receive(:find_by_id).
         
     | 
| 
       589 
     | 
    
         
            -
                  with(notification_rule.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 589 
     | 
    
         
            +
                  with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       590 
590 
     | 
    
         | 
| 
       591 
591 
     | 
    
         
             
                get "/notification_rules/#{notification_rule.id}"
         
     | 
| 
       592 
592 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -595,7 +595,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       595 
595 
     | 
    
         
             
              # POST /notification_rules
         
     | 
| 
       596 
596 
     | 
    
         
             
              it "creates a new notification rule" do
         
     | 
| 
       597 
597 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       598 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 598 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       599 
599 
     | 
    
         
             
                notification_rule.should_receive(:to_json).and_return('"rule_1"')
         
     | 
| 
       600 
600 
     | 
    
         | 
| 
       601 
601 
     | 
    
         
             
                # symbolize the keys
         
     | 
| 
         @@ -605,7 +605,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       605 
605 
     | 
    
         
             
                notification_rule_data_sym.delete(:contact_id)
         
     | 
| 
       606 
606 
     | 
    
         | 
| 
       607 
607 
     | 
    
         
             
                contact.should_receive(:add_notification_rule).
         
     | 
| 
       608 
     | 
    
         
            -
                  with(notification_rule_data_sym).and_return(notification_rule)
         
     | 
| 
      
 608 
     | 
    
         
            +
                  with(notification_rule_data_sym, :logger => @logger).and_return(notification_rule)
         
     | 
| 
       609 
609 
     | 
    
         | 
| 
       610 
610 
     | 
    
         
             
                post "/notification_rules", notification_rule_data.to_json,
         
     | 
| 
       611 
611 
     | 
    
         
             
                  {'CONTENT_TYPE' => 'application/json'}
         
     | 
| 
         @@ -615,7 +615,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       615 
615 
     | 
    
         | 
| 
       616 
616 
     | 
    
         
             
              it "does not create a notification_rule for a contact that's not present" do
         
     | 
| 
       617 
617 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       618 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 618 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       619 
619 
     | 
    
         | 
| 
       620 
620 
     | 
    
         
             
                post "/notification_rules", notification_rule_data.to_json,
         
     | 
| 
       621 
621 
     | 
    
         
             
                  {'CONTENT_TYPE' => 'application/json'}
         
     | 
| 
         @@ -633,10 +633,10 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       633 
633 
     | 
    
         
             
              # PUT /notification_rules/RULE_ID
         
     | 
| 
       634 
634 
     | 
    
         
             
              it "updates a notification rule" do
         
     | 
| 
       635 
635 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       636 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 636 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       637 
637 
     | 
    
         
             
                notification_rule.should_receive(:to_json).and_return('"rule_1"')
         
     | 
| 
       638 
638 
     | 
    
         
             
                Flapjack::Data::NotificationRule.should_receive(:find_by_id).
         
     | 
| 
       639 
     | 
    
         
            -
                  with(notification_rule.id, :redis => redis).and_return(notification_rule)
         
     | 
| 
      
 639 
     | 
    
         
            +
                  with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
         
     | 
| 
       640 
640 
     | 
    
         | 
| 
       641 
641 
     | 
    
         
             
                # symbolize the keys
         
     | 
| 
       642 
642 
     | 
    
         
             
                notification_rule_data_sym = notification_rule_data.inject({}){|memo,(k,v)|
         
     | 
| 
         @@ -644,7 +644,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       644 
644 
     | 
    
         
             
                }
         
     | 
| 
       645 
645 
     | 
    
         
             
                notification_rule_data_sym.delete(:contact_id)
         
     | 
| 
       646 
646 
     | 
    
         | 
| 
       647 
     | 
    
         
            -
                notification_rule.should_receive(:update).with(notification_rule_data_sym).and_return(true)
         
     | 
| 
      
 647 
     | 
    
         
            +
                notification_rule.should_receive(:update).with(notification_rule_data_sym, :logger => @logger).and_return(true)
         
     | 
| 
       648 
648 
     | 
    
         | 
| 
       649 
649 
     | 
    
         
             
                put "/notification_rules/#{notification_rule.id}", notification_rule_data.to_json,
         
     | 
| 
       650 
650 
     | 
    
         
             
                  {'CONTENT_TYPE' => 'application/json'}
         
     | 
| 
         @@ -654,7 +654,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       654 
654 
     | 
    
         | 
| 
       655 
655 
     | 
    
         
             
              it "does not update a notification rule that's not present" do
         
     | 
| 
       656 
656 
     | 
    
         
             
                Flapjack::Data::NotificationRule.should_receive(:find_by_id).
         
     | 
| 
       657 
     | 
    
         
            -
                  with(notification_rule.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 657 
     | 
    
         
            +
                  with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       658 
658 
     | 
    
         | 
| 
       659 
659 
     | 
    
         
             
                put "/notification_rules/#{notification_rule.id}", notification_rule_data
         
     | 
| 
       660 
660 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -662,9 +662,9 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       662 
662 
     | 
    
         | 
| 
       663 
663 
     | 
    
         
             
              it "does not update a notification_rule for a contact that's not present" do
         
     | 
| 
       664 
664 
     | 
    
         
             
                Flapjack::Data::NotificationRule.should_receive(:find_by_id).
         
     | 
| 
       665 
     | 
    
         
            -
                  with(notification_rule.id, :redis => redis).and_return(notification_rule)
         
     | 
| 
      
 665 
     | 
    
         
            +
                  with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
         
     | 
| 
       666 
666 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       667 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 667 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       668 
668 
     | 
    
         | 
| 
       669 
669 
     | 
    
         
             
                put "/notification_rules/#{notification_rule.id}", notification_rule_data.to_json,
         
     | 
| 
       670 
670 
     | 
    
         
             
                  {'CONTENT_TYPE' => 'application/json'}
         
     | 
| 
         @@ -675,10 +675,10 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       675 
675 
     | 
    
         
             
              it "deletes a notification rule" do
         
     | 
| 
       676 
676 
     | 
    
         
             
                notification_rule.should_receive(:contact_id).and_return(contact.id)
         
     | 
| 
       677 
677 
     | 
    
         
             
                Flapjack::Data::NotificationRule.should_receive(:find_by_id).
         
     | 
| 
       678 
     | 
    
         
            -
                  with(notification_rule.id, :redis => redis).and_return(notification_rule)
         
     | 
| 
      
 678 
     | 
    
         
            +
                  with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
         
     | 
| 
       679 
679 
     | 
    
         
             
                contact.should_receive(:delete_notification_rule).with(notification_rule)
         
     | 
| 
       680 
680 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       681 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 681 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       682 
682 
     | 
    
         | 
| 
       683 
683 
     | 
    
         
             
                delete "/notification_rules/#{notification_rule.id}"
         
     | 
| 
       684 
684 
     | 
    
         
             
                last_response.status.should == 204
         
     | 
| 
         @@ -686,7 +686,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       686 
686 
     | 
    
         | 
| 
       687 
687 
     | 
    
         
             
              it "does not delete a notification rule that's not present" do
         
     | 
| 
       688 
688 
     | 
    
         
             
                Flapjack::Data::NotificationRule.should_receive(:find_by_id).
         
     | 
| 
       689 
     | 
    
         
            -
                  with(notification_rule.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 689 
     | 
    
         
            +
                  with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       690 
690 
     | 
    
         | 
| 
       691 
691 
     | 
    
         
             
                delete "/notification_rules/#{notification_rule.id}"
         
     | 
| 
       692 
692 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -695,9 +695,9 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       695 
695 
     | 
    
         
             
              it "does not delete a notification rule if the contact is not present" do
         
     | 
| 
       696 
696 
     | 
    
         
             
                notification_rule.should_receive(:contact_id).and_return(contact.id)
         
     | 
| 
       697 
697 
     | 
    
         
             
                Flapjack::Data::NotificationRule.should_receive(:find_by_id).
         
     | 
| 
       698 
     | 
    
         
            -
                  with(notification_rule.id, :redis => redis).and_return(notification_rule)
         
     | 
| 
      
 698 
     | 
    
         
            +
                  with(notification_rule.id, {:redis => redis, :logger => @logger}).and_return(notification_rule)
         
     | 
| 
       699 
699 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       700 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 700 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       701 
701 
     | 
    
         | 
| 
       702 
702 
     | 
    
         
             
                delete "/notification_rules/#{notification_rule.id}"
         
     | 
| 
       703 
703 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -708,7 +708,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       708 
708 
     | 
    
         
             
                contact.should_receive(:media).and_return(media)
         
     | 
| 
       709 
709 
     | 
    
         
             
                contact.should_receive(:media_intervals).and_return(media_intervals)
         
     | 
| 
       710 
710 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       711 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 711 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       712 
712 
     | 
    
         
             
                result = Hash[ *(media.keys.collect {|m|
         
     | 
| 
       713 
713 
     | 
    
         
             
                  [m, {'address'  => media[m],
         
     | 
| 
       714 
714 
     | 
    
         
             
                       'interval' => media_intervals[m] }]
         
     | 
| 
         @@ -721,7 +721,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       721 
721 
     | 
    
         | 
| 
       722 
722 
     | 
    
         
             
              it "does not return the media of a contact if the contact is not present" do
         
     | 
| 
       723 
723 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       724 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 724 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       725 
725 
     | 
    
         | 
| 
       726 
726 
     | 
    
         
             
                get "/contacts/#{contact.id}/media"
         
     | 
| 
       727 
727 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -732,7 +732,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       732 
732 
     | 
    
         
             
                contact.should_receive(:media).twice.and_return(media)
         
     | 
| 
       733 
733 
     | 
    
         
             
                contact.should_receive(:media_intervals).and_return(media_intervals)
         
     | 
| 
       734 
734 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       735 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 735 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       736 
736 
     | 
    
         | 
| 
       737 
737 
     | 
    
         
             
                result = {'address' => media['sms'], 'interval' => media_intervals['sms']}
         
     | 
| 
       738 
738 
     | 
    
         | 
| 
         @@ -743,7 +743,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       743 
743 
     | 
    
         | 
| 
       744 
744 
     | 
    
         
             
              it "does not return the media of a contact if the contact is not present" do
         
     | 
| 
       745 
745 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       746 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 746 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       747 
747 
     | 
    
         | 
| 
       748 
748 
     | 
    
         
             
                get "/contacts/#{contact.id}/media/sms"
         
     | 
| 
       749 
749 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -752,7 +752,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       752 
752 
     | 
    
         
             
              it "does not return the media of a contact if the media is not present" do
         
     | 
| 
       753 
753 
     | 
    
         
             
                contact.should_receive(:media).and_return(media)
         
     | 
| 
       754 
754 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       755 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 755 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       756 
756 
     | 
    
         | 
| 
       757 
757 
     | 
    
         
             
                get "/contacts/#{contact.id}/media/telepathy"
         
     | 
| 
       758 
758 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -770,7 +770,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       770 
770 
     | 
    
         
             
                contact.should_receive(:media).and_return(alt_media)
         
     | 
| 
       771 
771 
     | 
    
         
             
                contact.should_receive(:media_intervals).and_return(alt_media_intervals)
         
     | 
| 
       772 
772 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       773 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 773 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       774 
774 
     | 
    
         | 
| 
       775 
775 
     | 
    
         
             
                result = {'address' => alt_media['sms'], 'interval' => alt_media_intervals['sms']}
         
     | 
| 
       776 
776 
     | 
    
         | 
| 
         @@ -781,7 +781,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       781 
781 
     | 
    
         | 
| 
       782 
782 
     | 
    
         
             
              it "does not create a media of a contact that's not present" do
         
     | 
| 
       783 
783 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       784 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 784 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       785 
785 
     | 
    
         | 
| 
       786 
786 
     | 
    
         
             
                put "/contacts/#{contact.id}/media/sms", {:address => '04987654321', :interval => '200'}
         
     | 
| 
       787 
787 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -789,7 +789,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       789 
789 
     | 
    
         | 
| 
       790 
790 
     | 
    
         
             
              it "does not create a media of a contact if no address is provided" do
         
     | 
| 
       791 
791 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       792 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 792 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       793 
793 
     | 
    
         | 
| 
       794 
794 
     | 
    
         
             
                put "/contacts/#{contact.id}/media/sms", {:interval => '200'}
         
     | 
| 
       795 
795 
     | 
    
         
             
                last_response.should be_forbidden
         
     | 
| 
         @@ -797,7 +797,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       797 
797 
     | 
    
         | 
| 
       798 
798 
     | 
    
         
             
              it "does not create a media of a contact if no interval is provided" do
         
     | 
| 
       799 
799 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       800 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 800 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       801 
801 
     | 
    
         | 
| 
       802 
802 
     | 
    
         
             
                put "/contacts/#{contact.id}/media/sms", {:address => '04987654321'}
         
     | 
| 
       803 
803 
     | 
    
         
             
                last_response.should be_forbidden
         
     | 
| 
         @@ -806,7 +806,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       806 
806 
     | 
    
         
             
              it "deletes a media of a contact" do
         
     | 
| 
       807 
807 
     | 
    
         
             
                contact.should_receive(:remove_media).with('sms')
         
     | 
| 
       808 
808 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       809 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 809 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       810 
810 
     | 
    
         | 
| 
       811 
811 
     | 
    
         
             
                delete "/contacts/#{contact.id}/media/sms"
         
     | 
| 
       812 
812 
     | 
    
         
             
                last_response.status.should == 204
         
     | 
| 
         @@ -814,7 +814,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       814 
814 
     | 
    
         | 
| 
       815 
815 
     | 
    
         
             
              it "does not delete a media of a contact that's not present" do
         
     | 
| 
       816 
816 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       817 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 817 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       818 
818 
     | 
    
         | 
| 
       819 
819 
     | 
    
         
             
                delete "/contacts/#{contact.id}/media/sms"
         
     | 
| 
       820 
820 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -824,7 +824,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       824 
824 
     | 
    
         
             
              it "returns the timezone of a contact" do
         
     | 
| 
       825 
825 
     | 
    
         
             
                contact.should_receive(:timezone).and_return(::ActiveSupport::TimeZone.new('Australia/Sydney'))
         
     | 
| 
       826 
826 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       827 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 827 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       828 
828 
     | 
    
         | 
| 
       829 
829 
     | 
    
         
             
                get "/contacts/#{contact.id}/timezone"
         
     | 
| 
       830 
830 
     | 
    
         
             
                last_response.should be_ok
         
     | 
| 
         @@ -833,7 +833,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       833 
833 
     | 
    
         | 
| 
       834 
834 
     | 
    
         
             
              it "doesn't get the timezone of a contact that doesn't exist" do
         
     | 
| 
       835 
835 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       836 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 836 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       837 
837 
     | 
    
         | 
| 
       838 
838 
     | 
    
         
             
                get "/contacts/#{contact.id}/timezone"
         
     | 
| 
       839 
839 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -844,7 +844,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       844 
844 
     | 
    
         
             
                contact.should_receive(:timezone=).with('Australia/Perth')
         
     | 
| 
       845 
845 
     | 
    
         
             
                contact.should_receive(:timezone).and_return(ActiveSupport::TimeZone.new('Australia/Perth'))
         
     | 
| 
       846 
846 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       847 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 847 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       848 
848 
     | 
    
         | 
| 
       849 
849 
     | 
    
         
             
                put "/contacts/#{contact.id}/timezone", {:timezone => 'Australia/Perth'}
         
     | 
| 
       850 
850 
     | 
    
         
             
                last_response.should be_ok
         
     | 
| 
         @@ -852,7 +852,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       852 
852 
     | 
    
         | 
| 
       853 
853 
     | 
    
         
             
              it "doesn't set the timezone of a contact who can't be found" do
         
     | 
| 
       854 
854 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       855 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 855 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       856 
856 
     | 
    
         | 
| 
       857 
857 
     | 
    
         
             
                put "/contacts/#{contact.id}/timezone", {:timezone => 'Australia/Perth'}
         
     | 
| 
       858 
858 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -862,7 +862,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       862 
862 
     | 
    
         
             
              it "deletes the timezone of a contact" do
         
     | 
| 
       863 
863 
     | 
    
         
             
                contact.should_receive(:timezone=).with(nil)
         
     | 
| 
       864 
864 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       865 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 865 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       866 
866 
     | 
    
         | 
| 
       867 
867 
     | 
    
         
             
                delete "/contacts/#{contact.id}/timezone"
         
     | 
| 
       868 
868 
     | 
    
         
             
                last_response.status.should == 204
         
     | 
| 
         @@ -870,7 +870,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       870 
870 
     | 
    
         | 
| 
       871 
871 
     | 
    
         
             
              it "does not delete the timezone of a contact that's not present" do
         
     | 
| 
       872 
872 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       873 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 873 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       874 
874 
     | 
    
         | 
| 
       875 
875 
     | 
    
         
             
                delete "/contacts/#{contact.id}/timezone"
         
     | 
| 
       876 
876 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -974,7 +974,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       974 
974 
     | 
    
         
             
                contact.should_receive(:add_tags).with('web')
         
     | 
| 
       975 
975 
     | 
    
         
             
                contact.should_receive(:tags).and_return(['web'])
         
     | 
| 
       976 
976 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       977 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 977 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       978 
978 
     | 
    
         | 
| 
       979 
979 
     | 
    
         
             
                post "contacts/#{contact.id}/tags", :tag => 'web'
         
     | 
| 
       980 
980 
     | 
    
         
             
                last_response.should be_ok
         
     | 
| 
         @@ -983,7 +983,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       983 
983 
     | 
    
         | 
| 
       984 
984 
     | 
    
         
             
              it "does not set a single tag on a contact that's not found" do
         
     | 
| 
       985 
985 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       986 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 986 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       987 
987 
     | 
    
         | 
| 
       988 
988 
     | 
    
         
             
                post "contacts/#{contact.id}/tags", :tag => 'web'
         
     | 
| 
       989 
989 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -993,7 +993,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       993 
993 
     | 
    
         
             
                contact.should_receive(:add_tags).with('web', 'app')
         
     | 
| 
       994 
994 
     | 
    
         
             
                contact.should_receive(:tags).and_return(['web', 'app'])
         
     | 
| 
       995 
995 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       996 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 996 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       997 
997 
     | 
    
         | 
| 
       998 
998 
     | 
    
         
             
                post "contacts/#{contact.id}/tags", :tag => ['web', 'app']
         
     | 
| 
       999 
999 
     | 
    
         
             
                last_response.should be_ok
         
     | 
| 
         @@ -1002,7 +1002,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       1002 
1002 
     | 
    
         | 
| 
       1003 
1003 
     | 
    
         
             
              it "does not set multiple tags on a contact that's not found" do
         
     | 
| 
       1004 
1004 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       1005 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 1005 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       1006 
1006 
     | 
    
         | 
| 
       1007 
1007 
     | 
    
         
             
                post "contacts/#{contact.id}/tags", :tag => ['web', 'app']
         
     | 
| 
       1008 
1008 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -1011,7 +1011,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       1011 
1011 
     | 
    
         
             
              it "removes a single tag from a contact" do
         
     | 
| 
       1012 
1012 
     | 
    
         
             
                contact.should_receive(:delete_tags).with('web')
         
     | 
| 
       1013 
1013 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       1014 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 1014 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       1015 
1015 
     | 
    
         | 
| 
       1016 
1016 
     | 
    
         
             
                delete "contacts/#{contact.id}/tags", :tag => 'web'
         
     | 
| 
       1017 
1017 
     | 
    
         
             
                last_response.status.should == 204
         
     | 
| 
         @@ -1019,7 +1019,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       1019 
1019 
     | 
    
         | 
| 
       1020 
1020 
     | 
    
         
             
              it "does not remove a single tag from a contact that's not found" do
         
     | 
| 
       1021 
1021 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       1022 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 1022 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       1023 
1023 
     | 
    
         | 
| 
       1024 
1024 
     | 
    
         
             
                delete "contacts/#{contact.id}/tags", :tag => 'web'
         
     | 
| 
       1025 
1025 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -1028,7 +1028,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       1028 
1028 
     | 
    
         
             
              it "removes multiple tags from a contact" do
         
     | 
| 
       1029 
1029 
     | 
    
         
             
                contact.should_receive(:delete_tags).with('web', 'app')
         
     | 
| 
       1030 
1030 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       1031 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 1031 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       1032 
1032 
     | 
    
         | 
| 
       1033 
1033 
     | 
    
         
             
                delete "contacts/#{contact.id}/tags", :tag => ['web', 'app']
         
     | 
| 
       1034 
1034 
     | 
    
         
             
                last_response.status.should == 204
         
     | 
| 
         @@ -1036,7 +1036,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       1036 
1036 
     | 
    
         | 
| 
       1037 
1037 
     | 
    
         
             
              it "does not remove multiple tags from a contact that's not found" do
         
     | 
| 
       1038 
1038 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       1039 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 1039 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       1040 
1040 
     | 
    
         | 
| 
       1041 
1041 
     | 
    
         
             
                delete "contacts/#{contact.id}/tags", :tag => ['web', 'app']
         
     | 
| 
       1042 
1042 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -1045,7 +1045,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       1045 
1045 
     | 
    
         
             
              it "gets all tags on a contact" do
         
     | 
| 
       1046 
1046 
     | 
    
         
             
                contact.should_receive(:tags).and_return(['web', 'app'])
         
     | 
| 
       1047 
1047 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       1048 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 1048 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       1049 
1049 
     | 
    
         | 
| 
       1050 
1050 
     | 
    
         
             
                get "contacts/#{contact.id}/tags"
         
     | 
| 
       1051 
1051 
     | 
    
         
             
                last_response.should be_ok
         
     | 
| 
         @@ -1054,7 +1054,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       1054 
1054 
     | 
    
         | 
| 
       1055 
1055 
     | 
    
         
             
              it "does not get all tags on a contact that's not found" do
         
     | 
| 
       1056 
1056 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       1057 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 1057 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       1058 
1058 
     | 
    
         | 
| 
       1059 
1059 
     | 
    
         
             
                get "contacts/#{contact.id}/tags"
         
     | 
| 
       1060 
1060 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -1071,7 +1071,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       1071 
1071 
     | 
    
         
             
                  and_return(tag_data)
         
     | 
| 
       1072 
1072 
     | 
    
         | 
| 
       1073 
1073 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       1074 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 1074 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       1075 
1075 
     | 
    
         | 
| 
       1076 
1076 
     | 
    
         
             
                get "contacts/#{contact.id}/entity_tags"
         
     | 
| 
       1077 
1077 
     | 
    
         
             
                last_response.should be_ok
         
     | 
| 
         @@ -1082,7 +1082,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       1082 
1082 
     | 
    
         | 
| 
       1083 
1083 
     | 
    
         
             
              it "does not get all entity tags for a contact that's not found" do
         
     | 
| 
       1084 
1084 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       1085 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 1085 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       1086 
1086 
     | 
    
         | 
| 
       1087 
1087 
     | 
    
         
             
                get "contacts/#{contact.id}/entity_tags"
         
     | 
| 
       1088 
1088 
     | 
    
         
             
                last_response.should be_not_found
         
     | 
| 
         @@ -1103,7 +1103,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       1103 
1103 
     | 
    
         
             
                contact.should_receive(:entities).with(:tags => true).and_return(tag_data)
         
     | 
| 
       1104 
1104 
     | 
    
         | 
| 
       1105 
1105 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       1106 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 1106 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       1107 
1107 
     | 
    
         | 
| 
       1108 
1108 
     | 
    
         
             
                post "contacts/#{contact.id}/entity_tags",
         
     | 
| 
       1109 
1109 
     | 
    
         
             
                  :entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
         
     | 
| 
         @@ -1115,7 +1115,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       1115 
1115 
     | 
    
         | 
| 
       1116 
1116 
     | 
    
         
             
              it "does not add tags to multiple entities for a contact that's not found" do
         
     | 
| 
       1117 
1117 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       1118 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 1118 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       1119 
1119 
     | 
    
         | 
| 
       1120 
1120 
     | 
    
         
             
                post "contacts/#{contact.id}/entity_tags",
         
     | 
| 
       1121 
1121 
     | 
    
         
             
                  :entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
         
     | 
| 
         @@ -1134,7 +1134,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       1134 
1134 
     | 
    
         
             
                contact.should_receive(:entities).and_return(entities)
         
     | 
| 
       1135 
1135 
     | 
    
         | 
| 
       1136 
1136 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       1137 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(contact)
         
     | 
| 
      
 1137 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(contact)
         
     | 
| 
       1138 
1138 
     | 
    
         | 
| 
       1139 
1139 
     | 
    
         
             
                delete "contacts/#{contact.id}/entity_tags",
         
     | 
| 
       1140 
1140 
     | 
    
         
             
                  :entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
         
     | 
| 
         @@ -1143,7 +1143,7 @@ describe 'Flapjack::Gateways::API', :sinatra => true, :logger => true, :json => 
     | 
|
| 
       1143 
1143 
     | 
    
         | 
| 
       1144 
1144 
     | 
    
         
             
              it "does not delete tags from multiple entities for a contact that's not found" do
         
     | 
| 
       1145 
1145 
     | 
    
         
             
                Flapjack::Data::Contact.should_receive(:find_by_id).
         
     | 
| 
       1146 
     | 
    
         
            -
                  with(contact.id, :redis => redis).and_return(nil)
         
     | 
| 
      
 1146 
     | 
    
         
            +
                  with(contact.id, {:redis => redis, :logger => @logger}).and_return(nil)
         
     | 
| 
       1147 
1147 
     | 
    
         | 
| 
       1148 
1148 
     | 
    
         
             
                delete "contacts/#{contact.id}/entity_tags",
         
     | 
| 
       1149 
1149 
     | 
    
         
             
                  :entity => {'entity_1' => ['web'], 'entity_2' => ['app']}
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: flapjack
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.7. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.7.7
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -11,7 +11,7 @@ authors: 
     | 
|
| 
       11 
11 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       12 
12 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       13 
13 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       14 
     | 
    
         
            -
            date: 2013-05- 
     | 
| 
      
 14 
     | 
    
         
            +
            date: 2013-05-22 00:00:00.000000000 Z
         
     | 
| 
       15 
15 
     | 
    
         
             
            dependencies:
         
     | 
| 
       16 
16 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       17 
17 
     | 
    
         
             
              name: dante
         
     | 
| 
         @@ -553,7 +553,7 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       553 
553 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       554 
554 
     | 
    
         
             
                  segments:
         
     | 
| 
       555 
555 
     | 
    
         
             
                  - 0
         
     | 
| 
       556 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 556 
     | 
    
         
            +
                  hash: 4574905656823869764
         
     | 
| 
       557 
557 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       558 
558 
     | 
    
         
             
              none: false
         
     | 
| 
       559 
559 
     | 
    
         
             
              requirements:
         
     | 
| 
         @@ -562,7 +562,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       562 
562 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       563 
563 
     | 
    
         
             
                  segments:
         
     | 
| 
       564 
564 
     | 
    
         
             
                  - 0
         
     | 
| 
       565 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 565 
     | 
    
         
            +
                  hash: 4574905656823869764
         
     | 
| 
       566 
566 
     | 
    
         
             
            requirements: []
         
     | 
| 
       567 
567 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       568 
568 
     | 
    
         
             
            rubygems_version: 1.8.23
         
     |