Skip to content

Commit

Permalink
added the ability to get all of the pull notifications for an app rat…
Browse files Browse the repository at this point in the history
…her than just the most recent one
  • Loading branch information
PRXci committed Nov 15, 2010
1 parent 0ace0be commit 672d058
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/apn_on_rails/app/models/apn/pull_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 36 additions & 0 deletions spec/apn_on_rails/app/models/apn/pull_notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 672d058

Please sign in to comment.