Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added the ability to get all of the pull notifications for an app rat…

…her than just the most recent one
  • Loading branch information...
commit 672d0580b4fb96d18c7509364440dce56a566508 1 parent 0ace0be
@PRXci PRXci authored
View
10 lib/apn_on_rails/app/models/apn/pull_notification.rb
@@ -15,4 +15,14 @@ def self.latest_since(app_id, since_date=nil)
end
res
end
+
+ def self.all_since(app_id, since_date=nil)
+ if since_date
+ res = all(:order => "created_at DESC",
+ :conditions => ["app_id = ? AND created_at > ? AND launch_notification = ?", app_id, since_date, false])
+ else
+ res = all(:order => "created_at DESC",
+ :conditions => ["app_id = ? AND launch_notification = ?", app_id, false])
+ end
+ end
end
View
36 spec/apn_on_rails/app/models/apn/pull_notification_spec.rb
@@ -61,4 +61,40 @@
end
end
+ describe 'all_since_date_with_date_given' do
+ it 'should return all the non-launch notifications after the given date but not the ones before it' do
+ APN::PullNotification.all.each { |n| n.destroy }
+ app = APN::App.first
+ noty_launch = PullNotificationFactory.create({:app_id => app.id, :launch_notification => true})
+ noty_launch.created_at = Time.now - 2.weeks
+ noty_launch.save
+ old_noty = PullNotificationFactory.create({:app_id => app.id})
+ old_noty.created_at = Time.now - 2.weeks
+ old_noty.save
+ new_noty_one = PullNotificationFactory.create({:app_id => app.id})
+ new_noty_one.created_at = Time.now - 1.day
+ new_noty_one.save
+ new_noty_two = PullNotificationFactory.create({:app_id => app.id})
+ APN::PullNotification.all_since(app.id, Time.now - 1.week).should == [new_noty_two,new_noty_one]
+ end
+ end
+
+ describe 'all_since_with_no_since_date_given' do
+ it 'should return all of the non-launch notifications' do
+ APN::PullNotification.all.each { |n| n.destroy }
+ app = APN::App.first
+ noty_launch = PullNotificationFactory.create({:app_id => app.id, :launch_notification => true})
+ noty_launch.created_at = Time.now - 2.weeks
+ noty_launch.save
+ old_noty = PullNotificationFactory.create({:app_id => app.id})
+ old_noty.created_at = Time.now - 2.weeks
+ old_noty.save
+ new_noty_one = PullNotificationFactory.create({:app_id => app.id})
+ new_noty_one.created_at = Time.now - 1.day
+ new_noty_one.save
+ new_noty_two = PullNotificationFactory.create({:app_id => app.id})
+ APN::PullNotification.all_since(app.id, Time.now - 3.weeks).should == [new_noty_two,new_noty_one,old_noty]
+ end
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.